contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
listlengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
listlengths 0
7
| demo-output
listlengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
255
|
A
|
Greg's Workout
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
|
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
|
[
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] |
[
"biceps\n",
"back\n",
"chest\n"
] |
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
| 500
|
[
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 1,656,175,915
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 61
| 92
| 4,505,600
|
i=int(input())
l=list(map(int,input().split()))
x,y,z=0,0,0
for n in range(i):
if n%3==0:x+=l[n]
elif n%3==1:y+=l[n]
else:z+=l[n]
if x>y and x>z:print("chest")
elif y>x and y>z:print("biceps")
elif z>x and z>y:print("back")
|
Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Output Specification:
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Demo Input:
['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n']
Demo Output:
['biceps\n', 'back\n', 'chest\n']
Note:
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
|
```python
i=int(input())
l=list(map(int,input().split()))
x,y,z=0,0,0
for n in range(i):
if n%3==0:x+=l[n]
elif n%3==1:y+=l[n]
else:z+=l[n]
if x>y and x>z:print("chest")
elif y>x and y>z:print("biceps")
elif z>x and z>y:print("back")
```
| 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,667,893,660
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 5
| 124
| 0
|
s,l,num,flag=input(),0,1,0
lef,rig=0,0
d,length=[],0
for i in s:
if not flag:#不处于配对状态
if i == '(':#进入配对
lef+=1
flag=1
else:#当前处于配对状态
if i=="(":
lef+=1
else:
rig+=1
if rig>lef:
flag=0#退出配对状态
length=lef*2
d.append(length)
lef,rig=0,0
if flag==1:#最后仍在配对的状态:
length=min(lef,rig)*2
d.append(length)
for j in d:#输出答案
if j>l:
l=j
num=1
elif j==l and j!=0:
num+=1
print(l,num)
|
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,l,num,flag=input(),0,1,0
lef,rig=0,0
d,length=[],0
for i in s:
if not flag:#不处于配对状态
if i == '(':#进入配对
lef+=1
flag=1
else:#当前处于配对状态
if i=="(":
lef+=1
else:
rig+=1
if rig>lef:
flag=0#退出配对状态
length=lef*2
d.append(length)
lef,rig=0,0
if flag==1:#最后仍在配对的状态:
length=min(lef,rig)*2
d.append(length)
for j in d:#输出答案
if j>l:
l=j
num=1
elif j==l and j!=0:
num+=1
print(l,num)
```
| 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,694,794,278
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 48
| 62
| 0
|
s = [int(i) for i in input().split()]
m = max(s)
mn = min(s)
count = 0
for i in s:
if mn < i < m:
count += (i - mn) + (m - i)
print(count)
|
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
s = [int(i) for i in input().split()]
m = max(s)
mn = min(s)
count = 0
for i in s:
if mn < i < m:
count += (i - mn) + (m - i)
print(count)
```
| 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,497,919,543
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 81
| 154
| 0
|
n = int(input())
flag = 0
y1 = 0
y2 = 0
y3 = 0
for i in range(n):
x1, x2, x3 = map(int, input().split())
y1 += x1
y2 += x2
y3 += x3
print("YES" if y1 == 0 and y2 == 0 and y3 == 0 else "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())
flag = 0
y1 = 0
y2 = 0
y3 = 0
for i in range(n):
x1, x2, x3 = map(int, input().split())
y1 += x1
y2 += x2
y3 += x3
print("YES" if y1 == 0 and y2 == 0 and y3 == 0 else "NO")
```
| 3.9615
|
934
|
A
|
A Compatible Pair
|
PROGRAMMING
| 1,400
|
[
"brute force",
"games"
] | null | null |
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
|
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
|
Print a single integer — the brightness of the chosen pair.
|
[
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] |
[
"252\n",
"2\n"
] |
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
| 500
|
[
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6",
"output": "100"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611",
"output": "127184126241438168"
},
{
"input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974",
"output": "922371547895579571"
},
{
"input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410",
"output": "663200522440413120"
},
{
"input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682",
"output": "883931400924882950"
},
{
"input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106",
"output": "910849554065102112"
},
{
"input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544",
"output": "504117593849498724"
},
{
"input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617",
"output": "534123411186652380"
},
{
"input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478",
"output": "848714444125692276"
},
{
"input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867",
"output": "866064226130454915"
},
{
"input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081",
"output": "501307028237810934"
},
{
"input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625",
"output": "822104826327386019"
},
{
"input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542",
"output": "941783658451562540"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604",
"output": "-1288212069119760"
},
{
"input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017",
"output": "-18990884587723"
},
{
"input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528",
"output": "-1464096896176096"
},
{
"input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396",
"output": "-120782803247464704"
},
{
"input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983",
"output": "-640647347631440"
},
{
"input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-1000000000000000000"
}
] | 1,602,844,158
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 9
| 93
| 307,200
|
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
minia=min(a)
minib=min(b)
maxia=max(a)
maxib=max(b)
if True:
if minia*minib>maxib*maxia:
a.remove(minia)
print(max(min(a)*minib,maxia,maxib))
else:
a.remove(maxia)
print(max(max(a)*maxib,minib*minia))
|
Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input Specification:
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
Output Specification:
Print a single integer — the brightness of the chosen pair.
Demo Input:
['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n']
Demo Output:
['252\n', '2\n']
Note:
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
|
```python
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
minia=min(a)
minib=min(b)
maxia=max(a)
maxib=max(b)
if True:
if minia*minib>maxib*maxia:
a.remove(minia)
print(max(min(a)*minib,maxia,maxib))
else:
a.remove(maxia)
print(max(max(a)*maxib,minib*minia))
```
| 0
|
|
299
|
B
|
Ksusha the Squirrel
|
PROGRAMMING
| 900
|
[
"brute force",
"implementation"
] | null | null |
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
|
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
|
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
|
[
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] |
[
"YES\n",
"YES\n",
"NO\n"
] |
none
| 1,000
|
[
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 1,584,545,401
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 33
| 310
| 1,945,600
|
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#--------------------------------WhiteHat010--------------------------------------#
n,k = get_int_list()
s = get_string()
if '#'*k in s:
print("NO")
else:
print("YES")
|
Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
Output Specification:
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
Demo Input:
['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none
|
```python
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#--------------------------------WhiteHat010--------------------------------------#
n,k = get_int_list()
s = get_string()
if '#'*k in s:
print("NO")
else:
print("YES")
```
| 3
|
|
60
|
B
|
Serial Time!
|
PROGRAMMING
| 1,400
|
[
"dfs and similar",
"dsu"
] |
B. Serial Time!
|
2
|
256
|
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.
Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes.
|
The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*.
|
The answer should contain a single number, showing in how many minutes the plate will be filled.
|
[
"1 1 1\n\n.\n\n1 1\n",
"2 1 1\n\n.\n\n#\n\n1 1\n",
"2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n",
"3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n",
"3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n"
] |
[
"1\n",
"1\n",
"5\n",
"7\n",
"13\n"
] |
none
| 1,000
|
[
{
"input": "1 1 1\n\n.\n\n1 1",
"output": "1"
},
{
"input": "2 1 1\n\n.\n\n#\n\n1 1",
"output": "1"
},
{
"input": "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1",
"output": "5"
},
{
"input": "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2",
"output": "7"
},
{
"input": "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1",
"output": "13"
},
{
"input": "2 2 2\n\n#.\n..\n\n.#\n#.\n\n2 1",
"output": "4"
},
{
"input": "4 7 8\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\n3 4",
"output": "224"
},
{
"input": "6 5 4\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\n5 1",
"output": "1"
},
{
"input": "8 2 6\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\n1 2",
"output": "52"
},
{
"input": "9 1 9\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n#####.###\n\n.........\n\n1 6",
"output": "49"
},
{
"input": "6 8 4\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#.##\n....\n#.##\n..##\n.##.\n\n6 4",
"output": "88"
},
{
"input": "8 1 8\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n........\n\n1 3",
"output": "64"
},
{
"input": "1 8 6\n\n######\n######\n.#####\n######\n######\n######\n######\n######\n\n3 1",
"output": "1"
},
{
"input": "6 1 9\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n##.######\n\n.........\n\n1 3",
"output": "30"
},
{
"input": "1 1 10\n\n..........\n\n1 6",
"output": "10"
},
{
"input": "5 2 8\n\n.##..#..\n.#.....#\n\n....##..\n#..###.#\n\n#..#.#..\n.#..#...\n\n###.#..#\n#......#\n\n#..#####\n##.....#\n\n1 7",
"output": "45"
},
{
"input": "9 2 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\n1 1",
"output": "18"
},
{
"input": "5 8 2\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\n4 2",
"output": "1"
},
{
"input": "6 10 2\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##\n##\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n2 2",
"output": "63"
},
{
"input": "8 6 2\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\n##\n##\n.#\n##\n##\n##\n\n3 1",
"output": "52"
},
{
"input": "4 1 3\n\n...\n\n...\n\n...\n\n...\n\n1 1",
"output": "12"
},
{
"input": "4 6 2\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\n5 1",
"output": "1"
},
{
"input": "2 9 2\n\n##\n##\n##\n##\n.#\n##\n##\n##\n##\n\n..\n..\n..\n..\n..\n..\n..\n..\n..\n\n5 1",
"output": "19"
},
{
"input": "10 6 5\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\n#####\n###.#\n#####\n#####\n#####\n#####\n\n.....\n.....\n.....\n.....\n.....\n.....\n\n#####\n###.#\n#####\n#####\n#####\n#####\n\n2 4",
"output": "155"
},
{
"input": "2 3 6\n\n......\n#..#..\n##.#.#\n\n#.##..\n.....#\n##..##\n\n1 3",
"output": "22"
},
{
"input": "8 5 6\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\n4 4",
"output": "1"
},
{
"input": "1 3 10\n\n##########\n####.#####\n##########\n\n2 5",
"output": "1"
},
{
"input": "8 3 3\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\n3 3",
"output": "40"
},
{
"input": "5 1 4\n\n#...\n\n####\n\n#.##\n\n.###\n\n###.\n\n1 4",
"output": "3"
},
{
"input": "9 2 2\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\n2 1",
"output": "2"
},
{
"input": "1 6 2\n\n##\n..\n##\n.#\n##\n#.\n\n6 2",
"output": "1"
},
{
"input": "5 9 2\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##\n\n4 2",
"output": "1"
},
{
"input": "5 8 7\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\n4 7",
"output": "132"
},
{
"input": "4 3 2\n\n#.\n#.\n##\n\n.#\n.#\n##\n\n..\n#.\n##\n\n#.\n..\n.#\n\n1 2",
"output": "2"
},
{
"input": "4 10 10\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\n8 1",
"output": "400"
},
{
"input": "4 10 10\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\n7 10",
"output": "1"
},
{
"input": "3 10 10\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\n1 8",
"output": "102"
},
{
"input": "2 10 10\n\n#..#...#..\n###..#..##\n..#..#..#.\n#..#.#...#\n#####...#.\n#.####..#.\n###..##.##\n.###..#...\n##..##.##.\n..#.#.####\n\n..##..#.#.\n.##....#..\n..#.#.##..\n#.####....\n##..##.#..\n######...#\n..#...###.\n####.###.#\n#...##.#..\n##.#####.#\n\n6 7",
"output": "57"
}
] | 1,486,334,003
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 46
| 156
| 5,120,000
|
from collections import deque
def solve():
k, n, m = map(int, input().rstrip().split())
plate = []
for a in range(k):
plate.append([])
for b in range(n):
plate[a].append([])
for a in range(k):
input()
for b in range(n):
for char in input().rstrip():
plate[a][b].append(char)
input()
x, y = map(int, input().rstrip().split())
q = deque()
q.append((0, x-1, y-1))
seen = set()
while len(q) > 0:
x, y, z = q.popleft()
if (x, y, z) not in seen:
if 0 <= x < k:
if 0 <= y < n:
if 0 <= z < m:
if plate[x][y][z] == '.':
seen.add((x, y, z))
for d in [-1, 1]:
q.append((x+d, y, z))
q.append((x, y+d, z))
q.append((x, y, z+d))
print(len(seen))
if __name__ == "__main__":
solve()
|
Title: Serial Time!
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped *k*<=×<=*n*<=×<=*m*, that is, it has *k* layers (the first layer is the upper one), each of which is a rectangle *n*<=×<=*m* with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (*x*,<=*y*) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.
Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1<=×<=1<=×<=1 cubes.
Input Specification:
The first line contains three numbers *k*, *n*, *m* (1<=≤<=*k*,<=*n*,<=*m*<=≤<=10) which are the sizes of the plate. Then follow *k* rectangles consisting of *n* lines each containing *m* characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) which are the tap's coordinates. *x* is the number of the line and *y* is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to *n*, columns of each layer are numbered from top to bottom by the integers from 1 to *m*.
Output Specification:
The answer should contain a single number, showing in how many minutes the plate will be filled.
Demo Input:
['1 1 1\n\n.\n\n1 1\n', '2 1 1\n\n.\n\n#\n\n1 1\n', '2 2 2\n\n.#\n##\n\n..\n..\n\n1 1\n', '3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2\n', '3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1\n']
Demo Output:
['1\n', '1\n', '5\n', '7\n', '13\n']
Note:
none
|
```python
from collections import deque
def solve():
k, n, m = map(int, input().rstrip().split())
plate = []
for a in range(k):
plate.append([])
for b in range(n):
plate[a].append([])
for a in range(k):
input()
for b in range(n):
for char in input().rstrip():
plate[a][b].append(char)
input()
x, y = map(int, input().rstrip().split())
q = deque()
q.append((0, x-1, y-1))
seen = set()
while len(q) > 0:
x, y, z = q.popleft()
if (x, y, z) not in seen:
if 0 <= x < k:
if 0 <= y < n:
if 0 <= z < m:
if plate[x][y][z] == '.':
seen.add((x, y, z))
for d in [-1, 1]:
q.append((x+d, y, z))
q.append((x, y+d, z))
q.append((x, y, z+d))
print(len(seen))
if __name__ == "__main__":
solve()
```
| 3.951463
|
765
|
A
|
Neverending competitions
|
PROGRAMMING
| 900
|
[
"implementation",
"math"
] | null | null |
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location!
|
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
|
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
|
[
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] |
[
"home\n",
"contest\n"
] |
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
| 500
|
[
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
{
"input": "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ",
"output": "contest"
},
{
"input": "10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\nPVO->DMN\nDMN->PVO",
"output": "home"
},
{
"input": "11\nIAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU",
"output": "contest"
},
{
"input": "10\nHPN\nDFI->HPN\nHPN->KAB\nHPN->DFI\nVSO->HPN\nHPN->KZX\nHPN->VSO\nKZX->HPN\nLDW->HPN\nKAB->HPN\nHPN->LDW",
"output": "home"
},
{
"input": "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE->FGH\nFGH->KQK\nFGH->QRE\nKQK->FGH\nFGH->UBK\nBRZ->FGH\nFGH->ALX\nALX->FGH\nFGH->KQK",
"output": "contest"
},
{
"input": "50\nPFH\nJFV->PFH\nBVP->PFH\nPFH->BVP\nPFH->JFV\nPFH->ETQ\nPFH->LQJ\nZTO->PFH\nPFH->BVP\nPFH->RXO\nPFH->ZTO\nHWL->PFH\nPFH->HIV\nPFH->AFP\nPFH->HWL\nOBB->PFH\nHIV->PFH\nPFH->LSR\nAFP->PFH\nLQJ->PFH\nHWL->PFH\nETQ->PFH\nPFH->HWL\nLSR->PFH\nWBR->PFH\nBNZ->PFH\nHQR->PFH\nZTO->PFH\nPFH->WBR\nPFH->BYJ\nRXO->PFH\nFHZ->PFH\nFHZ->PFH\nPFN->PFH\nPFH->GMB\nPFH->JFV\nJFV->PFH\nGNZ->PFH\nPFH->BNZ\nPFH->GNZ\nPFH->HQR\nBYJ->PFH\nGMB->PFH\nPFH->FHZ\nPFH->FHZ\nPFH->ZTO\nPFH->UGD\nBVP->PFH\nUGD->PFH\nPFH->PFN\nPFH->OBB",
"output": "home"
},
{
"input": "1\nAAK\nAAK->ABA",
"output": "contest"
},
{
"input": "1\nXYZ\nXYZ->XYR",
"output": "contest"
}
] | 1,582,309,126
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 23
| 140
| 0
|
n=int(input())
t=input()
gya=[]
aya=[]
for k in range(n):
p=input()
if p[:3]==t:
gya.append(p[-3:])
elif p[-3:]==t:
aya.append(p[:3])
gya.sort()
aya.sort()
if gya==aya:
print('home')
else:
print('contest')
|
Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location!
Input Specification:
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
Output Specification:
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
Demo Input:
['4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n', '3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n']
Demo Output:
['home\n', 'contest\n']
Note:
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
|
```python
n=int(input())
t=input()
gya=[]
aya=[]
for k in range(n):
p=input()
if p[:3]==t:
gya.append(p[-3:])
elif p[-3:]==t:
aya.append(p[:3])
gya.sort()
aya.sort()
if gya==aya:
print('home')
else:
print('contest')
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
|
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
|
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
|
[
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n"
] |
[
"Yes\nYes\nYes\nNo\nNo\nYes\n"
] |
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
| 0
|
[
{
"input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000",
"output": "Yes\nYes\nYes\nNo\nNo\nYes"
},
{
"input": "3\n1 1\n8 27\n1000 1331",
"output": "Yes\nNo\nNo"
},
{
"input": "1\n12004 18012002",
"output": "Yes"
},
{
"input": "1\n3331 11095561",
"output": "Yes"
},
{
"input": "1\n2 3",
"output": "No"
},
{
"input": "1\n1062961 1031",
"output": "Yes"
},
{
"input": "1\n6 12",
"output": "No"
},
{
"input": "1\n3 1",
"output": "No"
},
{
"input": "1\n3 10",
"output": "No"
},
{
"input": "1\n31159 970883281",
"output": "Yes"
},
{
"input": "1\n9907 98148649",
"output": "Yes"
},
{
"input": "1\n16 8",
"output": "No"
},
{
"input": "1\n90 72",
"output": "No"
}
] | 1,588,776,642
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 950
| 6,963,200
|
import math
def primefact(n):
arr=[]
if n==2 or n==1:
arr.append(n)
else:
for i in range(2,int(math.sqrt(n))+1):
while(n%i==0):
arr.append(i)
n=n//i
return arr
def countfreq(arr):
s=dict()
for i in arr:
s[i]=s.get(i,0)+1
return s
n=int(input())
for j in range(n):
a,b=[int(x) for x in input().split()]
arr1=primefact(a)
arr2=primefact(b)
arr=[]
arr=arr1+arr2
arr=sorted(arr)
hash1={
}
i=0
# while(i<len(arr)-1):
# cnt=1
# j=i
# while(arr[j]==arr[j+1]):
# cnt+=1
# if j<len(arr):
# i+=1
# print(i,len(arr)-1,arr)
# else:
# break
# hash1[arr[i]]=cnt
# for i in range(arr):
# hash1[arr[i]]=arr.count(arr[i])
hash1=countfreq(arr)
cnt=0
for i in hash1.values():
if i%3==0:
cnt+=1
else:
break
if cnt==len(hash1):
print("Yes")
else:
print("No")
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by *k*2, and the loser's score is multiplied by *k*. In the beginning of the game, both Slastyona and Pushok have scores equal to one.
Unfortunately, Slastyona had lost her notepad where the history of all *n* games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.
Input Specification:
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given.
Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
Output Specification:
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise.
You can output each letter in arbitrary case (upper or lower).
Demo Input:
['6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n']
Demo Output:
['Yes\nYes\nYes\nNo\nNo\nYes\n']
Note:
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.
The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
|
```python
import math
def primefact(n):
arr=[]
if n==2 or n==1:
arr.append(n)
else:
for i in range(2,int(math.sqrt(n))+1):
while(n%i==0):
arr.append(i)
n=n//i
return arr
def countfreq(arr):
s=dict()
for i in arr:
s[i]=s.get(i,0)+1
return s
n=int(input())
for j in range(n):
a,b=[int(x) for x in input().split()]
arr1=primefact(a)
arr2=primefact(b)
arr=[]
arr=arr1+arr2
arr=sorted(arr)
hash1={
}
i=0
# while(i<len(arr)-1):
# cnt=1
# j=i
# while(arr[j]==arr[j+1]):
# cnt+=1
# if j<len(arr):
# i+=1
# print(i,len(arr)-1,arr)
# else:
# break
# hash1[arr[i]]=cnt
# for i in range(arr):
# hash1[arr[i]]=arr.count(arr[i])
hash1=countfreq(arr)
cnt=0
for i in hash1.values():
if i%3==0:
cnt+=1
else:
break
if cnt==len(hash1):
print("Yes")
else:
print("No")
```
| 0
|
|
350
|
A
|
TL
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"implementation"
] | null | null |
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
|
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
|
If there is a valid TL value, print it. Otherwise, print -1.
|
[
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] |
[
"5",
"-1\n"
] |
none
| 500
|
[
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50",
"output": "49"
},
{
"input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2",
"output": "-1"
},
{
"input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90",
"output": "46"
},
{
"input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66",
"output": "14"
},
{
"input": "1 1\n4\n9",
"output": "8"
},
{
"input": "1 1\n2\n4",
"output": "-1"
},
{
"input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58",
"output": "-1"
},
{
"input": "1 1\n50\n100",
"output": "-1"
},
{
"input": "1 1\n49\n100",
"output": "98"
},
{
"input": "1 1\n100\n100",
"output": "-1"
},
{
"input": "1 1\n99\n100",
"output": "-1"
},
{
"input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100",
"output": "99"
},
{
"input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2",
"output": "-1"
},
{
"input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75",
"output": "2"
},
{
"input": "3 3\n2 3 4\n8 9 10",
"output": "4"
},
{
"input": "2 1\n2 3\n15",
"output": "4"
},
{
"input": "2 1\n2 4\n4",
"output": "-1"
},
{
"input": "2 3\n4 5\n10 11 12",
"output": "8"
},
{
"input": "3 1\n2 3 3\n5",
"output": "4"
},
{
"input": "2 1\n9 10\n100",
"output": "18"
},
{
"input": "3 3\n3 12 15\n7 8 9",
"output": "-1"
},
{
"input": "2 2\n3 5\n7 8",
"output": "6"
},
{
"input": "3 3\n4 5 6\n10 11 12",
"output": "8"
},
{
"input": "3 5\n2 3 3\n6 6 6 6 2",
"output": "-1"
},
{
"input": "3 6\n4 5 3\n8 9 7 10 7 11",
"output": "6"
},
{
"input": "3 6\n4 5 2\n8 9 6 10 7 4",
"output": "-1"
},
{
"input": "2 1\n4 6\n10",
"output": "8"
},
{
"input": "1 2\n1\n3 1",
"output": "-1"
},
{
"input": "2 1\n5 6\n20",
"output": "10"
},
{
"input": "2 1\n1 5\n5",
"output": "-1"
},
{
"input": "3 2\n10 20 30\n30 40",
"output": "-1"
},
{
"input": "2 2\n5 6\n7 100",
"output": "-1"
},
{
"input": "2 1\n2 5\n7",
"output": "5"
},
{
"input": "1 1\n5\n20",
"output": "10"
},
{
"input": "2 1\n10 11\n100",
"output": "20"
},
{
"input": "1 1\n1\n10",
"output": "2"
},
{
"input": "1 1\n10\n100",
"output": "20"
}
] | 1,594,323,148
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 7
| 216
| 6,963,200
|
n, m = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
ln.sort(reverse=True)
lm.sort()
min = 1000
i=0
for j in range(len(ln)):
if 2 * ln[j] <= ln[i]:
if min > ln[i]:
min = ln[i]
break
if min < lm[0] and min != 1000:
print(min)
else:
print(-1)
|
Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
Input Specification:
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
Output Specification:
If there is a valid TL value, print it. Otherwise, print -1.
Demo Input:
['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n']
Demo Output:
['5', '-1\n']
Note:
none
|
```python
n, m = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))
ln.sort(reverse=True)
lm.sort()
min = 1000
i=0
for j in range(len(ln)):
if 2 * ln[j] <= ln[i]:
if min > ln[i]:
min = ln[i]
break
if min < lm[0] and min != 1000:
print(min)
else:
print(-1)
```
| 0
|
|
266
|
A
|
Stones on the Table
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
|
Print a single integer — the answer to the problem.
|
[
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] |
[
"1\n",
"4\n",
"0\n"
] |
none
| 500
|
[
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "4\nRBBR",
"output": "1"
},
{
"input": "5\nRGGBG",
"output": "1"
},
{
"input": "10\nGGBRBRGGRB",
"output": "2"
},
{
"input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB",
"output": "18"
},
{
"input": "15\nBRRBRGGBBRRRRGR",
"output": "6"
},
{
"input": "20\nRRGBBRBRGRGBBGGRGRRR",
"output": "6"
},
{
"input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB",
"output": "6"
},
{
"input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB",
"output": "9"
},
{
"input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB",
"output": "14"
},
{
"input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG",
"output": "20"
},
{
"input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG",
"output": "11"
},
{
"input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG",
"output": "17"
},
{
"input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB",
"output": "16"
},
{
"input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG",
"output": "19"
},
{
"input": "10\nGRRBRBRBGR",
"output": "1"
},
{
"input": "10\nBRBGBGRRBR",
"output": "1"
},
{
"input": "20\nGBGBGGRRRRGRBBGRGRGR",
"output": "5"
},
{
"input": "20\nRRGGRBBGBBRBGRRBRRBG",
"output": "6"
},
{
"input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB",
"output": "8"
},
{
"input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB",
"output": "11"
},
{
"input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB",
"output": "9"
},
{
"input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG",
"output": "13"
},
{
"input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG",
"output": "13"
},
{
"input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB",
"output": "12"
},
{
"input": "2\nBB",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "49"
},
{
"input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "47"
},
{
"input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR",
"output": "43"
}
] | 1,695,183,450
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 62
| 0
|
n = int(input())
strr = input()
print(len(list(strr)) - len(set(list(strr))))
|
Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n']
Demo Output:
['1\n', '4\n', '0\n']
Note:
none
|
```python
n = int(input())
strr = input()
print(len(list(strr)) - len(set(list(strr))))
```
| 0
|
|
228
|
A
|
Is your horseshoe on the other hoof?
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
|
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
|
Print a single integer — the minimum number of horseshoes Valera needs to buy.
|
[
"1 7 3 3\n",
"7 7 7 7\n"
] |
[
"1\n",
"3\n"
] |
none
| 500
|
[
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 1,687,791,575
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 92
| 0
|
ar = input().split()
ar = [int(x) for x in ar]
ar = list(set(ar))
print(4 - len(ar))
|
Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
Input Specification:
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
Output Specification:
Print a single integer — the minimum number of horseshoes Valera needs to buy.
Demo Input:
['1 7 3 3\n', '7 7 7 7\n']
Demo Output:
['1\n', '3\n']
Note:
none
|
```python
ar = input().split()
ar = [int(x) for x in ar]
ar = list(set(ar))
print(4 - len(ar))
```
| 3
|
|
842
|
B
|
Gleb And Pizza
|
PROGRAMMING
| 1,100
|
[
"geometry"
] | null | null |
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the origin, and crust around the main part of the width *d*. Pieces of sausage are also circles. The radius of the *i* -th piece of the sausage is *r**i*, and the center is given as a pair (*x**i*, *y**i*).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
|
First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<=≤<=*x**i*,<=*y**i*<=≤<=500, 0<=≤<=*r**i*<=≤<=500), where *x**i* and *y**i* are coordinates of the center of *i*-th peace of sausage, *r**i* — radius of *i*-th peace of sausage.
|
Output the number of pieces of sausage that lay on the crust.
|
[
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] |
[
"2\n",
"0\n"
] |
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
| 1,000
|
[
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": "4"
},
{
"input": "9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0",
"output": "0"
},
{
"input": "10 2\n11\n1 1 0\n2 2 3\n3 3 0\n4 4 0\n5 5 0\n6 6 0\n7 7 4\n8 8 7\n9 9 3\n10 10 100\n9 0 1",
"output": "2"
},
{
"input": "5 3\n1\n500 500 10",
"output": "0"
}
] | 1,689,179,955
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
print("_RANDOM_GUESS_1689179955.3691452")# 1689179955.369163
|
Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the origin, and crust around the main part of the width *d*. Pieces of sausage are also circles. The radius of the *i* -th piece of the sausage is *r**i*, and the center is given as a pair (*x**i*, *y**i*).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input Specification:
First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<=≤<=*x**i*,<=*y**i*<=≤<=500, 0<=≤<=*r**i*<=≤<=500), where *x**i* and *y**i* are coordinates of the center of *i*-th peace of sausage, *r**i* — radius of *i*-th peace of sausage.
Output Specification:
Output the number of pieces of sausage that lay on the crust.
Demo Input:
['8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n', '10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n']
Demo Output:
['2\n', '0\n']
Note:
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
|
```python
print("_RANDOM_GUESS_1689179955.3691452")# 1689179955.369163
```
| 0
|
|
387
|
B
|
George and Round
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"two pointers"
] | null | null |
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
|
Print a single integer — the answer to the problem.
|
[
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] |
[
"0\n",
"2\n",
"3\n"
] |
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
| 1,000
|
[
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98",
"output": "24"
}
] | 1,398,581,675
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 41
| 77
| 307,200
|
R = lambda: list(map(int, input().split()))
n, m = R()
a = R()
b = R()
c = 0
i = j = 0
while i < n:
while j < m and b[j] < a[i]:
j += 1
if j == m:
break
c += 1
i += 1
j += 1
print(n - c)
|
Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n']
Demo Output:
['0\n', '2\n', '3\n']
Note:
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.
|
```python
R = lambda: list(map(int, input().split()))
n, m = R()
a = R()
b = R()
c = 0
i = j = 0
while i < n:
while j < m and b[j] < a[i]:
j += 1
if j == m:
break
c += 1
i += 1
j += 1
print(n - c)
```
| 3
|
|
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,677,739,928
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 106
| 1,090
| 0
|
n = int(input())
c = {}
for i in range(1,n+1): c[i] = int(input())
mx = 1
for i in range(1,n+1):
x = 1
j = i
while c[j] != -1:
x += 1
j = c[j]
if x > mx: mx = x
print(mx)
|
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())
c = {}
for i in range(1,n+1): c[i] = int(input())
mx = 1
for i in range(1,n+1):
x = 1
j = i
while c[j] != -1:
x += 1
j = c[j]
if x > mx: mx = x
print(mx)
```
| 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,675,085,480
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
s = input()
t = input(
is_true = True
for i in range(0,len(string)-1):
if s[i]==t[len(string)-i]:
pass
else:
is_true = False
break
if is_true:
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
s = input()
t = input(
is_true = True
for i in range(0,len(string)-1):
if s[i]==t[len(string)-i]:
pass
else:
is_true = False
break
if is_true:
print("YES")
else:
print("NO")
```
| -1
|
702
|
C
|
Cellular Network
|
PROGRAMMING
| 1,500
|
[
"binary search",
"implementation",
"two pointers"
] | null | null |
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower.
Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*.
If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower.
|
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order.
The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=≤<=*b**j*<=≤<=109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order.
|
Print minimal *r* so that each city will be covered by cellular network.
|
[
"3 2\n-2 2 4\n-3 0\n",
"5 3\n1 5 10 14 17\n4 11 15\n"
] |
[
"4\n",
"3\n"
] |
none
| 0
|
[
{
"input": "3 2\n-2 2 4\n-3 0",
"output": "4"
},
{
"input": "5 3\n1 5 10 14 17\n4 11 15",
"output": "3"
},
{
"input": "1 1\n-1000000000\n1000000000",
"output": "2000000000"
},
{
"input": "1 1\n1000000000\n-1000000000",
"output": "2000000000"
},
{
"input": "10 10\n1 1 2 2 2 4 4 6 7 9\n0 1 3 3 3 6 7 8 9 10",
"output": "1"
},
{
"input": "10 10\n2 52 280 401 416 499 721 791 841 943\n246 348 447 486 507 566 568 633 953 986",
"output": "244"
},
{
"input": "7 7\n1 2 3 3 4 5 6\n1 1 2 3 4 5 6",
"output": "0"
},
{
"input": "1 3\n-3\n-1 -1 8",
"output": "2"
},
{
"input": "1 2\n8\n-7 5",
"output": "3"
},
{
"input": "2 1\n4 8\n-1",
"output": "9"
},
{
"input": "1 2\n6\n-8 -8",
"output": "14"
},
{
"input": "1 4\n4\n-8 0 1 7",
"output": "3"
},
{
"input": "1 2\n2\n4 7",
"output": "2"
},
{
"input": "2 2\n-5 2\n-7 4",
"output": "2"
},
{
"input": "1 21\n3\n3 10 23 32 34 40 42 49 49 50 50 58 70 71 71 74 76 79 79 80 83",
"output": "0"
},
{
"input": "1 3\n-4\n-8 -1 1",
"output": "3"
},
{
"input": "4 1\n-6 -3 -1 2\n-7",
"output": "9"
},
{
"input": "2 3\n-2 7\n-7 -2 5",
"output": "2"
},
{
"input": "1 1\n-1\n0",
"output": "1"
},
{
"input": "1 3\n0\n-4 0 5",
"output": "0"
}
] | 1,675,911,046
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 92
| 2,048,000
|
# https://codeforces.com/contest/1703/problem/C
import sys
def main():
# sys.stdin = open("cypher.in", "r")
# sys.stdout = open("cypher.out", "w")
dir = {"D": 1, "U": -1}
t = int(input().strip())
for _ in range(t):
n = int(input().strip())
digits = list(map(int, input().strip().split()))
for i in range(n):
times, moves = input().strip().split()
for j in range(len(moves)):
digits[i] = (digits[i] + dir[moves[j]]) % 10
print(" ".join(map(str, digits)))
main()
|
Title: Cellular Network
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower.
Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*.
If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower.
Input Specification:
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order.
The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=≤<=*b**j*<=≤<=109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order.
Output Specification:
Print minimal *r* so that each city will be covered by cellular network.
Demo Input:
['3 2\n-2 2 4\n-3 0\n', '5 3\n1 5 10 14 17\n4 11 15\n']
Demo Output:
['4\n', '3\n']
Note:
none
|
```python
# https://codeforces.com/contest/1703/problem/C
import sys
def main():
# sys.stdin = open("cypher.in", "r")
# sys.stdout = open("cypher.out", "w")
dir = {"D": 1, "U": -1}
t = int(input().strip())
for _ in range(t):
n = int(input().strip())
digits = list(map(int, input().strip().split()))
for i in range(n):
times, moves = input().strip().split()
for j in range(len(moves)):
digits[i] = (digits[i] + dir[moves[j]]) % 10
print(" ".join(map(str, digits)))
main()
```
| -1
|
|
224
|
A
|
Parallelepiped
|
PROGRAMMING
| 1,100
|
[
"brute force",
"geometry",
"math"
] | null | null |
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
|
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
|
Print a single number — the sum of all edges of the parallelepiped.
|
[
"1 1 1\n",
"4 6 6\n"
] |
[
"12\n",
"28\n"
] |
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
| 500
|
[
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,587,762,267
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 27
| 218
| 0
|
a,b,c=map(int,input().split())
vol=(a*b*c)**(0.5)
print(int(4*(vol/a+vol/b+vol/c)))
|
Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
|
```python
a,b,c=map(int,input().split())
vol=(a*b*c)**(0.5)
print(int(4*(vol/a+vol/b+vol/c)))
```
| 3
|
|
716
|
B
|
Complete the Word
|
PROGRAMMING
| 1,300
|
[
"greedy",
"two pointers"
] | null | null |
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.
Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
|
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
|
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.
If there are multiple solutions, you may print any of them.
|
[
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] |
[
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] |
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.
In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1.
In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
| 1,000
|
[
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNOPQRSTUVW??M",
"output": "-1"
},
{
"input": "QWERTYUIOPASDFGHJKL???????",
"output": "QWERTYUIOPASDFGHJKLBCMNVXZ"
},
{
"input": "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z",
"output": "ABABABBABAAAAAAAAAAAAABABABABAAAAAAAAAAAAABABABABADEFGHIMNOKLCSJBPQRTUVWXYZ"
},
{
"input": "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N",
"output": "QAEATAUAOAAADAGAJALAXAVAMMQBECTFUHOIAKDPGRJSLWXYVZN"
},
{
"input": "???????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZA"
},
{
"input": "EJMGJAXCHXYIKZSQKUGRCLSTWDLNCVZIGXGWILAVFBEIGOHWGVEPRJTHWEDQRPOVZUQOSRVTIHFFHJMCLOWGHCIGJBCAAVBJFMJEFTEGFXZFVRZOXAFOFVXRAIZEWIKILFLYDZVDADYWYWYJXAGDFGNZBQKKKTGWPINLCDBZVULROGAKEKXXTWNYKQBMLQMQRUYOWUTWMNTJVGUXENHXWMFWMSBKVNGXSNFFTRTTGEGBBHMFZTKNJQDYUQOXVDWTDHZCCQNYYIOFPMKYQIGEEYBCKBAYVCTWARVMHIENKXKFXNXEFUHUNRQPEDFUBMKNQOYCQHGTLRHLWUAVZJDRBRTSVQHBKRDJFKKYEZAJWJKATRFZLNELPYGFUIWBXLIWVTHUILJHTQKDGRNCFTFELCOQPJDBYSPYJOUDKIFRCKEMJPUXTTAMHVENEVMNTZLUYSUALQOUPPRLZHCYICXAQFFRQZAAJNFKVRJDMDXFTBRJSAAHTSVG",
"output": "-1"
},
{
"input": "SVBWLLLPMPJUQVIGVXPCKMPEBPWMYORVTYELJOQGKEOJVCRBUJOOKQZQBYJIBCSHGSDBTIIMNGAXAQJRHHKQFAJSOJLAYRKWBASMLBQVUPPQWDGAVKDLFHEHVVWGSYQHYCPDIECHBTOIFYUFGKWIIMCKEBLECHCETBQMJPBPPGDHRLJIIMVJBZDRSDWWEJASQFRSCLOBAOLZQDPEZWDLMYTGDLUHCJMTXVURWQFCFDIGSUADTFMNGVHRYHQKWBGWWLQJQSFSWXGWIYUTSBUNZFDONBCFTGWTTQIISXJZUWSZWXXFMNB?UWPOWVWIWMBAPXYMGTRSGWMQRXULCMDTUKZS?CNMBRIYDZCUQWAKYQLLJLTXSVMUAYZHVBZFYBABBECIADQPUPZVVYHTGKOWKDNEUYPBTNUSQLLQRODUXFMSYUYIQGERINAPZWL?VKBVQJQLUJGDPFHNVXXSNOWHBZPMLOXVC?IEUMVLIBYLEATFUTILPPTP",
"output": "-1"
},
{
"input": "DMWSBHPGSJJD?EEV?CYAXQCCGNNQWNN?OMEDD?VC?CTKNQQPYXKKJFAYMJ?FMPXXCLKOL?OTRCE",
"output": "-1"
},
{
"input": "EOYJRKFABJIUOZILSHHCXIFQTXAVXJOVTQCDHXPNYPW?RVRKTB?OVXEL?NQHMZZXJLGSA?OTFSZQBV?SBHGKPJPCIQMLRSYDCFPYMEMXUEVHANXELHKSKNLGHGDCYMURXQRWMHEYXXCMGMUFZIPVOZQQBJGVKESTCDZCWFUCSGGIRWMXYXJLFLGUXQAWLZIKFUTVYDGKBVKBKXTICIKHXWFVJRHNMYRJZYNNYXMUOFERZPY?AJKSMUCTLOFH?LV?EHHCHKBHOJZAHFKJHHZJKZIEYAOAPDQRIUWDBMJGOOSNWN?CBKUXJCTEWVTRBDCNFMGBJUAODCCZVPZBQJNIRJVVF?QBWBV?AXOVOYNAWSKUVPHWJK?YPYOKTVFBWAGCC?JOWPPCAZDOYETAYYECWWURYHY?SJHMSJXDIMXFOTUWJLYDKCHOAPLFYPMFYFRNRKWY?CBPLQJJJ?BJYGBJT?FV?VDQEQAUFWZSOJHZFBVEALMMT?XP",
"output": "-1"
},
{
"input": "E?BIVQUPQQEJNMINFD?NKV?IROHPTGUIPMEVYPII?LZJMRI?FTKKKBHPOVQZZSAPDDWVSPVHOBT",
"output": "-1"
},
{
"input": "FDQHJSNDDXHJLWVZVXJZUGKVHWCZVRWVZTIURLMJNGAMCUBDGVSIDEYRJZOLDISDNTOEKLSNLBSOQZLJVPAMLEBAVUNBXNKMLZBGJJQCGCSKBFSEEDXEVSWGZHFJIZJESPZIKIONJWTFFYYZKIDBSDNPJVAUHQMRFKIJWCEGTBVZHWZEKLPHGZVKZFAFAQRNKHGACNRTSXQKKCYBMEMKNKKSURKHOSMEVUXNGOCVCLVVSKULGBKFPCEKVRAJMBWCFFFSCCNDOSEKXEFFZETTUZHMQETWCVZASTTULYOPBNMOMXMVUEEEYZHSMRPAEIHUKNPNJTARJKQKIOXDJASSQPQQHEQIQJQLVPIJRCFVOVECHBOCRYWQEDXZLJXUDZUBFTRWEWNYTSKGDBEBWFFLMUYWELNVAAXSMKYEZXQFKKHJTZKMKMYOBTVXAOVBRMAMHTBDDYMDGQYEEBYZUBMUCKLKXCZGTWVZAYJOXZVGUYNXOVAPXQVE",
"output": "-1"
},
{
"input": "KMNTIOJTLEKZW?JALAZYWYMKWRXTLAKNMDJLICZMETAKHVPTDOLAPCGHOEYSNIUJZVLPBTZ?YSR",
"output": "-1"
},
{
"input": "?MNURVAKIVSOGITVJZEZCAOZEFVNZERAHVNCVCYKTJVEHK?ZMDL?CROLIDFSG?EIFHYKELMQRBVLE?CERELHDVFODJ?LBGJVFPO?CVMPBW?DPGZMVA?BKPXQQCRMKHJWDNAJSGOTGLBNSWMXMKAQ?MWMXCNRSGHTL?LGLAHSDHAGZRGTNDFI?KJ?GSAWOEPOENXTJCVJGMYOFIQKKDWOCIKPGCMFEKNEUPFGBCBYQCM?EQSAX?HZ?MFKAUHOHRKZZSIVZCAKYIKBDJYOCZJRYNLSOKGAEGQRQ?TBURXXLHAFCNVGAUVWBXZILMHWSBYJTIMWPNEGATPURPTJYFWKHRL?QPYUQ?HKDDHWAHOWUSONQKSZFIYFMFUJAMIYAMPNBGVPJSDFDFSAHDWWGEAKXLHBURNTIMCUZIAFAOCVNKPJRNLNGSJVMGKQ?IFQSRHTZGKHGXFJBDGPLCUUMEWNOSCONIVCLAOAPPSFFLCPRIXTKNBSSOVM",
"output": "-1"
},
{
"input": "MRHKVVRBFEIFWIZGWCATJPBSZWNYANEWSSEVFQUUVNJKQOKVIGYBPFSZFTBUCNQEJEYVOWSPYER",
"output": "-1"
},
{
"input": "CNRFBWKRTQTDFOMIGPPGDBHPRNRXFASDDBCZXHORGXDRSIORLJEROJBLLEHLNBILBPX?KHQLCOUPTKUADCDNHNBWMVNUUVUFPIRXSPNUCCRLJTDSUIUDLBKNKMXSAVBJDUGWIMNBIUWJX?TCBDEBNDYUGPS?MQSSEIIUGEE?XXKW?CMFQMWUAEXTSZNNOCPHBAEAKWALYBBMUMQZXUKTQPWNMZKIDECWIZFHKQIUJZRSBZPQFUQNVKQZMYJDHXZWXFHIZ?HWPIPIWV?JMIYKEJDNPMKTTOY?NTOMZZXTNMWQENYRWFYM?WLJJFCIJSETZSJORBZZHAFWYKGQJAPYQQXUWROOZUDOJJLNCDRSGUKYAZLLENGUICGOYPLJQ?POSKHPMOFJMAOXCITWWL?LOEDKHZPQFZZCTB?JYZNXZSDREAMGGXHMCFTQNOUALEYHULSDQVOXZIWFHNNHHG?FYUOCQNKBLFGGZ?YNFNVLRMENYBDWMDSP",
"output": "-1"
},
{
"input": "KSRVTPFVRJWNPYUZMXBRLKVXIQPPBYVSYKRQPNGKTKRPFMKLIYFACFKBIQGPAXLEUESVGPBBXLY",
"output": "-1"
},
{
"input": "LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJEJSRBYREOZKHEXTBAXPTISPGIPOYBFFEJNAKKXAEPNGKWYGEJTNEZIXAWRSCEIRTKNEWSKSGKNIKDEOVXGYVEVFRGTNDFNWIFDRZQEJQZYIWNZXCONVZAKKKETPTPPXZMIVDWPGXOFODRNJZBATKGXAPXYHTUUFFASCHOLSMVSWBIJBAENEGNQTWKKOJUYQNXWDCDXBXBJOOWETWLQMGKHAJEMGXMYNVEHRAEGZOJJQPZGYRHXRNKMSWFYDIZLIBUTSKIKGQJZLGZQFJVIMNOHNZJKWVVPFMFACVXKJKTBZRXRZDJKSWSXBBKWIKEICSZEIPTOJCKJQYYPNUPRNPQNNCVITNXPLAKQBYAIQGNAHXDUQWQLYN",
"output": "-1"
},
{
"input": "PVCKCT?KLTFPIBBIHODCAABEQLJKQECRUJUSHSXPMBEVBKHQTIKQLBLTIRQZPOGPWMMNWWCUKAD",
"output": "-1"
},
{
"input": "BRTYNUVBBWMFDSRXAMLNSBIN???WDDQVPCSWGJTHLRAKTPFKGVLHAKNRIEYIDDRDZLLTBRKXRVRSPBSLXIZRRBEVMHJSAFPLZAIHFVTTEKDO?DYWKILEYRM?VHSEQCBYZZRZMICVZRYA?ONCSZOPGZUMIHJQJPIFX?YJMIERCMKTSFTDZIKEZPLDEOOCJLQIZ?RPHUEQHPNNSBRQRTDGLWNSCZ?WQVIZPTOETEXYI?DRQUOMREPUTOAJKFNBGYNWMGCAOELXEPLLZEYHTVLT?ETJJXLHJMAUDQESNQ?ZCGNDGI?JSGUXQV?QAWQIYKXBKCCSWNRTGHPZF?CSWDQSAZIWQNHOWHYAEZNXRMPAZEQQPPIBQQJEDHJEDHVXNEDETEN?ZHEPJJ?VVDYGPJUWGCBMB?ANFJHJXQVAJWCAZEZXZX?BACPPXORNENMCRMQPIYKNPHX?NSKGEABWWVLHQ?ESWLJUPQJSFIUEGMGHEYVLYEDWJG?L",
"output": "-1"
},
{
"input": "TESTEIGHTYFOUR",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "-1"
},
{
"input": "?????????????????????????",
"output": "-1"
},
{
"input": "Q?RYJPGLNQ",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRZTUVWXYS",
"output": "ABCDEFGHIJKLMNOPQRZTUVWXYS"
},
{
"input": "AACDEFGHIJKLMNOPQRZTUVWXYS",
"output": "-1"
},
{
"input": "ZA?ABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "ZAZABCDEFGHIJKLMNOPQRSTUVWXY"
},
{
"input": "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXYYYZABC",
"output": "-1"
},
{
"input": "????",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRZTUVWXYS??",
"output": "ABCDEFGHIJKLMNOPQRZTUVWXYSAA"
},
{
"input": "A",
"output": "-1"
},
{
"input": "NKBDABACEFGGGIJLLLLMMMOMPQWZSSRHHTTUWUWVXYY",
"output": "-1"
},
{
"input": "AA",
"output": "-1"
},
{
"input": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXA?CDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "???DEFGHIJKL??L?PQRSTUVW???",
"output": "-1"
},
{
"input": "?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A",
"output": "-1"
},
{
"input": "A?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA???????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????",
"output": "-1"
},
{
"input": "ZXXCVBNMLKJHGFDSAQWWERTYUIOP",
"output": "-1"
},
{
"input": "ABCA???????????????????????",
"output": "ABCADEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AB",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "BCDEFGHIAJKLMNOPQARSTUVWXYZ",
"output": "-1"
},
{
"input": "AABBCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "-1"
},
{
"input": "???AA????????????????????BB???",
"output": "-1"
},
{
"input": "ABC??FGAHIJ??MNOPQRST??WXYZ",
"output": "ABCDEFGAHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBN",
"output": "-1"
},
{
"input": "??????AAAAAAAAAAAAAAAAAAAABBBBB??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSFFFFFFF?????????DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??????WWWWWWWWWWEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRRRRRRHHHHHHHHHH?????",
"output": "-1"
}
] | 1,600,069,926
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 92
| 204,800
|
alpha = "abcdefghijklmnopqrstvuwxyz"
s = input().lower()
temp = s
temp = temp.replace("?","")
#print(len(s))
#print(sorted(s),sorted(temp))
if(len(s)==26 and sorted(s)!=sorted(temp)):
s1 = set(temp)
s2 = set(list(alpha))
diff = list(s2.difference(s1))
print(diff)
s = list(s)
c = 0
for i in range(len(s)):
if s[i] == "?":
s[i] = diff[c]
c+=1
print("".join(s).upper())
else:
print(-1)
|
Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.
Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
Input Specification:
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
Output Specification:
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.
If there are multiple solutions, you may print any of them.
Demo Input:
['ABC??FGHIJK???OPQR?TUVWXY?\n', 'WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n', '??????????????????????????\n', 'AABCDEFGHIJKLMNOPQRSTUVW??M\n']
Demo Output:
['ABCDEFGHIJKLMNOPQRZTUVWXYS', '-1', 'MNBVCXZLKJHGFDSAQPWOEIRUYT', '-1']
Note:
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.
In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1.
In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
|
```python
alpha = "abcdefghijklmnopqrstvuwxyz"
s = input().lower()
temp = s
temp = temp.replace("?","")
#print(len(s))
#print(sorted(s),sorted(temp))
if(len(s)==26 and sorted(s)!=sorted(temp)):
s1 = set(temp)
s2 = set(list(alpha))
diff = list(s2.difference(s1))
print(diff)
s = list(s)
c = 0
for i in range(len(s)):
if s[i] == "?":
s[i] = diff[c]
c+=1
print("".join(s).upper())
else:
print(-1)
```
| 0
|
|
415
|
A
|
Mashmokh and Lights
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed *m* distinct buttons *b*1,<=*b*2,<=...,<=*b**m* (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button *b**i* is actually *b**i*, not *i*.
Please, help Mashmokh, print these indices.
|
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*).
It is guaranteed that all lights will be turned off after pushing all buttons.
|
Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off.
|
[
"5 4\n4 3 1 2\n",
"5 5\n5 4 3 2 1\n"
] |
[
"1 1 3 4 4 \n",
"1 2 3 4 5 \n"
] |
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
| 500
|
[
{
"input": "5 4\n4 3 1 2",
"output": "1 1 3 4 4 "
},
{
"input": "5 5\n5 4 3 2 1",
"output": "1 2 3 4 5 "
},
{
"input": "16 11\n8 5 12 10 14 2 6 3 15 9 1",
"output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 "
},
{
"input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 61 12 60 57",
"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 28 28 28 28 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 76 76 76 76 "
},
{
"input": "25 19\n3 12 21 11 19 6 5 15 4 16 20 8 9 1 22 23 25 18 13",
"output": "1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 "
},
{
"input": "48 8\n42 27 40 1 18 3 19 2",
"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 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 42 42 42 42 42 42 42 "
},
{
"input": "44 19\n13 20 7 10 9 14 43 17 18 39 21 42 37 1 33 8 35 4 6",
"output": "1 1 1 1 1 1 7 7 7 7 7 7 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 "
},
{
"input": "80 29\n79 51 28 73 65 39 10 1 59 29 7 70 64 3 35 17 24 71 74 2 6 49 66 80 13 18 60 15 12",
"output": "1 1 1 1 1 1 1 1 1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 79 79 "
},
{
"input": "31 4\n8 18 30 1",
"output": "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 "
},
{
"input": "62 29\n61 55 35 13 51 56 23 6 8 26 27 40 48 11 18 12 19 50 54 14 24 21 32 17 43 33 1 2 3",
"output": "1 1 1 1 1 6 6 6 6 6 6 6 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 55 55 55 55 55 55 61 61 "
},
{
"input": "5 4\n2 3 4 1",
"output": "1 2 2 2 2 "
},
{
"input": "39 37\n2 5 17 24 19 33 35 16 20 3 1 34 10 36 15 37 14 8 28 21 13 31 30 29 7 25 32 12 6 27 22 4 11 39 18 9 26",
"output": "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 "
},
{
"input": "100 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": "1 1\n1",
"output": "1 "
},
{
"input": "18 3\n18 1 11",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 18 "
},
{
"input": "67 20\n66 23 40 49 3 39 60 43 52 47 16 36 22 5 41 10 55 34 64 1",
"output": "1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 66 66 "
},
{
"input": "92 52\n9 85 44 13 27 61 8 1 28 41 6 14 70 67 39 71 56 80 34 21 5 10 40 73 63 38 90 57 37 36 82 86 65 46 7 54 81 12 45 49 83 59 64 26 62 25 60 24 91 47 53 55",
"output": "1 1 1 1 1 1 1 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 "
},
{
"input": "66 36\n44 62 32 29 3 15 47 30 50 42 35 2 33 65 10 13 56 12 1 16 7 36 39 11 25 28 20 52 46 38 37 8 61 49 48 14",
"output": "1 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 29 29 29 32 32 32 32 32 32 32 32 32 32 32 32 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 "
},
{
"input": "32 8\n27 23 1 13 18 24 17 26",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 23 23 23 27 27 27 27 27 27 "
},
{
"input": "26 13\n1 14 13 2 4 24 21 22 16 3 10 12 6",
"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 "
},
{
"input": "31 20\n10 11 20 2 4 26 31 7 13 12 28 1 30 18 21 8 3 16 15 19",
"output": "1 2 2 2 2 2 2 2 2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "86 25\n22 62 8 23 53 77 9 31 43 1 58 16 72 11 15 35 60 39 79 4 82 64 76 63 59",
"output": "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 "
},
{
"input": "62 54\n2 5 4 47 40 61 37 31 41 16 44 42 48 32 10 6 62 38 52 49 11 20 55 22 3 36 25 21 50 8 28 14 18 39 34 54 53 19 46 27 15 23 12 24 60 17 33 57 58 1 35 29 51 7",
"output": "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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "57 19\n43 45 37 40 42 55 16 33 47 32 34 35 9 41 1 6 8 15 5",
"output": "1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 37 37 37 37 37 37 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 "
},
{
"input": "32 14\n4 7 13 1 25 22 9 27 6 28 30 2 14 21",
"output": "1 1 1 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 "
},
{
"input": "57 12\n8 53 51 38 1 6 16 33 13 46 28 35",
"output": "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 "
},
{
"input": "87 9\n57 34 78 1 52 67 56 6 54",
"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 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 "
},
{
"input": "88 42\n85 45 52 14 63 53 70 71 16 86 66 47 12 22 10 72 4 31 3 69 11 77 17 25 46 75 23 1 21 84 44 20 18 33 48 88 41 83 67 61 73 34",
"output": "1 1 3 4 4 4 4 4 4 10 10 12 12 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 85 85 85 85 "
},
{
"input": "27 25\n9 21 17 5 16 3 23 7 12 4 14 11 13 1 15 19 27 8 20 10 22 25 6 18 26",
"output": "1 1 3 3 5 5 5 5 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 "
},
{
"input": "89 28\n5 22 79 42 16 35 66 48 57 55 1 37 29 31 40 38 45 62 41 87 64 89 81 13 60 44 71 82",
"output": "1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 "
},
{
"input": "17 4\n4 3 1 2",
"output": "1 1 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 "
}
] | 1,665,470,824
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 31
| 46
| 0
|
n, m = map(int, input().split())
b = list(map(int, input().split()))
lights = [0] * n
for i in range(m):
for j in range(n):
if j < b[i] - 1:
continue
if lights[j] == 0:
lights[j] = b[i]
print(" ".join(str(light) for light in lights))
|
Title: Mashmokh and Lights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed *m* distinct buttons *b*1,<=*b*2,<=...,<=*b**m* (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button *b**i* is actually *b**i*, not *i*.
Please, help Mashmokh, print these indices.
Input Specification:
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output Specification:
Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off.
Demo Input:
['5 4\n4 3 1 2\n', '5 5\n5 4 3 2 1\n']
Demo Output:
['1 1 3 4 4 \n', '1 2 3 4 5 \n']
Note:
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
|
```python
n, m = map(int, input().split())
b = list(map(int, input().split()))
lights = [0] * n
for i in range(m):
for j in range(n):
if j < b[i] - 1:
continue
if lights[j] == 0:
lights[j] = b[i]
print(" ".join(str(light) for light in lights))
```
| 3
|
|
967
|
B
|
Watering System
|
PROGRAMMING
| 1,000
|
[
"math",
"sortings"
] | null | null |
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
|
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
|
Print a single integer — the number of holes Arkady should block.
|
[
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] |
[
"1\n",
"0\n",
"4\n"
] |
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole.
| 1,000
|
[
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 96",
"output": "8"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "2 2 2\n1 10000",
"output": "1"
},
{
"input": "2 10000 1\n1 9999",
"output": "0"
}
] | 1,637,906,905
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 8
| 1,000
| 6,144,000
|
#!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-26 13:53:20
LastEditTime: 2021-11-26 14:07:02
Description: Watering System
FilePath: CF967B.py
'''
def func():
n, a, b = map(int, input().strip().split())
s1, *s = map(int, input().strip().split())
s = sorted(s)
num = 0
while a * s1 / (s1 + sum(s[:(n - 1 - num)])) < b:
num += 1
print(num)
if __name__ == '__main__':
func()
|
Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
Input Specification:
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
Output Specification:
Print a single integer — the number of holes Arkady should block.
Demo Input:
['4 10 3\n2 2 2 2\n', '4 80 20\n3 2 1 4\n', '5 10 10\n1000 1 1 1 1\n']
Demo Output:
['1\n', '0\n', '4\n']
Note:
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole.
|
```python
#!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-26 13:53:20
LastEditTime: 2021-11-26 14:07:02
Description: Watering System
FilePath: CF967B.py
'''
def func():
n, a, b = map(int, input().strip().split())
s1, *s = map(int, input().strip().split())
s = sorted(s)
num = 0
while a * s1 / (s1 + sum(s[:(n - 1 - num)])) < b:
num += 1
print(num)
if __name__ == '__main__':
func()
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
|
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
|
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
|
[
"6 1\n",
"6 3\n",
"2 2\n"
] |
[
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] |
Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
| 0
|
[
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "3 10",
"output": "2.982641534996"
},
{
"input": "3 6",
"output": "2.910836762689"
},
{
"input": "1 8",
"output": "1.000000000000"
},
{
"input": "24438 9",
"output": "21994.699969310015"
},
{
"input": "94444 9",
"output": "85000.099992058866"
},
{
"input": "8 66716",
"output": "8.000000000000"
},
{
"input": "4 25132",
"output": "4.000000000000"
},
{
"input": "51520 73331",
"output": "51519.682650242677"
},
{
"input": "54230 31747",
"output": "54228.743352775018"
},
{
"input": "24236 90163",
"output": "24235.975171545670"
},
{
"input": "26946 99523",
"output": "26945.974480086279"
},
{
"input": "50323 7",
"output": "44033.124988408454"
},
{
"input": "53033 3",
"output": "39775.249995286234"
},
{
"input": "55743 5",
"output": "46452.999992525307"
},
{
"input": "59964 79",
"output": "59214.949890211828"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "3 1",
"output": "2.000000000000"
},
{
"input": "1 2",
"output": "1.000000000000"
},
{
"input": "53513 34040",
"output": "53511.875329020870"
},
{
"input": "100000 100000",
"output": "99999.418033254507"
},
{
"input": "1 100000",
"output": "1.000000000000"
},
{
"input": "100000 1",
"output": "50000.499999999935"
},
{
"input": "2 100000",
"output": "2.000000000000"
},
{
"input": "100000 2",
"output": "66667.166665000332"
},
{
"input": "50000 100000",
"output": "49999.843487110789"
},
{
"input": "99999 1111",
"output": "99909.571915885972"
},
{
"input": "99999 99999",
"output": "99998.418033254609"
},
{
"input": "1000 1000",
"output": "999.419018443269"
},
{
"input": "50000 50000",
"output": "49999.418043215679"
},
{
"input": "88888 88888",
"output": "88887.418034499773"
},
{
"input": "99999 100000",
"output": "99998.418042461126"
},
{
"input": "100000 555",
"output": "99820.643422392372"
},
{
"input": "10000 10000",
"output": "9999.418122897887"
},
{
"input": "100000 5001",
"output": "99980.503829474910"
},
{
"input": "100000 1000",
"output": "99900.599066768002"
}
] | 1,665,034,939
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 41
| 93
| 2,048,000
|
import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
######################################################################################
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlsts(): return [int(i) for i in sys.stdin.readline().split()]
def inp(): return int(sys.stdin.readline())
def instr(): return sys.stdin.readline().strip()
def words(): return [i for i in sys.stdin.readline().strip().split()]
def chars(): return [i for i in sys.stdin.readline().strip()]
######################################################################################
#--------------------------------------code here-------------------------------------#
######################################################################################
def solve():
m,n=values()
ans=0
for i in range(1,m+1):
ans+=i*( (i/m)**n-((i-1)/m)**n)
print(ans)
if __name__ == "__main__":
# for i in range(inp()):
solve()
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
Input Specification:
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output Specification:
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
Demo Input:
['6 1\n', '6 3\n', '2 2\n']
Demo Output:
['3.500000000000\n', '4.958333333333\n', '1.750000000000\n']
Note:
Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value
|
```python
import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
######################################################################################
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlsts(): return [int(i) for i in sys.stdin.readline().split()]
def inp(): return int(sys.stdin.readline())
def instr(): return sys.stdin.readline().strip()
def words(): return [i for i in sys.stdin.readline().strip().split()]
def chars(): return [i for i in sys.stdin.readline().strip()]
######################################################################################
#--------------------------------------code here-------------------------------------#
######################################################################################
def solve():
m,n=values()
ans=0
for i in range(1,m+1):
ans+=i*( (i/m)**n-((i-1)/m)**n)
print(ans)
if __name__ == "__main__":
# for i in range(inp()):
solve()
```
| 3
|
|
102
|
B
|
Sum of Digits
|
PROGRAMMING
| 1,000
|
[
"implementation"
] |
B. Sum of Digits
|
2
|
265
|
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
|
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
|
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
|
[
"0\n",
"10\n",
"991\n"
] |
[
"0\n",
"1\n",
"3\n"
] |
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
| 1,000
|
[
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,602,749,305
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 51
| 218
| 307,200
|
n=input()
c=0
while(len(n)!=1):
n=str(sum(int(i) for i in n))
c+=1
print(c)
|
Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
|
```python
n=input()
c=0
while(len(n)!=1):
n=str(sum(int(i) for i in n))
c+=1
print(c)
```
| 3.944947
|
741
|
B
|
Arpa's weak amphitheater and Mehrdad's valuable Hoses
|
PROGRAMMING
| 1,600
|
[
"dfs and similar",
"dp",
"dsu"
] | null | null |
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if and only if there is a sequence of Hoses *a*1,<=*a*2,<=...,<=*a**k* such that *a**i* and *a**i*<=+<=1 are friends for each 1<=≤<=*i*<=<<=*k*, and *a*1<==<=*x* and *a**k*<==<=*y*.
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most *w* weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than *w* and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed *w*.
|
The first line contains integers *n*, *m* and *w* (1<=<=≤<=<=*n*<=<=≤<=<=1000, , 1<=≤<=*w*<=≤<=1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=1000) — the weights of the Hoses.
The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=106) — the beauties of the Hoses.
The next *m* lines contain pairs of friends, the *i*-th of them contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*), meaning that Hoses *x**i* and *y**i* are friends. Note that friendship is bidirectional. All pairs (*x**i*,<=*y**i*) are distinct.
|
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed *w*.
|
[
"3 1 5\n3 2 5\n2 4 2\n1 2\n",
"4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n"
] |
[
"6\n",
"7\n"
] |
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
| 1,000
|
[
{
"input": "3 1 5\n3 2 5\n2 4 2\n1 2",
"output": "6"
},
{
"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3",
"output": "7"
},
{
"input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5",
"output": "2383854"
},
{
"input": "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\n6 8\n8 3\n3 9\n2 3\n10 3",
"output": "1495706"
},
{
"input": "10 5 100\n6 18 35 6 87 58 4 53 37 71\n465782 57034 547741 748298 315223 370368 679320 349012 9740 622511\n1 2\n10 9\n6 7\n3 6\n7 1",
"output": "2050129"
},
{
"input": "10 5 100\n78 89 3 2 95 96 87 11 13 60\n694709 921 799687 428614 221900 536251 117674 36488 219932 771513\n4 5\n3 4\n6 2\n2 3\n8 3",
"output": "1791132"
},
{
"input": "10 5 100\n48 73 30 46 95 19 98 73 94 24\n501216 675859 843572 565104 879875 828759 80776 766980 213551 492652\n1 2\n6 5\n7 6\n10 3\n8 1",
"output": "2237435"
},
{
"input": "10 5 100\n68 55 15 94 53 100 52 68 24 3\n286803 660813 226501 624597 215418 290774 416040 961916 910482 50278\n1 5\n7 2\n2 8\n5 3\n10 3",
"output": "1922676"
},
{
"input": "10 5 100\n19 8 95 18 9 79 42 94 20 49\n735491 935681 717266 935275 521356 866021 356037 394445 589369 585077\n9 4\n5 6\n5 1\n1 4\n7 1",
"output": "2456033"
}
] | 1,481,037,345
| 2,445
|
PyPy 3
|
COMPILATION_ERROR
|
PRETESTS
| 0
| 0
| 0
|
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
using namespace std;
vector < int > us;
vector < vector < int > > g, gr;
void dfs(int v) {
if (us[v])
return;
us[v] = 1;
gr[gr.size() - 1].push_back(v);
for (int i : g[v])
dfs(i);
return;
}
int main() {
//freopen("crosswords.in", "r", stdin);
//freopen("crosswords.out", "w", stdout);
iostream::sync_with_stdio(false);
int n, m, W;
cin >> n >> m >> W;
us.resize(n, 0);
g.resize(n);
vector < int > b(n), w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--, y--;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; i++) {
if (us[i])
continue;
gr.push_back(vector<int>());
dfs(i);
}
vector < int > whr(n + gr.size());
for (int i = 0; i < gr.size(); i++) {
whr[i + n] = i;
for (int j : gr[i])
whr[j] = i;
}
vector < pair < int, int > > a;
vector < int > _whr;
vector < int > sz(gr.size());
int cur = 0;
for (int i = 0; i < gr.size(); i++) {
int noww = 0, nowb = 0;
for (int j : gr[i]) {
noww += w[j];
nowb += b[j];
a.push_back({ b[j], w[j] });
_whr.push_back(i);
}
a.push_back({ nowb, noww });
_whr.push_back(i);
sz[i] = cur;
cur += gr[i].size();
}
vector < vector < int > > can(a.size() + 1, vector<int>(W + 1, 0));
int mx = 0;
for (int j = 1; j <= W; j++) {
for (int i = 1; i <= a.size(); i++) {
int pr = sz[_whr[i - 1]];
can[i][j] = can[i - 1][j];
if (j >= a[i - 1].second)
can[i][j] = max(can[i - 1][j], can[pr][j - a[i - 1].second] + a[i - 1].first);
mx = max(mx, can[i][j]);
}
}
cout << mx;
return 0;
}
|
Title: Arpa's weak amphitheater and Mehrdad's valuable Hoses
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if and only if there is a sequence of Hoses *a*1,<=*a*2,<=...,<=*a**k* such that *a**i* and *a**i*<=+<=1 are friends for each 1<=≤<=*i*<=<<=*k*, and *a*1<==<=*x* and *a**k*<==<=*y*.
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most *w* weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than *w* and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed *w*.
Input Specification:
The first line contains integers *n*, *m* and *w* (1<=<=≤<=<=*n*<=<=≤<=<=1000, , 1<=≤<=*w*<=≤<=1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=1000) — the weights of the Hoses.
The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=106) — the beauties of the Hoses.
The next *m* lines contain pairs of friends, the *i*-th of them contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*), meaning that Hoses *x**i* and *y**i* are friends. Note that friendship is bidirectional. All pairs (*x**i*,<=*y**i*) are distinct.
Output Specification:
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed *w*.
Demo Input:
['3 1 5\n3 2 5\n2 4 2\n1 2\n', '4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n']
Demo Output:
['6\n', '7\n']
Note:
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
|
```python
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
using namespace std;
vector < int > us;
vector < vector < int > > g, gr;
void dfs(int v) {
if (us[v])
return;
us[v] = 1;
gr[gr.size() - 1].push_back(v);
for (int i : g[v])
dfs(i);
return;
}
int main() {
//freopen("crosswords.in", "r", stdin);
//freopen("crosswords.out", "w", stdout);
iostream::sync_with_stdio(false);
int n, m, W;
cin >> n >> m >> W;
us.resize(n, 0);
g.resize(n);
vector < int > b(n), w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--, y--;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; i++) {
if (us[i])
continue;
gr.push_back(vector<int>());
dfs(i);
}
vector < int > whr(n + gr.size());
for (int i = 0; i < gr.size(); i++) {
whr[i + n] = i;
for (int j : gr[i])
whr[j] = i;
}
vector < pair < int, int > > a;
vector < int > _whr;
vector < int > sz(gr.size());
int cur = 0;
for (int i = 0; i < gr.size(); i++) {
int noww = 0, nowb = 0;
for (int j : gr[i]) {
noww += w[j];
nowb += b[j];
a.push_back({ b[j], w[j] });
_whr.push_back(i);
}
a.push_back({ nowb, noww });
_whr.push_back(i);
sz[i] = cur;
cur += gr[i].size();
}
vector < vector < int > > can(a.size() + 1, vector<int>(W + 1, 0));
int mx = 0;
for (int j = 1; j <= W; j++) {
for (int i = 1; i <= a.size(); i++) {
int pr = sz[_whr[i - 1]];
can[i][j] = can[i - 1][j];
if (j >= a[i - 1].second)
can[i][j] = max(can[i - 1][j], can[pr][j - a[i - 1].second] + a[i - 1].first);
mx = max(mx, can[i][j]);
}
}
cout << mx;
return 0;
}
```
| -1
|
|
352
|
A
|
Jeff and Digits
|
PROGRAMMING
| 1,000
|
[
"brute force",
"implementation",
"math"
] | null | null |
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
|
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
|
[
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] |
[
"0\n",
"5555555550\n"
] |
In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90.
| 500
|
[
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 5 5 0 0 5 5 5 5",
"output": "0"
},
{
"input": "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0",
"output": "55555555555555555500000"
},
{
"input": "9\n5 5 5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0",
"output": "55555555555555555500000"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10\n5 5 5 5 5 0 0 5 0 5",
"output": "0"
},
{
"input": "3\n5 5 0",
"output": "0"
},
{
"input": "5\n5 5 0 5 5",
"output": "0"
},
{
"input": "14\n0 5 5 0 0 0 0 0 0 5 5 5 5 5",
"output": "0"
},
{
"input": "3\n5 5 5",
"output": "-1"
},
{
"input": "3\n0 5 5",
"output": "0"
},
{
"input": "13\n0 0 5 0 5 0 5 5 0 0 0 0 0",
"output": "0"
},
{
"input": "9\n5 5 0 5 5 5 5 5 5",
"output": "0"
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 5 0 0",
"output": "5555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "214\n5 0 5 0 5 0 0 0 5 5 0 5 0 5 5 0 5 0 0 0 0 5 5 0 0 5 5 0 0 0 0 5 5 5 5 0 5 0 0 0 0 0 0 5 0 0 0 5 0 0 5 0 0 5 5 0 0 5 5 0 0 0 0 0 5 0 5 0 5 5 0 5 0 0 5 5 5 0 5 0 5 0 5 5 0 5 0 0 0 5 5 0 5 0 5 5 5 5 5 0 0 0 0 0 0 5 0 5 5 0 5 0 5 0 5 5 0 0 0 0 5 0 5 0 5 0 0 5 0 0 5 5 5 5 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 5 0 0 0 5 0 0 5 5 5 0 0 5 5 5 0 0 5 5 0 0 0 5 0 0 5 5 5 5 5 5 0 5 0 0 5 5 5 5 0 5 5 0 0 0 5 5 5 5 0 0 0 0 5 0 0 5 0 0 5 5 0 0",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "80\n0 0 0 0 5 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 0 0 5 5 0 5 0 0 0 0 0 0 5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 5 5 0 0 0",
"output": "555555555000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "-1"
},
{
"input": "2\n0 5",
"output": "0"
},
{
"input": "14\n5 5 5 5 5 5 5 5 5 5 5 5 5 0",
"output": "5555555550"
},
{
"input": "18\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 0",
"output": "5555555550"
},
{
"input": "10\n5 5 5 5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "20\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "-1"
}
] | 1,642,598,197
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 42
| 186
| 0
|
x = int(input())
ls = sorted(list(map(int, input().split())))
if ls.count(0) == 0:
print(-1)
else :
ct = ls.count(5)
if ct < 9:
print(0)
else:
print('5' * (ct - (ct % 9)), '0' * (ls.count(0)), sep = '')
|
Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card.
Output Specification:
In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.
Demo Input:
['4\n5 0 5 0\n', '11\n5 5 5 5 5 5 5 5 0 5 5\n']
Demo Output:
['0\n', '5555555550\n']
Note:
In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90.
|
```python
x = int(input())
ls = sorted(list(map(int, input().split())))
if ls.count(0) == 0:
print(-1)
else :
ct = ls.count(5)
if ct < 9:
print(0)
else:
print('5' * (ct - (ct % 9)), '0' * (ls.count(0)), sep = '')
```
| 3
|
|
350
|
A
|
TL
|
PROGRAMMING
| 1,200
|
[
"brute force",
"greedy",
"implementation"
] | null | null |
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
|
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
|
If there is a valid TL value, print it. Otherwise, print -1.
|
[
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] |
[
"5",
"-1\n"
] |
none
| 500
|
[
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50",
"output": "49"
},
{
"input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2",
"output": "-1"
},
{
"input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90",
"output": "46"
},
{
"input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66",
"output": "14"
},
{
"input": "1 1\n4\n9",
"output": "8"
},
{
"input": "1 1\n2\n4",
"output": "-1"
},
{
"input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58",
"output": "-1"
},
{
"input": "1 1\n50\n100",
"output": "-1"
},
{
"input": "1 1\n49\n100",
"output": "98"
},
{
"input": "1 1\n100\n100",
"output": "-1"
},
{
"input": "1 1\n99\n100",
"output": "-1"
},
{
"input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100",
"output": "99"
},
{
"input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2",
"output": "-1"
},
{
"input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75",
"output": "2"
},
{
"input": "3 3\n2 3 4\n8 9 10",
"output": "4"
},
{
"input": "2 1\n2 3\n15",
"output": "4"
},
{
"input": "2 1\n2 4\n4",
"output": "-1"
},
{
"input": "2 3\n4 5\n10 11 12",
"output": "8"
},
{
"input": "3 1\n2 3 3\n5",
"output": "4"
},
{
"input": "2 1\n9 10\n100",
"output": "18"
},
{
"input": "3 3\n3 12 15\n7 8 9",
"output": "-1"
},
{
"input": "2 2\n3 5\n7 8",
"output": "6"
},
{
"input": "3 3\n4 5 6\n10 11 12",
"output": "8"
},
{
"input": "3 5\n2 3 3\n6 6 6 6 2",
"output": "-1"
},
{
"input": "3 6\n4 5 3\n8 9 7 10 7 11",
"output": "6"
},
{
"input": "3 6\n4 5 2\n8 9 6 10 7 4",
"output": "-1"
},
{
"input": "2 1\n4 6\n10",
"output": "8"
},
{
"input": "1 2\n1\n3 1",
"output": "-1"
},
{
"input": "2 1\n5 6\n20",
"output": "10"
},
{
"input": "2 1\n1 5\n5",
"output": "-1"
},
{
"input": "3 2\n10 20 30\n30 40",
"output": "-1"
},
{
"input": "2 2\n5 6\n7 100",
"output": "-1"
},
{
"input": "2 1\n2 5\n7",
"output": "5"
},
{
"input": "1 1\n5\n20",
"output": "10"
},
{
"input": "2 1\n10 11\n100",
"output": "20"
},
{
"input": "1 1\n1\n10",
"output": "2"
},
{
"input": "1 1\n10\n100",
"output": "20"
}
] | 1,630,565,173
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 45
| 154
| 6,758,400
|
n , m = map(int,input().split())
cans = list(map(int,input().split()))
wans = list(map(int,input().split()))
v = max(min(cans) * 2 , max(cans))
if v < min(wans):
print(v)
else:
print(-1)
|
Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds.
As a result, Valera decided to set *v* seconds TL, that the following conditions are met:
1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
Input Specification:
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
Output Specification:
If there is a valid TL value, print it. Otherwise, print -1.
Demo Input:
['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n']
Demo Output:
['5', '-1\n']
Note:
none
|
```python
n , m = map(int,input().split())
cans = list(map(int,input().split()))
wans = list(map(int,input().split()))
v = max(min(cans) * 2 , max(cans))
if v < min(wans):
print(v)
else:
print(-1)
```
| 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,634,103,242
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 92
| 6,758,400
|
M,N=input().split()
m,n=int(M),int(N)
print(int(m*n//2))
|
Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as 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().split()
m,n=int(M),int(N)
print(int(m*n//2))
```
| 3.964411
|
278
|
A
|
Circle Line
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
|
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
|
Print a single number — the length of the shortest path between stations number *s* and *t*.
|
[
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] |
[
"5\n",
"15\n",
"1\n",
"0\n"
] |
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
| 500
|
[
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"input": "6\n89 82 87 32 67 33\n4 4",
"output": "0"
},
{
"input": "7\n2 3 17 10 2 2 2\n4 2",
"output": "18"
},
{
"input": "3\n4 37 33\n3 3",
"output": "0"
},
{
"input": "8\n87 40 96 7 86 86 72 97\n6 8",
"output": "158"
},
{
"input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8",
"output": "348"
},
{
"input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7",
"output": "0"
},
{
"input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16",
"output": "452"
},
{
"input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6",
"output": "337"
},
{
"input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64",
"output": "1740"
},
{
"input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5",
"output": "2127"
},
{
"input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57",
"output": "932"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6",
"output": "997"
},
{
"input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24",
"output": "195"
},
{
"input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10",
"output": "60"
},
{
"input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25",
"output": "2523"
},
{
"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\n1 51",
"output": "5000"
},
{
"input": "4\n1 1 1 1\n2 4",
"output": "2"
},
{
"input": "4\n1 1 2 1\n2 4",
"output": "2"
}
] | 1,620,583,033
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 23
| 124
| 6,758,400
|
inp = int(input())
ls = list(map(int, input().split()))
s1,s2 = map(int,input().split())
if s1>s2: s1,s2 = s2,s1
d1 = sum(ls[s1-1:s2-1])
d2 = sum(ls[:s1-1])+sum(ls[s2-1:])
print(min(d1,d2))
|
Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output Specification:
Print a single number — the length of the shortest path between stations number *s* and *t*.
Demo Input:
['4\n2 3 4 9\n1 3\n', '4\n5 8 2 100\n4 1\n', '3\n1 1 1\n3 1\n', '3\n31 41 59\n1 1\n']
Demo Output:
['5\n', '15\n', '1\n', '0\n']
Note:
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
|
```python
inp = int(input())
ls = list(map(int, input().split()))
s1,s2 = map(int,input().split())
if s1>s2: s1,s2 = s2,s1
d1 = sum(ls[s1-1:s2-1])
d2 = sum(ls[:s1-1])+sum(ls[s2-1:])
print(min(d1,d2))
```
| 3
|
|
34
|
A
|
Reconnaissance 2
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Reconnaissance 2
|
2
|
256
|
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
|
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
|
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
|
[
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] |
[
"5 1\n",
"1 2\n"
] |
none
| 500
|
[
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,662,103,327
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 20
| 154
| 0
|
#文字列入力はするな!!
#carpe diem
'''
██╗ ██╗ ███╗ ███╗ ██╗ ████████╗
██║ ██║ ████╗ ████║ ██║ ╚══██╔══╝
═════════██╠════════██╠═══██╔████╔██╠═══██╠══════██╠══════════
██║ ██║ ██║╚██╔╝██║ ██║ ██║
███████╗ ██║ ██║ ╚═╝ ██║ ██║ ██║
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
'''
#文字列入力はするな!!
#carpe diem
n=int(input())
L=list(map(int,input().split()))
diff=abs(L[0]-L[n-1])
ind1=1
ind2=n
for i in range(1,n):
if diff>abs(L[i]-L[i-1]):
diff=abs(L[i]-L[i-1])
ind1=i
ind2=i+1
print(ind1,ind2)
#carpe diem
#carpe diem
|
Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none
|
```python
#文字列入力はするな!!
#carpe diem
'''
██╗ ██╗ ███╗ ███╗ ██╗ ████████╗
██║ ██║ ████╗ ████║ ██║ ╚══██╔══╝
═════════██╠════════██╠═══██╔████╔██╠═══██╠══════██╠══════════
██║ ██║ ██║╚██╔╝██║ ██║ ██║
███████╗ ██║ ██║ ╚═╝ ██║ ██║ ██║
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
'''
#文字列入力はするな!!
#carpe diem
n=int(input())
L=list(map(int,input().split()))
diff=abs(L[0]-L[n-1])
ind1=1
ind2=n
for i in range(1,n):
if diff>abs(L[i]-L[i-1]):
diff=abs(L[i]-L[i-1])
ind1=i
ind2=i+1
print(ind1,ind2)
#carpe diem
#carpe diem
```
| 3.9615
|
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,674,658,425
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n = input()
l1= []
l2 = []
cnt = 0
for i in range(n):
x,y = map(int,raw_input().split())
l1.append(x)
l2.append(y)
for i in range(n):
for j in range(n):
if l1[i] == l2[j]:
cnt+=1
print cnt
|
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 = input()
l1= []
l2 = []
cnt = 0
for i in range(n):
x,y = map(int,raw_input().split())
l1.append(x)
l2.append(y)
for i in range(n):
for j in range(n):
if l1[i] == l2[j]:
cnt+=1
print cnt
```
| -1
|
|
306
|
A
|
Candies
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible.
For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one.
|
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
|
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
|
[
"12 3\n",
"15 4\n",
"18 7\n"
] |
[
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] |
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
| 500
|
[
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 "
},
{
"input": "100 100",
"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 10",
"output": "10 10 10 10 10 10 10 10 10 10 "
},
{
"input": "64 8",
"output": "8 8 8 8 8 8 8 8 "
},
{
"input": "81 27",
"output": "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 99",
"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 2 "
},
{
"input": "100 51",
"output": "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 2 2 2 "
},
{
"input": "100 49",
"output": "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 2 3 3 "
},
{
"input": "100 13",
"output": "7 7 7 7 8 8 8 8 8 8 8 8 8 "
},
{
"input": "97 11",
"output": "8 8 9 9 9 9 9 9 9 9 9 "
},
{
"input": "19 3",
"output": "6 6 7 "
},
{
"input": "99 10",
"output": "9 10 10 10 10 10 10 10 10 10 "
},
{
"input": "88 5",
"output": "17 17 18 18 18 "
},
{
"input": "87 34",
"output": "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 "
},
{
"input": "97 55",
"output": "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 "
}
] | 1,644,058,511
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 92
| 0
|
n,m=map(int,input().split())
k=n%m
for i in range(1,k+1):
print(((n-k)//m)+1,end=' ')
for i in range(1,(m-k)+1):
print((n-k)//m,end=' ')
|
Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *i*-th friend's present, that the maximum *a**i* differs from the least *a**i* as little as possible.
For example, if *n* is divisible by *m*, then he is going to present the same number of candies to all his friends, that is, the maximum *a**i* won't differ from the minimum one.
Input Specification:
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Output Specification:
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
Demo Input:
['12 3\n', '15 4\n', '18 7\n']
Demo Output:
['4 4 4 ', '3 4 4 4 ', '2 2 2 3 3 3 3 ']
Note:
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
|
```python
n,m=map(int,input().split())
k=n%m
for i in range(1,k+1):
print(((n-k)//m)+1,end=' ')
for i in range(1,(m-k)+1):
print((n-k)//m,end=' ')
```
| 3
|
|
660
|
C
|
Hard Process
|
PROGRAMMING
| 1,600
|
[
"binary search",
"dp",
"two pointers"
] | null | null |
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*).
|
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*.
|
On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them.
|
[
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] |
[
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] |
none
| 0
|
[
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"output": "1\n0 1 0 0 0 1 0"
},
{
"input": "7 2\n1 0 1 1 0 0 0",
"output": "5\n1 1 1 1 1 0 0"
},
{
"input": "7 3\n1 0 0 0 0 1 0",
"output": "4\n1 1 1 1 0 1 0"
},
{
"input": "3 0\n1 1 1",
"output": "3\n1 1 1"
},
{
"input": "1 0\n1",
"output": "1\n1"
},
{
"input": "2 0\n0 1",
"output": "1\n0 1"
},
{
"input": "1 1\n0",
"output": "1\n1"
},
{
"input": "3 1\n0 0 1",
"output": "2\n0 1 1"
},
{
"input": "2 0\n0 0",
"output": "0\n0 0"
},
{
"input": "3 1\n0 0 0",
"output": "1\n1 0 0"
},
{
"input": "7 7\n1 0 1 0 0 0 0",
"output": "7\n1 1 1 1 1 1 1"
},
{
"input": "1 1\n1",
"output": "1\n1"
},
{
"input": "3 0\n0 0 0",
"output": "0\n0 0 0"
},
{
"input": "7 3\n1 1 1 1 1 1 1",
"output": "7\n1 1 1 1 1 1 1"
},
{
"input": "10 3\n0 0 1 0 0 1 0 0 1 1",
"output": "6\n0 0 1 0 1 1 1 1 1 1"
},
{
"input": "2 1\n0 0",
"output": "1\n1 0"
},
{
"input": "2 2\n1 0",
"output": "2\n1 1"
}
] | 1,692,166,295
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
n, k = map(int, input().split())
a = list (map(int, input().split()))
left = 0
zeros = 0
max_length = 0
max_left = 0
for right in range(n):
if a[right] == 0:
zeros += 1
while zeros > k:
if a[left] == 0:
zeros -= 1
left += 1
if right - left + 1 > max_length:
max_length= right - left + 1
max_left = left
for i in range (max_left, max_left max_length):
a[i] = 1
print(max_length)
print (*a)
|
Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*).
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*.
Output Specification:
On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them.
Demo Input:
['7 1\n1 0 0 1 1 0 1\n', '10 2\n1 0 0 1 0 1 0 1 0 1\n']
Demo Output:
['4\n1 0 0 1 1 1 1\n', '5\n1 0 0 1 1 1 1 1 0 1\n']
Note:
none
|
```python
n, k = map(int, input().split())
a = list (map(int, input().split()))
left = 0
zeros = 0
max_length = 0
max_left = 0
for right in range(n):
if a[right] == 0:
zeros += 1
while zeros > k:
if a[left] == 0:
zeros -= 1
left += 1
if right - left + 1 > max_length:
max_length= right - left + 1
max_left = left
for i in range (max_left, max_left max_length):
a[i] = 1
print(max_length)
print (*a)
```
| -1
|
|
805
|
B
|
3-palindrome
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms"
] | null | null |
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
|
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
|
[
"2\n",
"3\n"
] |
[
"aa\n",
"bba\n"
] |
A palindrome is a sequence of characters which reads the same backward and forward.
| 1,000
|
[
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "67",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "77",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "89",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "98",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "109",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "117",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "1",
"output": "a"
},
{
"input": "200000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "100000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "143670",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "104217",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "17879",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "131809",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "140873",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "77859",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "153022",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "179227",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "182801",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "5188",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "86539",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "12802",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "120289",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "132866",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "133377",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "31775",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "160397",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "161415",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "163623",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "22942",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "134767",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "52257",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "64905",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "183758",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "60131",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "146883",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "6",
"output": "aabbaa"
},
{
"input": "4",
"output": "aabb"
}
] | 1,647,052,708
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 30
| 0
|
x = int(input())
s = ""
if x%2==0:
for i in range((x/2)-1):
s+="ab"
s+="bb"
else:
for i in range((x-1)/2):
s+="ab"
s+="b"
print(s)
|
Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Output Specification:
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['aa\n', 'bba\n']
Note:
A palindrome is a sequence of characters which reads the same backward and forward.
|
```python
x = int(input())
s = ""
if x%2==0:
for i in range((x/2)-1):
s+="ab"
s+="bb"
else:
for i in range((x-1)/2):
s+="ab"
s+="b"
print(s)
```
| -1
|
|
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,672,318,741
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 48
| 46
| 0
|
x=sorted(list(map(int,input().split())))
print(abs(x[1]-x[0])+abs(x[1]-x[2]))
|
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
x=sorted(list(map(int,input().split())))
print(abs(x[1]-x[0])+abs(x[1]-x[2]))
```
| 3
|
|
424
|
A
|
Squats
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
|
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
|
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
|
[
"4\nxxXx\n",
"2\nXX\n",
"6\nxXXxXx\n"
] |
[
"1\nXxXx\n",
"1\nxX\n",
"0\nxXXxXx\n"
] |
none
| 500
|
[
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "2\nXX",
"output": "1\nxX"
},
{
"input": "6\nxXXxXx",
"output": "0\nxXXxXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "22\nXXxXXxxXxXxXXXXXXXXXxx",
"output": "4\nxxxxxxxXxXxXXXXXXXXXxx"
},
{
"input": "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx",
"output": "0\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx"
},
{
"input": "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX",
"output": "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX"
},
{
"input": "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX",
"output": "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX"
},
{
"input": "200\nxxXXxxXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX",
"output": "4\nXXXXXXXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX"
},
{
"input": "198\nxXxxXxxXxxXXxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx",
"output": "5\nxxxxxxxxxxxxxXxXxXxxXXXxxXxxxxXXXXxxXxxxxXXXXxXxXXxxxXXXXXXXxXXXxxxxXXxXXxXxXXxxxxXxXXXXXXxXxxXxXxxxXxXXXXxxXXxxXxxxXXxXxXXxXxXXxXXXXxxxxxXxXXxxxXxXXXXxXxXXxxXxXXxXxXXxxxXxXXXXxXxxXxXXXxxxxXxXXXXxXx"
},
{
"input": "200\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "198\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "99\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "200\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"output": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
{
"input": "198\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"output": "99\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
{
"input": "2\nxx",
"output": "1\nXx"
},
{
"input": "2\nXx",
"output": "0\nXx"
},
{
"input": "2\nxX",
"output": "0\nxX"
},
{
"input": "4\nXXXX",
"output": "2\nxxXX"
},
{
"input": "4\nxxxx",
"output": "2\nXXxx"
},
{
"input": "4\nxxXX",
"output": "0\nxxXX"
},
{
"input": "4\nXXxx",
"output": "0\nXXxx"
},
{
"input": "4\nxXxx",
"output": "1\nXXxx"
},
{
"input": "4\nXxxx",
"output": "1\nXXxx"
},
{
"input": "4\nxxxX",
"output": "1\nXxxX"
},
{
"input": "4\nxxXx",
"output": "1\nXxXx"
},
{
"input": "4\nXXXx",
"output": "1\nxXXx"
},
{
"input": "4\nxXXX",
"output": "1\nxxXX"
},
{
"input": "4\nXxXX",
"output": "1\nxxXX"
},
{
"input": "4\nXXxX",
"output": "1\nxXxX"
},
{
"input": "4\nXxXx",
"output": "0\nXxXx"
},
{
"input": "6\nxXXxXX",
"output": "1\nxxXxXX"
}
] | 1,553,592,749
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 32
| 124
| 0
|
n=input()
n=int(n)
y=input()
x_s=0
x_c=0
b=""
for i in range(n):
if y[i]=='x':
x_s+=1
else:
x_c+=1
if x_s==x_c:
print(0)
for i in y:
print(i ,end="")
if x_s>x_c:
u=n/2-x_c
o=n/2-x_c
while u>0:
for i in range(n):
if y[i]=='x' and not u<1:
b+='X'
u -= 1
else:
b+=y[i]
print(int(o))
for i in b:
print(i, end="")
if x_s<x_c:
u=n/2-x_s
o = n / 2 - x_s
while u>0:
for i in range(n):
if y[i]=='X' and not u<1:
b+='x'
u-=1
else:
b+=y[i]
print(int(o))
for i in b:
print(i, end="")
|
Title: Squats
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting.
Output Specification:
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
Demo Input:
['4\nxxXx\n', '2\nXX\n', '6\nxXXxXx\n']
Demo Output:
['1\nXxXx\n', '1\nxX\n', '0\nxXXxXx\n']
Note:
none
|
```python
n=input()
n=int(n)
y=input()
x_s=0
x_c=0
b=""
for i in range(n):
if y[i]=='x':
x_s+=1
else:
x_c+=1
if x_s==x_c:
print(0)
for i in y:
print(i ,end="")
if x_s>x_c:
u=n/2-x_c
o=n/2-x_c
while u>0:
for i in range(n):
if y[i]=='x' and not u<1:
b+='X'
u -= 1
else:
b+=y[i]
print(int(o))
for i in b:
print(i, end="")
if x_s<x_c:
u=n/2-x_s
o = n / 2 - x_s
while u>0:
for i in range(n):
if y[i]=='X' and not u<1:
b+='x'
u-=1
else:
b+=y[i]
print(int(o))
for i in b:
print(i, end="")
```
| 3
|
|
447
|
B
|
DZY Loves Strings
|
PROGRAMMING
| 1,000
|
[
"greedy",
"implementation"
] | null | null |
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
|
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
|
Print a single integer — the largest possible value of the resulting string DZY could get.
|
[
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] |
[
"41\n"
] |
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
| 1,000
|
[
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314",
"output": "1762894"
},
{
"input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585",
"output": "2960349"
},
{
"input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933",
"output": "99140444"
},
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686",
"output": "301124161"
},
{
"input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495",
"output": "30125295"
},
{
"input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165",
"output": "136422"
},
{
"input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348",
"output": "2578628"
},
{
"input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338",
"output": "9168707"
},
{
"input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657",
"output": "144901921"
},
{
"input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860",
"output": "809931"
},
{
"input": "a\n0\n5 1 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": "5"
},
{
"input": "lol\n3\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",
"output": "21"
}
] | 1,635,517,016
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 24
| 77
| 28,979,200
|
s=list(input())
k=int(input())
a=list(map(int,input().split()))
m=max(a)
c=0
for i in range(len(s)):
c+=a[ord(s[i])-97]*(i+1)
#print(c)
for i in range(len(s)+1,len(s)+k+1,1):
c+=m*i
print(c)
|
Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input Specification:
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Output Specification:
Print a single integer — the largest possible value of the resulting string DZY could get.
Demo Input:
['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n']
Demo Output:
['41\n']
Note:
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
```python
s=list(input())
k=int(input())
a=list(map(int,input().split()))
m=max(a)
c=0
for i in range(len(s)):
c+=a[ord(s[i])-97]*(i+1)
#print(c)
for i in range(len(s)+1,len(s)+k+1,1):
c+=m*i
print(c)
```
| 3
|
|
366
|
B
|
Dima and To-do List
|
PROGRAMMING
| 1,200
|
[
"brute force",
"implementation"
] | null | null |
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
|
The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*.
|
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
|
[
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] |
[
"1\n",
"3\n"
] |
Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
| 1,000
|
[
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "4 2\n2 1 1 3",
"output": "1"
},
{
"input": "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 4 5",
"output": "1"
},
{
"input": "20 10\n3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 6 4",
"output": "1"
}
] | 1,612,967,355
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 36
| 139
| 6,656,000
|
def todo_list(end, k, arr):
count = 0
start = 0
result = 100000*1000000
while count != k:
b = 0
for x in range(start, end, k):
b += arr[x]
if b < result:
result = b
ans = start+1
start += 1
count += 1
return ans
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(todo_list(n, k, arr))
|
Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
Input Specification:
The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*.
Output Specification:
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
Demo Input:
['6 2\n3 2 1 6 5 4\n', '10 5\n1 3 5 7 9 9 4 1 8 5\n']
Demo Output:
['1\n', '3\n']
Note:
Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
|
```python
def todo_list(end, k, arr):
count = 0
start = 0
result = 100000*1000000
while count != k:
b = 0
for x in range(start, end, k):
b += arr[x]
if b < result:
result = b
ans = start+1
start += 1
count += 1
return ans
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(todo_list(n, k, arr))
```
| 3
|
|
592
|
A
|
PawnChess
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
|
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
|
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
|
[
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] |
[
"A\n",
"B\n"
] |
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
| 500
|
[
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n........\n...BB.B.\nW.WWWW.W",
"output": "A"
},
{
"input": "BB......\nW....BBW\n........\n.B.B.BBB\n....BB..\nB....BB.\n...WWWW.\n....WW..",
"output": "A"
},
{
"input": ".B.B..B.\nB.B....B\n...B.B.B\n..B.W..B\n.BBB.B.B\nB.BB.B.B\nBB..BBBB\nW.W.W.WW",
"output": "B"
},
{
"input": "..BB....\n.B.B.B.B\n..B.B...\n..B..B.B\nWWWBWWB.\n.BB...B.\n..BBB...\n......W.",
"output": "B"
},
{
"input": "..BB....\n.WBWBWBB\n.....BBB\n..WW....\n.W.W...W\nWWW...W.\n.W....W.\nW...W.W.",
"output": "A"
},
{
"input": "....BB..\nBB......\n.B.....B\nWW..WWW.\n...BB.B.\nB...BB..\n..W..WWW\n...W...W",
"output": "B"
},
{
"input": "B...BBBB\n...BBB..\nBBWBWW.W\n.B..BB.B\nW..W..WW\nW.WW....\n........\nWW.....W",
"output": "A"
},
{
"input": ".B......\n.B....B.\n...W....\n......W.\nW.WWWW.W\nW.WW....\n..WWW...\n..W...WW",
"output": "A"
},
{
"input": "B.......\nBBB.....\n.B....B.\n.W.BWB.W\n......B.\nW..WW...\n...W....\nW...W..W",
"output": "A"
},
{
"input": ".....B..\n........\n........\n.BB..B..\n..BB....\n........\n....WWW.\n......W.",
"output": "B"
},
{
"input": "B.B...B.\n...BBBBB\n....B...\n...B...B\nB.B.B..B\n........\n........\nWWW..WW.",
"output": "B"
},
{
"input": "B.B...B.\n........\n.......B\n.BB....B\n.....W..\n.W.WW.W.\n...W.WW.\nW..WW..W",
"output": "A"
},
{
"input": "......B.\nB....B..\n...B.BB.\n...B....\n........\n..W....W\nWW......\n.W....W.",
"output": "B"
},
{
"input": ".BBB....\nB.B.B...\nB.BB.B..\nB.BB.B.B\n........\n........\nW.....W.\n..WW..W.",
"output": "B"
},
{
"input": "..B..BBB\n........\n........\n........\n...W.W..\n...W..W.\nW.......\n..W...W.",
"output": "A"
},
{
"input": "........\n.B.B....\n...B..BB\n........\n........\nW...W...\nW...W...\nW.WW.W..",
"output": "A"
},
{
"input": "B....BB.\n...B...B\n.B......\n........\n........\n........\n........\n....W..W",
"output": "B"
},
{
"input": "...BB.BB\nBB...B..\n........\n........\n........\n........\n..W..W..\n......W.",
"output": "A"
},
{
"input": "...BB...\n........\n........\n........\n........\n........\n......W.\nWW...WW.",
"output": "A"
},
{
"input": "...B.B..\n........\n........\n........\n........\n........\n........\nWWW...WW",
"output": "A"
},
{
"input": "BBBBBBB.\n........\n........\n........\n........\n........\n........\n.WWWWWWW",
"output": "A"
},
{
"input": ".BBBBBB.\nB.......\n........\n........\n........\n........\n........\n.WWWWWWW",
"output": "B"
},
{
"input": ".BBBBBBB\n........\n........\n........\n........\n........\n........\nWWWWWWW.",
"output": "A"
},
{
"input": ".BBBBBB.\n.......B\n........\n........\n........\n........\n........\nWWWWWWW.",
"output": "B"
},
{
"input": "B..BB...\n..B...B.\n.WBB...B\nBW......\nW.B...W.\n..BBW.B.\nBW..BB..\n......W.",
"output": "B"
},
{
"input": "B.BBBBBB\nB..BBB.B\nW.BB.W.B\nB.BWBB.B\nBWBWBBBB\n...BBBBB\nB.B...BB\nWW..WW.W",
"output": "B"
},
{
"input": "BBBB.BBB\nBBBB.B.B\nB.B..BBB\nB.BB.BWW\nB.BB.BBB\nB.BB.BBB\n..BW.BB.\nW.WWWWWW",
"output": "B"
},
{
"input": "BBBB.BBB\n.B....WB\nBB.B...B\nWWWW.WWB\nBB...BWW\nWWW..BBB\nW.BW.BB.\nWWWWWWW.",
"output": "B"
},
{
"input": "B.BBBBBB\nW.WWBBBW\nW.BB.WBB\nW.W.BBBW\nW.BWW.WB\nB..B..BB\nB.B.W.BB\nWWWWW.WW",
"output": "B"
},
{
"input": "BBBBBB.B\n.BBWBB.B\nWWW..B.W\n..WW.W.W\nBWB..W.W\n..BW.B.W\nB..B....\nWWWW.WWW",
"output": "B"
},
{
"input": ".B...BB.\nWBB.BWBB\n.BWBW...\n..W...B.\nWB.BWW..\nWBW.....\n.W..W.B.\n.W.W.WW.",
"output": "A"
},
{
"input": ".B..BBBB\nBB...WWB\nB..B.W.B\nWB.W...B\n...W.WW.\nW.....W.\nWB.W.W.W\n.WW...WW",
"output": "A"
},
{
"input": "B.BBBBBB\nW.BB.W.B\nW.BBW...\n..WWWW.B\n....W..B\n.WW.W..W\n.W..WW.W\nW.W....W",
"output": "A"
},
{
"input": "........\n.B......\n.W......\n........\n....B...\n........\n........\n.......W",
"output": "B"
}
] | 1,491,234,233
| 713
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 46
| 5,529,600
|
#!/bin/python3
import sys
b = []
for i in range(8):
b.append(list(input()));
ans1 = 8;
ans2 = 8;
for j in range(8):
for i in range(8):
if b[i][j] == 'B':
break;
if b[i][j] == 'W':
ans1 = min(i,ans1)
for j in range(8):
for i in range(7, -1, -1):
if b[i][j] == 'W':
break;
if b[i][j] == 'B':
ans2 = min( 8 - i - 1, ans2)
if ans1 < ans2 :
print("A")
else:
print("B")
|
Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
Input Specification:
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
Output Specification:
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
Demo Input:
['........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n', '..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n']
Demo Output:
['A\n', 'B\n']
Note:
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
|
```python
#!/bin/python3
import sys
b = []
for i in range(8):
b.append(list(input()));
ans1 = 8;
ans2 = 8;
for j in range(8):
for i in range(8):
if b[i][j] == 'B':
break;
if b[i][j] == 'W':
ans1 = min(i,ans1)
for j in range(8):
for i in range(7, -1, -1):
if b[i][j] == 'W':
break;
if b[i][j] == 'B':
ans2 = min( 8 - i - 1, ans2)
if ans1 < ans2 :
print("A")
else:
print("B")
```
| 0
|
|
660
|
A
|
Co-prime Array
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation",
"math",
"number theory"
] | null | null |
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
|
Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
If there are multiple answers you can print any one of them.
|
[
"3\n2 7 28\n"
] |
[
"1\n2 7 9 28\n"
] |
none
| 0
|
[
{
"input": "3\n2 7 28",
"output": "1\n2 7 1 28"
},
{
"input": "1\n1",
"output": "0\n1"
},
{
"input": "1\n548",
"output": "0\n548"
},
{
"input": "1\n963837006",
"output": "0\n963837006"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0\n1 1 1 1 1 1 1 1 1 1"
},
{
"input": "10\n26 723 970 13 422 968 875 329 234 983",
"output": "2\n26 723 970 13 422 1 968 875 1 329 234 983"
},
{
"input": "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396",
"output": "7\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396"
},
{
"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": "19\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1"
},
{
"input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917",
"output": "38\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917"
},
{
"input": "5\n472882027 472882027 472882027 472882027 472882027",
"output": "4\n472882027 1 472882027 1 472882027 1 472882027 1 472882027"
},
{
"input": "2\n1000000000 1000000000",
"output": "1\n1000000000 1 1000000000"
},
{
"input": "2\n8 6",
"output": "1\n8 1 6"
},
{
"input": "3\n100000000 1000000000 1000000000",
"output": "2\n100000000 1 1000000000 1 1000000000"
},
{
"input": "5\n1 2 3 4 5",
"output": "0\n1 2 3 4 5"
},
{
"input": "20\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000",
"output": "19\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000"
},
{
"input": "2\n223092870 23",
"output": "1\n223092870 1 23"
},
{
"input": "2\n100000003 100000003",
"output": "1\n100000003 1 100000003"
},
{
"input": "2\n999999937 999999937",
"output": "1\n999999937 1 999999937"
},
{
"input": "4\n999 999999937 999999937 999",
"output": "1\n999 999999937 1 999999937 999"
},
{
"input": "2\n999999929 999999929",
"output": "1\n999999929 1 999999929"
},
{
"input": "2\n1049459 2098918",
"output": "1\n1049459 1 2098918"
},
{
"input": "2\n352229 704458",
"output": "1\n352229 1 704458"
},
{
"input": "2\n7293 4011",
"output": "1\n7293 1 4011"
},
{
"input": "2\n5565651 3999930",
"output": "1\n5565651 1 3999930"
},
{
"input": "2\n997 997",
"output": "1\n997 1 997"
},
{
"input": "3\n9994223 9994223 9994223",
"output": "2\n9994223 1 9994223 1 9994223"
},
{
"input": "2\n99999998 1000000000",
"output": "1\n99999998 1 1000000000"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "2\n1000000000 1 1000000000 1 1000000000"
},
{
"input": "2\n130471 130471",
"output": "1\n130471 1 130471"
},
{
"input": "3\n1000000000 2 2",
"output": "2\n1000000000 1 2 1 2"
},
{
"input": "2\n223092870 66526",
"output": "1\n223092870 1 66526"
},
{
"input": "14\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449",
"output": "10\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449"
},
{
"input": "2\n3996017 3996017",
"output": "1\n3996017 1 3996017"
},
{
"input": "2\n999983 999983",
"output": "1\n999983 1 999983"
},
{
"input": "2\n618575685 773990454",
"output": "1\n618575685 1 773990454"
},
{
"input": "3\n9699690 3 7",
"output": "1\n9699690 1 3 7"
},
{
"input": "2\n999999999 999999996",
"output": "1\n999999999 1 999999996"
},
{
"input": "2\n99999910 99999910",
"output": "1\n99999910 1 99999910"
},
{
"input": "12\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491",
"output": "9\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491"
},
{
"input": "3\n999999937 999999937 999999937",
"output": "2\n999999937 1 999999937 1 999999937"
},
{
"input": "2\n99839 99839",
"output": "1\n99839 1 99839"
},
{
"input": "3\n19999909 19999909 19999909",
"output": "2\n19999909 1 19999909 1 19999909"
},
{
"input": "4\n1 1000000000 1 1000000000",
"output": "0\n1 1000000000 1 1000000000"
},
{
"input": "2\n64006 64006",
"output": "1\n64006 1 64006"
},
{
"input": "2\n1956955 1956955",
"output": "1\n1956955 1 1956955"
},
{
"input": "3\n1 1000000000 1000000000",
"output": "1\n1 1000000000 1 1000000000"
},
{
"input": "2\n982451707 982451707",
"output": "1\n982451707 1 982451707"
},
{
"input": "2\n999999733 999999733",
"output": "1\n999999733 1 999999733"
},
{
"input": "3\n999999733 999999733 999999733",
"output": "2\n999999733 1 999999733 1 999999733"
},
{
"input": "2\n3257 3257",
"output": "1\n3257 1 3257"
},
{
"input": "2\n223092870 181598",
"output": "1\n223092870 1 181598"
},
{
"input": "3\n959919409 105935 105935",
"output": "2\n959919409 1 105935 1 105935"
},
{
"input": "2\n510510 510510",
"output": "1\n510510 1 510510"
},
{
"input": "3\n223092870 1000000000 1000000000",
"output": "2\n223092870 1 1000000000 1 1000000000"
},
{
"input": "14\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000",
"output": "11\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000"
},
{
"input": "7\n1 982451653 982451653 1 982451653 982451653 982451653",
"output": "3\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653"
},
{
"input": "2\n100000007 100000007",
"output": "1\n100000007 1 100000007"
},
{
"input": "3\n999999757 999999757 999999757",
"output": "2\n999999757 1 999999757 1 999999757"
},
{
"input": "3\n99999989 99999989 99999989",
"output": "2\n99999989 1 99999989 1 99999989"
},
{
"input": "5\n2 4 982451707 982451707 3",
"output": "2\n2 1 4 982451707 1 982451707 3"
},
{
"input": "2\n20000014 20000014",
"output": "1\n20000014 1 20000014"
},
{
"input": "2\n99999989 99999989",
"output": "1\n99999989 1 99999989"
},
{
"input": "2\n111546435 111546435",
"output": "1\n111546435 1 111546435"
},
{
"input": "2\n55288874 33538046",
"output": "1\n55288874 1 33538046"
},
{
"input": "5\n179424673 179424673 179424673 179424673 179424673",
"output": "4\n179424673 1 179424673 1 179424673 1 179424673 1 179424673"
},
{
"input": "2\n199999978 199999978",
"output": "1\n199999978 1 199999978"
},
{
"input": "2\n1000000000 2",
"output": "1\n1000000000 1 2"
},
{
"input": "3\n19999897 19999897 19999897",
"output": "2\n19999897 1 19999897 1 19999897"
},
{
"input": "2\n19999982 19999982",
"output": "1\n19999982 1 19999982"
},
{
"input": "2\n10000007 10000007",
"output": "1\n10000007 1 10000007"
},
{
"input": "3\n999999937 999999937 2",
"output": "1\n999999937 1 999999937 2"
},
{
"input": "5\n2017 2017 2017 2017 2017",
"output": "4\n2017 1 2017 1 2017 1 2017 1 2017"
},
{
"input": "2\n19999909 39999818",
"output": "1\n19999909 1 39999818"
},
{
"input": "2\n62615533 7919",
"output": "1\n62615533 1 7919"
},
{
"input": "5\n39989 39989 33 31 29",
"output": "1\n39989 1 39989 33 31 29"
},
{
"input": "2\n1000000000 100000",
"output": "1\n1000000000 1 100000"
},
{
"input": "2\n1938 10010",
"output": "1\n1938 1 10010"
},
{
"input": "2\n199999 199999",
"output": "1\n199999 1 199999"
},
{
"input": "2\n107273 107273",
"output": "1\n107273 1 107273"
},
{
"input": "3\n49999 49999 49999",
"output": "2\n49999 1 49999 1 49999"
},
{
"input": "2\n1999966 1999958",
"output": "1\n1999966 1 1999958"
},
{
"input": "2\n86020 300846",
"output": "1\n86020 1 300846"
},
{
"input": "2\n999999997 213",
"output": "1\n999999997 1 213"
},
{
"input": "2\n200000014 200000434",
"output": "1\n200000014 1 200000434"
}
] | 1,677,703,316
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 9
| 93
| 9,523,200
|
def gcd(a, b):
if (a == 0 or b == 0): return 0
if (a == b): return a
if (a > b):
return gcd(a - b, b)
return gcd(a, b - a)
n = int(input())
nums = list(map(int, input().split()))
res = [nums[0]]
for i in range(1, n):
if gcd(nums[i], res[-1]) > 1:
res.append(1)
res.append(nums[i])
print(len(res) - n)
print(" ".join(str(e) for e in res))
|
Title: Co-prime Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Output Specification:
Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
If there are multiple answers you can print any one of them.
Demo Input:
['3\n2 7 28\n']
Demo Output:
['1\n2 7 9 28\n']
Note:
none
|
```python
def gcd(a, b):
if (a == 0 or b == 0): return 0
if (a == b): return a
if (a > b):
return gcd(a - b, b)
return gcd(a, b - a)
n = int(input())
nums = list(map(int, input().split()))
res = [nums[0]]
for i in range(1, n):
if gcd(nums[i], res[-1]) > 1:
res.append(1)
res.append(nums[i])
print(len(res) - n)
print(" ".join(str(e) for e in res))
```
| -1
|
|
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,696,539,491
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 46
| 0
|
n = int(input())
x = list(map(int, input().split()))
x.sort()
for i in range(n):
print(x[i], end=' ')
|
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())
x = list(map(int, input().split()))
x.sort()
for i in range(n):
print(x[i], end=' ')
```
| 3
|
|
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,572,280
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 2
| 62
| 0
|
n,k = map(int,input().split())
grades = list(map(int,input().split()))
Promotion_quota = k
# "as long as the contestant earns a positive score"
if grades[k-1] <= 0:
print(0)
else:
# take in mind if last advance contestant is the same with the first failling contestant, we make more room for advanced quota.
for x in range(n):
if grades[k+x-1] == grades [k+x]:
Promotion_quota += 1
else:
break
print(Promotion_quota)
|
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())
grades = list(map(int,input().split()))
Promotion_quota = k
# "as long as the contestant earns a positive score"
if grades[k-1] <= 0:
print(0)
else:
# take in mind if last advance contestant is the same with the first failling contestant, we make more room for advanced quota.
for x in range(n):
if grades[k+x-1] == grades [k+x]:
Promotion_quota += 1
else:
break
print(Promotion_quota)
```
| -1
|
|
61
|
A
|
Ultra-Fast Mathematician
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Ultra-Fast Mathematician
|
2
|
256
|
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
|
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
|
Write one line — the corresponding answer. Do not omit the leading 0s.
|
[
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] |
[
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] |
none
| 500
|
[
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,690,619,032
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 46
| 0
|
s=input()
z=input()
x=""
for i in range(len(s)):
if s[i]!=z[i]:
x+="1"
continue
x+="0"
print(x)
|
Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none
|
```python
s=input()
z=input()
x=""
for i in range(len(s)):
if s[i]!=z[i]:
x+="1"
continue
x+="0"
print(x)
```
| 3.9885
|
688
|
A
|
Opponents
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
|
The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day.
|
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.
|
[
"2 2\n10\n00\n",
"4 1\n0100\n",
"4 5\n1101\n1111\n0110\n1011\n1111\n"
] |
[
"2\n",
"1\n",
"2\n"
] |
In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
| 500
|
[
{
"input": "2 2\n10\n00",
"output": "2"
},
{
"input": "4 1\n0100",
"output": "1"
},
{
"input": "4 5\n1101\n1111\n0110\n1011\n1111",
"output": "2"
},
{
"input": "3 2\n110\n110",
"output": "2"
},
{
"input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111",
"output": "1"
},
{
"input": "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111",
"output": "1"
},
{
"input": "10 10\n0000100011\n0100001111\n1111111111\n1100011111\n1111111111\n1000111000\n1111000010\n0111001001\n1101010110\n1111111111",
"output": "4"
},
{
"input": "10 10\n1100110010\n0000000001\n1011100111\n1111111111\n1111111111\n1111111111\n1100010110\n1111111111\n1001001010\n1111111111",
"output": "3"
},
{
"input": "10 7\n0000111001\n1111111111\n0110110001\n1111111111\n1111111111\n1000111100\n0110000111",
"output": "2"
},
{
"input": "5 10\n00110\n11000\n10010\n00010\n11110\n01101\n11111\n10001\n11111\n01001",
"output": "6"
},
{
"input": "5 9\n11111\n11101\n11111\n11111\n01010\n01010\n00000\n11111\n00111",
"output": "3"
},
{
"input": "5 10\n11111\n00010\n11010\n11111\n11111\n00100\n11111\n11111\n01000\n11111",
"output": "2"
},
{
"input": "5 9\n11111\n11111\n11111\n11111\n11100\n11111\n11111\n11111\n00000",
"output": "1"
},
{
"input": "5 8\n11111\n10110\n01001\n11111\n01100\n10010\n11111\n11111",
"output": "2"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "100 1\n0011001100100010000011001100000001011101110110010001110001101100110011111101001011011001000010001111",
"output": "1"
},
{
"input": "100 1\n1011011100000101000111110000110111010101110010010011110010001110100011001110110101111100100110000000",
"output": "1"
},
{
"input": "100 1\n1110000011110101010111111100011001100000101101010110100101110000011100110110110101011100110110010011",
"output": "1"
},
{
"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "0"
},
{
"input": "1 100\n1\n0\n0\n0\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n0\n0",
"output": "6"
},
{
"input": "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "49"
},
{
"input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "0"
},
{
"input": "1 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "100"
},
{
"input": "2 2\n11\n10",
"output": "1"
},
{
"input": "1 1\n0",
"output": "1"
}
] | 1,684,669,312
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 56
| 46
| 0
|
n,d = map(int,input().split())
present = []
for i in range(d):
a = list(map(int,input().strip()))
present.append(a)
maxi = 0
count = 0
for i in range(d):
if 0 in present[i]:
count += 1
maxi = max(maxi,count)
else:
count = 0
print(maxi)
|
Title: Opponents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input Specification:
The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively.
The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day.
Output Specification:
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.
Demo Input:
['2 2\n10\n00\n', '4 1\n0100\n', '4 5\n1101\n1111\n0110\n1011\n1111\n']
Demo Output:
['2\n', '1\n', '2\n']
Note:
In the first and the second samples, Arya will beat all present opponents each of the *d* days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
|
```python
n,d = map(int,input().split())
present = []
for i in range(d):
a = list(map(int,input().strip()))
present.append(a)
maxi = 0
count = 0
for i in range(d):
if 0 in present[i]:
count += 1
maxi = max(maxi,count)
else:
count = 0
print(maxi)
```
| 3
|
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
|
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
|
Write the needed number of flagstones.
|
[
"6 6 4\n"
] |
[
"4\n"
] |
none
| 0
|
[
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,690,846,110
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 0
|
import math
def dimentions_are(m,n,a):
return math.ceil(m/a) * math.ceil(n/a)
if (1) :
m=int(input())
n=int(input())
a=int(input())
print(dimentions_are(m,n,a))
|
Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none
|
```python
import math
def dimentions_are(m,n,a):
return math.ceil(m/a) * math.ceil(n/a)
if (1) :
m=int(input())
n=int(input())
a=int(input())
print(dimentions_are(m,n,a))
```
| -1
|
500
|
A
|
New Year Transportation
|
PROGRAMMING
| 1,000
|
[
"dfs and similar",
"graphs",
"implementation"
] | null | null |
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
|
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
|
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
|
[
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] |
[
"YES\n",
"NO\n"
] |
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
| 500
|
[
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,653,888,959
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 46
| 1,433,600
|
n, t = [*map(int,input().split())]
portal = [*map(int,input().split())]
position,i = 1, 0
ans = "NO"
while i < n:
position += portal[i]
i += portal[i]
if position == t:
ans = "YES"
break
elif position > t:
break
print(ans)
|
Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
|
```python
n, t = [*map(int,input().split())]
portal = [*map(int,input().split())]
position,i = 1, 0
ans = "NO"
while i < n:
position += portal[i]
i += portal[i]
if position == t:
ans = "YES"
break
elif position > t:
break
print(ans)
```
| 3
|
|
670
|
D1
|
Magic Powder - 1
|
PROGRAMMING
| 1,400
|
[
"binary search",
"brute force",
"implementation"
] | null | null |
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs *n* ingredients, and for each ingredient she knows the value *a**i* — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all *n* ingredients.
Apollinaria has *b**i* gram of the *i*-th ingredient. Also she has *k* grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the *n* ingredients and can be used for baking cookies.
Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.
|
The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie.
The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has.
|
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
|
[
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] |
[
"4\n",
"3\n"
] |
In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
| 1,000
|
[
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 898 965 807 786 670 626 873 968 745 878 359 760 781 829 882 777 740 907 779",
"output": "150"
},
{
"input": "30 300\n1 4 2 1 2 5 6 4 1 3 2 1 1 1 1 1 2 3 1 3 4 2 2 3 2 2 2 1 1 1\n997 817 767 860 835 809 817 565 630 804 586 953 977 356 905 890 958 916 740 583 902 945 313 956 871 729 976 707 516 788",
"output": "164"
},
{
"input": "40 538\n1 3 3 1 4 1 1 1 1 5 3 3 4 1 4 2 7 1 4 1 1 2 2 1 1 1 1 4 1 4 2 3 3 3 1 3 4 1 3 5\n975 635 795 835 982 965 639 787 688 796 988 779 839 942 491 696 396 995 718 810 796 879 957 783 844 765 968 783 647 214 995 868 318 453 989 889 504 962 945 925",
"output": "104"
},
{
"input": "50 530\n2 3 3 1 1 1 3 4 4 2 4 2 5 1 3 1 2 6 1 1 2 5 3 2 1 5 1 3 3 2 1 1 1 1 2 1 1 2 2 1 4 2 1 3 1 2 1 1 4 2\n959 972 201 990 675 679 972 268 976 886 488 924 795 959 647 994 969 862 898 646 763 797 978 763 995 641 923 856 829 921 934 883 904 986 728 980 1000 775 716 745 833 832 999 651 571 626 827 456 636 795",
"output": "133"
},
{
"input": "60 735\n3 1 4 7 1 7 3 1 1 5 4 7 3 3 3 2 5 3 1 2 3 6 1 1 1 1 1 2 5 3 2 1 3 5 2 1 2 2 2 2 1 3 3 3 6 4 3 5 1 3 2 2 1 3 1 1 1 7 1 2\n596 968 975 493 665 571 598 834 948 941 737 649 923 848 950 907 929 865 227 836 956 796 861 801 746 667 539 807 405 355 501 879 994 890 573 848 597 873 130 985 924 426 999 550 586 924 601 807 994 878 410 817 922 898 982 525 611 685 806 847",
"output": "103"
},
{
"input": "1 1\n1\n1",
"output": "2"
},
{
"input": "70 130\n2 1 2 2 3 3 2 5 2 2 3 3 3 1 1 4 3 5 3 2 1 3 7 1 2 7 5 2 1 6 3 4 1 2 1 1 1 1 3 6 4 2 2 8 2 2 4 1 4 2 1 4 4 3 5 1 1 1 1 1 2 3 1 5 1 3 3 4 2 2\n473 311 758 768 797 572 656 898 991 534 989 702 934 767 777 799 1000 655 806 727 718 948 834 965 832 778 706 861 799 874 745 970 772 967 984 886 835 795 832 837 950 952 475 891 947 952 903 929 689 478 725 945 585 943 771 631 729 887 557 738 824 758 999 786 669 992 918 762 964 941",
"output": "119"
},
{
"input": "80 979\n2 1 1 1 2 1 1 1 3 1 4 4 2 1 1 3 1 1 2 1 4 1 1 2 5 4 8 1 3 6 5 7 2 3 4 1 2 2 6 1 2 2 4 1 1 2 3 2 8 1 1 3 3 4 1 1 2 1 4 4 1 4 3 2 6 5 2 1 4 1 2 3 2 1 3 3 1 2 1 3\n498 976 513 869 917 914 664 656 957 893 981 947 985 693 576 958 987 822 981 718 884 729 295 683 485 998 730 894 731 975 739 854 906 740 987 976 606 689 990 775 522 994 920 893 529 651 989 799 643 215 946 987 297 868 425 810 694 908 736 903 970 751 625 904 955 945 839 777 977 974 905 900 666 680 799 873 565 919 536 686",
"output": "128"
},
{
"input": "1 1000\n1000\n1000",
"output": "2"
},
{
"input": "1 1000\n1\n1000",
"output": "2000"
},
{
"input": "1 1\n4\n6",
"output": "1"
},
{
"input": "1 1\n10\n2",
"output": "0"
},
{
"input": "2 1\n2 2\n1 1",
"output": "0"
},
{
"input": "2 6\n1 3\n6 2",
"output": "2"
}
] | 1,686,078,339
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 119
| 77
| 1,945,600
|
def check(mid):
needed=0
#mid=5
# 1 2 3
# 4 8 6
for i in range (0,len(a)):
if(a[i]*mid>b[i]) :
needed+=((a[i]*mid)-b[i])
if needed > k:
return False
else:
return True
def bs():
left=0
right=10000000
while left<right:
mid=((left+right+1)//2)
if check(mid)==True:
left=mid
elif check(mid)==False:
right=mid-1
return right
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(bs())
|
Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs *n* ingredients, and for each ingredient she knows the value *a**i* — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all *n* ingredients.
Apollinaria has *b**i* gram of the *i*-th ingredient. Also she has *k* grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the *n* ingredients and can be used for baking cookies.
Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.
Input Specification:
The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, needed to bake one cookie.
The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of the *i*-th ingredient, which Apollinaria has.
Output Specification:
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
Demo Input:
['3 1\n2 1 4\n11 3 16\n', '4 3\n4 3 5 6\n11 12 14 20\n']
Demo Output:
['4\n', '3\n']
Note:
In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
|
```python
def check(mid):
needed=0
#mid=5
# 1 2 3
# 4 8 6
for i in range (0,len(a)):
if(a[i]*mid>b[i]) :
needed+=((a[i]*mid)-b[i])
if needed > k:
return False
else:
return True
def bs():
left=0
right=10000000
while left<right:
mid=((left+right+1)//2)
if check(mid)==True:
left=mid
elif check(mid)==False:
right=mid-1
return right
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(bs())
```
| 3
|
|
1,005
|
B
|
Delete from the Left
|
PROGRAMMING
| 900
|
[
"brute force",
"implementation",
"strings"
] | null | null |
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
|
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
|
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
|
[
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] |
[
"2\n",
"9\n",
"7\n",
"1\n"
] |
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted.
| 0
|
[
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
"output": "18"
},
{
"input": "z\na",
"output": "2"
},
{
"input": "ama\nsama",
"output": "1"
},
{
"input": "aaabc\nbc",
"output": "3"
},
{
"input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa",
"output": "32"
},
{
"input": "ahmedaly\naly",
"output": "5"
},
{
"input": "aa\na",
"output": "1"
},
{
"input": "aa\nba",
"output": "2"
},
{
"input": "cccba\nba",
"output": "3"
},
{
"input": "a\nab",
"output": "3"
},
{
"input": "dadc\ndddc",
"output": "4"
},
{
"input": "aacaaab\nb",
"output": "6"
},
{
"input": "dddc\ncdcde",
"output": "9"
},
{
"input": "bbdab\ndab",
"output": "2"
},
{
"input": "a\naa",
"output": "1"
},
{
"input": "aa\nab",
"output": "4"
},
{
"input": "codeforces\nces",
"output": "7"
}
] | 1,695,796,456
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 28
| 62
| 31,232,000
|
s = input()
t = input()
w = 0
while True:
i = len(s) - w - 1
j = len(t) - w - 1
if i >= 0 and j >= 0 and s[i] == t[j]:
w += 1
else:
break
print(len(s) + len(t) - 2 * w)
|
Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
Input Specification:
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output Specification:
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
Demo Input:
['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n']
Demo Output:
['2\n', '9\n', '7\n', '1\n']
Note:
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted.
|
```python
s = input()
t = input()
w = 0
while True:
i = len(s) - w - 1
j = len(t) - w - 1
if i >= 0 and j >= 0 and s[i] == t[j]:
w += 1
else:
break
print(len(s) + len(t) - 2 * w)
```
| 3
|
|
629
|
A
|
Far Relative’s Birthday Cake
|
PROGRAMMING
| 800
|
[
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null |
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
|
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
|
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
|
[
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] |
[
"4\n",
"9\n"
] |
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
| 500
|
[
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},
{
"input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.",
"output": "80"
},
{
"input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C",
"output": "144"
},
{
"input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC",
"output": "190"
},
{
"input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..",
"output": "228"
},
{
"input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..",
"output": "2103"
},
{
"input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC",
"output": "2071"
},
{
"input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.",
"output": "1160"
},
{
"input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C",
"output": "789"
},
{
"input": "1\n.",
"output": "0"
},
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C",
"output": "529"
},
{
"input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C",
"output": "874"
},
{
"input": "2\nCC\nCC",
"output": "4"
},
{
"input": "3\nC..\nC..\nC..",
"output": "3"
}
] | 1,455,987,128
| 1,028
|
PyPy 3
|
OK
|
TESTS
| 48
| 124
| 716,800
|
from math import factorial
n = int(input())
a = []
for i in range(n):
temp = input()
a.append(temp)
r = [0]*n
c = [0]*n
for i in range(n):
for j in range(n):
if a[i][j] == 'C':
r[i] += 1
c[j] += 1
ans = 0
comb = lambda x, y: factorial(x)//factorial(y)//factorial(x-y)
for (i, j) in zip(r, c):
if i >= 2:
ans += comb(i, 2)
if j >= 2:
ans += comb(j, 2)
print(ans)
|
Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
Input Specification:
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Output Specification:
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
Demo Input:
['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n']
Demo Output:
['4\n', '9\n']
Note:
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
|
```python
from math import factorial
n = int(input())
a = []
for i in range(n):
temp = input()
a.append(temp)
r = [0]*n
c = [0]*n
for i in range(n):
for j in range(n):
if a[i][j] == 'C':
r[i] += 1
c[j] += 1
ans = 0
comb = lambda x, y: factorial(x)//factorial(y)//factorial(x-y)
for (i, j) in zip(r, c):
if i >= 2:
ans += comb(i, 2)
if j >= 2:
ans += comb(j, 2)
print(ans)
```
| 3
|
|
20
|
B
|
Equation
|
PROGRAMMING
| 2,000
|
[
"math"
] |
B. Equation
|
1
|
256
|
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
|
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0.
|
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
|
[
"1 -5 6\n"
] |
[
"2\n2.0000000000\n3.0000000000"
] |
none
| 1,000
|
[
{
"input": "1 -5 6",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "1\n-1.0000000000"
},
{
"input": "0 0 0",
"output": "-1"
},
{
"input": "0 -2 1",
"output": "1\n0.5000000000"
},
{
"input": "0 -2 0",
"output": "1\n0.0000000000"
},
{
"input": "0 0 1",
"output": "0"
},
{
"input": "0 0 -100000",
"output": "0"
},
{
"input": "0 10000 -100000",
"output": "1\n10.0000000000"
},
{
"input": "1 100000 -100000",
"output": "2\n-100000.9999900002\n0.9999900002"
},
{
"input": "0 3431 43123",
"output": "1\n-12.5686388808"
},
{
"input": "100 200 100",
"output": "1\n-1.0000000000"
},
{
"input": "50000 100000 50000",
"output": "1\n-1.0000000000"
},
{
"input": "-1 10 20",
"output": "2\n-1.7082039325\n11.7082039325"
},
{
"input": "-50000 100000 -50000",
"output": "1\n1.0000000000"
},
{
"input": "1 -2 1",
"output": "1\n1.0000000000"
},
{
"input": "1000 -5000 6000",
"output": "2\n2.0000000000\n3.0000000000"
},
{
"input": "0 -100000 0",
"output": "1\n0.0000000000"
},
{
"input": "1 -100000 0",
"output": "2\n0.0000000000\n100000.0000000000"
},
{
"input": "1223 -23532 1232",
"output": "2\n0.0524974745\n19.1887126645"
},
{
"input": "-1 -2 -1",
"output": "1\n-1.0000000000"
},
{
"input": "1 0 0",
"output": "1\n0.0000000000"
},
{
"input": "0 1 0",
"output": "1\n-0.0000000000"
},
{
"input": "0 0 1",
"output": "0"
},
{
"input": "0 1 -1",
"output": "1\n1.0000000000"
},
{
"input": "5 0 5",
"output": "0"
},
{
"input": "-2 -5 0",
"output": "2\n-2.5000000000\n-0.0000000000"
},
{
"input": "-2 -4 0",
"output": "2\n-2.0000000000\n-0.0000000000"
},
{
"input": "-2 0 0",
"output": "1\n-0.0000000000"
},
{
"input": "0 -4 -4",
"output": "1\n-1.0000000000"
},
{
"input": "1 1 0",
"output": "2\n-1.0000000000\n0.0000000000"
},
{
"input": "1 0 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "0 0 0",
"output": "-1"
}
] | 1,459,695,623
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 1
| 124
| 5,120,000
|
import re
arr = re.split(' ', input())
A = int(arr[0])
B = int(arr[1])
C = int(arr[2])
dis = B*B-4*A*C
if (A == 0 and B == 0 and C == 0):
print(-1)
elif (A == 0 and B == 0):
print(0)
elif (A == 0):
print(1)
print(-B/A)
elif (dis<0):
print(0)
elif (dis==0):
print(1)
print(-B/(2*A))
else:
print(2)
print((-B-dis**0.5)/(2*A))
print((-B+dis**0.5)/(2*A))
|
Title: Equation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given an equation:
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input Specification:
The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0.
Output Specification:
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Demo Input:
['1 -5 6\n']
Demo Output:
['2\n2.0000000000\n3.0000000000']
Note:
none
|
```python
import re
arr = re.split(' ', input())
A = int(arr[0])
B = int(arr[1])
C = int(arr[2])
dis = B*B-4*A*C
if (A == 0 and B == 0 and C == 0):
print(-1)
elif (A == 0 and B == 0):
print(0)
elif (A == 0):
print(1)
print(-B/A)
elif (dis<0):
print(0)
elif (dis==0):
print(1)
print(-B/(2*A))
else:
print(2)
print((-B-dis**0.5)/(2*A))
print((-B+dis**0.5)/(2*A))
```
| -1
|
154
|
A
|
Hometask
|
PROGRAMMING
| 1,600
|
[
"greedy"
] | null | null |
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about the task until half an hour before the next lesson and hastily scribbled something down. But then he recollected that in the last lesson he learned the grammar of *N*-ish. The spelling rules state that *N*-ish contains some "forbidden" pairs of letters: such letters can never occur in a sentence next to each other. Also, the order of the letters doesn't matter (for example, if the pair of letters "ab" is forbidden, then any occurrences of substrings "ab" and "ba" are also forbidden). Also, each pair has different letters and each letter occurs in no more than one forbidden pair.
Now Sergey wants to correct his sentence so that it doesn't contain any "forbidden" pairs of letters that stand next to each other. However, he is running out of time, so he decided to simply cross out some letters from the sentence. What smallest number of letters will he have to cross out? When a letter is crossed out, it is "removed" so that the letters to its left and right (if they existed), become neighboring. For example, if we cross out the first letter from the string "aba", we get the string "ba", and if we cross out the second letter, we get "aa".
|
The first line contains a non-empty string *s*, consisting of lowercase Latin letters — that's the initial sentence in *N*-ish, written by Sergey. The length of string *s* doesn't exceed 105.
The next line contains integer *k* (0<=≤<=*k*<=≤<=13) — the number of forbidden pairs of letters.
Next *k* lines contain descriptions of forbidden pairs of letters. Each line contains exactly two different lowercase Latin letters without separators that represent the forbidden pairs. It is guaranteed that each letter is included in no more than one pair.
|
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
|
[
"ababa\n1\nab\n",
"codeforces\n2\ndo\ncs\n"
] |
[
"2\n",
"1\n"
] |
In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
| 500
|
[
{
"input": "ababa\n1\nab",
"output": "2"
},
{
"input": "codeforces\n2\ndo\ncs",
"output": "1"
},
{
"input": "nllnrlrnll\n1\nrl",
"output": "1"
},
{
"input": "aludfbjtwnkgnfl\n1\noy",
"output": "0"
},
{
"input": "pgpgppgggpbbnnn\n2\npg\nnb",
"output": "7"
},
{
"input": "eepeeeeppppppeepeppe\n1\npe",
"output": "10"
},
{
"input": "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy",
"output": "1"
},
{
"input": "drvwfaacccwnncfwuptsorrrvvvrgdzytrwweeexzyyyxuwuuk\n13\nld\nac\nnp\nrv\nmo\njh\ngb\nuw\nfq\nst\nkx\nzy\nei",
"output": "11"
},
{
"input": "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp",
"output": "4"
},
{
"input": "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp",
"output": "37"
},
{
"input": "z\n0",
"output": "0"
},
{
"input": "t\n13\nzx\nig\nyq\nbd\nph\nar\nne\nwo\ntk\njl\ncv\nfs\nmu",
"output": "0"
},
{
"input": "rbnxovfcwkdjctdjfskaozjzthlcntuaoiavnbsfpuzxyvhfbxetvryvwrqetokdshadxpxijtpkrqvghsrejgnqntwiypiglzmp\n13\njr\nnf\nyk\ntq\nwe\nil\ngu\npb\naz\nxm\nhc\nvd\nso",
"output": "0"
},
{
"input": "yynynnyyyiynyniiiinyynniiyiyyyniyniyynyyyynyynnniiiniyyniiyyiynyiynnnnyiiyiyniyyininiyiiiyynnnyiyinnnnyiinnnnnyninyinyynynyiynyyyiyinyynnyyinynyinininyniniynniiyyiiyy\n1\nni",
"output": "28"
},
{
"input": "eowsgsewestwsootoetteoeeeetwssesstswegswetwetggewsteeteoggetssetseegwteswtteowsgowwoowetwgogewssogwgtttgwwoeotgoswwwwswsgeeoowwwwetwgeswsgwtsgewswtstwgggtegsssggsstwsoggeoseotgwswwggtggweewwgwegggoteweessotsewttwseosgegswwsoewgwstetwteegseowgwoteegwttwwowtwtosweeggweeeeoeesgseetgwgtswteotgwewetssggteewteeetetweeotwttwoeswggoosogoeg\n3\nst\neo\ngw",
"output": "49"
},
{
"input": "ttspivgoupgupvgpusvppogsseueusuglpiugssviuutlvgvugtpovuvspvpipggooplgvgugpogvesppulovugsvuougveiivgvslllviogpvtolepglguuellotpvgevspvoiiggiiplppgosuguvtstttpielteuglopgeoeeuivtptggltoltpgliviotsospvitupiopisoetupvvspooilsopslpoloptigstspoiuutiuvvuvlpplvioitsuvlpvtleveslslovolloogsgpvpepgueesslgtssttuupieppsstoeopeeppvopglpvtvuugpsuoplttsgstsiplpiugtoolisgpeeiuvutstpulvtllipsvsslvoepooslvteoevipvpsuoiippeuegoovoovstlvgsstitsivlvseguoolpslueuepgeooltviovpveeivolssloieuugovguoleulvssopetlpivpgoigtv\n1\ngs",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n1\nab",
"output": "75"
}
] | 1,660,994,123
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 42
| 216
| 2,662,400
|
import sys;sc = sys.stdin.readline;out=sys.stdout.write
s=str(sc());n=int(sc());ans=0
for e in range(n):
ss=str(sc());a,b=0,0
for e in s:
if e==ss[0]:a+=1
elif e==ss[1]:b+=1
else :ans+=min(a,b);a=0;b=0
ans+=min(a,b)
out(str(ans))
|
Title: Hometask
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about the task until half an hour before the next lesson and hastily scribbled something down. But then he recollected that in the last lesson he learned the grammar of *N*-ish. The spelling rules state that *N*-ish contains some "forbidden" pairs of letters: such letters can never occur in a sentence next to each other. Also, the order of the letters doesn't matter (for example, if the pair of letters "ab" is forbidden, then any occurrences of substrings "ab" and "ba" are also forbidden). Also, each pair has different letters and each letter occurs in no more than one forbidden pair.
Now Sergey wants to correct his sentence so that it doesn't contain any "forbidden" pairs of letters that stand next to each other. However, he is running out of time, so he decided to simply cross out some letters from the sentence. What smallest number of letters will he have to cross out? When a letter is crossed out, it is "removed" so that the letters to its left and right (if they existed), become neighboring. For example, if we cross out the first letter from the string "aba", we get the string "ba", and if we cross out the second letter, we get "aa".
Input Specification:
The first line contains a non-empty string *s*, consisting of lowercase Latin letters — that's the initial sentence in *N*-ish, written by Sergey. The length of string *s* doesn't exceed 105.
The next line contains integer *k* (0<=≤<=*k*<=≤<=13) — the number of forbidden pairs of letters.
Next *k* lines contain descriptions of forbidden pairs of letters. Each line contains exactly two different lowercase Latin letters without separators that represent the forbidden pairs. It is guaranteed that each letter is included in no more than one pair.
Output Specification:
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
Demo Input:
['ababa\n1\nab\n', 'codeforces\n2\ndo\ncs\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
|
```python
import sys;sc = sys.stdin.readline;out=sys.stdout.write
s=str(sc());n=int(sc());ans=0
for e in range(n):
ss=str(sc());a,b=0,0
for e in s:
if e==ss[0]:a+=1
elif e==ss[1]:b+=1
else :ans+=min(a,b);a=0;b=0
ans+=min(a,b)
out(str(ans))
```
| 3
|
|
680
|
A
|
Bear and Five Cards
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation"
] | null | null |
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
|
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
|
Print the minimum possible sum of numbers written on remaining cards.
|
[
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] |
[
"26\n",
"28\n",
"20\n"
] |
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
| 500
|
[
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output": "4"
},
{
"input": "8 8 2 2 2",
"output": "6"
},
{
"input": "5 50 5 5 60",
"output": "110"
},
{
"input": "100 100 100 100 100",
"output": "200"
},
{
"input": "1 1 1 1 1",
"output": "2"
},
{
"input": "29 29 20 20 20",
"output": "58"
},
{
"input": "20 29 20 29 20",
"output": "58"
},
{
"input": "31 31 20 20 20",
"output": "60"
},
{
"input": "20 20 20 31 31",
"output": "60"
},
{
"input": "20 31 20 31 20",
"output": "60"
},
{
"input": "20 20 20 30 30",
"output": "60"
},
{
"input": "30 30 20 20 20",
"output": "60"
},
{
"input": "8 1 8 8 8",
"output": "9"
},
{
"input": "1 1 1 8 1",
"output": "9"
},
{
"input": "1 2 3 4 5",
"output": "15"
},
{
"input": "100 99 98 97 96",
"output": "490"
},
{
"input": "1 1 100 100 100",
"output": "2"
},
{
"input": "100 100 99 99 98",
"output": "296"
},
{
"input": "98 99 100 99 100",
"output": "296"
},
{
"input": "1 90 1 91 1",
"output": "181"
},
{
"input": "60 1 75 1 92",
"output": "227"
},
{
"input": "15 40 90 40 90",
"output": "95"
},
{
"input": "1 1 15 20 20",
"output": "17"
},
{
"input": "90 11 11 10 10",
"output": "110"
},
{
"input": "20 21 22 23 24",
"output": "110"
},
{
"input": "1 1 2 98 99",
"output": "199"
},
{
"input": "3 7 7 7 10",
"output": "13"
},
{
"input": "1 3 3 3 1",
"output": "2"
},
{
"input": "1 9 9 9 10",
"output": "11"
},
{
"input": "100 1 1 1 1",
"output": "101"
},
{
"input": "2 2 2 100 100",
"output": "6"
},
{
"input": "1 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2 2 5",
"output": "7"
},
{
"input": "1 2 3 4 1",
"output": "9"
},
{
"input": "11 10 10 10 10",
"output": "21"
},
{
"input": "2 2 2 10 10",
"output": "6"
},
{
"input": "1 1 1 1 4",
"output": "5"
},
{
"input": "98 98 98 98 23",
"output": "121"
},
{
"input": "1 2 3 100 100",
"output": "6"
},
{
"input": "2 2 5 10 10",
"output": "9"
},
{
"input": "2 2 3 3 3",
"output": "4"
},
{
"input": "1 1 1 1 2",
"output": "3"
},
{
"input": "12 12 7 7 7",
"output": "21"
}
] | 1,697,612,754
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 46
| 0
|
n = 5
sum_val = 0
mp = {}
mx = 0
for i in range(n):
x = int(input())
sum_val += x
if x in mp and mp[x] == 1:
mx = max(mx, 2 * x)
elif x in mp and mp[x] == 2:
mx = max(mx, 3 * x)
if x in mp:
mp[x] += 1
else:
mp[x] = 1
print(sum_val - mx)
|
Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
Input Specification:
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Output Specification:
Print the minimum possible sum of numbers written on remaining cards.
Demo Input:
['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n']
Demo Output:
['26\n', '28\n', '20\n']
Note:
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
|
```python
n = 5
sum_val = 0
mp = {}
mx = 0
for i in range(n):
x = int(input())
sum_val += x
if x in mp and mp[x] == 1:
mx = max(mx, 2 * x)
elif x in mp and mp[x] == 2:
mx = max(mx, 3 * x)
if x in mp:
mp[x] += 1
else:
mp[x] = 1
print(sum_val - mx)
```
| -1
|
|
818
|
D
|
Multicolored Cars
|
PROGRAMMING
| 1,700
|
[
"data structures",
"implementation"
] | null | null |
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after *i*-th car *cnt**A*(*i*) and *cnt**B*(*i*).
- If *cnt**A*(*i*)<=><=*cnt**B*(*i*) for every *i* then the winner is Alice. - If *cnt**B*(*i*)<=≥<=*cnt**A*(*i*) for every *i* then the winner is Bob. - Otherwise it's a draw.
Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color *A* and Bob now wants to choose such color *B* that he will win the game (draw is not a win). Help him find this color.
If there are multiple solutions, print any of them. If there is no such color then print -1.
|
The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice.
The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their appearance.
|
Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106).
|
[
"4 1\n2 1 4 2\n",
"5 2\n2 2 4 5 3\n",
"3 10\n1 2 3\n"
] |
[
"2\n",
"-1\n",
"4\n"
] |
Let's consider availability of colors in the first example:
- *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning one for Bob. - All the other colors also have *cnt*<sub class="lower-index">*j*</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), thus they are not available.
In the third example every color is acceptable except for 10.
| 0
|
[
{
"input": "4 1\n2 1 4 2",
"output": "2"
},
{
"input": "5 2\n2 2 4 5 3",
"output": "-1"
},
{
"input": "3 10\n1 2 3",
"output": "4"
},
{
"input": "1 1\n2",
"output": "3"
},
{
"input": "1 2\n2",
"output": "-1"
},
{
"input": "10 6\n8 5 1 6 6 5 10 6 9 8",
"output": "-1"
},
{
"input": "7 2\n1 2 2 1 1 1 1",
"output": "-1"
},
{
"input": "8 2\n1 1 3 2 3 2 3 2",
"output": "3"
},
{
"input": "10 9\n6 4 7 1 8 9 5 9 4 5",
"output": "-1"
},
{
"input": "6 1\n2 3 3 1 1 2",
"output": "3"
},
{
"input": "4 1\n2 1 1 2",
"output": "-1"
},
{
"input": "5 1\n3 2 1 2 1",
"output": "2"
},
{
"input": "5 3\n1 2 3 2 3",
"output": "2"
},
{
"input": "1 1000000\n1",
"output": "2"
},
{
"input": "6 3\n1 2 3 2 3 2",
"output": "2"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "6 2\n5 3 2 4 4 2",
"output": "-1"
},
{
"input": "6 1\n5 2 1 4 2 1",
"output": "2"
},
{
"input": "6 1\n2 2 2 1 1 1",
"output": "2"
},
{
"input": "5 2\n3 1 1 2 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "30 1\n2 2 2 2 2 3 3 3 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 1 1 1",
"output": "2"
},
{
"input": "2 1\n1 2",
"output": "-1"
},
{
"input": "5 3\n1 2 2 3 3",
"output": "2"
},
{
"input": "10 1000000\n1 2 3 4 5 6 7 8 9 10",
"output": "11"
},
{
"input": "6 1\n3 1 2 2 3 1",
"output": "3"
},
{
"input": "5 1\n2 3 3 1 1",
"output": "3"
},
{
"input": "9 1\n2 3 3 1 4 1 3 2 1",
"output": "3"
},
{
"input": "10 9\n8 9 1 1 1 1 1 1 1 9",
"output": "-1"
},
{
"input": "13 2\n3 3 3 2 1 1 1 1 1 2 3 2 2",
"output": "3"
},
{
"input": "5 1\n2 3 1 3 1",
"output": "3"
},
{
"input": "8 7\n6 7 2 2 4 5 4 4",
"output": "6"
},
{
"input": "2 7\n6 7",
"output": "6"
},
{
"input": "3 5\n9 5 7",
"output": "9"
},
{
"input": "6 2\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 3\n1000 2 3 2 2 3",
"output": "2"
},
{
"input": "10 5\n1 1 1 1 1 5 5 5 5 5",
"output": "1"
},
{
"input": "4 9\n4 9 9 4",
"output": "-1"
},
{
"input": "4 1\n2 1 3 3",
"output": "2"
},
{
"input": "19 3\n1 2 3 1 2 3 1 2 3 5 5 5 5 5 5 5 5 2 3",
"output": "2"
},
{
"input": "15 1\n2 5 5 1 2 1 5 2 1 5 2 1 5 1 5",
"output": "5"
},
{
"input": "14 1\n2 5 5 1 2 1 5 2 1 5 2 1 5 1",
"output": "5"
},
{
"input": "8 5\n1 2 5 1 2 5 2 5",
"output": "2"
},
{
"input": "5 1000000\n1 2 1000000 2 1",
"output": "1"
},
{
"input": "8 2\n1 2 1 3 2 3 3 3",
"output": "1"
},
{
"input": "9 10\n4 9 7 3 3 3 10 3 10",
"output": "3"
},
{
"input": "6 2\n5 3 9 2 10 1",
"output": "3"
},
{
"input": "10 4\n7 5 4 4 1 5 7 9 10 6",
"output": "-1"
},
{
"input": "2 1\n9 1",
"output": "9"
},
{
"input": "3 7\n5 7 1",
"output": "5"
},
{
"input": "6 3\n1 3 5 4 2 3",
"output": "-1"
},
{
"input": "7 1\n7 3 1 4 5 8 5",
"output": "3"
},
{
"input": "2 3\n6 3",
"output": "6"
},
{
"input": "10 8\n2 8 8 9 6 9 1 3 2 4",
"output": "-1"
},
{
"input": "6 1\n1 7 8 4 8 6",
"output": "-1"
}
] | 1,498,753,094
| 4,394
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 6
| 61
| 5,529,600
|
n,A = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = -1
d={}
for i in c:
d[str(i)] = c.count(i)
for i in c:
try:
if(i!=A):
if(d[str(i)] > d[str(A)] ):
ans = i
break
except:
ans = i
break
print(ans)
|
Title: Multicolored Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after *i*-th car *cnt**A*(*i*) and *cnt**B*(*i*).
- If *cnt**A*(*i*)<=><=*cnt**B*(*i*) for every *i* then the winner is Alice. - If *cnt**B*(*i*)<=≥<=*cnt**A*(*i*) for every *i* then the winner is Bob. - Otherwise it's a draw.
Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color *A* and Bob now wants to choose such color *B* that he will win the game (draw is not a win). Help him find this color.
If there are multiple solutions, print any of them. If there is no such color then print -1.
Input Specification:
The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice.
The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their appearance.
Output Specification:
Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106).
Demo Input:
['4 1\n2 1 4 2\n', '5 2\n2 2 4 5 3\n', '3 10\n1 2 3\n']
Demo Output:
['2\n', '-1\n', '4\n']
Note:
Let's consider availability of colors in the first example:
- *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning one for Bob. - All the other colors also have *cnt*<sub class="lower-index">*j*</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), thus they are not available.
In the third example every color is acceptable except for 10.
|
```python
n,A = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = -1
d={}
for i in c:
d[str(i)] = c.count(i)
for i in c:
try:
if(i!=A):
if(d[str(i)] > d[str(A)] ):
ans = i
break
except:
ans = i
break
print(ans)
```
| 0
|
|
892
|
B
|
Wrath
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation",
"two pointers"
] | null | null |
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *j*<=≥<=*i*<=-<=*L**i*.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
|
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
|
Print one integer — the total number of alive people after the bell rings.
|
[
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] |
[
"1\n",
"2\n",
"3\n"
] |
In first sample the last person kills everyone in front of him.
| 1,000
|
[
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0",
"output": "4"
},
{
"input": "6\n3 1 1 0 3 3",
"output": "1"
},
{
"input": "8\n0 0 0 1 0 0 1 2",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "2\n1 3",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "11\n1 0 0 1 1 3 2 0 0 2 3",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
}
] | 1,510,933,653
| 4,353
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 11
| 1,637
| 77,926,400
|
n = int(input())
L = [int(i) for i in input().split()]
last_killed = n - 1
killed = 0
for i in range(n - 1, 0, -1):
killed += min(i, max(0, L[i] - (i - last_killed)))
last_killed = min(last_killed, i - L[i], i - 1)
if last_killed < 0:
print(n - killed)
break
else:
print(n - killed)
|
Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *j*<=≥<=*i*<=-<=*L**i*.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw.
Output Specification:
Print one integer — the total number of alive people after the bell rings.
Demo Input:
['4\n0 1 0 10\n', '2\n0 0\n', '10\n1 1 3 0 0 0 2 1 0 3\n']
Demo Output:
['1\n', '2\n', '3\n']
Note:
In first sample the last person kills everyone in front of him.
|
```python
n = int(input())
L = [int(i) for i in input().split()]
last_killed = n - 1
killed = 0
for i in range(n - 1, 0, -1):
killed += min(i, max(0, L[i] - (i - last_killed)))
last_killed = min(last_killed, i - L[i], i - 1)
if last_killed < 0:
print(n - killed)
break
else:
print(n - killed)
```
| 0
|
|
43
|
A
|
Football
|
PROGRAMMING
| 1,000
|
[
"strings"
] |
A. Football
|
2
|
256
|
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
|
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
|
[
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] |
[
"ABC\n",
"A\n"
] |
none
| 500
|
[
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,614,127,949
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 156
| 0
|
n = int(input())
season = []
for i in range(n):
match = input()
season.append(match)
try:
a, b = list(set(season))
awon = season.count(a)
bwon = n - awon
if awon > bwon:
print(a)
else:
print(b)
except (TypeError, ValueError):
team = list(set(season))
print(team[0])
|
Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none
|
```python
n = int(input())
season = []
for i in range(n):
match = input()
season.append(match)
try:
a, b = list(set(season))
awon = season.count(a)
bwon = n - awon
if awon > bwon:
print(a)
else:
print(b)
except (TypeError, ValueError):
team = list(set(season))
print(team[0])
```
| 3.961
|
224
|
A
|
Parallelepiped
|
PROGRAMMING
| 1,100
|
[
"brute force",
"geometry",
"math"
] | null | null |
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
|
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
|
Print a single number — the sum of all edges of the parallelepiped.
|
[
"1 1 1\n",
"4 6 6\n"
] |
[
"12\n",
"28\n"
] |
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
| 500
|
[
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{
"input": "1022 584 112",
"output": "380"
},
{
"input": "66 174 319",
"output": "184"
},
{
"input": "912 276 1748",
"output": "444"
},
{
"input": "65 156 60",
"output": "120"
},
{
"input": "1 10000 10000",
"output": "40008"
},
{
"input": "1485 55 27",
"output": "332"
},
{
"input": "152 108 4104",
"output": "528"
},
{
"input": "1656 6900 1350",
"output": "740"
},
{
"input": "12 14 42",
"output": "60"
},
{
"input": "615 18 1230",
"output": "856"
},
{
"input": "680 60 408",
"output": "336"
},
{
"input": "644 966 6",
"output": "1308"
},
{
"input": "1 432 432",
"output": "1736"
},
{
"input": "2239 2239 1",
"output": "8964"
},
{
"input": "4106 8212 2",
"output": "16436"
},
{
"input": "10000 10000 10000",
"output": "1200"
},
{
"input": "3623 3623 1",
"output": "14500"
},
{
"input": "9801 9801 9801",
"output": "1188"
},
{
"input": "10000 1 10000",
"output": "40008"
},
{
"input": "9 9 9",
"output": "36"
},
{
"input": "9801 9702 9702",
"output": "1184"
}
] | 1,594,027,666
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 27
| 216
| 6,656,000
|
import math
x,y,z =map(int,input().split())
total1=4*(math.sqrt(x*y/z))
total2=4*(math.sqrt(x*z/y))
total3=4*(math.sqrt(z*y/x))
print(math.floor(total1+total2+total3))
# print(math.floor(total))
|
Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input Specification:
The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Output Specification:
Print a single number — the sum of all edges of the parallelepiped.
Demo Input:
['1 1 1\n', '4 6 6\n']
Demo Output:
['12\n', '28\n']
Note:
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.
|
```python
import math
x,y,z =map(int,input().split())
total1=4*(math.sqrt(x*y/z))
total2=4*(math.sqrt(x*z/y))
total3=4*(math.sqrt(z*y/x))
print(math.floor(total1+total2+total3))
# print(math.floor(total))
```
| 3
|
|
216
|
B
|
Forming Teams
|
PROGRAMMING
| 1,700
|
[
"dfs and similar",
"implementation"
] | null | null |
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then student *B* is an archenemy to student *A*.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last.
|
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*) — the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to *n*.
|
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
|
[
"5 4\n1 2\n2 4\n5 3\n1 4\n",
"6 2\n1 4\n3 4\n",
"6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n"
] |
[
"1",
"0",
"2"
] |
none
| 1,500
|
[
{
"input": "5 4\n1 2\n2 4\n5 3\n1 4",
"output": "1"
},
{
"input": "6 2\n1 4\n3 4",
"output": "0"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4",
"output": "2"
},
{
"input": "5 1\n1 2",
"output": "1"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1",
"output": "0"
},
{
"input": "28 3\n15 3\n10 19\n17 25",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "3 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 2\n3 2",
"output": "1"
},
{
"input": "3 3\n1 2\n1 3\n2 3",
"output": "1"
},
{
"input": "4 1\n1 4",
"output": "0"
},
{
"input": "4 2\n4 1\n2 1",
"output": "0"
},
{
"input": "4 3\n1 3\n3 2\n2 4",
"output": "0"
},
{
"input": "4 3\n3 2\n4 2\n4 3",
"output": "2"
},
{
"input": "5 3\n4 2\n3 4\n5 1",
"output": "1"
},
{
"input": "10 7\n8 9\n3 6\n2 4\n4 1\n1 3\n2 7\n7 10",
"output": "0"
},
{
"input": "29 20\n15 9\n21 15\n14 12\n12 16\n3 28\n5 13\n19 1\n19 21\n23 17\n27 9\n26 10\n20 5\n8 16\n11 6\n4 22\n29 22\n29 11\n14 17\n28 6\n1 23",
"output": "1"
},
{
"input": "68 50\n10 9\n28 25\n53 46\n38 32\n46 9\n35 13\n65 21\n64 1\n15 52\n43 52\n31 7\n61 67\n41 49\n30 1\n14 4\n17 44\n25 7\n24 31\n57 51\n27 12\n3 37\n17 11\n41 16\n65 23\n10 2\n16 22\n40 36\n15 51\n58 44\n61 2\n50 30\n48 35\n45 32\n56 59\n37 49\n62 55\n62 11\n6 19\n34 33\n53 66\n67 39\n47 21\n56 40\n12 58\n4 23\n26 42\n42 5\n60 8\n5 63\n6 47",
"output": "0"
},
{
"input": "89 30\n86 72\n43 16\n32 80\n17 79\n29 8\n89 37\n84 65\n3 41\n55 79\n33 56\n60 40\n43 45\n59 38\n26 23\n66 61\n81 30\n65 25\n13 71\n25 8\n56 59\n46 13\n22 30\n87 3\n26 32\n75 44\n48 87\n47 4\n63 21\n36 6\n42 86",
"output": "1"
},
{
"input": "100 1\n3 87",
"output": "0"
},
{
"input": "100 10\n88 82\n5 78\n66 31\n65 100\n92 25\n71 62\n47 31\n17 67\n69 68\n59 49",
"output": "0"
},
{
"input": "100 50\n82 99\n27 56\n74 38\n16 68\n90 27\n77 4\n7 88\n77 33\n25 85\n18 70\n50 7\n31 5\n21 20\n50 83\n55 5\n46 83\n55 81\n73 6\n76 58\n60 67\n66 99\n71 23\n100 13\n76 8\n52 14\n6 54\n53 54\n88 22\n12 4\n33 60\n43 62\n42 31\n19 67\n98 80\n15 17\n78 79\n62 37\n66 96\n40 44\n37 86\n71 58\n42 92\n8 38\n92 13\n73 70\n46 41\n30 34\n15 65\n97 19\n14 53",
"output": "0"
},
{
"input": "10 9\n5 10\n3 2\n8 6\n4 5\n4 10\n6 1\n1 8\n9 2\n3 9",
"output": "4"
},
{
"input": "50 48\n33 21\n1 46\n43 37\n1 48\n42 32\n31 45\n14 29\n34 28\n38 19\n46 48\n49 31\n8 3\n27 23\n26 37\n15 9\n27 17\n9 35\n18 7\n35 15\n32 4\n23 17\n36 22\n16 33\n39 6\n40 13\n11 6\n21 16\n10 40\n30 36\n20 5\n24 3\n43 26\n22 30\n41 20\n50 38\n25 29\n5 41\n34 44\n12 7\n8 24\n44 28\n25 14\n12 18\n39 11\n42 4\n45 49\n50 19\n13 10",
"output": "16"
},
{
"input": "19 16\n2 16\n7 10\n17 16\n17 14\n1 5\n19 6\n11 13\n15 19\n7 9\n13 5\n4 6\n1 11\n12 9\n10 12\n2 14\n4 15",
"output": "1"
},
{
"input": "70 70\n27 54\n45 23\n67 34\n66 25\n64 38\n30 68\n51 65\n19 4\n15 33\n47 14\n3 9\n42 29\n69 56\n10 50\n34 58\n51 23\n55 14\n18 53\n27 68\n17 6\n48 6\n8 5\n46 37\n37 33\n21 36\n69 24\n16 13\n50 12\n59 31\n63 38\n22 11\n46 28\n67 62\n63 26\n70 31\n7 59\n55 52\n28 43\n18 35\n53 3\n16 60\n43 40\n61 9\n20 44\n47 41\n35 1\n32 4\n13 54\n30 60\n45 19\n39 42\n2 20\n2 26\n52 8\n12 25\n5 41\n21 10\n58 48\n29 11\n7 56\n49 57\n65 32\n15 40\n66 36\n64 44\n22 57\n1 61\n39 49\n24 70\n62 17",
"output": "10"
},
{
"input": "33 33\n2 16\n28 20\n13 9\n4 22\n18 1\n6 12\n13 29\n32 1\n17 15\n10 7\n6 15\n16 5\n11 10\n31 29\n25 8\n23 21\n14 32\n8 2\n19 3\n11 4\n21 25\n31 30\n33 5\n26 7\n27 26\n27 12\n30 24\n33 17\n28 22\n18 24\n19 9\n3 23\n14 20",
"output": "1"
},
{
"input": "10 8\n8 3\n9 7\n6 1\n10 9\n2 6\n2 1\n3 4\n4 8",
"output": "2"
},
{
"input": "20 12\n16 20\n8 3\n20 5\n5 10\n17 7\n13 2\n18 9\n17 18\n1 6\n14 4\n11 12\n10 16",
"output": "0"
},
{
"input": "35 21\n15 3\n13 5\n2 28\n26 35\n9 10\n22 18\n17 1\n31 32\n35 33\n5 15\n14 24\n29 12\n16 2\n14 10\n7 4\n29 4\n23 27\n30 34\n19 26\n23 11\n25 21",
"output": "1"
},
{
"input": "49 36\n17 47\n19 27\n41 23\n31 27\n11 29\n34 10\n35 2\n42 24\n19 16\n38 24\n5 9\n26 9\n36 14\n18 47\n28 40\n45 13\n35 22\n2 15\n31 30\n20 48\n39 3\n8 34\n36 7\n25 17\n5 39\n29 1\n32 33\n16 30\n38 49\n25 18\n1 11\n7 44\n12 43\n15 22\n49 21\n8 23",
"output": "3"
},
{
"input": "77 54\n18 56\n72 2\n6 62\n58 52\n5 70\n24 4\n67 66\n65 47\n43 77\n61 66\n24 51\n70 7\n48 39\n46 11\n77 28\n65 76\n15 6\n22 13\n34 75\n33 42\n59 37\n7 31\n50 23\n28 9\n17 29\n1 14\n11 45\n36 46\n32 39\n59 21\n22 34\n53 21\n29 47\n16 44\n69 4\n62 16\n36 3\n68 75\n51 69\n49 43\n30 55\n40 20\n57 60\n45 3\n38 33\n49 9\n71 19\n73 20\n48 32\n63 67\n8 54\n42 38\n26 12\n5 74",
"output": "5"
},
{
"input": "93 72\n3 87\n88 60\n73 64\n45 35\n61 85\n68 80\n54 29\n4 88\n19 91\n82 48\n50 2\n40 53\n56 8\n66 82\n83 81\n62 8\n79 30\n89 26\n77 10\n65 15\n27 47\n15 51\n70 6\n59 85\n63 20\n64 92\n7 1\n93 52\n74 38\n71 23\n83 12\n86 52\n46 56\n34 36\n37 84\n18 16\n11 42\n69 72\n53 20\n78 84\n54 91\n14 5\n65 49\n90 19\n42 39\n68 57\n75 27\n57 32\n44 9\n79 74\n48 66\n43 93\n31 30\n58 24\n80 67\n6 60\n39 5\n23 17\n25 1\n18 36\n32 67\n10 9\n14 11\n63 21\n92 73\n13 43\n28 78\n33 51\n4 70\n75 45\n37 28\n62 46",
"output": "5"
},
{
"input": "100 72\n2 88\n55 80\n22 20\n78 52\n66 74\n91 82\n59 77\n97 93\n46 44\n99 35\n73 62\n58 24\n6 16\n47 41\n98 86\n23 19\n39 68\n32 28\n85 29\n37 40\n16 62\n19 61\n84 72\n17 15\n76 96\n37 31\n67 35\n48 15\n80 85\n90 47\n79 36\n39 54\n57 87\n42 60\n34 56\n23 61\n92 2\n88 63\n20 42\n27 81\n65 84\n6 73\n64 100\n76 95\n43 4\n65 86\n21 46\n11 64\n72 98\n63 92\n7 50\n14 22\n89 30\n31 40\n8 57\n90 70\n53 59\n69 24\n96 49\n67 99\n51 70\n18 66\n91 3\n26 38\n13 58\n51 41\n9 11\n5 74\n3 25\n4 32\n28 43\n71 56",
"output": "6"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
},
{
"input": "6 4\n1 2\n1 3\n4 5\n4 6",
"output": "0"
},
{
"input": "16 16\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n7 8\n8 9\n9 10\n10 11\n11 7\n12 13\n13 14\n14 15\n15 16\n16 12",
"output": "4"
},
{
"input": "4 4\n1 2\n4 3\n1 4\n2 3",
"output": "0"
},
{
"input": "9 9\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n7 8\n8 9\n9 7",
"output": "3"
},
{
"input": "20 11\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 1",
"output": "2"
},
{
"input": "4 3\n1 2\n3 4\n1 3",
"output": "0"
},
{
"input": "4 2\n2 4\n3 4",
"output": "0"
},
{
"input": "10 10\n1 2\n2 3\n3 4\n4 5\n5 1\n6 7\n7 8\n8 9\n9 10\n10 6",
"output": "2"
},
{
"input": "6 5\n2 1\n3 4\n2 3\n4 5\n5 6",
"output": "0"
},
{
"input": "8 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n1 5",
"output": "2"
},
{
"input": "8 8\n1 2\n2 3\n3 4\n1 4\n5 6\n6 7\n7 8\n5 8",
"output": "0"
},
{
"input": "6 5\n1 3\n1 2\n2 4\n5 3\n5 4",
"output": "2"
}
] | 1,692,012,498
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#define forn(i, n) for(int i=0;i<n;++i)
#define fore(i, l, r) for(int i = int(l); i <= int(r); ++i)
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define x first
#define y1 ________y1
#define y second
#define ft first
#define sc second
#define pt pair<int, int>
template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }
typedef long long li;
typedef long double ld;
using namespace std;
const int INF = 1000 * 1000 * 1000;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
const int N = 100 + 13;
int n, m;
vector<int> g[N];
bool used[N];
int ans;
int cnt;
bool cyc;
inline void read() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
}
inline void dfs(int v, int p) {
used[v] = true;
cnt++;
for (int i = 0; i < sz(g[v]); i++) {
int to = g[v][i];
if (to == p) {
continue;
}
if (used[to]) {
cyc = true;
} else {
dfs(to, v);
}
}
}
inline void solve() {
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
if (used[i]) {
continue;
}
cnt = 0;
cyc = false;
dfs(i, -1);
if (cnt % 2 == 0) {
cnt1 += cnt / 2;
cnt2 += cnt / 2;
continue;
}
if (cyc) {
ans++;
} else {
if (cnt1 > cnt2) {
cnt2 = cnt1;
} else if (cnt1 < cnt2) {
cnt1 = cnt2;
} else {
cnt1++;
}
}
}
if (cnt1 != cnt2) {
ans++;
}
cout << ans << endl;
}
int main () {
#ifdef fcspartakm
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
srand(time(NULL));
cerr << setprecision(10) << fixed;
read();
solve();
//cerr << "TIME: " << clock() << endl;
}
|
Title: Forming Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student *A* is an archenemy to student *B*, then student *B* is an archenemy to student *A*.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100) — the number of students and the number of pairs of archenemies correspondingly.
Next *m* lines describe enmity between students. Each enmity is described as two numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*) — the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to *n*.
Output Specification:
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
Demo Input:
['5 4\n1 2\n2 4\n5 3\n1 4\n', '6 2\n1 4\n3 4\n', '6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n']
Demo Output:
['1', '0', '2']
Note:
none
|
```python
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#define forn(i, n) for(int i=0;i<n;++i)
#define fore(i, l, r) for(int i = int(l); i <= int(r); ++i)
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define x first
#define y1 ________y1
#define y second
#define ft first
#define sc second
#define pt pair<int, int>
template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }
typedef long long li;
typedef long double ld;
using namespace std;
const int INF = 1000 * 1000 * 1000;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
const int N = 100 + 13;
int n, m;
vector<int> g[N];
bool used[N];
int ans;
int cnt;
bool cyc;
inline void read() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
}
inline void dfs(int v, int p) {
used[v] = true;
cnt++;
for (int i = 0; i < sz(g[v]); i++) {
int to = g[v][i];
if (to == p) {
continue;
}
if (used[to]) {
cyc = true;
} else {
dfs(to, v);
}
}
}
inline void solve() {
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
if (used[i]) {
continue;
}
cnt = 0;
cyc = false;
dfs(i, -1);
if (cnt % 2 == 0) {
cnt1 += cnt / 2;
cnt2 += cnt / 2;
continue;
}
if (cyc) {
ans++;
} else {
if (cnt1 > cnt2) {
cnt2 = cnt1;
} else if (cnt1 < cnt2) {
cnt1 = cnt2;
} else {
cnt1++;
}
}
}
if (cnt1 != cnt2) {
ans++;
}
cout << ans << endl;
}
int main () {
#ifdef fcspartakm
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
srand(time(NULL));
cerr << setprecision(10) << fixed;
read();
solve();
//cerr << "TIME: " << clock() << endl;
}
```
| -1
|
|
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,599,621,112
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 186
| 0
|
X = int(input())
a = int(input())
b = int(input())
count = 0
for i in range(a, b):
if i % X == 0:
count += 1
print(count)
|
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
X = int(input())
a = int(input())
b = int(input())
count = 0
for i in range(a, b):
if i % X == 0:
count += 1
print(count)
```
| -1
|
549
|
A
|
Face Detection
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] | null | null |
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
|
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
|
In the single line print the number of faces on the image.
|
[
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] |
[
"1\n",
"1\n",
"2\n",
"0\n"
] |
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In the fourth sample the image has no faces on it.
| 250
|
[
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "0"
},
{
"input": "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk",
"output": "1"
},
{
"input": "1 1\np",
"output": "0"
},
{
"input": "2 5\nacdmw\nefazb",
"output": "1"
},
{
"input": "5 2\ndz\nda\nsx\nyu\nzz",
"output": "0"
},
{
"input": "5 5\nxeljd\nwriac\nveief\nlcacf\nbqefn",
"output": "2"
},
{
"input": "5 5\nacnbx\nefacp\nlrefa\norqce\nzvbay",
"output": "3"
},
{
"input": "5 5\nbyjvu\nkmaca\nalefe\nwcacg\nrefez",
"output": "5"
},
{
"input": "5 5\npuxac\nbbaef\naccfa\nefaec\nligsr",
"output": "5"
},
{
"input": "37 4\nacjo\nefac\nacef\nefac\nwpef\nicac\naefe\ncfac\naece\ncfaf\nyqce\nmiaf\nirce\nycaf\naefc\ncfae\nrsnc\nbacz\nqefb\npdhs\nffac\nfaef\nacfd\nacmi\nefvm\nacaz\nefpn\nacao\nefer\nacap\nefec\nacaf\nefef\nacbj\nefac\nacef\nefoz",
"output": "49"
},
{
"input": "7 3\njac\naef\ncfa\naec\ncfq\ndig\nxyq",
"output": "5"
},
{
"input": "35 1\ny\na\nk\ng\ni\nd\nv\nn\nl\nx\nu\nx\nu\no\nd\nf\nk\nj\nr\nm\nq\ns\nc\nd\nc\nm\nv\nh\nn\ne\nl\nt\nz\ny\no",
"output": "0"
},
{
"input": "9 46\nuuexbaacesjclggslacermcbkxlcxhdgqtacdwfryxzuxc\naclrsaefakndbnzlkefenuphgcgoedhkaxefjtnkgfeaca\nefuqunpmfxdyyffyhvracozzrxlpekhtsrfhlilfmyhefg\numyacfzffvicqtdpiulefnwcojuwtfbvlxkfsiapdnzpqo\nactefvuxqptremlqjhdbdwacjxdxitxjktecvefacamjcz\neflarseklqrkayhosverpfefzirqigzlxezabhzeferkwm\nztpypwxyohtacsnnvoigqwcachtaceyxlkhfhgwbnfmklb\nfzpqeymhljiefctvqtbgcdjefkxefarbciyosmktmoziac\nbssxizyrzyhacszttwhrzspbfkgfcejybdjcpuczhrkqef",
"output": "20"
},
{
"input": "7 30\nmjfracgaacacctacrreyrlkacuacay\nrlacefacefeftaeftkacacaefcefev\nacefacefacraccfaeaefefecaeacaf\nefacefacefaefaecfcfacacaecfefa\nncefacefacecacfaeaecefefcaeace\nfafaceacuafaefadcfcafacaefcfea\nzsvefafukcecfarkaeaecefecailgu",
"output": "95"
},
{
"input": "2 2\nff\nee",
"output": "0"
},
{
"input": "2 2\nfa\ncc",
"output": "0"
},
{
"input": "2 2\nfa\naa",
"output": "0"
},
{
"input": "2 2\nfa\nea",
"output": "0"
},
{
"input": "2 2\nfa\ndd",
"output": "0"
},
{
"input": "2 2\nee\nff",
"output": "0"
},
{
"input": "2 2\ncc\ncf",
"output": "0"
},
{
"input": "2 2\naa\nae",
"output": "0"
},
{
"input": "2 2\nef\nac",
"output": "1"
},
{
"input": "2 2\nfe\nca",
"output": "1"
}
] | 1,433,609,909
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 37
| 62
| 0
|
import sys
def solve():
n, m = map(int, input().split())
tab = [list(input()) for x in range(n)]
need = set(['f', 'a', 'c', 'e'])
res = 0
for row in range(n - 1):
for col in range(m - 1):
s = set()
for r in range(row, row + 2):
for c in range(col, col + 2):
s.add(tab[r][c])
if need.issubset(s):
res+=1
return res
def run():
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
print(solve())
run()
|
Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input Specification:
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
Output Specification:
In the single line print the number of faces on the image.
Demo Input:
['4 4\nxxxx\nxfax\nxcex\nxxxx\n', '4 2\nxx\ncf\nae\nxx\n', '2 3\nfac\ncef\n', '1 4\nface\n']
Demo Output:
['1\n', '1\n', '2\n', '0\n']
Note:
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In the fourth sample the image has no faces on it.
|
```python
import sys
def solve():
n, m = map(int, input().split())
tab = [list(input()) for x in range(n)]
need = set(['f', 'a', 'c', 'e'])
res = 0
for row in range(n - 1):
for col in range(m - 1):
s = set()
for r in range(row, row + 2):
for c in range(col, col + 2):
s.add(tab[r][c])
if need.issubset(s):
res+=1
return res
def run():
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
print(solve())
run()
```
| 3
|
|
231
|
A
|
Team
|
PROGRAMMING
| 800
|
[
"brute force",
"greedy"
] | null | null |
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
|
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
|
Print a single integer — the number of problems the friends will implement on the contest.
|
[
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] |
[
"2\n",
"1\n"
] |
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
| 500
|
[
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,698,237,845
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 60
| 0
|
t=int(input())
count=0
while t!=0:
a,b,c=map(int, input().split())
if a+b+c <2:
count+=1
|
Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
|
```python
t=int(input())
count=0
while t!=0:
a,b,c=map(int, input().split())
if a+b+c <2:
count+=1
```
| -1
|
|
572
|
A
|
Arrays
|
PROGRAMMING
| 900
|
[
"sortings"
] | null | null |
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
|
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
|
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
|
[
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
| 500
|
[
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"output": "NO"
},
{
"input": "3 3\n1 1\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n1 2\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n2 2\n1 2 3\n1 2 3",
"output": "NO"
},
{
"input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49",
"output": "YES"
},
{
"input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100",
"output": "YES"
},
{
"input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99",
"output": "YES"
},
{
"input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81",
"output": "YES"
},
{
"input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10",
"output": "NO"
},
{
"input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "1 1\n1 1\n-1000000000\n30",
"output": "YES"
},
{
"input": "3 3\n1 3\n1 3 3\n3 3 3",
"output": "YES"
},
{
"input": "3 3\n1 1\n3 3 3\n2 2 2",
"output": "NO"
},
{
"input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7",
"output": "NO"
},
{
"input": "3 4\n2 2\n5 6 7\n1 2 3 4",
"output": "NO"
},
{
"input": "3 3\n3 3\n1 2 3\n4 5 6",
"output": "YES"
},
{
"input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9",
"output": "YES"
}
] | 1,581,212,246
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 52
| 592
| 17,100,800
|
import heapq
def main():
Na, Nb = map(int, input().split())
K, M = map(int, input().split())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
# find K number of Array A, ensure it's smallest K numbers
smallest = heapq.nsmallest(K, arrA)
# find K number of Array A, ensure it's largest M numbers
largest = heapq.nlargest(M, arrB)
# compare smallest of smallest ft. largest of largest
# print(smallest, largest)
if smallest[-1] >= largest[-1]:
print("NO")
else:
print("YES")
return True
main()
|
Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
Input Specification:
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Output Specification:
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
Demo Input:
['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
|
```python
import heapq
def main():
Na, Nb = map(int, input().split())
K, M = map(int, input().split())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
# find K number of Array A, ensure it's smallest K numbers
smallest = heapq.nsmallest(K, arrA)
# find K number of Array A, ensure it's largest M numbers
largest = heapq.nlargest(M, arrB)
# compare smallest of smallest ft. largest of largest
# print(smallest, largest)
if smallest[-1] >= largest[-1]:
print("NO")
else:
print("YES")
return True
main()
```
| 3
|
|
896
|
B
|
Ithea Plays With Chtholly
|
PROGRAMMING
| 2,000
|
[
"binary search",
"constructive algorithms",
"games",
"greedy",
"interactive"
] | null | null |
This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right.
This game will go on for *m* rounds. In each round, Ithea will give Chtholly an integer between 1 and *c*, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one).
Chtholly wins if, at any time, all the sheets are filled with a number and the *n* numbers are in non-decreasing order looking from left to right from sheet 1 to sheet *n*, and if after *m* rounds she still doesn't win, she loses the game.
Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.
|
The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.
|
none
|
[
"2 4 4\n2\n1\n3\n"
] |
[
"1\n2\n2\n"
] |
In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets were filled with a number and they were non-decreasing, so she won the game.
Note that it is required that your program terminate immediately after Chtholly wins and do not read numbers from the input for the remaining rounds. If not, undefined behaviour may arise and it won't be sure whether your program will be accepted or rejected. Also because of this, please be careful when hacking others' codes. In the sample, Chtholly won the game after the 3rd round, so it is required that your program doesn't read the number of the remaining 4th round.
The input format for hacking:
- The first line contains 3 integers *n*, *m* and *c*; - The following *m* lines each contains an integer between 1 and *c*, indicating the number given to Chtholly in each round.
| 1,000
|
[
{
"input": "2 4 4\n2\n1\n3\n4",
"output": "3"
},
{
"input": "2 2 2\n1\n2",
"output": "2"
},
{
"input": "3 6 3\n1\n2\n1\n3\n1\n3",
"output": "3"
},
{
"input": "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4",
"output": "4"
},
{
"input": "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8\n3\n11\n13\n5\n12\n11\n9\n3\n10\n9\n9\n13\n13\n5\n6\n11\n3\n15\n8\n8\n10\n13\n7\n6\n4\n14\n9\n10\n5\n13\n4\n1\n8\n6\n13\n1\n3\n4\n9\n12\n2\n7\n3\n3\n7\n2\n2\n9\n2\n4\n2\n2\n11\n12\n15\n13\n6\n2\n11\n1\n8\n3\n13\n6\n15\n6\n4\n3\n4\n15\n15\n9\n5\n8\n3\n6\n14\n14\n5\n9\n4\n4\n14\n1\n12\n4\n12\n9\n11\n7\n4\n2\n5\n4\n4\n13\n13\n4\n5\n8\n3\n4\n2\n15\n3\n10\n9\n8\n12\n8",
"output": "20"
},
{
"input": "2 2 2\n2\n1",
"output": "2"
},
{
"input": "2 2 1\n1\n1",
"output": "2"
},
{
"input": "2 2 2\n2\n2",
"output": "2"
},
{
"input": "3 3 2\n2\n2\n1",
"output": "3"
},
{
"input": "3 3 2\n1\n2\n1",
"output": "3"
},
{
"input": "3 3 2\n2\n1\n2",
"output": "3"
},
{
"input": "3 3 2\n2\n1\n1",
"output": "3"
},
{
"input": "3 3 1\n1\n1\n1",
"output": "3"
},
{
"input": "3 6 3\n2\n2\n3\n3\n1\n1",
"output": "5"
},
{
"input": "3 6 3\n2\n2\n1\n1\n3\n3",
"output": "3"
},
{
"input": "3 6 3\n3\n3\n2\n2\n1\n1",
"output": "3"
},
{
"input": "4 4 2\n1\n2\n2\n1",
"output": "4"
},
{
"input": "4 4 2\n1\n2\n1\n2",
"output": "4"
},
{
"input": "4 4 2\n2\n2\n2\n1",
"output": "4"
},
{
"input": "4 8 3\n2\n1\n2\n1\n2\n1\n1\n1",
"output": "4"
},
{
"input": "4 8 3\n3\n2\n3\n2\n3\n2\n3\n1",
"output": "6"
},
{
"input": "4 8 3\n2\n3\n2\n3\n3\n3\n3\n1",
"output": "6"
},
{
"input": "4 8 4\n2\n3\n2\n3\n2\n3\n2\n3",
"output": "4"
},
{
"input": "4 8 4\n3\n4\n3\n3\n4\n4\n1\n2",
"output": "7"
},
{
"input": "10 100 20\n4\n1\n15\n2\n11\n1\n18\n9\n17\n5\n17\n12\n20\n6\n14\n19\n20\n3\n6\n14\n12\n17\n17\n10\n11\n8\n6\n6\n19\n16\n20\n6\n14\n5\n6\n19\n16\n11\n12\n1\n18\n10\n20\n8\n6\n12\n18\n16\n9\n10\n13\n17\n19\n7\n15\n7\n11\n1\n9\n10\n12\n5\n4\n16\n5\n7\n9\n15\n14\n20\n6\n3\n12\n10\n3\n6\n1\n16\n15\n18\n6\n19\n4\n17\n15\n15\n2\n6\n18\n12\n20\n10\n5\n13\n9\n11\n20\n20\n4\n16",
"output": "20"
},
{
"input": "10 100 20\n11\n11\n11\n11\n11\n11\n11\n11\n11\n10\n10\n10\n10\n10\n10\n10\n10\n10\n9\n9\n9\n9\n9\n9\n9\n9\n9\n8\n8\n8\n8\n8\n8\n8\n8\n8\n7\n7\n7\n7\n7\n7\n7\n7\n7\n6\n6\n6\n6\n6\n6\n6\n6\n6\n5\n5\n5\n5\n5\n5\n5\n5\n5\n4\n4\n4\n4\n4\n4\n4\n4\n4\n3\n3\n3\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n12",
"output": "10"
}
] | 1,642,789,092
| 2,472
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 7
| 109
| 4,608,000
|
import sys
#import random
input = sys.stdin.buffer.readline
def process(n, m, c):
#I = [random.sample(range(1, c+1), 1)[0] for i in range(m)]
A = [None for i in range(n)]
for i in range(m):
x = int(input())
if A[0] is None:
print("1")
sys.stdout.flush()
A[0] = x
curr = 1
else:
if x < A[0]:
print("1")
sys.stdout.flush()
A[0] = x
elif x >= A[curr-1]:
print(f'{curr+1}')
sys.stdout.flush()
A[curr] = x
curr+=1
if curr==n:
sys.exit()
else:
s = 0
e = curr-1
while s+1 < e:
m = (s+e)//2
if x >= A[m]:
s, e = m, e
else:
s, e = s, m
#A[s+1] > x >= A[s]
print(f'{e+1}')
sys.stdout.flush()
A[e] = x
n, m, c = [int(x) for x in input().split()]
process(n, m, c)
|
Title: Ithea Plays With Chtholly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right.
This game will go on for *m* rounds. In each round, Ithea will give Chtholly an integer between 1 and *c*, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one).
Chtholly wins if, at any time, all the sheets are filled with a number and the *n* numbers are in non-decreasing order looking from left to right from sheet 1 to sheet *n*, and if after *m* rounds she still doesn't win, she loses the game.
Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.
Input Specification:
The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.
Output Specification:
none
Demo Input:
['2 4 4\n2\n1\n3\n']
Demo Output:
['1\n2\n2\n']
Note:
In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets were filled with a number and they were non-decreasing, so she won the game.
Note that it is required that your program terminate immediately after Chtholly wins and do not read numbers from the input for the remaining rounds. If not, undefined behaviour may arise and it won't be sure whether your program will be accepted or rejected. Also because of this, please be careful when hacking others' codes. In the sample, Chtholly won the game after the 3rd round, so it is required that your program doesn't read the number of the remaining 4th round.
The input format for hacking:
- The first line contains 3 integers *n*, *m* and *c*; - The following *m* lines each contains an integer between 1 and *c*, indicating the number given to Chtholly in each round.
|
```python
import sys
#import random
input = sys.stdin.buffer.readline
def process(n, m, c):
#I = [random.sample(range(1, c+1), 1)[0] for i in range(m)]
A = [None for i in range(n)]
for i in range(m):
x = int(input())
if A[0] is None:
print("1")
sys.stdout.flush()
A[0] = x
curr = 1
else:
if x < A[0]:
print("1")
sys.stdout.flush()
A[0] = x
elif x >= A[curr-1]:
print(f'{curr+1}')
sys.stdout.flush()
A[curr] = x
curr+=1
if curr==n:
sys.exit()
else:
s = 0
e = curr-1
while s+1 < e:
m = (s+e)//2
if x >= A[m]:
s, e = m, e
else:
s, e = s, m
#A[s+1] > x >= A[s]
print(f'{e+1}')
sys.stdout.flush()
A[e] = x
n, m, c = [int(x) for x in input().split()]
process(n, m, c)
```
| 0
|
|
1,008
|
A
|
Romaji
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] | null | null |
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese.
|
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
|
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower).
|
[
"sumimasen\n",
"ninja\n",
"codeforces\n"
] |
[
"YES\n",
"YES\n",
"NO\n"
] |
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
| 500
|
[
{
"input": "sumimasen",
"output": "YES"
},
{
"input": "ninja",
"output": "YES"
},
{
"input": "codeforces",
"output": "NO"
},
{
"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen",
"output": "YES"
},
{
"input": "n",
"output": "YES"
},
{
"input": "necnei",
"output": "NO"
},
{
"input": "nternn",
"output": "NO"
},
{
"input": "aucunuohja",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "b",
"output": "NO"
},
{
"input": "nn",
"output": "YES"
},
{
"input": "nnnzaaa",
"output": "YES"
},
{
"input": "zn",
"output": "NO"
},
{
"input": "ab",
"output": "NO"
},
{
"input": "aaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaab",
"output": "NO"
},
{
"input": "aaaaaaaaan",
"output": "YES"
},
{
"input": "baaaaaaaaa",
"output": "YES"
},
{
"input": "naaaaaaaaa",
"output": "YES"
},
{
"input": "nbaaaaaaaa",
"output": "YES"
},
{
"input": "bbaaaaaaaa",
"output": "NO"
},
{
"input": "bnaaaaaaaa",
"output": "NO"
},
{
"input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu",
"output": "YES"
},
{
"input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino",
"output": "NO"
},
{
"input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul",
"output": "NO"
},
{
"input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu",
"output": "YES"
},
{
"input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo",
"output": "NO"
},
{
"input": "y",
"output": "NO"
},
{
"input": "by",
"output": "NO"
},
{
"input": "yy",
"output": "NO"
},
{
"input": "nbn",
"output": "NO"
},
{
"input": "nz",
"output": "NO"
},
{
"input": "king",
"output": "NO"
},
{
"input": "g",
"output": "NO"
},
{
"input": "az",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "yn",
"output": "NO"
},
{
"input": "aeo",
"output": "YES"
},
{
"input": "nb",
"output": "NO"
},
{
"input": "npn",
"output": "NO"
},
{
"input": "kini",
"output": "YES"
},
{
"input": "pya",
"output": "NO"
},
{
"input": "m",
"output": "NO"
},
{
"input": "p",
"output": "NO"
},
{
"input": "aaaaaaaak",
"output": "NO"
},
{
"input": "aab",
"output": "NO"
},
{
"input": "d",
"output": "NO"
},
{
"input": "at",
"output": "NO"
},
{
"input": "aaaaaak",
"output": "NO"
},
{
"input": "aaz",
"output": "NO"
},
{
"input": "aaab",
"output": "NO"
},
{
"input": "s",
"output": "NO"
},
{
"input": "nzzen",
"output": "NO"
},
{
"input": "aeionnhhhn",
"output": "NO"
},
{
"input": "h",
"output": "NO"
},
{
"input": "ny",
"output": "NO"
}
] | 1,638,014,451
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
s=input()
n=len(s)
if s[-1] not in "aeioun":
x="NO"
else:
x="YES"
for i in range(n):
if s[i] not in "aeioun"
if s[i+1] not in "aeioun":
x="NO"
print(x)
|
Title: Romaji
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word $s$ is Berlanese.
Input Specification:
The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters.
Output Specification:
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower).
Demo Input:
['sumimasen\n', 'ninja\n', 'codeforces\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
|
```python
s=input()
n=len(s)
if s[-1] not in "aeioun":
x="NO"
else:
x="YES"
for i in range(n):
if s[i] not in "aeioun"
if s[i+1] not in "aeioun":
x="NO"
print(x)
```
| -1
|
|
988
|
A
|
Diverse Team
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
|
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student.
|
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them.
Assume that the students are numbered from $1$ to $n$.
|
[
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] |
[
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] |
All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter.
| 0
|
[
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17 33 35 24 20 48 56 73 12 14 39 55 58 13 59 73 29 26 40 33 22 29 34 22 55 38 63 66 36 13 60 42 10 15 21 9 11 5 23 37 79 47 26 3 79 53 44 8 71 75 42 11 34 39 79 33 10 26 23 23 17 14 54 41 60 31 83 5 45 4 14 35 6 60 28 48 23 18 60 36 21 28 7 34 9 25 52 43 54 19",
"output": "YES\n1 2 3 4 5 6 7 9 10 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 31 33 36 37 38 39 41 42 43 44 45 47 49 50 51 52 54 57 58 59 60 73 74 76 77 79 80 83 "
},
{
"input": "2 2\n100 100",
"output": "NO"
},
{
"input": "2 2\n100 99",
"output": "YES\n1 2 "
},
{
"input": "100 100\n63 100 75 32 53 24 73 98 76 15 70 48 8 81 88 58 95 78 27 92 14 16 72 43 46 39 66 38 64 42 59 9 22 51 4 6 10 94 28 99 68 80 35 50 45 20 47 7 30 26 49 91 77 19 96 57 65 1 11 13 31 12 82 87 93 34 62 3 21 79 56 41 89 18 44 23 74 86 2 33 69 36 61 67 25 83 5 84 90 37 40 29 97 60 52 55 54 71 17 85",
"output": "YES\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 "
},
{
"input": "100 41\n54 16 42 3 45 6 9 72 100 13 24 57 35 5 89 13 97 27 43 9 73 89 48 16 48 55 18 15 55 28 30 6 18 41 100 61 9 42 35 54 57 25 73 15 42 54 49 5 72 48 30 55 4 43 94 5 60 92 93 23 89 75 53 92 74 93 89 28 69 6 3 49 15 28 49 57 54 55 30 57 69 18 89 6 25 23 93 74 30 13 87 53 6 42 4 54 60 30 4 35",
"output": "NO"
},
{
"input": "100 2\n70 64 70 32 70 64 32 70 64 32 32 64 70 64 64 32 64 64 64 70 70 64 64 64 64 70 32 64 70 64 32 70 70 70 64 70 64 70 64 32 70 32 70 64 64 64 32 70 64 70 70 32 70 32 32 32 70 32 70 32 64 64 70 32 32 64 70 64 32 32 64 64 32 32 70 70 32 70 32 64 32 70 64 64 32 64 32 64 70 32 70 32 70 64 64 64 70 70 64 70",
"output": "YES\n1 2 "
}
] | 1,695,829,361
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 4
| 62
| 0
|
# Wadea #
n,k = map(int,input().split())
arr = list(map(int,input().split()))
c = 0
arr1 = []
arr2 = []
for i in range(n):
if arr[i] in arr1:
pass
else:
c += 1
arr1.append(arr[i])
arr2.append(i+1)
if c == k:
print("YES")
print(*arr2)
else:
print("NO")
|
Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.
Input Specification:
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student.
Output Specification:
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them.
Assume that the students are numbered from $1$ to $n$.
Demo Input:
['5 3\n15 13 15 15 12\n', '5 4\n15 13 15 15 12\n', '4 4\n20 10 40 30\n']
Demo Output:
['YES\n1 2 5 \n', 'NO\n', 'YES\n1 2 3 4 \n']
Note:
All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter.
|
```python
# Wadea #
n,k = map(int,input().split())
arr = list(map(int,input().split()))
c = 0
arr1 = []
arr2 = []
for i in range(n):
if arr[i] in arr1:
pass
else:
c += 1
arr1.append(arr[i])
arr2.append(i+1)
if c == k:
print("YES")
print(*arr2)
else:
print("NO")
```
| 0
|
|
733
|
A
|
Grasshopper And the String
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
|
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
|
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
|
[
"ABABBBACFEYUKOTT\n",
"AAA\n"
] |
[
"4",
"1"
] |
none
| 500
|
[
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
"output": "39"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI",
"output": "1"
},
{
"input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC",
"output": "85"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ",
"output": "18"
},
{
"input": "PKLKBWTXVJ",
"output": "11"
},
{
"input": "CFHFPTGMOKXVLJJZJDQW",
"output": "12"
},
{
"input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX",
"output": "9"
},
{
"input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY",
"output": "4"
},
{
"input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD",
"output": "101"
},
{
"input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC",
"output": "76"
},
{
"input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC",
"output": "45"
},
{
"input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT",
"output": "48"
},
{
"input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX",
"output": "47"
},
{
"input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA",
"output": "65"
},
{
"input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS",
"output": "28"
},
{
"input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW",
"output": "35"
},
{
"input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL",
"output": "30"
},
{
"input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL",
"output": "19"
},
{
"input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB",
"output": "30"
},
{
"input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB",
"output": "34"
},
{
"input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR",
"output": "17"
},
{
"input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT",
"output": "15"
},
{
"input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB",
"output": "9"
},
{
"input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW",
"output": "5"
},
{
"input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA",
"output": "4"
},
{
"input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE",
"output": "5"
},
{
"input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA",
"output": "5"
},
{
"input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO",
"output": "3"
},
{
"input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY",
"output": "3"
},
{
"input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY",
"output": "2"
},
{
"input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE",
"output": "2"
},
{
"input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII",
"output": "2"
},
{
"input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE",
"output": "2"
},
{
"input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU",
"output": "1"
},
{
"input": "ABBABBB",
"output": "4"
},
{
"input": "ABCD",
"output": "4"
},
{
"input": "XXYC",
"output": "3"
},
{
"input": "YYY",
"output": "1"
},
{
"input": "ABABBBBBBB",
"output": "8"
},
{
"input": "YYYY",
"output": "1"
},
{
"input": "YYYYY",
"output": "1"
},
{
"input": "AXXX",
"output": "4"
},
{
"input": "YYYYYYY",
"output": "1"
},
{
"input": "BYYBBB",
"output": "4"
},
{
"input": "YYYYYYYYY",
"output": "1"
},
{
"input": "CAAAAA",
"output": "2"
},
{
"input": "CCCACCCC",
"output": "5"
},
{
"input": "ABABBBACFEYUKOTTTT",
"output": "5"
},
{
"input": "AABBYYYYYYYY",
"output": "3"
},
{
"input": "BYBACYC",
"output": "2"
},
{
"input": "Y",
"output": "1"
},
{
"input": "ABBBBBB",
"output": "7"
},
{
"input": "BACDYDI",
"output": "3"
},
{
"input": "XEXXXXXXXXXXXXXXX",
"output": "16"
},
{
"input": "TTYTT",
"output": "3"
},
{
"input": "AAYBC",
"output": "3"
},
{
"input": "ABABBBACFEYUKOTTTTT",
"output": "6"
},
{
"input": "YYAYY",
"output": "1"
},
{
"input": "YZZY",
"output": "3"
},
{
"input": "YY",
"output": "1"
},
{
"input": "ZZYZZ",
"output": "3"
},
{
"input": "YBBBY",
"output": "4"
},
{
"input": "BBBACCCCCCC",
"output": "8"
},
{
"input": "YBBBBY",
"output": "5"
},
{
"input": "YYYYYYYYYY",
"output": "1"
},
{
"input": "ABABBBBBBBBBBBB",
"output": "13"
}
] | 1,656,412,228
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 70
| 46
| 0
|
st = input()
st2 = list(st).copy()
st2.append('A')
st2.insert(0,'A')
l = ['A','E','I','O','U','Y']
b = []
for i in range(len(st2)):
if st2[i] in l:
b.append(i)
maxx = 0
for i in range(len(b)-1):
if b[i+1]-b[i]>maxx:
maxx=b[i+1]-b[i]
print(maxx)
|
Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
Input Specification:
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Output Specification:
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
Demo Input:
['ABABBBACFEYUKOTT\n', 'AAA\n']
Demo Output:
['4', '1']
Note:
none
|
```python
st = input()
st2 = list(st).copy()
st2.append('A')
st2.insert(0,'A')
l = ['A','E','I','O','U','Y']
b = []
for i in range(len(st2)):
if st2[i] in l:
b.append(i)
maxx = 0
for i in range(len(b)-1):
if b[i+1]-b[i]>maxx:
maxx=b[i+1]-b[i]
print(maxx)
```
| 3
|
|
779
|
B
|
Weird Rounding
|
PROGRAMMING
| 1,100
|
[
"brute force",
"greedy"
] | null | null |
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103<==<=1000.
Write a program that prints the minimum number of digits to be deleted from the given integer number *n*, so that the result is divisible by 10*k*. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).
It is guaranteed that the answer exists.
|
The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.
|
Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).
|
[
"30020 3\n",
"100 9\n",
"10203049 2\n"
] |
[
"1\n",
"2\n",
"3\n"
] |
In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number.
| 1,000
|
[
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102030404 2",
"output": "2"
},
{
"input": "1000999999 3",
"output": "6"
},
{
"input": "12000000 4",
"output": "0"
},
{
"input": "1090090090 5",
"output": "2"
},
{
"input": "10 1",
"output": "0"
},
{
"input": "10 2",
"output": "1"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "100 1",
"output": "0"
},
{
"input": "100 3",
"output": "2"
},
{
"input": "101010110 3",
"output": "3"
},
{
"input": "101010110 1",
"output": "0"
},
{
"input": "101010110 2",
"output": "2"
},
{
"input": "101010110 4",
"output": "4"
},
{
"input": "101010110 5",
"output": "8"
},
{
"input": "101010110 9",
"output": "8"
},
{
"input": "1234567890 1",
"output": "0"
},
{
"input": "1234567890 2",
"output": "9"
},
{
"input": "1234567890 9",
"output": "9"
},
{
"input": "2000000000 1",
"output": "0"
},
{
"input": "2000000000 2",
"output": "0"
},
{
"input": "2000000000 3",
"output": "0"
},
{
"input": "2000000000 9",
"output": "0"
},
{
"input": "1010101010 1",
"output": "0"
},
{
"input": "1010101010 2",
"output": "1"
},
{
"input": "1010101010 3",
"output": "2"
},
{
"input": "1010101010 4",
"output": "3"
},
{
"input": "1010101010 5",
"output": "4"
},
{
"input": "1010101010 6",
"output": "9"
},
{
"input": "1010101010 7",
"output": "9"
},
{
"input": "1010101010 8",
"output": "9"
},
{
"input": "1010101010 9",
"output": "9"
},
{
"input": "10001000 1",
"output": "0"
},
{
"input": "10001000 2",
"output": "0"
},
{
"input": "10001000 3",
"output": "0"
},
{
"input": "10001000 4",
"output": "1"
},
{
"input": "10001000 5",
"output": "1"
},
{
"input": "10001000 6",
"output": "1"
},
{
"input": "10001000 7",
"output": "7"
},
{
"input": "10001000 8",
"output": "7"
},
{
"input": "10001000 9",
"output": "7"
},
{
"input": "1000000001 1",
"output": "1"
},
{
"input": "1000000001 2",
"output": "1"
},
{
"input": "1000000001 3",
"output": "1"
},
{
"input": "1000000001 6",
"output": "1"
},
{
"input": "1000000001 7",
"output": "1"
},
{
"input": "1000000001 8",
"output": "1"
},
{
"input": "1000000001 9",
"output": "9"
},
{
"input": "1000 1",
"output": "0"
},
{
"input": "100001100 3",
"output": "2"
},
{
"input": "7057 6",
"output": "3"
},
{
"input": "30000000 5",
"output": "0"
},
{
"input": "470 1",
"output": "0"
},
{
"input": "500500000 4",
"output": "0"
},
{
"input": "2103 8",
"output": "3"
},
{
"input": "600000000 2",
"output": "0"
},
{
"input": "708404442 1",
"output": "4"
},
{
"input": "5000140 6",
"output": "6"
},
{
"input": "1100047 3",
"output": "2"
},
{
"input": "309500 5",
"output": "5"
},
{
"input": "70053160 4",
"output": "7"
},
{
"input": "44000 1",
"output": "0"
},
{
"input": "400370000 3",
"output": "0"
},
{
"input": "5800 6",
"output": "3"
},
{
"input": "20700050 1",
"output": "0"
},
{
"input": "650 1",
"output": "0"
},
{
"input": "320005070 6",
"output": "8"
},
{
"input": "370000 4",
"output": "0"
},
{
"input": "1011 2",
"output": "3"
},
{
"input": "1000111 5",
"output": "6"
},
{
"input": "1001111 5",
"output": "6"
},
{
"input": "99990 3",
"output": "4"
},
{
"input": "10100200 6",
"output": "7"
},
{
"input": "200 3",
"output": "2"
},
{
"input": "103055 3",
"output": "5"
},
{
"input": "1030555 3",
"output": "6"
},
{
"input": "100111 4",
"output": "5"
},
{
"input": "101 2",
"output": "2"
},
{
"input": "1001 3",
"output": "3"
},
{
"input": "100000 6",
"output": "5"
},
{
"input": "1100000 6",
"output": "6"
},
{
"input": "123450 2",
"output": "5"
},
{
"input": "1003 3",
"output": "3"
},
{
"input": "1111100 4",
"output": "6"
},
{
"input": "532415007 8",
"output": "8"
},
{
"input": "801 2",
"output": "2"
},
{
"input": "1230 2",
"output": "3"
},
{
"input": "9900 3",
"output": "3"
},
{
"input": "14540444 2",
"output": "7"
},
{
"input": "11111100 4",
"output": "7"
},
{
"input": "11001 3",
"output": "4"
},
{
"input": "1011110 3",
"output": "6"
},
{
"input": "15450112 2",
"output": "7"
},
{
"input": "2220 3",
"output": "3"
},
{
"input": "90099 3",
"output": "4"
},
{
"input": "10005 4",
"output": "4"
},
{
"input": "1010 3",
"output": "3"
},
{
"input": "444444400 3",
"output": "8"
},
{
"input": "10020 4",
"output": "4"
},
{
"input": "10303 3",
"output": "4"
},
{
"input": "123000 4",
"output": "5"
},
{
"input": "12300 3",
"output": "4"
},
{
"input": "101 1",
"output": "1"
},
{
"input": "500001 8",
"output": "5"
},
{
"input": "121002 3",
"output": "5"
},
{
"input": "10011 3",
"output": "4"
},
{
"input": "505050 4",
"output": "5"
},
{
"input": "1421011 2",
"output": "6"
},
{
"input": "1202022 3",
"output": "6"
},
{
"input": "1000023 7",
"output": "6"
},
{
"input": "110 2",
"output": "2"
},
{
"input": "111000 4",
"output": "5"
},
{
"input": "10340 3",
"output": "4"
},
{
"input": "101 9",
"output": "2"
},
{
"input": "2001 3",
"output": "3"
},
{
"input": "122320 2",
"output": "5"
},
{
"input": "22200 3",
"output": "4"
},
{
"input": "11110 2",
"output": "4"
},
{
"input": "11010 3",
"output": "4"
},
{
"input": "1000002333 6",
"output": "9"
},
{
"input": "101010 4",
"output": "5"
},
{
"input": "210 9",
"output": "2"
},
{
"input": "500555 3",
"output": "5"
},
{
"input": "1110111 3",
"output": "6"
},
{
"input": "1100000000 9",
"output": "9"
},
{
"input": "11000 4",
"output": "4"
},
{
"input": "100 4",
"output": "2"
},
{
"input": "234560 3",
"output": "5"
},
{
"input": "10230 3",
"output": "4"
},
{
"input": "10030234 5",
"output": "7"
},
{
"input": "1200 3",
"output": "3"
},
{
"input": "123400 3",
"output": "5"
},
{
"input": "1034543 4",
"output": "6"
},
{
"input": "10100 4",
"output": "4"
},
{
"input": "10 5",
"output": "1"
},
{
"input": "4501022 3",
"output": "6"
},
{
"input": "12340 2",
"output": "4"
},
{
"input": "30020 4",
"output": "4"
},
{
"input": "1111100 6",
"output": "6"
},
{
"input": "10101 5",
"output": "4"
},
{
"input": "32132100 3",
"output": "7"
},
{
"input": "1000023 6",
"output": "6"
},
{
"input": "12300 4",
"output": "4"
},
{
"input": "78400 3",
"output": "4"
},
{
"input": "10203049 5",
"output": "7"
},
{
"input": "404044 3",
"output": "5"
},
{
"input": "1024 2",
"output": "3"
},
{
"input": "505 2",
"output": "2"
},
{
"input": "20 2",
"output": "1"
},
{
"input": "1111100 3",
"output": "6"
},
{
"input": "1000 9",
"output": "3"
},
{
"input": "3333300 3",
"output": "6"
},
{
"input": "1100 3",
"output": "3"
},
{
"input": "963000 4",
"output": "5"
},
{
"input": "100457 5",
"output": "5"
},
{
"input": "10049 3",
"output": "4"
}
] | 1,488,107,936
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 111
| 62
| 4,608,000
|
def f():
ipt = input().strip().split()
k = int(ipt[1])
ns = ipt[0]
a = [int(i) for i in ns]
n = len(a)
flag = 1
for i in a:
if i== 0:
flag = 0
break
if n< k+1:
if flag==0:
print(n-1)
return
print(n)
return
count = 0
d = 0
for i in reversed(a):
if count == k:
print( d-count)
return
if i == 0:
count += 1
d += 1
if flag == 0:
print(n-1)
return
print(n)
f()
|
Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103<==<=1000.
Write a program that prints the minimum number of digits to be deleted from the given integer number *n*, so that the result is divisible by 10*k*. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).
It is guaranteed that the answer exists.
Input Specification:
The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.
Output Specification:
Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).
Demo Input:
['30020 3\n', '100 9\n', '10203049 2\n']
Demo Output:
['1\n', '2\n', '3\n']
Note:
In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number.
|
```python
def f():
ipt = input().strip().split()
k = int(ipt[1])
ns = ipt[0]
a = [int(i) for i in ns]
n = len(a)
flag = 1
for i in a:
if i== 0:
flag = 0
break
if n< k+1:
if flag==0:
print(n-1)
return
print(n)
return
count = 0
d = 0
for i in reversed(a):
if count == k:
print( d-count)
return
if i == 0:
count += 1
d += 1
if flag == 0:
print(n-1)
return
print(n)
f()
```
| 3
|
|
991
|
A
|
If at first you don't succeed...
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
|
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
|
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
|
[
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] |
[
"5",
"-1",
"-1"
] |
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
| 500
|
[
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
},
{
"input": "6 7 5 8",
"output": "-1"
},
{
"input": "6 7 5 9",
"output": "1"
},
{
"input": "6 7 5 7",
"output": "-1"
},
{
"input": "50 50 1 100",
"output": "1"
},
{
"input": "8 3 2 12",
"output": "3"
},
{
"input": "10 19 6 25",
"output": "2"
},
{
"input": "1 0 0 99",
"output": "98"
},
{
"input": "0 1 0 98",
"output": "97"
},
{
"input": "1 1 0 97",
"output": "95"
},
{
"input": "1 1 1 96",
"output": "95"
},
{
"input": "0 0 0 0",
"output": "-1"
},
{
"input": "100 0 0 0",
"output": "-1"
},
{
"input": "0 100 0 0",
"output": "-1"
},
{
"input": "100 100 0 0",
"output": "-1"
},
{
"input": "0 0 100 0",
"output": "-1"
},
{
"input": "100 0 100 0",
"output": "-1"
},
{
"input": "0 100 100 0",
"output": "-1"
},
{
"input": "100 100 100 0",
"output": "-1"
},
{
"input": "0 0 0 100",
"output": "100"
},
{
"input": "100 0 0 100",
"output": "-1"
},
{
"input": "0 100 0 100",
"output": "-1"
},
{
"input": "100 100 0 100",
"output": "-1"
},
{
"input": "0 0 100 100",
"output": "-1"
},
{
"input": "100 0 100 100",
"output": "-1"
},
{
"input": "0 100 100 100",
"output": "-1"
},
{
"input": "100 100 100 100",
"output": "-1"
},
{
"input": "10 45 7 52",
"output": "4"
},
{
"input": "38 1 1 68",
"output": "30"
},
{
"input": "8 45 2 67",
"output": "16"
},
{
"input": "36 36 18 65",
"output": "11"
},
{
"input": "10 30 8 59",
"output": "27"
},
{
"input": "38 20 12 49",
"output": "3"
},
{
"input": "8 19 4 38",
"output": "15"
},
{
"input": "36 21 17 72",
"output": "32"
},
{
"input": "14 12 12 89",
"output": "75"
},
{
"input": "38 6 1 44",
"output": "1"
},
{
"input": "13 4 6 82",
"output": "-1"
},
{
"input": "5 3 17 56",
"output": "-1"
},
{
"input": "38 5 29 90",
"output": "-1"
},
{
"input": "22 36 18 55",
"output": "15"
},
{
"input": "13 0 19 75",
"output": "-1"
},
{
"input": "62 65 10 89",
"output": "-1"
},
{
"input": "2 29 31 72",
"output": "-1"
},
{
"input": "1 31 19 55",
"output": "-1"
},
{
"input": "1 25 28 88",
"output": "-1"
},
{
"input": "34 32 28 33",
"output": "-1"
},
{
"input": "43 36 1 100",
"output": "22"
},
{
"input": "16 39 55 70",
"output": "-1"
},
{
"input": "2 3 0 91",
"output": "86"
},
{
"input": "55 29 12 48",
"output": "-1"
},
{
"input": "7 33 20 88",
"output": "-1"
},
{
"input": "40 38 27 99",
"output": "48"
},
{
"input": "18 28 14 84",
"output": "52"
},
{
"input": "34 25 25 92",
"output": "58"
},
{
"input": "4 24 5 76",
"output": "-1"
},
{
"input": "5 22 16 96",
"output": "-1"
},
{
"input": "1 1 0 4",
"output": "2"
},
{
"input": "5 5 3 1",
"output": "-1"
},
{
"input": "0 0 0 1",
"output": "1"
},
{
"input": "2 3 0 8",
"output": "3"
},
{
"input": "5 5 2 5",
"output": "-1"
},
{
"input": "1 2 1 3",
"output": "1"
},
{
"input": "3 0 0 4",
"output": "1"
},
{
"input": "0 0 0 5",
"output": "5"
},
{
"input": "5 5 0 3",
"output": "-1"
},
{
"input": "5 6 1 7",
"output": "-1"
},
{
"input": "10 10 10 11",
"output": "1"
},
{
"input": "0 0 0 10",
"output": "10"
},
{
"input": "5 15 5 30",
"output": "15"
},
{
"input": "3 2 0 7",
"output": "2"
}
] | 1,681,945,798
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 76
| 61
| 0
|
a, b, c, n = map(int, input().split())
a -= c
b -= c
if a + b + c + 1 > n or a < 0 or b < 0:
print(-1)
else:
print(n - a - b - c)
|
Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input Specification:
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
Output Specification:
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
Demo Input:
['10 10 5 20\n', '2 2 0 4\n', '2 2 2 1\n']
Demo Output:
['5', '-1', '-1']
Note:
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.
|
```python
a, b, c, n = map(int, input().split())
a -= c
b -= c
if a + b + c + 1 > n or a < 0 or b < 0:
print(-1)
else:
print(n - a - b - c)
```
| 3
|
|
45
|
J
|
Planting Trees
|
PROGRAMMING
| 1,800
|
[
"constructive algorithms"
] |
J. Planting Trees
|
2
|
256
|
Vasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into *n*<=×<=*m* squares and decided to plant a forest there. Vasya will plant *nm* trees of all different heights from 1 to *nm*. For his forest to look more natural he wants any two trees growing in the side neighbouring squares to have the absolute value of difference in heights to be strictly more than 1. Help Vasya: make the plan of the forest planting for which this condition is fulfilled.
|
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns on Vasya's field
|
If there's no solution, print -1. Otherwise, print *n* lines containing *m* numbers each — the trees' planting plan. In every square of the plan the height of a tree that should be planted on this square should be written. If there are several solutions to that problem, print any of them.
|
[
"2 3\n",
"2 1\n"
] |
[
"3 6 2\n5 1 4\n",
"-1\n"
] |
none
| 0
|
[
{
"input": "2 3",
"output": "4 1 5 \n2 6 3 "
},
{
"input": "2 1",
"output": "-1"
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "3 1 4 2 "
},
{
"input": "1 5",
"output": "1 4 2 5 3 "
},
{
"input": "1 6",
"output": "1 4 2 5 3 6 "
},
{
"input": "1 98",
"output": "1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 58 10 59 11 60 12 61 13 62 14 63 15 64 16 65 17 66 18 67 19 68 20 69 21 70 22 71 23 72 24 73 25 74 26 75 27 76 28 77 29 78 30 79 31 80 32 81 33 82 34 83 35 84 36 85 37 86 38 87 39 88 40 89 41 90 42 91 43 92 44 93 45 94 46 95 47 96 48 97 49 98 "
},
{
"input": "1 99",
"output": "1 51 2 52 3 53 4 54 5 55 6 56 7 57 8 58 9 59 10 60 11 61 12 62 13 63 14 64 15 65 16 66 17 67 18 68 19 69 20 70 21 71 22 72 23 73 24 74 25 75 26 76 27 77 28 78 29 79 30 80 31 81 32 82 33 83 34 84 35 85 36 86 37 87 38 88 39 89 40 90 41 91 42 92 43 93 44 94 45 95 46 96 47 97 48 98 49 99 50 "
},
{
"input": "1 100",
"output": "1 51 2 52 3 53 4 54 5 55 6 56 7 57 8 58 9 59 10 60 11 61 12 62 13 63 14 64 15 65 16 66 17 67 18 68 19 69 20 70 21 71 22 72 23 73 24 74 25 75 26 76 27 77 28 78 29 79 30 80 31 81 32 82 33 83 34 84 35 85 36 86 37 87 38 88 39 89 40 90 41 91 42 92 43 93 44 94 45 95 46 96 47 97 48 98 49 99 50 100 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "-1"
},
{
"input": "3 1",
"output": "-1"
},
{
"input": "4 1",
"output": "3 \n1 \n4 \n2 "
},
{
"input": "5 1",
"output": "1 \n4 \n2 \n5 \n3 "
},
{
"input": "6 1",
"output": "1 \n4 \n2 \n5 \n3 \n6 "
},
{
"input": "98 1",
"output": "1 \n50 \n2 \n51 \n3 \n52 \n4 \n53 \n5 \n54 \n6 \n55 \n7 \n56 \n8 \n57 \n9 \n58 \n10 \n59 \n11 \n60 \n12 \n61 \n13 \n62 \n14 \n63 \n15 \n64 \n16 \n65 \n17 \n66 \n18 \n67 \n19 \n68 \n20 \n69 \n21 \n70 \n22 \n71 \n23 \n72 \n24 \n73 \n25 \n74 \n26 \n75 \n27 \n76 \n28 \n77 \n29 \n78 \n30 \n79 \n31 \n80 \n32 \n81 \n33 \n82 \n34 \n83 \n35 \n84 \n36 \n85 \n37 \n86 \n38 \n87 \n39 \n88 \n40 \n89 \n41 \n90 \n42 \n91 \n43 \n92 \n44 \n93 \n45 \n94 \n46 \n95 \n47 \n96 \n48 \n97 \n49 \n98 "
},
{
"input": "99 1",
"output": "1 \n51 \n2 \n52 \n3 \n53 \n4 \n54 \n5 \n55 \n6 \n56 \n7 \n57 \n8 \n58 \n9 \n59 \n10 \n60 \n11 \n61 \n12 \n62 \n13 \n63 \n14 \n64 \n15 \n65 \n16 \n66 \n17 \n67 \n18 \n68 \n19 \n69 \n20 \n70 \n21 \n71 \n22 \n72 \n23 \n73 \n24 \n74 \n25 \n75 \n26 \n76 \n27 \n77 \n28 \n78 \n29 \n79 \n30 \n80 \n31 \n81 \n32 \n82 \n33 \n83 \n34 \n84 \n35 \n85 \n36 \n86 \n37 \n87 \n38 \n88 \n39 \n89 \n40 \n90 \n41 \n91 \n42 \n92 \n43 \n93 \n44 \n94 \n45 \n95 \n46 \n96 \n47 \n97 \n48 \n98 \n49 \n99 \n50 "
},
{
"input": "100 1",
"output": "1 \n51 \n2 \n52 \n3 \n53 \n4 \n54 \n5 \n55 \n6 \n56 \n7 \n57 \n8 \n58 \n9 \n59 \n10 \n60 \n11 \n61 \n12 \n62 \n13 \n63 \n14 \n64 \n15 \n65 \n16 \n66 \n17 \n67 \n18 \n68 \n19 \n69 \n20 \n70 \n21 \n71 \n22 \n72 \n23 \n73 \n24 \n74 \n25 \n75 \n26 \n76 \n27 \n77 \n28 \n78 \n29 \n79 \n30 \n80 \n31 \n81 \n32 \n82 \n33 \n83 \n34 \n84 \n35 \n85 \n36 \n86 \n37 \n87 \n38 \n88 \n39 \n89 \n40 \n90 \n41 \n91 \n42 \n92 \n43 \n93 \n44 \n94 \n45 \n95 \n46 \n96 \n47 \n97 \n48 \n98 \n49 \n99 \n50 \n100 "
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "2 4",
"output": "1 5 2 6 \n7 3 8 4 "
},
{
"input": "2 5",
"output": "1 6 2 7 3 \n8 4 9 5 10 "
},
{
"input": "2 6",
"output": "1 7 2 8 3 9 \n10 4 11 5 12 6 "
},
{
"input": "2 99",
"output": "1 100 2 101 3 102 4 103 5 104 6 105 7 106 8 107 9 108 10 109 11 110 12 111 13 112 14 113 15 114 16 115 17 116 18 117 19 118 20 119 21 120 22 121 23 122 24 123 25 124 26 125 27 126 28 127 29 128 30 129 31 130 32 131 33 132 34 133 35 134 36 135 37 136 38 137 39 138 40 139 41 140 42 141 43 142 44 143 45 144 46 145 47 146 48 147 49 148 50 \n149 51 150 52 151 53 152 54 153 55 154 56 155 57 156 58 157 59 158 60 159 61 160 62 161 63 162 64 163 65 164 66 165 67 166 68 167 69 168 70 169 71 170 72 171 73 172 74 173 ..."
},
{
"input": "2 100",
"output": "1 101 2 102 3 103 4 104 5 105 6 106 7 107 8 108 9 109 10 110 11 111 12 112 13 113 14 114 15 115 16 116 17 117 18 118 19 119 20 120 21 121 22 122 23 123 24 124 25 125 26 126 27 127 28 128 29 129 30 130 31 131 32 132 33 133 34 134 35 135 36 136 37 137 38 138 39 139 40 140 41 141 42 142 43 143 44 144 45 145 46 146 47 147 48 148 49 149 50 150 \n151 51 152 52 153 53 154 54 155 55 156 56 157 57 158 58 159 59 160 60 161 61 162 62 163 63 164 64 165 65 166 66 167 67 168 68 169 69 170 70 171 71 172 72 173 73 174 74 ..."
},
{
"input": "3 2",
"output": "1 4 \n5 2 \n3 6 "
},
{
"input": "3 3",
"output": "1 6 2 \n7 3 8 \n4 9 5 "
},
{
"input": "3 4",
"output": "1 7 2 8 \n9 3 10 4 \n5 11 6 12 "
},
{
"input": "3 5",
"output": "1 9 2 10 3 \n11 4 12 5 13 \n6 14 7 15 8 "
},
{
"input": "3 99",
"output": "1 150 2 151 3 152 4 153 5 154 6 155 7 156 8 157 9 158 10 159 11 160 12 161 13 162 14 163 15 164 16 165 17 166 18 167 19 168 20 169 21 170 22 171 23 172 24 173 25 174 26 175 27 176 28 177 29 178 30 179 31 180 32 181 33 182 34 183 35 184 36 185 37 186 38 187 39 188 40 189 41 190 42 191 43 192 44 193 45 194 46 195 47 196 48 197 49 198 50 \n199 51 200 52 201 53 202 54 203 55 204 56 205 57 206 58 207 59 208 60 209 61 210 62 211 63 212 64 213 65 214 66 215 67 216 68 217 69 218 70 219 71 220 72 221 73 222 74 223 ..."
},
{
"input": "3 100",
"output": "1 151 2 152 3 153 4 154 5 155 6 156 7 157 8 158 9 159 10 160 11 161 12 162 13 163 14 164 15 165 16 166 17 167 18 168 19 169 20 170 21 171 22 172 23 173 24 174 25 175 26 176 27 177 28 178 29 179 30 180 31 181 32 182 33 183 34 184 35 185 36 186 37 187 38 188 39 189 40 190 41 191 42 192 43 193 44 194 45 195 46 196 47 197 48 198 49 199 50 200 \n201 51 202 52 203 53 204 54 205 55 206 56 207 57 208 58 209 59 210 60 211 61 212 62 213 63 214 64 215 65 216 66 217 67 218 68 219 69 220 70 221 71 222 72 223 73 224 74 ..."
},
{
"input": "4 2",
"output": "1 5 \n6 2 \n3 7 \n8 4 "
},
{
"input": "4 3",
"output": "1 7 2 \n8 3 9 \n4 10 5 \n11 6 12 "
},
{
"input": "4 4",
"output": "1 9 2 10 \n11 3 12 4 \n5 13 6 14 \n15 7 16 8 "
},
{
"input": "4 5",
"output": "1 11 2 12 3 \n13 4 14 5 15 \n6 16 7 17 8 \n18 9 19 10 20 "
},
{
"input": "4 99",
"output": "1 199 2 200 3 201 4 202 5 203 6 204 7 205 8 206 9 207 10 208 11 209 12 210 13 211 14 212 15 213 16 214 17 215 18 216 19 217 20 218 21 219 22 220 23 221 24 222 25 223 26 224 27 225 28 226 29 227 30 228 31 229 32 230 33 231 34 232 35 233 36 234 37 235 38 236 39 237 40 238 41 239 42 240 43 241 44 242 45 243 46 244 47 245 48 246 49 247 50 \n248 51 249 52 250 53 251 54 252 55 253 56 254 57 255 58 256 59 257 60 258 61 259 62 260 63 261 64 262 65 263 66 264 67 265 68 266 69 267 70 268 71 269 72 270 73 271 74 272 ..."
},
{
"input": "4 100",
"output": "1 201 2 202 3 203 4 204 5 205 6 206 7 207 8 208 9 209 10 210 11 211 12 212 13 213 14 214 15 215 16 216 17 217 18 218 19 219 20 220 21 221 22 222 23 223 24 224 25 225 26 226 27 227 28 228 29 229 30 230 31 231 32 232 33 233 34 234 35 235 36 236 37 237 38 238 39 239 40 240 41 241 42 242 43 243 44 244 45 245 46 246 47 247 48 248 49 249 50 250 \n251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 ..."
},
{
"input": "5 2",
"output": "1 6 \n7 2 \n3 8 \n9 4 \n5 10 "
},
{
"input": "5 3",
"output": "1 9 2 \n10 3 11 \n4 12 5 \n13 6 14 \n7 15 8 "
},
{
"input": "5 4",
"output": "1 11 2 12 \n13 3 14 4 \n5 15 6 16 \n17 7 18 8 \n9 19 10 20 "
},
{
"input": "5 5",
"output": "1 14 2 15 3 \n16 4 17 5 18 \n6 19 7 20 8 \n21 9 22 10 23 \n11 24 12 25 13 "
},
{
"input": "5 99",
"output": "1 249 2 250 3 251 4 252 5 253 6 254 7 255 8 256 9 257 10 258 11 259 12 260 13 261 14 262 15 263 16 264 17 265 18 266 19 267 20 268 21 269 22 270 23 271 24 272 25 273 26 274 27 275 28 276 29 277 30 278 31 279 32 280 33 281 34 282 35 283 36 284 37 285 38 286 39 287 40 288 41 289 42 290 43 291 44 292 45 293 46 294 47 295 48 296 49 297 50 \n298 51 299 52 300 53 301 54 302 55 303 56 304 57 305 58 306 59 307 60 308 61 309 62 310 63 311 64 312 65 313 66 314 67 315 68 316 69 317 70 318 71 319 72 320 73 321 74 322 ..."
},
{
"input": "5 100",
"output": "1 251 2 252 3 253 4 254 5 255 6 256 7 257 8 258 9 259 10 260 11 261 12 262 13 263 14 264 15 265 16 266 17 267 18 268 19 269 20 270 21 271 22 272 23 273 24 274 25 275 26 276 27 277 28 278 29 279 30 280 31 281 32 282 33 283 34 284 35 285 36 286 37 287 38 288 39 289 40 290 41 291 42 292 43 293 44 294 45 295 46 296 47 297 48 298 49 299 50 300 \n301 51 302 52 303 53 304 54 305 55 306 56 307 57 308 58 309 59 310 60 311 61 312 62 313 63 314 64 315 65 316 66 317 67 318 68 319 69 320 70 321 71 322 72 323 73 324 74 ..."
},
{
"input": "98 2",
"output": "1 99 \n100 2 \n3 101 \n102 4 \n5 103 \n104 6 \n7 105 \n106 8 \n9 107 \n108 10 \n11 109 \n110 12 \n13 111 \n112 14 \n15 113 \n114 16 \n17 115 \n116 18 \n19 117 \n118 20 \n21 119 \n120 22 \n23 121 \n122 24 \n25 123 \n124 26 \n27 125 \n126 28 \n29 127 \n128 30 \n31 129 \n130 32 \n33 131 \n132 34 \n35 133 \n134 36 \n37 135 \n136 38 \n39 137 \n138 40 \n41 139 \n140 42 \n43 141 \n142 44 \n45 143 \n144 46 \n47 145 \n146 48 \n49 147 \n148 50 \n51 149 \n150 52 \n53 151 \n152 54 \n55 153 \n154 56 \n57 155 \n156 58 \n..."
},
{
"input": "98 3",
"output": "1 148 2 \n149 3 150 \n4 151 5 \n152 6 153 \n7 154 8 \n155 9 156 \n10 157 11 \n158 12 159 \n13 160 14 \n161 15 162 \n16 163 17 \n164 18 165 \n19 166 20 \n167 21 168 \n22 169 23 \n170 24 171 \n25 172 26 \n173 27 174 \n28 175 29 \n176 30 177 \n31 178 32 \n179 33 180 \n34 181 35 \n182 36 183 \n37 184 38 \n185 39 186 \n40 187 41 \n188 42 189 \n43 190 44 \n191 45 192 \n46 193 47 \n194 48 195 \n49 196 50 \n197 51 198 \n52 199 53 \n200 54 201 \n55 202 56 \n203 57 204 \n58 205 59 \n206 60 207 \n61 208 62 \n209 63 2..."
},
{
"input": "98 4",
"output": "1 197 2 198 \n199 3 200 4 \n5 201 6 202 \n203 7 204 8 \n9 205 10 206 \n207 11 208 12 \n13 209 14 210 \n211 15 212 16 \n17 213 18 214 \n215 19 216 20 \n21 217 22 218 \n219 23 220 24 \n25 221 26 222 \n223 27 224 28 \n29 225 30 226 \n227 31 228 32 \n33 229 34 230 \n231 35 232 36 \n37 233 38 234 \n235 39 236 40 \n41 237 42 238 \n239 43 240 44 \n45 241 46 242 \n243 47 244 48 \n49 245 50 246 \n247 51 248 52 \n53 249 54 250 \n251 55 252 56 \n57 253 58 254 \n255 59 256 60 \n61 257 62 258 \n259 63 260 64 \n65 261 6..."
},
{
"input": "98 5",
"output": "1 246 2 247 3 \n248 4 249 5 250 \n6 251 7 252 8 \n253 9 254 10 255 \n11 256 12 257 13 \n258 14 259 15 260 \n16 261 17 262 18 \n263 19 264 20 265 \n21 266 22 267 23 \n268 24 269 25 270 \n26 271 27 272 28 \n273 29 274 30 275 \n31 276 32 277 33 \n278 34 279 35 280 \n36 281 37 282 38 \n283 39 284 40 285 \n41 286 42 287 43 \n288 44 289 45 290 \n46 291 47 292 48 \n293 49 294 50 295 \n51 296 52 297 53 \n298 54 299 55 300 \n56 301 57 302 58 \n303 59 304 60 305 \n61 306 62 307 63 \n308 64 309 65 310 \n66 311 67 312..."
},
{
"input": "98 99",
"output": "1 4852 2 4853 3 4854 4 4855 5 4856 6 4857 7 4858 8 4859 9 4860 10 4861 11 4862 12 4863 13 4864 14 4865 15 4866 16 4867 17 4868 18 4869 19 4870 20 4871 21 4872 22 4873 23 4874 24 4875 25 4876 26 4877 27 4878 28 4879 29 4880 30 4881 31 4882 32 4883 33 4884 34 4885 35 4886 36 4887 37 4888 38 4889 39 4890 40 4891 41 4892 42 4893 43 4894 44 4895 45 4896 46 4897 47 4898 48 4899 49 4900 50 \n4901 51 4902 52 4903 53 4904 54 4905 55 4906 56 4907 57 4908 58 4909 59 4910 60 4911 61 4912 62 4913 63 4914 64 4915 65 491..."
},
{
"input": "98 100",
"output": "1 4901 2 4902 3 4903 4 4904 5 4905 6 4906 7 4907 8 4908 9 4909 10 4910 11 4911 12 4912 13 4913 14 4914 15 4915 16 4916 17 4917 18 4918 19 4919 20 4920 21 4921 22 4922 23 4923 24 4924 25 4925 26 4926 27 4927 28 4928 29 4929 30 4930 31 4931 32 4932 33 4933 34 4934 35 4935 36 4936 37 4937 38 4938 39 4939 40 4940 41 4941 42 4942 43 4943 44 4944 45 4945 46 4946 47 4947 48 4948 49 4949 50 4950 \n4951 51 4952 52 4953 53 4954 54 4955 55 4956 56 4957 57 4958 58 4959 59 4960 60 4961 61 4962 62 4963 63 4964 64 4965 6..."
},
{
"input": "99 2",
"output": "1 100 \n101 2 \n3 102 \n103 4 \n5 104 \n105 6 \n7 106 \n107 8 \n9 108 \n109 10 \n11 110 \n111 12 \n13 112 \n113 14 \n15 114 \n115 16 \n17 116 \n117 18 \n19 118 \n119 20 \n21 120 \n121 22 \n23 122 \n123 24 \n25 124 \n125 26 \n27 126 \n127 28 \n29 128 \n129 30 \n31 130 \n131 32 \n33 132 \n133 34 \n35 134 \n135 36 \n37 136 \n137 38 \n39 138 \n139 40 \n41 140 \n141 42 \n43 142 \n143 44 \n45 144 \n145 46 \n47 146 \n147 48 \n49 148 \n149 50 \n51 150 \n151 52 \n53 152 \n153 54 \n55 154 \n155 56 \n57 156 \n157 58 ..."
},
{
"input": "99 3",
"output": "1 150 2 \n151 3 152 \n4 153 5 \n154 6 155 \n7 156 8 \n157 9 158 \n10 159 11 \n160 12 161 \n13 162 14 \n163 15 164 \n16 165 17 \n166 18 167 \n19 168 20 \n169 21 170 \n22 171 23 \n172 24 173 \n25 174 26 \n175 27 176 \n28 177 29 \n178 30 179 \n31 180 32 \n181 33 182 \n34 183 35 \n184 36 185 \n37 186 38 \n187 39 188 \n40 189 41 \n190 42 191 \n43 192 44 \n193 45 194 \n46 195 47 \n196 48 197 \n49 198 50 \n199 51 200 \n52 201 53 \n202 54 203 \n55 204 56 \n205 57 206 \n58 207 59 \n208 60 209 \n61 210 62 \n211 63 2..."
},
{
"input": "99 4",
"output": "1 199 2 200 \n201 3 202 4 \n5 203 6 204 \n205 7 206 8 \n9 207 10 208 \n209 11 210 12 \n13 211 14 212 \n213 15 214 16 \n17 215 18 216 \n217 19 218 20 \n21 219 22 220 \n221 23 222 24 \n25 223 26 224 \n225 27 226 28 \n29 227 30 228 \n229 31 230 32 \n33 231 34 232 \n233 35 234 36 \n37 235 38 236 \n237 39 238 40 \n41 239 42 240 \n241 43 242 44 \n45 243 46 244 \n245 47 246 48 \n49 247 50 248 \n249 51 250 52 \n53 251 54 252 \n253 55 254 56 \n57 255 58 256 \n257 59 258 60 \n61 259 62 260 \n261 63 262 64 \n65 263 6..."
},
{
"input": "99 5",
"output": "1 249 2 250 3 \n251 4 252 5 253 \n6 254 7 255 8 \n256 9 257 10 258 \n11 259 12 260 13 \n261 14 262 15 263 \n16 264 17 265 18 \n266 19 267 20 268 \n21 269 22 270 23 \n271 24 272 25 273 \n26 274 27 275 28 \n276 29 277 30 278 \n31 279 32 280 33 \n281 34 282 35 283 \n36 284 37 285 38 \n286 39 287 40 288 \n41 289 42 290 43 \n291 44 292 45 293 \n46 294 47 295 48 \n296 49 297 50 298 \n51 299 52 300 53 \n301 54 302 55 303 \n56 304 57 305 58 \n306 59 307 60 308 \n61 309 62 310 63 \n311 64 312 65 313 \n66 314 67 315..."
},
{
"input": "99 99",
"output": "1 4902 2 4903 3 4904 4 4905 5 4906 6 4907 7 4908 8 4909 9 4910 10 4911 11 4912 12 4913 13 4914 14 4915 15 4916 16 4917 17 4918 18 4919 19 4920 20 4921 21 4922 22 4923 23 4924 24 4925 25 4926 26 4927 27 4928 28 4929 29 4930 30 4931 31 4932 32 4933 33 4934 34 4935 35 4936 36 4937 37 4938 38 4939 39 4940 40 4941 41 4942 42 4943 43 4944 44 4945 45 4946 46 4947 47 4948 48 4949 49 4950 50 \n4951 51 4952 52 4953 53 4954 54 4955 55 4956 56 4957 57 4958 58 4959 59 4960 60 4961 61 4962 62 4963 63 4964 64 4965 65 496..."
},
{
"input": "99 100",
"output": "1 4951 2 4952 3 4953 4 4954 5 4955 6 4956 7 4957 8 4958 9 4959 10 4960 11 4961 12 4962 13 4963 14 4964 15 4965 16 4966 17 4967 18 4968 19 4969 20 4970 21 4971 22 4972 23 4973 24 4974 25 4975 26 4976 27 4977 28 4978 29 4979 30 4980 31 4981 32 4982 33 4983 34 4984 35 4985 36 4986 37 4987 38 4988 39 4989 40 4990 41 4991 42 4992 43 4993 44 4994 45 4995 46 4996 47 4997 48 4998 49 4999 50 5000 \n5001 51 5002 52 5003 53 5004 54 5005 55 5006 56 5007 57 5008 58 5009 59 5010 60 5011 61 5012 62 5013 63 5014 64 5015 6..."
},
{
"input": "100 2",
"output": "1 101 \n102 2 \n3 103 \n104 4 \n5 105 \n106 6 \n7 107 \n108 8 \n9 109 \n110 10 \n11 111 \n112 12 \n13 113 \n114 14 \n15 115 \n116 16 \n17 117 \n118 18 \n19 119 \n120 20 \n21 121 \n122 22 \n23 123 \n124 24 \n25 125 \n126 26 \n27 127 \n128 28 \n29 129 \n130 30 \n31 131 \n132 32 \n33 133 \n134 34 \n35 135 \n136 36 \n37 137 \n138 38 \n39 139 \n140 40 \n41 141 \n142 42 \n43 143 \n144 44 \n45 145 \n146 46 \n47 147 \n148 48 \n49 149 \n150 50 \n51 151 \n152 52 \n53 153 \n154 54 \n55 155 \n156 56 \n57 157 \n158 58 ..."
},
{
"input": "100 3",
"output": "1 151 2 \n152 3 153 \n4 154 5 \n155 6 156 \n7 157 8 \n158 9 159 \n10 160 11 \n161 12 162 \n13 163 14 \n164 15 165 \n16 166 17 \n167 18 168 \n19 169 20 \n170 21 171 \n22 172 23 \n173 24 174 \n25 175 26 \n176 27 177 \n28 178 29 \n179 30 180 \n31 181 32 \n182 33 183 \n34 184 35 \n185 36 186 \n37 187 38 \n188 39 189 \n40 190 41 \n191 42 192 \n43 193 44 \n194 45 195 \n46 196 47 \n197 48 198 \n49 199 50 \n200 51 201 \n52 202 53 \n203 54 204 \n55 205 56 \n206 57 207 \n58 208 59 \n209 60 210 \n61 211 62 \n212 63 2..."
},
{
"input": "100 4",
"output": "1 201 2 202 \n203 3 204 4 \n5 205 6 206 \n207 7 208 8 \n9 209 10 210 \n211 11 212 12 \n13 213 14 214 \n215 15 216 16 \n17 217 18 218 \n219 19 220 20 \n21 221 22 222 \n223 23 224 24 \n25 225 26 226 \n227 27 228 28 \n29 229 30 230 \n231 31 232 32 \n33 233 34 234 \n235 35 236 36 \n37 237 38 238 \n239 39 240 40 \n41 241 42 242 \n243 43 244 44 \n45 245 46 246 \n247 47 248 48 \n49 249 50 250 \n251 51 252 52 \n53 253 54 254 \n255 55 256 56 \n57 257 58 258 \n259 59 260 60 \n61 261 62 262 \n263 63 264 64 \n65 265 6..."
},
{
"input": "100 5",
"output": "1 251 2 252 3 \n253 4 254 5 255 \n6 256 7 257 8 \n258 9 259 10 260 \n11 261 12 262 13 \n263 14 264 15 265 \n16 266 17 267 18 \n268 19 269 20 270 \n21 271 22 272 23 \n273 24 274 25 275 \n26 276 27 277 28 \n278 29 279 30 280 \n31 281 32 282 33 \n283 34 284 35 285 \n36 286 37 287 38 \n288 39 289 40 290 \n41 291 42 292 43 \n293 44 294 45 295 \n46 296 47 297 48 \n298 49 299 50 300 \n51 301 52 302 53 \n303 54 304 55 305 \n56 306 57 307 58 \n308 59 309 60 310 \n61 311 62 312 63 \n313 64 314 65 315 \n66 316 67 317..."
},
{
"input": "100 99",
"output": "1 4951 2 4952 3 4953 4 4954 5 4955 6 4956 7 4957 8 4958 9 4959 10 4960 11 4961 12 4962 13 4963 14 4964 15 4965 16 4966 17 4967 18 4968 19 4969 20 4970 21 4971 22 4972 23 4973 24 4974 25 4975 26 4976 27 4977 28 4978 29 4979 30 4980 31 4981 32 4982 33 4983 34 4984 35 4985 36 4986 37 4987 38 4988 39 4989 40 4990 41 4991 42 4992 43 4993 44 4994 45 4995 46 4996 47 4997 48 4998 49 4999 50 \n5000 51 5001 52 5002 53 5003 54 5004 55 5005 56 5006 57 5007 58 5008 59 5009 60 5010 61 5011 62 5012 63 5013 64 5014 65 501..."
},
{
"input": "100 100",
"output": "1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5037 38 5038 39 5039 40 5040 41 5041 42 5042 43 5043 44 5044 45 5045 46 5046 47 5047 48 5048 49 5049 50 5050 \n5051 51 5052 52 5053 53 5054 54 5055 55 5056 56 5057 57 5058 58 5059 59 5060 60 5061 61 5062 62 5063 63 5064 64 5065 6..."
},
{
"input": "8 97",
"output": "1 389 2 390 3 391 4 392 5 393 6 394 7 395 8 396 9 397 10 398 11 399 12 400 13 401 14 402 15 403 16 404 17 405 18 406 19 407 20 408 21 409 22 410 23 411 24 412 25 413 26 414 27 415 28 416 29 417 30 418 31 419 32 420 33 421 34 422 35 423 36 424 37 425 38 426 39 427 40 428 41 429 42 430 43 431 44 432 45 433 46 434 47 435 48 436 49 \n437 50 438 51 439 52 440 53 441 54 442 55 443 56 444 57 445 58 446 59 447 60 448 61 449 62 450 63 451 64 452 65 453 66 454 67 455 68 456 69 457 70 458 71 459 72 460 73 461 74 462 ..."
},
{
"input": "33 81",
"output": "1 1338 2 1339 3 1340 4 1341 5 1342 6 1343 7 1344 8 1345 9 1346 10 1347 11 1348 12 1349 13 1350 14 1351 15 1352 16 1353 17 1354 18 1355 19 1356 20 1357 21 1358 22 1359 23 1360 24 1361 25 1362 26 1363 27 1364 28 1365 29 1366 30 1367 31 1368 32 1369 33 1370 34 1371 35 1372 36 1373 37 1374 38 1375 39 1376 40 1377 41 \n1378 42 1379 43 1380 44 1381 45 1382 46 1383 47 1384 48 1385 49 1386 50 1387 51 1388 52 1389 53 1390 54 1391 55 1392 56 1393 57 1394 58 1395 59 1396 60 1397 61 1398 62 1399 63 1400 64 1401 65 140..."
},
{
"input": "11 17",
"output": "1 95 2 96 3 97 4 98 5 99 6 100 7 101 8 102 9 \n103 10 104 11 105 12 106 13 107 14 108 15 109 16 110 17 111 \n18 112 19 113 20 114 21 115 22 116 23 117 24 118 25 119 26 \n120 27 121 28 122 29 123 30 124 31 125 32 126 33 127 34 128 \n35 129 36 130 37 131 38 132 39 133 40 134 41 135 42 136 43 \n137 44 138 45 139 46 140 47 141 48 142 49 143 50 144 51 145 \n52 146 53 147 54 148 55 149 56 150 57 151 58 152 59 153 60 \n154 61 155 62 156 63 157 64 158 65 159 66 160 67 161 68 162 \n69 163 70 164 71 165 72 166 73 16..."
},
{
"input": "36 1",
"output": "1 \n19 \n2 \n20 \n3 \n21 \n4 \n22 \n5 \n23 \n6 \n24 \n7 \n25 \n8 \n26 \n9 \n27 \n10 \n28 \n11 \n29 \n12 \n30 \n13 \n31 \n14 \n32 \n15 \n33 \n16 \n34 \n17 \n35 \n18 \n36 "
},
{
"input": "62 85",
"output": "1 2636 2 2637 3 2638 4 2639 5 2640 6 2641 7 2642 8 2643 9 2644 10 2645 11 2646 12 2647 13 2648 14 2649 15 2650 16 2651 17 2652 18 2653 19 2654 20 2655 21 2656 22 2657 23 2658 24 2659 25 2660 26 2661 27 2662 28 2663 29 2664 30 2665 31 2666 32 2667 33 2668 34 2669 35 2670 36 2671 37 2672 38 2673 39 2674 40 2675 41 2676 42 2677 43 \n2678 44 2679 45 2680 46 2681 47 2682 48 2683 49 2684 50 2685 51 2686 52 2687 53 2688 54 2689 55 2690 56 2691 57 2692 58 2693 59 2694 60 2695 61 2696 62 2697 63 2698 64 2699 65 270..."
},
{
"input": "39 69",
"output": "1 1347 2 1348 3 1349 4 1350 5 1351 6 1352 7 1353 8 1354 9 1355 10 1356 11 1357 12 1358 13 1359 14 1360 15 1361 16 1362 17 1363 18 1364 19 1365 20 1366 21 1367 22 1368 23 1369 24 1370 25 1371 26 1372 27 1373 28 1374 29 1375 30 1376 31 1377 32 1378 33 1379 34 1380 35 \n1381 36 1382 37 1383 38 1384 39 1385 40 1386 41 1387 42 1388 43 1389 44 1390 45 1391 46 1392 47 1393 48 1394 49 1395 50 1396 51 1397 52 1398 53 1399 54 1400 55 1401 56 1402 57 1403 58 1404 59 1405 60 1406 61 1407 62 1408 63 1409 64 1410 65 141..."
},
{
"input": "64 5",
"output": "1 161 2 162 3 \n163 4 164 5 165 \n6 166 7 167 8 \n168 9 169 10 170 \n11 171 12 172 13 \n173 14 174 15 175 \n16 176 17 177 18 \n178 19 179 20 180 \n21 181 22 182 23 \n183 24 184 25 185 \n26 186 27 187 28 \n188 29 189 30 190 \n31 191 32 192 33 \n193 34 194 35 195 \n36 196 37 197 38 \n198 39 199 40 200 \n41 201 42 202 43 \n203 44 204 45 205 \n46 206 47 207 48 \n208 49 209 50 210 \n51 211 52 212 53 \n213 54 214 55 215 \n56 216 57 217 58 \n218 59 219 60 220 \n61 221 62 222 63 \n223 64 224 65 225 \n66 226 67 227..."
},
{
"input": "90 89",
"output": "1 4006 2 4007 3 4008 4 4009 5 4010 6 4011 7 4012 8 4013 9 4014 10 4015 11 4016 12 4017 13 4018 14 4019 15 4020 16 4021 17 4022 18 4023 19 4024 20 4025 21 4026 22 4027 23 4028 24 4029 25 4030 26 4031 27 4032 28 4033 29 4034 30 4035 31 4036 32 4037 33 4038 34 4039 35 4040 36 4041 37 4042 38 4043 39 4044 40 4045 41 4046 42 4047 43 4048 44 4049 45 \n4050 46 4051 47 4052 48 4053 49 4054 50 4055 51 4056 52 4057 53 4058 54 4059 55 4060 56 4061 57 4062 58 4063 59 4064 60 4065 61 4066 62 4067 63 4068 64 4069 65 407..."
},
{
"input": "67 73",
"output": "1 2447 2 2448 3 2449 4 2450 5 2451 6 2452 7 2453 8 2454 9 2455 10 2456 11 2457 12 2458 13 2459 14 2460 15 2461 16 2462 17 2463 18 2464 19 2465 20 2466 21 2467 22 2468 23 2469 24 2470 25 2471 26 2472 27 2473 28 2474 29 2475 30 2476 31 2477 32 2478 33 2479 34 2480 35 2481 36 2482 37 \n2483 38 2484 39 2485 40 2486 41 2487 42 2488 43 2489 44 2490 45 2491 46 2492 47 2493 48 2494 49 2495 50 2496 51 2497 52 2498 53 2499 54 2500 55 2501 56 2502 57 2503 58 2504 59 2505 60 2506 61 2507 62 2508 63 2509 64 2510 65 251..."
},
{
"input": "40 75",
"output": "1 1501 2 1502 3 1503 4 1504 5 1505 6 1506 7 1507 8 1508 9 1509 10 1510 11 1511 12 1512 13 1513 14 1514 15 1515 16 1516 17 1517 18 1518 19 1519 20 1520 21 1521 22 1522 23 1523 24 1524 25 1525 26 1526 27 1527 28 1528 29 1529 30 1530 31 1531 32 1532 33 1533 34 1534 35 1535 36 1536 37 1537 38 \n1538 39 1539 40 1540 41 1541 42 1542 43 1543 44 1544 45 1545 46 1546 47 1547 48 1548 49 1549 50 1550 51 1551 52 1552 53 1553 54 1554 55 1555 56 1556 57 1557 58 1558 59 1559 60 1560 61 1561 62 1562 63 1563 64 1564 65 156..."
},
{
"input": "10 13",
"output": "1 66 2 67 3 68 4 69 5 70 6 71 7 \n72 8 73 9 74 10 75 11 76 12 77 13 78 \n14 79 15 80 16 81 17 82 18 83 19 84 20 \n85 21 86 22 87 23 88 24 89 25 90 26 91 \n27 92 28 93 29 94 30 95 31 96 32 97 33 \n98 34 99 35 100 36 101 37 102 38 103 39 104 \n40 105 41 106 42 107 43 108 44 109 45 110 46 \n111 47 112 48 113 49 114 50 115 51 116 52 117 \n53 118 54 119 55 120 56 121 57 122 58 123 59 \n124 60 125 61 126 62 127 63 128 64 129 65 130 "
},
{
"input": "33 51",
"output": "1 843 2 844 3 845 4 846 5 847 6 848 7 849 8 850 9 851 10 852 11 853 12 854 13 855 14 856 15 857 16 858 17 859 18 860 19 861 20 862 21 863 22 864 23 865 24 866 25 867 26 \n868 27 869 28 870 29 871 30 872 31 873 32 874 33 875 34 876 35 877 36 878 37 879 38 880 39 881 40 882 41 883 42 884 43 885 44 886 45 887 46 888 47 889 48 890 49 891 50 892 51 893 \n52 894 53 895 54 896 55 897 56 898 57 899 58 900 59 901 60 902 61 903 62 904 63 905 64 906 65 907 66 908 67 909 68 910 69 911 70 912 71 913 72 914 73 915 74 91..."
},
{
"input": "4 38",
"output": "1 77 2 78 3 79 4 80 5 81 6 82 7 83 8 84 9 85 10 86 11 87 12 88 13 89 14 90 15 91 16 92 17 93 18 94 19 95 \n96 20 97 21 98 22 99 23 100 24 101 25 102 26 103 27 104 28 105 29 106 30 107 31 108 32 109 33 110 34 111 35 112 36 113 37 114 38 \n39 115 40 116 41 117 42 118 43 119 44 120 45 121 46 122 47 123 48 124 49 125 50 126 51 127 52 128 53 129 54 130 55 131 56 132 57 133 \n134 58 135 59 136 60 137 61 138 62 139 63 140 64 141 65 142 66 143 67 144 68 145 69 146 70 147 71 148 72 149 73 150 74 151 75 152 76 "
},
{
"input": "27 76",
"output": "1 1027 2 1028 3 1029 4 1030 5 1031 6 1032 7 1033 8 1034 9 1035 10 1036 11 1037 12 1038 13 1039 14 1040 15 1041 16 1042 17 1043 18 1044 19 1045 20 1046 21 1047 22 1048 23 1049 24 1050 25 1051 26 1052 27 1053 28 1054 29 1055 30 1056 31 1057 32 1058 33 1059 34 1060 35 1061 36 1062 37 1063 38 1064 \n1065 39 1066 40 1067 41 1068 42 1069 43 1070 44 1071 45 1072 46 1073 47 1074 48 1075 49 1076 50 1077 51 1078 52 1079 53 1080 54 1081 55 1082 56 1083 57 1084 58 1085 59 1086 60 1087 61 1088 62 1089 63 1090 64 1091 6..."
},
{
"input": "98 15",
"output": "1 736 2 737 3 738 4 739 5 740 6 741 7 742 8 \n743 9 744 10 745 11 746 12 747 13 748 14 749 15 750 \n16 751 17 752 18 753 19 754 20 755 21 756 22 757 23 \n758 24 759 25 760 26 761 27 762 28 763 29 764 30 765 \n31 766 32 767 33 768 34 769 35 770 36 771 37 772 38 \n773 39 774 40 775 41 776 42 777 43 778 44 779 45 780 \n46 781 47 782 48 783 49 784 50 785 51 786 52 787 53 \n788 54 789 55 790 56 791 57 792 58 793 59 794 60 795 \n61 796 62 797 63 798 64 799 65 800 66 801 67 802 68 \n803 69 804 70 805 71 806 72 80..."
},
{
"input": "21 53",
"output": "1 558 2 559 3 560 4 561 5 562 6 563 7 564 8 565 9 566 10 567 11 568 12 569 13 570 14 571 15 572 16 573 17 574 18 575 19 576 20 577 21 578 22 579 23 580 24 581 25 582 26 583 27 \n584 28 585 29 586 30 587 31 588 32 589 33 590 34 591 35 592 36 593 37 594 38 595 39 596 40 597 41 598 42 599 43 600 44 601 45 602 46 603 47 604 48 605 49 606 50 607 51 608 52 609 53 610 \n54 611 55 612 56 613 57 614 58 615 59 616 60 617 61 618 62 619 63 620 64 621 65 622 66 623 67 624 68 625 69 626 70 627 71 628 72 629 73 630 74 63..."
},
{
"input": "92 39",
"output": "1 1795 2 1796 3 1797 4 1798 5 1799 6 1800 7 1801 8 1802 9 1803 10 1804 11 1805 12 1806 13 1807 14 1808 15 1809 16 1810 17 1811 18 1812 19 1813 20 \n1814 21 1815 22 1816 23 1817 24 1818 25 1819 26 1820 27 1821 28 1822 29 1823 30 1824 31 1825 32 1826 33 1827 34 1828 35 1829 36 1830 37 1831 38 1832 39 1833 \n40 1834 41 1835 42 1836 43 1837 44 1838 45 1839 46 1840 47 1841 48 1842 49 1843 50 1844 51 1845 52 1846 53 1847 54 1848 55 1849 56 1850 57 1851 58 1852 59 \n1853 60 1854 61 1855 62 1856 63 1857 64 1858 65..."
},
{
"input": "15 78",
"output": "1 586 2 587 3 588 4 589 5 590 6 591 7 592 8 593 9 594 10 595 11 596 12 597 13 598 14 599 15 600 16 601 17 602 18 603 19 604 20 605 21 606 22 607 23 608 24 609 25 610 26 611 27 612 28 613 29 614 30 615 31 616 32 617 33 618 34 619 35 620 36 621 37 622 38 623 39 624 \n625 40 626 41 627 42 628 43 629 44 630 45 631 46 632 47 633 48 634 49 635 50 636 51 637 52 638 53 639 54 640 55 641 56 642 57 643 58 644 59 645 60 646 61 647 62 648 63 649 64 650 65 651 66 652 67 653 68 654 69 655 70 656 71 657 72 658 73 659 74 ..."
}
] | 1,525,449,736
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 124
| 7,065,600
|
n=int(input())
m=int(input())
k=int(m*(n-1)+(m+1)/2+1)
if k%m==1:
print("-1")
else:
for i in range(2,m*n+1):
if i==k:
print("1",end=' ')
if (i-1)%m==0:
print(i)
else:
print(i,end=' ')
|
Title: Planting Trees
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into *n*<=×<=*m* squares and decided to plant a forest there. Vasya will plant *nm* trees of all different heights from 1 to *nm*. For his forest to look more natural he wants any two trees growing in the side neighbouring squares to have the absolute value of difference in heights to be strictly more than 1. Help Vasya: make the plan of the forest planting for which this condition is fulfilled.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns on Vasya's field
Output Specification:
If there's no solution, print -1. Otherwise, print *n* lines containing *m* numbers each — the trees' planting plan. In every square of the plan the height of a tree that should be planted on this square should be written. If there are several solutions to that problem, print any of them.
Demo Input:
['2 3\n', '2 1\n']
Demo Output:
['3 6 2\n5 1 4\n', '-1\n']
Note:
none
|
```python
n=int(input())
m=int(input())
k=int(m*(n-1)+(m+1)/2+1)
if k%m==1:
print("-1")
else:
for i in range(2,m*n+1):
if i==k:
print("1",end=' ')
if (i-1)%m==0:
print(i)
else:
print(i,end=' ')
```
| -1
|
508
|
A
|
Pasha and Pixels
|
PROGRAMMING
| 1,100
|
[
"brute force"
] | null | null |
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
|
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
|
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
|
[
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] |
[
"4\n",
"5\n",
"0\n"
] |
none
| 500
|
[
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
"output": "9"
},
{
"input": "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2",
"output": "5"
},
{
"input": "518 518 10\n37 97\n47 278\n17 467\n158 66\n483 351\n83 123\n285 219\n513 187\n380 75\n304 352",
"output": "0"
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0"
},
{
"input": "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5",
"output": "0"
},
{
"input": "5 1 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "0"
},
{
"input": "1 1 1\n1 1",
"output": "0"
},
{
"input": "10 10 4\n5 9\n6 9\n6 10\n5 10",
"output": "4"
},
{
"input": "1000 1000 4\n999 999\n999 1000\n1000 999\n1000 1000",
"output": "4"
},
{
"input": "2 3 5\n2 3\n1 3\n1 2\n1 1\n2 2",
"output": "5"
},
{
"input": "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000",
"output": "4"
}
] | 1,668,002,576
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 52
| 498
| 5,324,800
|
def check(a, x, y):
if a[x-1][y-1]+a[x-1][y]+a[x][y-1] == 3 or a[x+1][y-1]+a[x+1][y]+a[x][y-1] == 3:
return True
elif a[x+1][y+1]+a[x+1][y]+a[x][y+1] == 3 or a[x-1][y+1]+a[x-1][y]+a[x][y+1] == 3:
return True
else:
return False
n, m, k = map(int, input().split())
ans = True
chess = [[0 for i in range(m+2)] for j in range(n+2)]
for i in range(k):
b, c = map(int, input().split())
chess[b][c] = 1
if check(chess, b, c):
print(i+1)
ans = False
break
if ans:
print(0)
|
Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed.
Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
Input Specification:
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
Output Specification:
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
Demo Input:
['2 2 4\n1 1\n1 2\n2 1\n2 2\n', '2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n', '5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n']
Demo Output:
['4\n', '5\n', '0\n']
Note:
none
|
```python
def check(a, x, y):
if a[x-1][y-1]+a[x-1][y]+a[x][y-1] == 3 or a[x+1][y-1]+a[x+1][y]+a[x][y-1] == 3:
return True
elif a[x+1][y+1]+a[x+1][y]+a[x][y+1] == 3 or a[x-1][y+1]+a[x-1][y]+a[x][y+1] == 3:
return True
else:
return False
n, m, k = map(int, input().split())
ans = True
chess = [[0 for i in range(m+2)] for j in range(n+2)]
for i in range(k):
b, c = map(int, input().split())
chess[b][c] = 1
if check(chess, b, c):
print(i+1)
ans = False
break
if ans:
print(0)
```
| 3
|
|
61
|
A
|
Ultra-Fast Mathematician
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Ultra-Fast Mathematician
|
2
|
256
|
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
|
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
|
Write one line — the corresponding answer. Do not omit the leading 0s.
|
[
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] |
[
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] |
none
| 500
|
[
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,649,775,103
| 2,147,483,647
|
PyPy 3-64
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i;
char a[99],b[99];
scanf("%s",a);
scanf("%s",b);
for(i=0; i<strlen(a); i++)
{
if(a[i]=='0'&&b[i]=='0')
{
a[i]='0';
}
else if(a[i]=='0'&&b[i]=='1')
{
a[i]='1';
}
else if(a[i]=='1'&&b[i]=='0')
{
a[i]='1';
}
else if(a[i]=='1'&&b[i]=='1')
{
a[i]='0';
}
}
printf("%s\n",a);
return 0;
}
|
Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none
|
```python
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i;
char a[99],b[99];
scanf("%s",a);
scanf("%s",b);
for(i=0; i<strlen(a); i++)
{
if(a[i]=='0'&&b[i]=='0')
{
a[i]='0';
}
else if(a[i]=='0'&&b[i]=='1')
{
a[i]='1';
}
else if(a[i]=='1'&&b[i]=='0')
{
a[i]='1';
}
else if(a[i]=='1'&&b[i]=='1')
{
a[i]='0';
}
}
printf("%s\n",a);
return 0;
}
```
| -1
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
|
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
|
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
|
[
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] |
[
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] |
none
| 0
|
[
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 1,505,707,978
| 4,078
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 61
| 4,608,000
|
vov = 'aeiou'
def is_defected_block(a, b, c):
if a == b and b == c:
return False
if a not in vov and b not in vov and c not in vov:
return True
return False
s = input()
ss = [s[0], s[1]]
for i in s[2:]:
if is_defected_block(i, ss[-1], ss[-2]):
ss.append(' ')
ss.append(i)
print(''.join(ss))
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input Specification:
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output Specification:
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Demo Input:
['hellno\n', 'abacaba\n', 'asdfasdf\n']
Demo Output:
['hell no \n', 'abacaba \n', 'asd fasd f \n']
Note:
none
|
```python
vov = 'aeiou'
def is_defected_block(a, b, c):
if a == b and b == c:
return False
if a not in vov and b not in vov and c not in vov:
return True
return False
s = input()
ss = [s[0], s[1]]
for i in s[2:]:
if is_defected_block(i, ss[-1], ss[-2]):
ss.append(' ')
ss.append(i)
print(''.join(ss))
```
| 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,599,327,021
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 0
| 108
| 0
|
a,b,n=map(int, input().split())
flag=-1
for i in range(10):
temp=str(a)+str(i)
if int(temp)%b==0:
flag=int(temp)
break
print(flag)
|
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
a,b,n=map(int, input().split())
flag=-1
for i in range(10):
temp=str(a)+str(i)
if int(temp)%b==0:
flag=int(temp)
break
print(flag)
```
| 0
|
|
349
|
A
|
Cinema Line
|
PROGRAMMING
| 1,100
|
[
"greedy",
"implementation"
] | null | null |
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
|
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
|
[
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] |
[
"YES\n",
"NO\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"input": "10\n50 50 50 50 50 50 50 50 50 50",
"output": "NO"
},
{
"input": "10\n100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "7\n25 25 25 25 50 100 50",
"output": "YES"
},
{
"input": "2\n25 25",
"output": "YES"
},
{
"input": "3\n50 100 100",
"output": "NO"
},
{
"input": "3\n25 50 50",
"output": "NO"
},
{
"input": "2\n50 25",
"output": "NO"
},
{
"input": "14\n25 25 25 25 25 25 25 50 50 50 100 100 100 100",
"output": "NO"
},
{
"input": "5\n25 25 25 100 100",
"output": "NO"
},
{
"input": "7\n25 50 25 50 25 50 100",
"output": "NO"
},
{
"input": "5\n25 50 25 50 100",
"output": "NO"
},
{
"input": "5\n25 25 50 50 50",
"output": "NO"
},
{
"input": "5\n25 25 50 100 50",
"output": "NO"
},
{
"input": "5\n25 25 50 50 100",
"output": "NO"
},
{
"input": "1\n50",
"output": "NO"
}
] | 1,679,752,206
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 0
|
size = int(input())
people = [int(i) for i in input().split()]
need = []
flag = True
for i in people:
if i == 25:
need.append(25)
if i == 50:
need.append(50)
if 25 in need:
del need[need.index(25)]
else:
flag = False
if i == 100:
need.append(100)
if need.count(25) >= 3:
del need[need.index(25)]
del need[need.index(25)]
del need[need.index(25)]
elif need.count(50) >= 1 and need.count(25) >= 1:
del need[need.index(50)]
del need[need.index(25)]
else:
flag = False
if flag:
print('YES')
else:
print('NO')
|
Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Output Specification:
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
Demo Input:
['4\n25 25 50 50\n', '2\n25 100\n', '4\n50 50 25 25\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none
|
```python
size = int(input())
people = [int(i) for i in input().split()]
need = []
flag = True
for i in people:
if i == 25:
need.append(25)
if i == 50:
need.append(50)
if 25 in need:
del need[need.index(25)]
else:
flag = False
if i == 100:
need.append(100)
if need.count(25) >= 3:
del need[need.index(25)]
del need[need.index(25)]
del need[need.index(25)]
elif need.count(50) >= 1 and need.count(25) >= 1:
del need[need.index(50)]
del need[need.index(25)]
else:
flag = False
if flag:
print('YES')
else:
print('NO')
```
| 0
|
|
746
|
G
|
New Roads
|
PROGRAMMING
| 2,100
|
[
"constructive algorithms",
"graphs",
"trees"
] | null | null |
There are *n* cities in Berland, each of them has a unique id — an integer from 1 to *n*, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.
That is why there was a decision to build *n*<=-<=1 roads so that there will be exactly one simple path between each pair of cities.
In the construction plan *t* integers *a*1,<=*a*2,<=...,<=*a**t* were stated, where *t* equals to the distance from the capital to the most distant city, concerning new roads. *a**i* equals the number of cities which should be at the distance *i* from the capital. The distance between two cities is the number of roads one has to pass on the way from one city to another.
Also, it was decided that among all the cities except the capital there should be exactly *k* cities with exactly one road going from each of them. Such cities are dead-ends and can't be economically attractive. In calculation of these cities the capital is not taken into consideration regardless of the number of roads from it.
Your task is to offer a plan of road's construction which satisfies all the described conditions or to inform that it is impossible.
|
The first line contains three positive numbers *n*, *t* and *k* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*t*,<=*k*<=<<=*n*) — the distance to the most distant city from the capital and the number of cities which should be dead-ends (the capital in this number is not taken into consideration).
The second line contains a sequence of *t* integers *a*1,<=*a*2,<=...,<=*a**t* (1<=≤<=*a**i*<=<<=*n*), the *i*-th number is the number of cities which should be at the distance *i* from the capital. It is guaranteed that the sum of all the values *a**i* equals *n*<=-<=1.
|
If it is impossible to built roads which satisfy all conditions, print -1.
Otherwise, in the first line print one integer *n* — the number of cities in Berland. In the each of the next *n*<=-<=1 line print two integers — the ids of cities that are connected by a road. Each road should be printed exactly once. You can print the roads and the cities connected by a road in any order.
If there are multiple answers, print any of them. Remember that the capital has id 1.
|
[
"7 3 3\n2 3 1\n",
"14 5 6\n4 4 2 2 1\n",
"3 1 1\n2\n"
] |
[
"7\n1 3\n2 1\n2 6\n2 4\n7 4\n3 5\n",
"14\n3 1\n1 4\n11 6\n1 2\n10 13\n6 10\n10 12\n14 12\n8 4\n5 1\n3 7\n2 6\n5 9\n",
"-1\n"
] |
none
| 3,000
|
[
{
"input": "7 3 3\n2 3 1",
"output": "7\n1 2\n2 6\n5 3\n2 4\n1 3\n7 4"
},
{
"input": "14 5 6\n4 4 2 2 1",
"output": "14\n12 14\n7 3\n6 10\n5 1\n13 10\n1 3\n8 4\n9 5\n4 1\n6 2\n12 10\n6 11\n2 1"
},
{
"input": "3 1 1\n2",
"output": "-1"
},
{
"input": "6 3 3\n1 2 2",
"output": "6\n3 5\n6 3\n2 1\n4 2\n2 3"
},
{
"input": "11 6 4\n1 2 2 1 3 1",
"output": "11\n3 5\n11 8\n7 9\n10 7\n7 8\n2 3\n2 4\n6 4\n1 2\n5 7"
},
{
"input": "21 10 9\n2 1 3 1 1 1 3 2 3 3",
"output": "21\n5 4\n14 18\n7 4\n12 10\n17 15\n2 1\n10 11\n20 16\n9 10\n14 16\n4 2\n1 3\n14 11\n8 9\n13 10\n16 19\n5 8\n16 21\n6 4\n15 12"
},
{
"input": "51 16 31\n1 3 3 3 4 4 3 5 4 1 3 3 3 2 3 5",
"output": "51\n49 44\n28 32\n31 23\n36 33\n16 20\n9 12\n4 2\n42 45\n18 12\n44 51\n33 38\n11 8\n34 32\n23 20\n8 5\n39 36\n39 42\n48 44\n16 21\n12 16\n23 30\n12 19\n9 15\n20 24\n37 33\n13 9\n20 25\n23 29\n6 3\n17 12\n42 44\n50 44\n7 4\n36 40\n28 23\n35 32\n33 32\n9 6\n43 39\n36 41\n1 2\n47 44\n20 27\n22 16\n46 42\n14 9\n7 10\n5 2\n3 2\n20 26"
},
{
"input": "1001 179 490\n8 8 6 7 1 6 10 3 7 8 8 7 2 4 9 8 4 5 8 3 5 7 9 10 9 5 2 6 5 3 3 2 9 6 4 2 10 2 3 5 7 4 5 8 3 9 5 9 2 5 4 9 3 8 2 9 6 7 4 4 10 9 8 5 2 6 9 10 9 3 1 9 9 3 9 4 10 1 7 4 4 9 2 5 6 4 9 3 4 10 1 3 10 3 3 10 9 2 5 6 6 1 1 9 4 9 9 7 5 5 10 3 8 7 10 3 2 10 6 1 4 4 5 7 4 7 1 1 8 5 8 6 2 9 3 3 5 8 7 1 8 3 6 2 8 10 4 5 1 6 3 4 6 9 8 10 1 3 9 9 4 6 6 7 10 2 4 8 2 1 5 4 5 3 7 2 5 9 3",
"output": "1001\n695 689\n737 746\n383 376\n188 185\n312 318\n901 891\n33 39\n413 404\n793 794\n865 854\n831 839\n811 814\n340 351\n944 952\n985 991\n569 579\n776 770\n845 840\n20 26\n1 2\n56 48\n778 789\n471 475\n811 815\n415 419\n767 758\n146 137\n510 498\n621 612\n383 389\n649 663\n360 369\n83 87\n756 750\n531 534\n164 169\n489 494\n258 255\n24 31\n513 516\n188 193\n794 802\n740 729\n440 449\n890 887\n738 729\n444 434\n813 811\n649 646\n240 244\n704 714\n905 891\n167 158\n192 188\n305 302\n958 962\n169 175\n705 70..."
},
{
"input": "200000 5 190092\n47191 35051 33744 40989 43024",
"output": "200000\n115988 194495\n115988 186970\n136478 82244\n150960 82244\n185127 115988\n191591 115988\n187442 115988\n115988 181548\n115988 167357\n90874 47193\n115988 182235\n166965 115988\n115988 195352\n115988 177339\n188896 115988\n186993 115988\n115988 192573\n172293 115988\n115988 199003\n196650 115988\n166407 115988\n115988 186132\n115988 192130\n115988 192121\n115988 175735\n178910 115988\n121195 82244\n115988 193692\n188417 115988\n127665 82244\n199363 115988\n155907 82244\n147227 82244\n115988 186681\n1..."
},
{
"input": "2000 3 1337\n970 632 397",
"output": "2000\n1 695\n1786 972\n1327 357\n1 188\n1253 283\n972 1891\n1787 972\n1 413\n156 1126\n865 1\n1705 972\n1 814\n1 348\n992 1624\n1068 98\n1 575\n972 1957\n1 845\n149 1119\n972 1993\n1 54\n1 789\n1 475\n1 815\n1 419\n1841 972\n1 147\n507 1\n1 621\n427 1397\n1 663\n1118 148\n1 87\n756 1\n556 1526\n972 1970\n972 1837\n1872 972\n1 31\n1 517\n192 1\n391 1361\n242 1212\n1 449\n890 1\n1379 409\n983 1615\n813 1\n1 649\n1128 158\n1945 972\n978 1610\n167 1\n319 1289\n1592 622\n1986 972\n371 1341\n1 705\n1524 554\n175..."
},
{
"input": "2001 34 1714\n28 91 43 47 52 42 69 95 11 70 59 68 88 92 71 19 7 70 100 66 1 38 36 88 58 52 87 85 40 75 26 42 85 99",
"output": "2001\n294 336\n954 1024\n345 303\n1265 1376\n1463 1596\n1776 1892\n1025 954\n487 469\n1470 1411\n1411 1528\n2 61\n954 1090\n1194 1190\n228 280\n1872 1776\n1265 1403\n1485 1411\n1644 1550\n941 857\n869 765\n568 480\n1353 1433\n1476 1411\n609 759\n469 501\n944 857\n699 609\n1635 1688\n948 928\n609 755\n1229 1191\n1463 1579\n1955 1818\n765 912\n907 765\n1024 1158\n263 350\n550 665\n954 1083\n1969 1818\n876 765\n104 2\n1003 947\n1919 1818\n609 744\n1776 1893\n1408 1265\n663 550\n1534 1411\n154 63\n28 1\n1411 1..."
},
{
"input": "150001 7 147760\n8286 37995 4975 28947 23162 15808 30827",
"output": "150001\n139099 103367\n136999 103367\n125242 103367\n122472 103367\n35871 2\n80205 106310\n103367 134790\n128032 103367\n145793 103367\n46283 56175\n116621 80205\n131527 103367\n103367 146171\n103367 132459\n103367 133969\n103367 129263\n112482 80205\n85396 51258\n129908 103367\n108776 80205\n103367 142201\n127810 103367\n109636 80205\n103367 140692\n1 3018\n140898 103367\n103367 147446\n46283 75221\n103367 127230\n103367 142840\n2 41625\n103367 133122\n131090 103367\n101465 51258\n103367 123412\n138388 10..."
},
{
"input": "200000 5 195020\n47330 743 46163 36629 69134",
"output": "200000\n94238 194495\n94238 186970\n136478 94238\n150960 94238\n185127 94238\n191591 94238\n187442 94238\n94238 181548\n94238 167357\n91616 47332\n94238 182235\n166965 94238\n94238 195352\n94238 177339\n188896 94238\n186993 94238\n94238 192573\n172293 94238\n94238 199003\n196650 94238\n166407 94238\n94238 186132\n94238 192130\n94238 192121\n94238 175735\n178910 94238\n124686 48075\n94238 193692\n188417 94238\n94528 48365\n199363 94238\n155907 94238\n147227 94238\n94238 186681\n189754 94238\n94238 195609\n1..."
},
{
"input": "200000 18 199982\n19878 5843 2935 16419 14574 12751 15665 18170 12578 14385 6515 9607 4121 224 14079 4972 10940 16343",
"output": "200000\n174928 167746\n167746 176523\n172718 191873\n153667 171107\n172718 193613\n172718 197400\n172718 192738\n198484 172718\n110297 88067\n172718 186509\n139715 153381\n153667 167876\n167746 180125\n172718 185267\n153443 155797\n172718 190718\n116189 88067\n163463 153443\n172718 196975\n166400 153443\n150876 139715\n149767 139715\n172718 191355\n172718 187814\n156266 153443\n106237 131171\n178082 167746\n172718 194718\n172718 199797\n172718 193391\n172718 199525\n133200 143479\n184398 172718\n178155 167..."
},
{
"input": "200000 4 90823\n63010 23084 77424 36481",
"output": "-1"
},
{
"input": "200000 1 199999\n199999",
"output": "200000\n1 120418\n162163 1\n156675 1\n187544 1\n1 187800\n1 192966\n184902 1\n191949 1\n1 126665\n191367 1\n1 183579\n1 181788\n1 129868\n197312 1\n1 197439\n1 179130\n1 164809\n1 114623\n188700 1\n104067 1\n1 177790\n181957 1\n1 136583\n169479 1\n1 197419\n191015 1\n8501 1\n196002 1\n1 161615\n1 199967\n1 191729\n184391 1\n1 187114\n194633 1\n173285 1\n1 189731\n1 172409\n174313 1\n126009 1\n177518 1\n189355 1\n1 168589\n184969 1\n1 179245\n1 158495\n171452 1\n130676 1\n1 198971\n180303 1\n190327 1\n15838..."
},
{
"input": "6390 29 1740\n407 261 213 375 118 127 276 322 353 166 120 308 178 261 270 275 157 26 36 159 20 272 152 316 213 237 167 372 232",
"output": "-1"
},
{
"input": "2 1 1\n1",
"output": "2\n2 1"
},
{
"input": "4 2 3\n1 2",
"output": "-1"
},
{
"input": "17 5 11\n5 3 2 5 1",
"output": "17\n3 8\n17 12\n14 10\n6 1\n10 7\n13 10\n4 1\n15 10\n1 3\n7 2\n1 2\n2 9\n10 12\n1 5\n16 10\n7 11"
},
{
"input": "16 4 10\n2 3 5 5",
"output": "16\n8 5\n7 12\n7 4\n2 4\n2 1\n9 4\n4 11\n4 10\n5 3\n13 7\n7 15\n2 6\n1 3\n16 7\n14 7"
},
{
"input": "2 1 1\n1",
"output": "2\n2 1"
},
{
"input": "3 2 2\n1 1",
"output": "-1"
},
{
"input": "3 2 2\n1 1",
"output": "-1"
},
{
"input": "4 2 3\n2 1",
"output": "-1"
},
{
"input": "4 1 1\n3",
"output": "-1"
},
{
"input": "4 3 1\n1 1 1",
"output": "4\n2 1\n2 3\n3 4"
},
{
"input": "5 4 3\n1 1 1 1",
"output": "-1"
},
{
"input": "5 4 3\n1 1 1 1",
"output": "-1"
},
{
"input": "5 4 4\n1 1 1 1",
"output": "-1"
},
{
"input": "5 4 4\n1 1 1 1",
"output": "-1"
},
{
"input": "6 4 5\n1 1 1 2",
"output": "-1"
}
] | 1,661,486,598
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 7
| 46
| 2,764,800
|
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n,t,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0]*(t + 1)
b[t] = a[t]
for d in range(1, t):
b[d] = max(0, a[d] - a[d+1])
remaining = k - sum(b)
if remaining < 0:
print(-1)
exit()
for d in range(1, t):
gap = a[d] - 1 - b[d]
assert gap>=0
assign = min(remaining, gap)
b[d] += assign
remaining -= assign
assert sum(b)==k
print(n)
def add_edge(u,v):
print(u,v)
previous_layer = [1]
cur = 2
for d in range(1, t):
num_nodes = a[d]
num_leaves = b[d]
cnt = num_nodes - num_leaves
cur_layer = list(range(cur, cur + cnt))
cur += cnt
leaves = list(range(cur, cur + num_leaves))
cur += num_leaves
for i in range(len(cur_layer)):
u = cur_layer[i]
v = previous_layer[i % len(previous_layer)]
add_edge(u,v)
v = previous_layer[-1]
for u in leaves:
add_edge(u,v)
previous_layer = cur_layer
final_leaves = list(range(cur, cur + b[t]))
for i in range(len(final_leaves)):
u = final_leaves[i]
v = previous_layer[i % len(previous_layer)]
add_edge(u,v)
|
Title: New Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Berland, each of them has a unique id — an integer from 1 to *n*, the capital is the one with id 1. Now there is a serious problem in Berland with roads — there are no roads.
That is why there was a decision to build *n*<=-<=1 roads so that there will be exactly one simple path between each pair of cities.
In the construction plan *t* integers *a*1,<=*a*2,<=...,<=*a**t* were stated, where *t* equals to the distance from the capital to the most distant city, concerning new roads. *a**i* equals the number of cities which should be at the distance *i* from the capital. The distance between two cities is the number of roads one has to pass on the way from one city to another.
Also, it was decided that among all the cities except the capital there should be exactly *k* cities with exactly one road going from each of them. Such cities are dead-ends and can't be economically attractive. In calculation of these cities the capital is not taken into consideration regardless of the number of roads from it.
Your task is to offer a plan of road's construction which satisfies all the described conditions or to inform that it is impossible.
Input Specification:
The first line contains three positive numbers *n*, *t* and *k* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*t*,<=*k*<=<<=*n*) — the distance to the most distant city from the capital and the number of cities which should be dead-ends (the capital in this number is not taken into consideration).
The second line contains a sequence of *t* integers *a*1,<=*a*2,<=...,<=*a**t* (1<=≤<=*a**i*<=<<=*n*), the *i*-th number is the number of cities which should be at the distance *i* from the capital. It is guaranteed that the sum of all the values *a**i* equals *n*<=-<=1.
Output Specification:
If it is impossible to built roads which satisfy all conditions, print -1.
Otherwise, in the first line print one integer *n* — the number of cities in Berland. In the each of the next *n*<=-<=1 line print two integers — the ids of cities that are connected by a road. Each road should be printed exactly once. You can print the roads and the cities connected by a road in any order.
If there are multiple answers, print any of them. Remember that the capital has id 1.
Demo Input:
['7 3 3\n2 3 1\n', '14 5 6\n4 4 2 2 1\n', '3 1 1\n2\n']
Demo Output:
['7\n1 3\n2 1\n2 6\n2 4\n7 4\n3 5\n', '14\n3 1\n1 4\n11 6\n1 2\n10 13\n6 10\n10 12\n14 12\n8 4\n5 1\n3 7\n2 6\n5 9\n', '-1\n']
Note:
none
|
```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n,t,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0]*(t + 1)
b[t] = a[t]
for d in range(1, t):
b[d] = max(0, a[d] - a[d+1])
remaining = k - sum(b)
if remaining < 0:
print(-1)
exit()
for d in range(1, t):
gap = a[d] - 1 - b[d]
assert gap>=0
assign = min(remaining, gap)
b[d] += assign
remaining -= assign
assert sum(b)==k
print(n)
def add_edge(u,v):
print(u,v)
previous_layer = [1]
cur = 2
for d in range(1, t):
num_nodes = a[d]
num_leaves = b[d]
cnt = num_nodes - num_leaves
cur_layer = list(range(cur, cur + cnt))
cur += cnt
leaves = list(range(cur, cur + num_leaves))
cur += num_leaves
for i in range(len(cur_layer)):
u = cur_layer[i]
v = previous_layer[i % len(previous_layer)]
add_edge(u,v)
v = previous_layer[-1]
for u in leaves:
add_edge(u,v)
previous_layer = cur_layer
final_leaves = list(range(cur, cur + b[t]))
for i in range(len(final_leaves)):
u = final_leaves[i]
v = previous_layer[i % len(previous_layer)]
add_edge(u,v)
```
| 0
|
|
793
|
A
|
Oleg and shares
|
PROGRAMMING
| 900
|
[
"implementation",
"math"
] | null | null |
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
|
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
|
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
|
[
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] |
[
"3",
"-1",
"2999999997"
] |
Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
| 500
|
[
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14",
"output": "151"
},
{
"input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54",
"output": "-1"
},
{
"input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260",
"output": "2157"
},
{
"input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354",
"output": "-1"
},
{
"input": "4 2\n1 2 3 4",
"output": "-1"
},
{
"input": "3 4\n3 5 5",
"output": "-1"
},
{
"input": "3 2\n88888884 88888886 88888888",
"output": "3"
},
{
"input": "2 1\n1000000000 1000000000",
"output": "0"
},
{
"input": "4 2\n1000000000 100000000 100000000 100000000",
"output": "450000000"
},
{
"input": "2 2\n1000000000 1000000000",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "-1"
},
{
"input": "3 4\n3 5 3",
"output": "-1"
},
{
"input": "3 2\n1 2 2",
"output": "-1"
},
{
"input": "4 2\n2 3 3 2",
"output": "-1"
},
{
"input": "3 2\n1 2 4",
"output": "-1"
},
{
"input": "3 2\n3 4 4",
"output": "-1"
},
{
"input": "3 3\n4 7 10",
"output": "3"
},
{
"input": "4 3\n2 2 5 1",
"output": "-1"
},
{
"input": "3 3\n1 3 5",
"output": "-1"
},
{
"input": "2 5\n5 9",
"output": "-1"
},
{
"input": "2 3\n5 7",
"output": "-1"
},
{
"input": "3 137\n1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 5\n1 2 5",
"output": "-1"
},
{
"input": "3 3\n1000000000 1000000000 999999997",
"output": "2"
},
{
"input": "2 4\n5 6",
"output": "-1"
},
{
"input": "4 1\n1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "2 3\n5 8",
"output": "1"
},
{
"input": "2 6\n8 16",
"output": "-1"
},
{
"input": "5 3\n15 14 9 12 18",
"output": "-1"
},
{
"input": "3 3\n1 2 3",
"output": "-1"
},
{
"input": "3 3\n3 4 5",
"output": "-1"
},
{
"input": "2 5\n8 17",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "0"
},
{
"input": "3 3\n5 3 4",
"output": "-1"
},
{
"input": "3 6\n10 14 12",
"output": "-1"
},
{
"input": "2 2\n3 5",
"output": "1"
},
{
"input": "3 5\n1 3 4",
"output": "-1"
},
{
"input": "4 3\n1 6 6 6",
"output": "-1"
},
{
"input": "2 3\n1 8",
"output": "-1"
},
{
"input": "3 5\n6 11 17",
"output": "-1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "2 4\n6 8",
"output": "-1"
},
{
"input": "2 1\n2 3",
"output": "1"
},
{
"input": "4 4\n1 5 8 14",
"output": "-1"
},
{
"input": "3 3\n1 5 3",
"output": "-1"
},
{
"input": "4 3\n1 2 2 5",
"output": "-1"
},
{
"input": "3 2\n1 4 6",
"output": "-1"
},
{
"input": "2 3\n6 9",
"output": "1"
},
{
"input": "3 3\n2 3 4",
"output": "-1"
},
{
"input": "3 2\n9 10 10",
"output": "-1"
},
{
"input": "2 2\n9 12",
"output": "-1"
},
{
"input": "2 2\n100000003 100000005",
"output": "1"
},
{
"input": "2 3\n2 4",
"output": "-1"
},
{
"input": "3 2\n2 3 5",
"output": "-1"
},
{
"input": "3 3\n1 3 4",
"output": "-1"
},
{
"input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "4499999991"
},
{
"input": "3 5\n2 4 5",
"output": "-1"
},
{
"input": "2 3\n7 10",
"output": "1"
},
{
"input": "3 10\n10 13 17",
"output": "-1"
},
{
"input": "2 3\n1 6",
"output": "-1"
},
{
"input": "1 7\n1000000000",
"output": "0"
},
{
"input": "2 4\n3 7",
"output": "1"
},
{
"input": "2 3\n2 5",
"output": "1"
},
{
"input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0"
},
{
"input": "3 3\n7 8 8",
"output": "-1"
},
{
"input": "4 10\n1 11 100 11",
"output": "-1"
}
] | 1,492,966,309
| 409
|
Python 3
|
CHALLENGED
|
CHALLENGES
| 7
| 77
| 13,414,400
|
fread = input
def main():
n,k = [int(inpNum) for inpNum in fread().strip().split()]
a = [int(inpNum) for inpNum in fread().strip().split()]
ans = (sum(a)-n*min(a))/k
if ans == int(ans):
print(int(ans))
else:
print(-1)
main()
|
Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Output Specification:
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
Demo Input:
['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n']
Demo Output:
['3', '-1', '2999999997']
Note:
Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.
In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.
In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
|
```python
fread = input
def main():
n,k = [int(inpNum) for inpNum in fread().strip().split()]
a = [int(inpNum) for inpNum in fread().strip().split()]
ans = (sum(a)-n*min(a))/k
if ans == int(ans):
print(int(ans))
else:
print(-1)
main()
```
| -1
|
|
254
|
A
|
Cards with Numbers
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"sortings"
] | null | null |
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
|
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
|
[
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] |
[
"4 2\n1 5\n6 3\n",
"-1"
] |
none
| 500
|
[
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"input": "5\n1 2 2 2 1 2 2 1 2 1",
"output": "3 2\n1 5\n6 4\n7 9\n10 8"
},
{
"input": "5\n3 3 1 1 1 3 2 3 1 2",
"output": "2 1\n3 4\n8 6\n5 9\n10 7"
},
{
"input": "5\n1 1 3 1 3 3 3 1 1 1",
"output": "2 1\n3 5\n7 6\n4 8\n10 9"
},
{
"input": "5\n3 1 1 1 2 3 3 3 2 1",
"output": "3 2\n1 6\n8 7\n5 9\n10 4"
},
{
"input": "5\n3 3 2 2 3 3 1 3 1 3",
"output": "2 1\n3 4\n6 5\n7 9\n10 8"
},
{
"input": "5\n4 1 3 1 4 1 2 2 3 1",
"output": "4 2\n1 5\n8 7\n3 9\n10 6"
},
{
"input": "100\n8 6 7 8 7 9 1 7 3 3 5 8 7 8 5 4 8 4 8 1 2 8 3 7 8 7 6 5 7 9 6 10 7 6 7 8 6 8 9 5 1 5 6 1 4 8 4 8 7 2 6 2 6 6 2 8 2 8 7 1 5 4 4 6 4 9 7 5 1 8 1 3 9 2 3 2 4 7 6 10 5 3 4 10 8 9 6 7 2 7 10 1 8 10 4 1 1 1 2 7 5 4 9 10 6 8 3 1 10 9 9 6 1 5 8 6 6 3 3 4 10 10 8 9 7 10 9 3 7 6 3 2 10 8 5 8 5 5 5 10 8 5 7 6 10 7 7 9 10 10 9 9 3 6 5 6 8 1 9 8 2 4 8 8 6 8 10 2 3 5 2 6 8 4 8 6 4 5 10 8 1 10 5 2 5 6 8 2 6 8 1 3 4 5 7 5 6 9 2 8",
"output": "4 1\n3 5\n10 9\n8 13\n14 12\n11 15\n18 16\n17 19\n20 7\n22 25\n26 24\n2 27\n30 6\n29 33\n34 31\n36 38\n40 28\n37 43\n44 41\n45 47\n48 46\n35 49\n50 21\n51 53\n55 52\n56 58\n61 42\n62 63\n64 54\n39 66\n67 59\n60 69\n72 23\n57 74\n77 65\n32 80\n81 68\n75 82\n85 70\n73 86\n87 79\n78 88\n89 76\n84 91\n92 71\n83 95\n97 96\n90 100\n104 94\n93 106\n108 98\n103 110\n112 105\n101 114\n117 116\n107 118\n120 102\n109 121\n123 115\n111 124\n126 122\n119 128\n129 125\n99 132\n136 134\n135 137\n139 138\n133 140\n144 130..."
},
{
"input": "100\n7 3 8 8 1 9 6 6 3 3 8 2 7 9 9 10 2 10 4 4 9 3 6 5 2 6 3 6 3 5 2 3 8 2 5 10 3 9 7 2 1 6 7 4 8 3 9 10 9 4 3 3 7 1 4 2 2 5 6 6 1 7 9 1 8 1 2 2 5 9 7 7 6 4 6 10 1 1 8 1 5 6 4 9 5 4 4 10 6 4 5 1 9 1 7 8 6 10 3 2 4 7 10 4 8 10 6 7 8 4 1 3 8 3 2 1 9 4 2 4 3 1 6 8 6 2 2 5 6 8 6 10 1 6 4 2 7 3 6 10 6 5 6 6 3 9 4 6 4 1 5 4 4 2 8 4 10 3 7 6 6 10 2 5 5 6 1 6 1 9 9 1 10 5 10 1 1 5 7 5 2 1 4 2 3 3 3 5 1 8 10 3 3 5 9 6 3 6 8 1",
"output": "4 3\n7 8\n9 2\n1 13\n14 6\n12 17\n18 16\n19 20\n21 15\n10 22\n26 23\n27 29\n30 24\n25 31\n33 11\n32 37\n40 34\n5 41\n42 28\n39 43\n47 38\n36 48\n50 44\n46 51\n57 56\n35 58\n60 59\n54 61\n62 53\n49 63\n65 45\n64 66\n68 67\n71 72\n74 55\n73 75\n78 77\n69 81\n84 70\n83 86\n88 76\n82 89\n90 87\n85 91\n92 80\n79 96\n99 52\n95 102\n103 98\n101 104\n107 97\n105 109\n111 94\n112 114\n115 100\n93 117\n118 110\n116 122\n124 113\n123 125\n126 119\n129 131\n132 106\n120 135\n136 127\n108 137\n138 121\n134 139\n142 128..."
},
{
"input": "100\n6 3 6 8 8 4 3 7 10 3 1 3 9 5 10 10 6 7 6 6 2 3 8 8 7 6 4 9 6 7 4 4 10 4 7 3 2 7 10 8 6 7 9 1 3 5 3 7 9 1 1 7 1 1 7 7 8 3 2 7 4 8 7 8 10 3 1 7 2 7 9 8 8 8 5 2 8 1 2 7 8 7 8 8 5 10 10 4 9 10 8 7 8 8 7 7 3 6 4 3 4 8 10 8 6 3 7 1 8 6 3 3 7 10 3 9 3 5 10 9 9 2 8 7 2 3 2 1 10 9 6 2 8 7 2 2 5 3 10 6 7 2 1 1 5 10 7 5 4 9 7 7 8 1 1 3 3 7 10 5 9 8 6 8 2 2 1 7 8 9 6 2 2 6 2 9 10 2 10 9 6 3 3 10 6 5 3 6 6 3 6 10 8 7 4 8 6 3 4 7",
"output": "-1"
},
{
"input": "1\n2 2",
"output": "2 1"
},
{
"input": "2\n1 2 4 7",
"output": "-1"
}
] | 1,683,631,776
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 0
| 61
| 2,764,800
|
def Cards_with_Numbers():
print("yes")
n = int(input())
cardNum_sequence = [int(x) for x in input().split()]
Cards_with_Numbers()
|
Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
Output Specification:
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
Demo Input:
['3\n20 30 10 30 20 10\n', '1\n1 2\n']
Demo Output:
['4 2\n1 5\n6 3\n', '-1']
Note:
none
|
```python
def Cards_with_Numbers():
print("yes")
n = int(input())
cardNum_sequence = [int(x) for x in input().split()]
Cards_with_Numbers()
```
| -1
|
|
558
|
A
|
Lala Land and Apple Trees
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation",
"sortings"
] | null | null |
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
|
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
|
Output the maximum number of apples Amr can collect.
|
[
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] |
[
"10",
"9",
"9"
] |
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
| 500
|
[
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "300000"
},
{
"input": "1\n-1 1",
"output": "1"
},
{
"input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463",
"output": "1036452"
},
{
"input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532",
"output": "632240"
},
{
"input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044",
"output": "891593"
},
{
"input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422",
"output": "1109655"
},
{
"input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834",
"output": "847241"
},
{
"input": "3\n-94146 4473\n28707 99079\n-4153 8857",
"output": "112409"
},
{
"input": "3\n-3 3\n-2 2\n-1 1",
"output": "1"
},
{
"input": "2\n100000 3\n-100000 9",
"output": "12"
},
{
"input": "2\n-100000 100000\n100000 99999",
"output": "199999"
}
] | 1,584,515,587
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 46
| 124
| 512,000
|
n = int(input())
pos = []
neg = []
for _ in range(n):
xi, ai = map(int,input().split())
if xi > 0:
pos.append((xi, ai))
else:
neg.append((xi, ai))
lim = min(len(pos), len(neg))
ans = 0
if len(pos) > len(neg):
for x, a in sorted(pos)[:lim+1]:
ans += a
for x, a in sorted(neg)[-lim:]:
ans += a
elif len(pos) < len(neg):
for x, a in sorted(pos)[:lim]:
ans += a
for x, a in sorted(neg)[-lim-1:]:
ans += a
else:
for x, a in sorted(pos)[:lim]:
ans += a
for x, a in sorted(neg)[-lim:]:
ans += a
print(ans)
|
Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input Specification:
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output Specification:
Output the maximum number of apples Amr can collect.
Demo Input:
['2\n-1 5\n1 5\n', '3\n-2 2\n1 4\n-1 3\n', '3\n1 9\n3 5\n7 10\n']
Demo Output:
['10', '9', '9']
Note:
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
|
```python
n = int(input())
pos = []
neg = []
for _ in range(n):
xi, ai = map(int,input().split())
if xi > 0:
pos.append((xi, ai))
else:
neg.append((xi, ai))
lim = min(len(pos), len(neg))
ans = 0
if len(pos) > len(neg):
for x, a in sorted(pos)[:lim+1]:
ans += a
for x, a in sorted(neg)[-lim:]:
ans += a
elif len(pos) < len(neg):
for x, a in sorted(pos)[:lim]:
ans += a
for x, a in sorted(neg)[-lim-1:]:
ans += a
else:
for x, a in sorted(pos)[:lim]:
ans += a
for x, a in sorted(neg)[-lim:]:
ans += a
print(ans)
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query *l**j*,<=*r**j* the Little Elephant has to count, how many numbers *x* exist, such that number *x* occurs exactly *x* times among numbers *a**l**j*,<=*a**l**j*<=+<=1,<=...,<=*a**r**j*.
Help the Little Elephant to count the answers to all queries.
|
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. The *j*-th of these lines contains the description of the *j*-th query as two space-separated integers *l**j* and *r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*).
|
In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query.
|
[
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
] |
[
"3\n1\n"
] |
none
| 0
|
[
{
"input": "7 2\n3 1 2 2 3 3 7\n1 7\n3 4",
"output": "3\n1"
},
{
"input": "6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6",
"output": "1\n0\n2\n1\n1\n3"
},
{
"input": "1 2\n1\n1 1\n1 1",
"output": "1\n1"
},
{
"input": "1 1\n1000000000\n1 1",
"output": "0"
}
] | 1,678,707,041
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MXN = 1e5 + 5, BLOCK_SIZE = 316;
struct Query {
int l, r, idx;
bool operator<(const Query &y) const {
// Current query x is being compared with other query y
int x_block = l / BLOCK_SIZE;
int y_block = y.l / BLOCK_SIZE;
// If x and y both lie in the same block, sort in non decreasing order of endpoint
if (x_block == y_block)
return r < y.r;
// x and y lie in different blocks
return x_block < y_block;
}
};
int A[MXN], final_ans[MXN], freq[MXN];
int cur_ans;
void operate(int idx, int delta) {
int x = A[idx];
if (x >= MXN) return;
if (freq[x] == x) cur_ans--;
freq[x] += delta;
if (freq[x] == x) cur_ans++;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++)
cin >> A[i];
vector<Query> queries(M);
for (int i = 0; i < M; i++) {
cin >> queries[i].l >> queries[i].r;
queries[i].l--, queries[i].r--; // 0 based indexing
queries[i].idx = i;
}
sort(queries.begin(), queries.end());
int i = 0, j = -1;
for (const auto &[l, r, idx] : queries) {
while (j < r) operate(++j, 1);
while (i > l) operate(--i, 1);
while (i < l) operate(i++, -1);
while (j > r) operate(j--, -1);
final_ans[idx] = cur_ans;
}
for (int i = 0; i < M; i++)
cout << final_ans[i] << "\n";
}
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves playing with arrays. He has array *a*, consisting of *n* positive integers, indexed from 1 to *n*. Let's denote the number with index *i* as *a**i*.
Additionally the Little Elephant has *m* queries to the array, each query is characterised by a pair of integers *l**j* and *r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query *l**j*,<=*r**j* the Little Elephant has to count, how many numbers *x* exist, such that number *x* occurs exactly *x* times among numbers *a**l**j*,<=*a**l**j*<=+<=1,<=...,<=*a**r**j*.
Help the Little Elephant to count the answers to all queries.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of array *a* and the number of queries to it. The next line contains *n* space-separated positive integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). Next *m* lines contain descriptions of queries, one per line. The *j*-th of these lines contains the description of the *j*-th query as two space-separated integers *l**j* and *r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*).
Output Specification:
In *m* lines print *m* integers — the answers to the queries. The *j*-th line should contain the answer to the *j*-th query.
Demo Input:
['7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n']
Demo Output:
['3\n1\n']
Note:
none
|
```python
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MXN = 1e5 + 5, BLOCK_SIZE = 316;
struct Query {
int l, r, idx;
bool operator<(const Query &y) const {
// Current query x is being compared with other query y
int x_block = l / BLOCK_SIZE;
int y_block = y.l / BLOCK_SIZE;
// If x and y both lie in the same block, sort in non decreasing order of endpoint
if (x_block == y_block)
return r < y.r;
// x and y lie in different blocks
return x_block < y_block;
}
};
int A[MXN], final_ans[MXN], freq[MXN];
int cur_ans;
void operate(int idx, int delta) {
int x = A[idx];
if (x >= MXN) return;
if (freq[x] == x) cur_ans--;
freq[x] += delta;
if (freq[x] == x) cur_ans++;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++)
cin >> A[i];
vector<Query> queries(M);
for (int i = 0; i < M; i++) {
cin >> queries[i].l >> queries[i].r;
queries[i].l--, queries[i].r--; // 0 based indexing
queries[i].idx = i;
}
sort(queries.begin(), queries.end());
int i = 0, j = -1;
for (const auto &[l, r, idx] : queries) {
while (j < r) operate(++j, 1);
while (i > l) operate(--i, 1);
while (i < l) operate(i++, -1);
while (j > r) operate(j--, -1);
final_ans[idx] = cur_ans;
}
for (int i = 0; i < M; i++)
cout << final_ans[i] << "\n";
}
```
| -1
|
|
766
|
A
|
Mahmoud and Longest Uncommon Subsequence
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms",
"strings"
] | null | null |
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
|
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
|
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
|
[
"abcd\ndefgh\n",
"a\na\n"
] |
[
"5\n",
"-1\n"
] |
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
| 500
|
[
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd",
"output": "100"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "199"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb",
"output": "99"
},
{
"input": "abcde\nfghij",
"output": "5"
},
{
"input": "abcde\nabcdf",
"output": "5"
},
{
"input": "abcde\nbbcde",
"output": "5"
},
{
"input": "abcde\neabcd",
"output": "5"
},
{
"input": "abcdefgh\nabdcefgh",
"output": "8"
},
{
"input": "mmmmm\nmnmmm",
"output": "5"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa",
"output": "34"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy",
"output": "26"
},
{
"input": "a\nab",
"output": "2"
},
{
"input": "b\nab",
"output": "2"
},
{
"input": "ab\nb",
"output": "2"
},
{
"input": "ab\nc",
"output": "2"
},
{
"input": "aaaaaa\naaaaaa",
"output": "-1"
},
{
"input": "abacaba\nabacaba",
"output": "-1"
},
{
"input": "aabb\nbbaa",
"output": "4"
},
{
"input": "ab\nba",
"output": "2"
},
{
"input": "abcd\nabc",
"output": "4"
},
{
"input": "abaa\nabaa",
"output": "-1"
},
{
"input": "ab\nab",
"output": "-1"
},
{
"input": "ab\nabcd",
"output": "4"
},
{
"input": "abc\nabcd",
"output": "4"
},
{
"input": "mo\nmomo",
"output": "4"
},
{
"input": "koooooooooooooooo\nloooooooooooooooo",
"output": "17"
},
{
"input": "aaa\naa",
"output": "3"
},
{
"input": "abc\nabc",
"output": "-1"
},
{
"input": "abcd\nabcd",
"output": "-1"
},
{
"input": "abc\ncba",
"output": "3"
},
{
"input": "ahc\nahc",
"output": "-1"
},
{
"input": "abc\nbac",
"output": "3"
},
{
"input": "aa\naaa",
"output": "3"
},
{
"input": "aaa\naaa",
"output": "-1"
},
{
"input": "abc\nacb",
"output": "3"
},
{
"input": "abc\nab",
"output": "3"
},
{
"input": "abb\nabb",
"output": "-1"
},
{
"input": "abc\ncab",
"output": "3"
},
{
"input": "aaaaaa\naaaaa",
"output": "6"
},
{
"input": "aa\naab",
"output": "3"
},
{
"input": "len\nlena",
"output": "4"
},
{
"input": "aaaaa\naa",
"output": "5"
},
{
"input": "aaa\naaaa",
"output": "4"
},
{
"input": "bcd\nabcd",
"output": "4"
},
{
"input": "aaabbc\naaaccc",
"output": "6"
},
{
"input": "abcd\nzycd",
"output": "4"
},
{
"input": "baa\nzaa",
"output": "3"
},
{
"input": "asdf\nadfs",
"output": "4"
},
{
"input": "abcdefgh\nabcdefgh",
"output": "-1"
},
{
"input": "aba\naab",
"output": "3"
},
{
"input": "aba\naba",
"output": "-1"
},
{
"input": "abcccc\naccccc",
"output": "6"
},
{
"input": "acb\nabc",
"output": "3"
},
{
"input": "a\naa",
"output": "2"
},
{
"input": "abababab\nab",
"output": "8"
},
{
"input": "ababab\nab",
"output": "6"
}
] | 1,696,630,221
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 73
| 62
| 204,800
|
from sys import stdin, stdout
def input():
return stdin.readline().strip()
def print(string):
return stdout.write(str(string) + "\n")
def main():
a = input()
b = input()
la, lb = len(a), len(b)
if la > lb:
print(la)
elif lb > la:
print(lb)
else:
if a == b:
print(-1)
else:
print(la)
if __name__ == "__main__":
main()
|
Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input Specification:
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output Specification:
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
Demo Input:
['abcd\ndefgh\n', 'a\na\n']
Demo Output:
['5\n', '-1\n']
Note:
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
|
```python
from sys import stdin, stdout
def input():
return stdin.readline().strip()
def print(string):
return stdout.write(str(string) + "\n")
def main():
a = input()
b = input()
la, lb = len(a), len(b)
if la > lb:
print(la)
elif lb > la:
print(lb)
else:
if a == b:
print(-1)
else:
print(la)
if __name__ == "__main__":
main()
```
| 3
|
|
811
|
A
|
Vladik and Courtesy
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
|
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
|
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
|
[
"1 1\n",
"7 6\n"
] |
[
"Valera\n",
"Vladik\n"
] |
Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 500
|
[
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
"output": "Valera"
},
{
"input": "999963734 999994456",
"output": "Vladik"
},
{
"input": "1000000000 1000000000",
"output": "Vladik"
},
{
"input": "946 879",
"output": "Valera"
},
{
"input": "10819 45238",
"output": "Vladik"
},
{
"input": "101357 236928",
"output": "Vladik"
},
{
"input": "1033090 7376359",
"output": "Vladik"
},
{
"input": "9754309 9525494",
"output": "Valera"
},
{
"input": "90706344 99960537",
"output": "Vladik"
},
{
"input": "965161805 908862070",
"output": "Valera"
},
{
"input": "9 11",
"output": "Valera"
},
{
"input": "3 2",
"output": "Vladik"
},
{
"input": "6 6",
"output": "Vladik"
},
{
"input": "4 4",
"output": "Valera"
},
{
"input": "5 5",
"output": "Valera"
},
{
"input": "5 4",
"output": "Valera"
},
{
"input": "12345680 1",
"output": "Valera"
},
{
"input": "9 10",
"output": "Valera"
},
{
"input": "678 76687",
"output": "Vladik"
},
{
"input": "1 678",
"output": "Vladik"
},
{
"input": "45 1678",
"output": "Vladik"
},
{
"input": "3 3",
"output": "Vladik"
},
{
"input": "10 11",
"output": "Valera"
},
{
"input": "2 1",
"output": "Valera"
},
{
"input": "1 2",
"output": "Vladik"
},
{
"input": "2 2",
"output": "Vladik"
},
{
"input": "4 5",
"output": "Valera"
},
{
"input": "9 6",
"output": "Valera"
},
{
"input": "1 5",
"output": "Vladik"
},
{
"input": "7 8",
"output": "Vladik"
},
{
"input": "1000000000 999982505",
"output": "Valera"
},
{
"input": "12 12",
"output": "Vladik"
},
{
"input": "1000 950",
"output": "Valera"
},
{
"input": "10 9",
"output": "Valera"
},
{
"input": "100 9",
"output": "Valera"
},
{
"input": "1000 996",
"output": "Vladik"
},
{
"input": "9 5",
"output": "Valera"
}
] | 1,582,654,829
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 3
| 140
| 0
|
a,b=list(map(int,input().split()))
if a==b:
print('Valera')
else:
if (max(a,b)%min(a,b))%2==0:
print('Valera')
else:
print('Vladik')
|
Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Input Specification:
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Output Specification:
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
Demo Input:
['1 1\n', '7 6\n']
Demo Output:
['Valera\n', 'Vladik\n']
Note:
Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
a,b=list(map(int,input().split()))
if a==b:
print('Valera')
else:
if (max(a,b)%min(a,b))%2==0:
print('Valera')
else:
print('Vladik')
```
| 0
|
|
825
|
A
|
Binary Protocol
|
PROGRAMMING
| 1,100
|
[
"implementation"
] | null | null |
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
|
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
|
Print the decoded number.
|
[
"3\n111\n",
"9\n110011101\n"
] |
[
"3\n",
"2031\n"
] |
none
| 0
|
[
{
"input": "3\n111",
"output": "3"
},
{
"input": "9\n110011101",
"output": "2031"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "3\n100",
"output": "100"
},
{
"input": "5\n10001",
"output": "1001"
},
{
"input": "14\n11001100011000",
"output": "202002000"
},
{
"input": "31\n1000011111111100011110111111111",
"output": "100090049"
},
{
"input": "53\n10110111011110111110111111011111110111111110111111111",
"output": "123456789"
},
{
"input": "89\n11111111101111111110111111111011111111101111111110111111111011111111101111111110111111111",
"output": "999999999"
},
{
"input": "10\n1000000000",
"output": "1000000000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "4\n1110",
"output": "30"
},
{
"input": "8\n10101010",
"output": "11110"
}
] | 1,607,860,117
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 13
| 124
| 0
|
n=int(input())
s=input().strip()
print(*map(len, s.split('0')), sep='')
|
Title: Binary Protocol
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
- Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). - Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=89) — length of the string *s*.
The second line contains string *s* — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output Specification:
Print the decoded number.
Demo Input:
['3\n111\n', '9\n110011101\n']
Demo Output:
['3\n', '2031\n']
Note:
none
|
```python
n=int(input())
s=input().strip()
print(*map(len, s.split('0')), sep='')
```
| 3
|
|
66
|
A
|
Petya and Java
|
PROGRAMMING
| 1,300
|
[
"implementation",
"strings"
] |
A. Petya and Java
|
2
|
256
|
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.
But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer *n*?"
Petya knows only 5 integer types:
1) byte occupies 1 byte and allows you to store numbers from <=-<=128 to 127
2) short occupies 2 bytes and allows you to store numbers from <=-<=32768 to 32767
3) int occupies 4 bytes and allows you to store numbers from <=-<=2147483648 to 2147483647
4) long occupies 8 bytes and allows you to store numbers from <=-<=9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.
For all the types given above the boundary values are included in the value range.
From this list, Petya wants to choose the smallest type that can store a positive integer *n*. Since BigInteger works much slower, Peter regards it last. Help him.
|
The first line contains a positive number *n*. It consists of no more than 100 digits and doesn't contain any leading zeros. The number *n* can't be represented as an empty string.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
|
Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number *n*, in accordance with the data given above.
|
[
"127\n",
"130\n",
"123456789101112131415161718192021222324\n"
] |
[
"byte\n",
"short\n",
"BigInteger\n"
] |
none
| 500
|
[
{
"input": "127",
"output": "byte"
},
{
"input": "130",
"output": "short"
},
{
"input": "123456789101112131415161718192021222324",
"output": "BigInteger"
},
{
"input": "6",
"output": "byte"
},
{
"input": "16",
"output": "byte"
},
{
"input": "126",
"output": "byte"
},
{
"input": "128",
"output": "short"
},
{
"input": "32766",
"output": "short"
},
{
"input": "111111",
"output": "int"
},
{
"input": "22222",
"output": "short"
},
{
"input": "32767",
"output": "short"
},
{
"input": "32768",
"output": "int"
},
{
"input": "32769",
"output": "int"
},
{
"input": "2147483645",
"output": "int"
},
{
"input": "2147483646",
"output": "int"
},
{
"input": "2147483647",
"output": "int"
},
{
"input": "2147483648",
"output": "long"
},
{
"input": "2147483649",
"output": "long"
},
{
"input": "9223372036854775805",
"output": "long"
},
{
"input": "9223372036854775806",
"output": "long"
},
{
"input": "9223372036854775807",
"output": "long"
},
{
"input": "9223372036854775808",
"output": "BigInteger"
},
{
"input": "9223372036854775809",
"output": "BigInteger"
},
{
"input": "1111111111111111111111111111111111111111111111",
"output": "BigInteger"
},
{
"input": "232",
"output": "short"
},
{
"input": "241796563564014133460267652699",
"output": "BigInteger"
},
{
"input": "29360359146807441660707083821018832188095237636414144034857851003419752010124705615779249",
"output": "BigInteger"
},
{
"input": "337300529263821789926982715723773719445001702036602052198530564",
"output": "BigInteger"
},
{
"input": "381127467969689863953686682245136076127159921",
"output": "BigInteger"
},
{
"input": "2158324958633591462",
"output": "long"
},
{
"input": "268659422768117401499491767189496733446324586965055954729177892248858259490346",
"output": "BigInteger"
},
{
"input": "3023764505449745844381036446038799100004717936344985",
"output": "BigInteger"
},
{
"input": "13408349824892484976400774",
"output": "BigInteger"
},
{
"input": "18880842614378213198381172973704766723997934818440985546083314104481253291692101136681",
"output": "BigInteger"
},
{
"input": "1180990956946757129733650596194933741",
"output": "BigInteger"
},
{
"input": "73795216631038776655609800540262114612084443385902708034055020082090470662930545328551",
"output": "BigInteger"
},
{
"input": "1658370691480968202384509492140362150472696196949",
"output": "BigInteger"
},
{
"input": "59662093286671707493190399502717308574459619342109544431740791973099298641871347858082458491958703",
"output": "BigInteger"
},
{
"input": "205505005582428018613354752739589866670902346355933720701937",
"output": "BigInteger"
},
{
"input": "53348890623013817139699",
"output": "BigInteger"
},
{
"input": "262373979958859125198440634134122707574734706745701184688685117904709744",
"output": "BigInteger"
},
{
"input": "69113784278456828987289369893745977",
"output": "BigInteger"
},
{
"input": "2210209454022702335652564247406666491086662454147967686455330365147159266087",
"output": "BigInteger"
},
{
"input": "630105816139991597267787581532092408135",
"output": "BigInteger"
},
{
"input": "800461429306907809762708270",
"output": "BigInteger"
},
{
"input": "7685166910821197056344900917707673568669808490600751439157",
"output": "BigInteger"
},
{
"input": "713549841568602590705962611607726022334779480510421458817648621376683672722573289661127894",
"output": "BigInteger"
},
{
"input": "680504312323996476676434432",
"output": "BigInteger"
},
{
"input": "3376595620091080825479292544658464163405755746884100218035",
"output": "BigInteger"
},
{
"input": "303681723783491968617491075591006152690484825330764215796396316561122383310011589365655481",
"output": "BigInteger"
},
{
"input": "4868659422768117401499491767189496733446324586965055954729177892248858259490346614099717639491763430",
"output": "BigInteger"
},
{
"input": "3502376450544974584438103644603879910000471793634498544789130945841846713263971487355748226237288709",
"output": "BigInteger"
},
{
"input": "2334083498248924849764007740114454487565621932425948046430072197452845278935316358800789014185793377",
"output": "BigInteger"
},
{
"input": "1988808426143782131983811729737047667239979348184409855460833141044812532916921011366813880911319644",
"output": "BigInteger"
},
{
"input": "1018099095694675712973365059619493374113337270925179793757322992466016001294122941535439492265169131",
"output": "BigInteger"
},
{
"input": "8437952166310387766556098005402621146120844433859027080340550200820904706629305453285512716464931911",
"output": "BigInteger"
},
{
"input": "6965837069148096820238450949214036215047269619694967357734070611376013382163559966747678150791825071",
"output": "BigInteger"
},
{
"input": "4596620932866717074931903995027173085744596193421095444317407919730992986418713478580824584919587030",
"output": "BigInteger"
},
{
"input": "1905505005582428018613354752739589866670902346355933720701937408006000562951996789032987808118459990",
"output": "BigInteger"
},
{
"input": "8433488906230138171396997888322916936677429522910871017295155818340819168386140293774243244435122950",
"output": "BigInteger"
},
{
"input": "6862373979958859125198440634134122707574734706745701184688685117904709744830303784215298687654884810",
"output": "BigInteger"
},
{
"input": "4491137842784568289872893698937459777201151060689848471272003426250808340375567208957554901863756992",
"output": "BigInteger"
},
{
"input": "9721020945402270233565256424740666649108666245414796768645533036514715926608741510409618545180420952",
"output": "BigInteger"
},
{
"input": "7330105816139991597267787581532092408135003429259616955239761315950805521264994021242873979309182812",
"output": "BigInteger"
},
{
"input": "2000461429306907809762708270752707617318091579531521957022940951538737203583768926365382290530636885",
"output": "BigInteger"
},
{
"input": "9868516691082119705634490091770767356866980849060075143915700796802700437762260163478754592094654326",
"output": "BigInteger"
},
{
"input": "8713549841568602590705962611607726022334779480510421458817648621376683672722573289661127894678771177",
"output": "BigInteger"
},
{
"input": "4580504312323996476676434432646986768872786931159974634901608445720467716981185426771899006352697916",
"output": "BigInteger"
},
{
"input": "2537659562009108082547929254465846416340575574688410021803548570097340949141688442074263189944614467",
"output": "BigInteger"
},
{
"input": "1403681723783491968617491075591006152690484825330764215796396316561122383310011589365655481428540208",
"output": "BigInteger"
},
{
"input": "26",
"output": "byte"
},
{
"input": "302376450544",
"output": "long"
},
{
"input": "13",
"output": "byte"
},
{
"input": "188808426143",
"output": "long"
},
{
"input": "118099095694675",
"output": "long"
},
{
"input": "73795216631038",
"output": "long"
},
{
"input": "1658370691480",
"output": "long"
},
{
"input": "596620932866",
"output": "long"
},
{
"input": "2055050055",
"output": "int"
},
{
"input": "533488906",
"output": "int"
},
{
"input": "26237397",
"output": "int"
},
{
"input": "6911378",
"output": "int"
},
{
"input": "221020945402270233",
"output": "long"
},
{
"input": "63010581613999159",
"output": "long"
},
{
"input": "80046142930",
"output": "long"
},
{
"input": "7685166910821197",
"output": "long"
},
{
"input": "71",
"output": "byte"
},
{
"input": "6805043123239964766",
"output": "long"
},
{
"input": "3376",
"output": "short"
},
{
"input": "3036817237",
"output": "long"
}
] | 1,694,582,253
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 6
| 62
| 0
|
n = int(input())
if (n >= -128 and n <= 128):print('byte')
elif (n >= -32768 and n <= 32767):print('short')
elif (n >= -2147483648 and n <= 2147483647):print('int')
elif (n >= -9223372036854775808 and n <= 9223372036854775807): print('long')
else:print('BigInteger')
|
Title: Petya and Java
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.
But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer *n*?"
Petya knows only 5 integer types:
1) byte occupies 1 byte and allows you to store numbers from <=-<=128 to 127
2) short occupies 2 bytes and allows you to store numbers from <=-<=32768 to 32767
3) int occupies 4 bytes and allows you to store numbers from <=-<=2147483648 to 2147483647
4) long occupies 8 bytes and allows you to store numbers from <=-<=9223372036854775808 to 9223372036854775807
5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.
For all the types given above the boundary values are included in the value range.
From this list, Petya wants to choose the smallest type that can store a positive integer *n*. Since BigInteger works much slower, Peter regards it last. Help him.
Input Specification:
The first line contains a positive number *n*. It consists of no more than 100 digits and doesn't contain any leading zeros. The number *n* can't be represented as an empty string.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Output Specification:
Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number *n*, in accordance with the data given above.
Demo Input:
['127\n', '130\n', '123456789101112131415161718192021222324\n']
Demo Output:
['byte\n', 'short\n', 'BigInteger\n']
Note:
none
|
```python
n = int(input())
if (n >= -128 and n <= 128):print('byte')
elif (n >= -32768 and n <= 32767):print('short')
elif (n >= -2147483648 and n <= 2147483647):print('int')
elif (n >= -9223372036854775808 and n <= 9223372036854775807): print('long')
else:print('BigInteger')
```
| 0
|
359
|
A
|
Table
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms",
"greedy",
"implementation"
] | null | null |
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.
|
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
|
Print a single number — the minimum number of operations Simon needs to carry out his idea.
|
[
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n"
] |
[
"4\n",
"2\n"
] |
In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:
- For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1).
| 500
|
[
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0",
"output": "4"
},
{
"input": "5 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\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\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\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 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": "2"
},
{
"input": "4 32\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\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\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\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",
"output": "2"
},
{
"input": "7 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 0",
"output": "2"
},
{
"input": "13 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 3\n0 1 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 1 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n1 0 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 0 1\n0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0 0\n0 0 0 0\n0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "2"
},
{
"input": "3 5\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "4 3\n0 1 0\n0 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "4 3\n0 0 0\n0 0 0\n0 0 0\n0 1 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 0 0\n1 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 0 0\n0 0 0",
"output": "2"
},
{
"input": "5 3\n0 0 0\n0 1 0\n0 0 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "4 4\n0 0 0 0\n0 1 1 0\n0 1 1 0\n0 0 0 0",
"output": "4"
},
{
"input": "5 3\n0 0 0\n0 0 1\n0 0 0\n0 1 0\n0 0 0",
"output": "2"
},
{
"input": "3 3\n0 0 0\n0 1 1\n0 0 0",
"output": "2"
},
{
"input": "4 3\n0 0 0\n0 0 0\n0 1 0\n0 0 0",
"output": "4"
},
{
"input": "5 5\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "5 3\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n0 0 0",
"output": "2"
}
] | 1,625,152,900
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 37
| 93
| 1,536,000
|
n, m = list(map(int, input().split()))
good_cells = []
for i in range(n):
row = list(map(int, input().split()))
for j, element in enumerate(row):
if element == 1:
good_cells.append((i,j))
def ismarginal(cell):
x, y = cell
if x == 0 or x == n-1:
return True
elif y == 0 or y == m-1:
return True
return False
condition = False
for cell in good_cells:
if ismarginal(cell):
condition = True
break
if condition:
print(2)
else:
print(4)
|
Title: Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a rectangular table consisting of *n* rows and *m* columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the *x*-th row and the *y*-th column as a pair of numbers (*x*,<=*y*). The table corners are cells: (1,<=1), (*n*,<=1), (1,<=*m*), (*n*,<=*m*).
Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.
Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (*x*1,<=*y*1), an arbitrary corner of the table (*x*2,<=*y*2) and color all cells of the table (*p*,<=*q*), which meet both inequations: *min*(*x*1,<=*x*2)<=≤<=*p*<=≤<=*max*(*x*1,<=*x*2), *min*(*y*1,<=*y*2)<=≤<=*q*<=≤<=*max*(*y*1,<=*y*2).
Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.
Input Specification:
The first line contains exactly two integers *n*, *m* (3<=≤<=*n*,<=*m*<=≤<=50).
Next *n* lines contain the description of the table cells. Specifically, the *i*-th line contains *m* space-separated integers *a**i*1,<=*a**i*2,<=...,<=*a**im*. If *a**ij* equals zero, then cell (*i*,<=*j*) isn't good. Otherwise *a**ij* equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.
Output Specification:
Print a single number — the minimum number of operations Simon needs to carry out his idea.
Demo Input:
['3 3\n0 0 0\n0 1 0\n0 0 0\n', '4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n']
Demo Output:
['4\n', '2\n']
Note:
In the first sample, the sequence of operations can be like this:
- For the first time you need to choose cell (2, 2) and corner (1, 1). - For the second time you need to choose cell (2, 2) and corner (3, 3). - For the third time you need to choose cell (2, 2) and corner (3, 1). - For the fourth time you need to choose cell (2, 2) and corner (1, 3).
In the second sample the sequence of operations can be like this:
- For the first time you need to choose cell (3, 1) and corner (4, 3). - For the second time you need to choose cell (2, 3) and corner (1, 1).
|
```python
n, m = list(map(int, input().split()))
good_cells = []
for i in range(n):
row = list(map(int, input().split()))
for j, element in enumerate(row):
if element == 1:
good_cells.append((i,j))
def ismarginal(cell):
x, y = cell
if x == 0 or x == n-1:
return True
elif y == 0 or y == m-1:
return True
return False
condition = False
for cell in good_cells:
if ismarginal(cell):
condition = True
break
if condition:
print(2)
else:
print(4)
```
| 3
|
|
250
|
D
|
Building Bridge
|
PROGRAMMING
| 1,900
|
[
"geometry",
"ternary search",
"two pointers"
] | null | null |
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages.
The river banks can be assumed to be vertical straight lines *x*<==<=*a* and *x*<==<=*b* (0<=<<=*a*<=<<=*b*).
The west village lies in a steppe at point *O*<==<=(0,<=0). There are *n* pathways leading from the village to the river, they end at points *A**i*<==<=(*a*,<=*y**i*). The villagers there are plain and simple, so their pathways are straight segments as well.
The east village has reserved and cunning people. Their village is in the forest on the east bank of the river, but its exact position is not clear. There are *m* twisted paths leading from this village to the river and ending at points *B**i*<==<=(*b*,<=*y*'*i*). The lengths of all these paths are known, the length of the path that leads from the eastern village to point *B**i*, equals *l**i*.
The villagers want to choose exactly one point on the left bank of river *A**i*, exactly one point on the right bank *B**j* and connect them by a straight-line bridge so as to make the total distance between the villages (the sum of |*OA**i*|<=+<=|*A**i**B**j*|<=+<=*l**j*, where |*XY*| is the Euclidean distance between points *X* and *Y*) were minimum. The Euclidean distance between points (*x*1,<=*y*1) and (*x*2,<=*y*2) equals .
Help them and find the required pair of points.
|
The first line contains integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=<<=*a*<=<<=*b*<=<<=106).
The second line contains *n* integers in the ascending order: the *i*-th integer determines the coordinate of point *A**i* and equals *y**i* (|*y**i*|<=≤<=106).
The third line contains *m* integers in the ascending order: the *i*-th integer determines the coordinate of point *B**i* and equals *y*'*i* (|*y*'*i*|<=≤<=106).
The fourth line contains *m* more integers: the *i*-th of them determines the length of the path that connects the eastern village and point *B**i*, and equals *l**i* (1<=≤<=*l**i*<=≤<=106).
It is guaranteed, that there is such a point *C* with abscissa at least *b*, that |*B**i**C*|<=≤<=*l**i* for all *i* (1<=≤<=*i*<=≤<=*m*). It is guaranteed that no two points *A**i* coincide. It is guaranteed that no two points *B**i* coincide.
|
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to *n*, in the order in which they are given in the input. Similarly, the points on the east bank are numbered from 1 to *m* in the order in which they are given in the input.
If there are multiple solutions, print any of them. The solution will be accepted if the final length of the path will differ from the answer of the jury by no more than 10<=-<=6 in absolute or relative value.
|
[
"3 2 3 5\n-2 -1 4\n-1 2\n7 3\n"
] |
[
"2 2"
] |
none
| 1,500
|
[
{
"input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3",
"output": "2 2"
},
{
"input": "1 1 10 20\n5\n-5\n1",
"output": "1 1"
},
{
"input": "2 2 1 2\n-1 10\n8 9\n3 7",
"output": "1 1"
},
{
"input": "10 20 50 60\n-96 -75 32 37 42 43 44 57 61 65\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94 100\n138 75 132 116 49 43 96 166 96 161 146 112 195 192 201 186 251 254 220 227",
"output": "2 6"
}
] | 1,624,433,916
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 10
| 1,000
| 11,571,200
|
from math import sqrt
def bs(x, a):
l = 0
r = len(a)
while r-l>1:
m = (l+r)//2
if a[m] <= x:
l = m
else:
r = m
return l
n, m, a, b = map(int, input().split())
x, y, ans = 0, 0, 10**16
v1, v2, vl = list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))
for i in range(m):
lf = v2[i]*a/b
l = bs(lf, v1)
k = vl[i] + sqrt(a**2 + v1[l]**2) + sqrt((b-a)**2 + (v2[i]-v1[l])**2)
if k <= ans:
ans = k
x = l+1
y = i+1
l+=1
if l < n:
k = vl[i] + sqrt(a**2 + v1[l]**2) + sqrt((b-a)**2 + (v2[i]-v1[l])**2)
if k <= ans:
ans = k
x = l+1
y = i+1
print(x, y)
|
Title: Building Bridge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages.
The river banks can be assumed to be vertical straight lines *x*<==<=*a* and *x*<==<=*b* (0<=<<=*a*<=<<=*b*).
The west village lies in a steppe at point *O*<==<=(0,<=0). There are *n* pathways leading from the village to the river, they end at points *A**i*<==<=(*a*,<=*y**i*). The villagers there are plain and simple, so their pathways are straight segments as well.
The east village has reserved and cunning people. Their village is in the forest on the east bank of the river, but its exact position is not clear. There are *m* twisted paths leading from this village to the river and ending at points *B**i*<==<=(*b*,<=*y*'*i*). The lengths of all these paths are known, the length of the path that leads from the eastern village to point *B**i*, equals *l**i*.
The villagers want to choose exactly one point on the left bank of river *A**i*, exactly one point on the right bank *B**j* and connect them by a straight-line bridge so as to make the total distance between the villages (the sum of |*OA**i*|<=+<=|*A**i**B**j*|<=+<=*l**j*, where |*XY*| is the Euclidean distance between points *X* and *Y*) were minimum. The Euclidean distance between points (*x*1,<=*y*1) and (*x*2,<=*y*2) equals .
Help them and find the required pair of points.
Input Specification:
The first line contains integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=<<=*a*<=<<=*b*<=<<=106).
The second line contains *n* integers in the ascending order: the *i*-th integer determines the coordinate of point *A**i* and equals *y**i* (|*y**i*|<=≤<=106).
The third line contains *m* integers in the ascending order: the *i*-th integer determines the coordinate of point *B**i* and equals *y*'*i* (|*y*'*i*|<=≤<=106).
The fourth line contains *m* more integers: the *i*-th of them determines the length of the path that connects the eastern village and point *B**i*, and equals *l**i* (1<=≤<=*l**i*<=≤<=106).
It is guaranteed, that there is such a point *C* with abscissa at least *b*, that |*B**i**C*|<=≤<=*l**i* for all *i* (1<=≤<=*i*<=≤<=*m*). It is guaranteed that no two points *A**i* coincide. It is guaranteed that no two points *B**i* coincide.
Output Specification:
Print two integers — the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to *n*, in the order in which they are given in the input. Similarly, the points on the east bank are numbered from 1 to *m* in the order in which they are given in the input.
If there are multiple solutions, print any of them. The solution will be accepted if the final length of the path will differ from the answer of the jury by no more than 10<=-<=6 in absolute or relative value.
Demo Input:
['3 2 3 5\n-2 -1 4\n-1 2\n7 3\n']
Demo Output:
['2 2']
Note:
none
|
```python
from math import sqrt
def bs(x, a):
l = 0
r = len(a)
while r-l>1:
m = (l+r)//2
if a[m] <= x:
l = m
else:
r = m
return l
n, m, a, b = map(int, input().split())
x, y, ans = 0, 0, 10**16
v1, v2, vl = list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))
for i in range(m):
lf = v2[i]*a/b
l = bs(lf, v1)
k = vl[i] + sqrt(a**2 + v1[l]**2) + sqrt((b-a)**2 + (v2[i]-v1[l])**2)
if k <= ans:
ans = k
x = l+1
y = i+1
l+=1
if l < n:
k = vl[i] + sqrt(a**2 + v1[l]**2) + sqrt((b-a)**2 + (v2[i]-v1[l])**2)
if k <= ans:
ans = k
x = l+1
y = i+1
print(x, y)
```
| 0
|
|
474
|
B
|
Worms
|
PROGRAMMING
| 1,200
|
[
"binary search",
"implementation"
] | null | null |
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
|
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
|
[
"5\n2 7 3 4 9\n3\n1 25 11\n"
] |
[
"1\n5\n3\n"
] |
For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
| 1,000
|
[
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,677,167,126
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 38
| 421
| 14,028,800
|
n = int(input())
a = [int(x) for x in input().split()]
lookup = []
group_no = 0
for x in a:
group_no += 1
for i in range(x):
lookup.append(group_no)
m = int(input())
b = [int(x) for x in input().split()]
for x in b:
print(lookup[x - 1])
|
Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding.
Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot.
The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
Output Specification:
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
Demo Input:
['5\n2 7 3 4 9\n3\n1 25 11\n']
Demo Output:
['1\n5\n3\n']
Note:
For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
|
```python
n = int(input())
a = [int(x) for x in input().split()]
lookup = []
group_no = 0
for x in a:
group_no += 1
for i in range(x):
lookup.append(group_no)
m = int(input())
b = [int(x) for x in input().split()]
for x in b:
print(lookup[x - 1])
```
| 3
|
|
472
|
A
|
Design Tutorial: Learn from Math
|
PROGRAMMING
| 800
|
[
"math",
"number theory"
] | null | null |
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
|
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
|
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
|
[
"12\n",
"15\n",
"23\n",
"1000000\n"
] |
[
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] |
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
| 500
|
[
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,695,239,865
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 33
| 46
| 0
|
num=int(input())
a=num//2
b=num-a
while (a%2!=0 and a%3!=0) or (b%2!=0 and b%3!=0):
if a%2!=0 and a%3!=0 :
a-=1
b+=1
if b%2!=0 and b%3!=0 :
a-=1
b+=1
print(a,b)
|
Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
|
```python
num=int(input())
a=num//2
b=num-a
while (a%2!=0 and a%3!=0) or (b%2!=0 and b%3!=0):
if a%2!=0 and a%3!=0 :
a-=1
b+=1
if b%2!=0 and b%3!=0 :
a-=1
b+=1
print(a,b)
```
| 3
|
|
908
|
A
|
New Year and Counting Cards
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
|
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
|
Print a single integer, the minimum number of cards you must turn over to verify your claim.
|
[
"ee\n",
"z\n",
"0ay1\n"
] |
[
"2\n",
"0\n",
"2\n"
] |
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards.
| 500
|
[
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01234567890123456789012345678901234567890123456789",
"output": "25"
},
{
"input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb",
"output": "10"
},
{
"input": "cjw2dwmr10pku4yxohe0wglktd",
"output": "4"
},
{
"input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6",
"output": "13"
},
{
"input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1",
"output": "13"
},
{
"input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs",
"output": "8"
},
{
"input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc",
"output": "14"
},
{
"input": "2222",
"output": "0"
},
{
"input": "13579",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "a",
"output": "1"
},
{
"input": "y",
"output": "0"
},
{
"input": "w",
"output": "0"
},
{
"input": "oo",
"output": "2"
},
{
"input": "oy",
"output": "1"
},
{
"input": "yo",
"output": "1"
},
{
"input": "yy",
"output": "0"
},
{
"input": "a0",
"output": "1"
},
{
"input": "a9",
"output": "2"
},
{
"input": "y0",
"output": "0"
},
{
"input": "y7",
"output": "1"
},
{
"input": "0a",
"output": "1"
},
{
"input": "3a",
"output": "2"
},
{
"input": "06",
"output": "0"
},
{
"input": "07",
"output": "1"
},
{
"input": "70",
"output": "1"
},
{
"input": "77",
"output": "2"
},
{
"input": "13570",
"output": "4"
},
{
"input": "0000000000011111",
"output": "5"
},
{
"input": "1357",
"output": "4"
},
{
"input": "uuuuuuuuuuuuuuuuuu",
"output": "18"
},
{
"input": "gabieurat",
"output": "5"
}
] | 1,650,055,466
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 38
| 46
| 0
|
VOGAIS = 'aeiou'
IMPARES = '13579'
s = input()
vezes = 0
for caractere in s:
if caractere not in VOGAIS and caractere not in IMPARES:
continue
vezes += 1
print(vezes)
|
Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
Input Specification:
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Output Specification:
Print a single integer, the minimum number of cards you must turn over to verify your claim.
Demo Input:
['ee\n', 'z\n', '0ay1\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards.
|
```python
VOGAIS = 'aeiou'
IMPARES = '13579'
s = input()
vezes = 0
for caractere in s:
if caractere not in VOGAIS and caractere not in IMPARES:
continue
vezes += 1
print(vezes)
```
| 3
|
|
598
|
A
|
Tricky Sum
|
PROGRAMMING
| 900
|
[
"math"
] | null | null |
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*.
|
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
|
Print the requested sum for each of *t* integers *n* given in the input.
|
[
"2\n4\n1000000000\n"
] |
[
"-4\n499999998352516354\n"
] |
The answer for the first sample is explained in the statement.
| 0
|
[
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n1305"
},
{
"input": "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\n102\n486\n333\n580\n431\n537\n355\n624\n23\n429\n276\n84\n704\n96\n536\n855\n653\n72\n718\n776\n658\n802\n777\n995\n285\n328\n405\n184\n555\n956\n410\n846\n853\n525\n983\n65\n549\n839\n929\n620\n725\n635\n303\n201\n878\n580\n139\n182\n69\n400\n788\n985\n792\n103\n248\n570\n839\n253\n417",
"output": "404305\n251782\n0\n227457\n210832\n284857\n462120\n8535\n20605\n392670\n357082\n39164\n172890\n482574\n-1\n1765\n144024\n484545\n449679\n264039\n5206\n29380\n124228\n105469\n31116\n232909\n197350\n320760\n136555\n178254\n498454\n402504\n83644\n23580\n176457\n57631\n295560\n59704\n127756\n298654\n102263\n4999\n117319\n54589\n166444\n92074\n142407\n62168\n192954\n214\n91213\n37204\n3316\n246114\n4402\n141870\n363894\n211485\n2374\n256075\n299430\n214765\n319957\n300207\n493464\n39733\n52934\n81193\n16510\n15..."
},
{
"input": "1\n16",
"output": "74"
},
{
"input": "60\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457\n536870912\n536870911\n536870913\n1000000000\n999999999\n1\n2\n3\n4\n268435456\n268435455\n268435457",
"output": "144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875331\n144115186196807682\n144115186733678594\n144115186733678595\n499999998352516354\n499999997352516354\n-1\n-3\n0\n-4\n36028796079439874\n36028796347875330\n36028796347875..."
},
{
"input": "13\n1\n19\n31\n19\n19\n92\n74\n69\n32\n32\n91\n42\n73",
"output": "-1\n128\n434\n128\n128\n4024\n2521\n2161\n402\n402\n3932\n777\n2447"
},
{
"input": "1\n16383",
"output": "134176770"
},
{
"input": "16\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100\n100100",
"output": "5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908\n5009792908"
},
{
"input": "1\n414234",
"output": "85794061921"
},
{
"input": "1\n414232",
"output": "85793233454"
},
{
"input": "3\n414231\n414231\n414231",
"output": "85792819222\n85792819222\n85792819222"
},
{
"input": "1\n121",
"output": "7127"
}
] | 1,696,434,574
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 0
| 1,000
| 0
|
m = set()
p = 1
m.add(p)
for q in range(33):
p = p*2
if p < 1000000000:
m.add(p)
# print(m)
def sum2(n):
s = 0
for k in range(n+1):
if k in m:
s -= k
else:
s += k
return s
t = int(input())
for i in range(t):
n = int(input())
print(sum2(n))
|
Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*.
Input Specification:
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print the requested sum for each of *t* integers *n* given in the input.
Demo Input:
['2\n4\n1000000000\n']
Demo Output:
['-4\n499999998352516354\n']
Note:
The answer for the first sample is explained in the statement.
|
```python
m = set()
p = 1
m.add(p)
for q in range(33):
p = p*2
if p < 1000000000:
m.add(p)
# print(m)
def sum2(n):
s = 0
for k in range(n+1):
if k in m:
s -= k
else:
s += k
return s
t = int(input())
for i in range(t):
n = int(input())
print(sum2(n))
```
| 0
|
|
705
|
A
|
Hulk
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
|
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
|
Print Dr.Banner's feeling in one line.
|
[
"1\n",
"2\n",
"3\n"
] |
[
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] |
none
| 500
|
[
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output": "I hate that I love that I hate that I love that I hate it"
},
{
"input": "10",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "18",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "19",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "76",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "77",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "81",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "82",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "85",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "86",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "99",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "98",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "33",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it"
},
{
"input": "34",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it"
},
{
"input": "57",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
},
{
"input": "100",
"output": "I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate ..."
}
] | 1,694,882,617
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 1
| 62
| 0
|
n=int(input())
lst=list()
for i in range(1,n+1):
if i%2!=0:
lst.append("I hate it")
else:
lst.append("I love it")
print(" that ".join(lst))
|
Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on...
For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Output Specification:
Print Dr.Banner's feeling in one line.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n']
Note:
none
|
```python
n=int(input())
lst=list()
for i in range(1,n+1):
if i%2!=0:
lst.append("I hate it")
else:
lst.append("I love it")
print(" that ".join(lst))
```
| 0
|
|
776
|
A
|
A Serial Killer
|
PROGRAMMING
| 900
|
[
"brute force",
"implementation",
"strings"
] | null | null |
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
|
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
|
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
|
[
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] |
[
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] |
In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
| 500
|
[
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\nb d\nd e",
"output": "a b\nc b\nc d\nc e"
},
{
"input": "ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg",
"output": "ze udggmyop\nszhrbmft udggmyop\nszhrbmft mjorab\nojdtfnzxj mjorab\nyjlkg mjorab"
},
{
"input": "q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o",
"output": "q s\nb s\nj s\nj g\nf g\nm g\nm c\nm a\nd a\nz a\no a"
},
{
"input": "iii iiiiii\n7\niii iiiiiiiiii\niiiiiiiiii iiii\niiii i\niiiiii iiiiiiii\niiiiiiii iiiiiiiii\ni iiiii\niiiii ii",
"output": "iii iiiiii\niiiiiiiiii iiiiii\niiii iiiiii\ni iiiiii\ni iiiiiiii\ni iiiiiiiii\niiiii iiiiiiiii\nii iiiiiiiii"
},
{
"input": "bwyplnjn zkms\n26\nzkms nzmcsytxh\nnzmcsytxh yujsb\nbwyplnjn gtbzhudpb\ngtbzhudpb hpk\nyujsb xvy\nhpk wrwnfokml\nwrwnfokml ndouuikw\nndouuikw ucgrja\nucgrja tgfmpldz\nxvy nycrfphn\nnycrfphn quvs\nquvs htdy\nhtdy k\ntgfmpldz xtdpkxm\nxtdpkxm suwqxs\nk fv\nsuwqxs qckllwy\nqckllwy diun\nfv lefa\nlefa gdoqjysx\ndiun dhpz\ngdoqjysx bdmqdyt\ndhpz dgz\ndgz v\nbdmqdyt aswy\naswy ydkayhlrnm",
"output": "bwyplnjn zkms\nbwyplnjn nzmcsytxh\nbwyplnjn yujsb\ngtbzhudpb yujsb\nhpk yujsb\nhpk xvy\nwrwnfokml xvy\nndouuikw xvy\nucgrja xvy\ntgfmpldz xvy\ntgfmpldz nycrfphn\ntgfmpldz quvs\ntgfmpldz htdy\ntgfmpldz k\nxtdpkxm k\nsuwqxs k\nsuwqxs fv\nqckllwy fv\ndiun fv\ndiun lefa\ndiun gdoqjysx\ndhpz gdoqjysx\ndhpz bdmqdyt\ndgz bdmqdyt\nv bdmqdyt\nv aswy\nv ydkayhlrnm"
},
{
"input": "wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqrpd ttwrtio\nttwrtio xapvds\nxapvds zk\nwxz yryk\nzk b",
"output": "wxz hbeqwqp\nwxz cpieghnszh\nwxz tlqrpd\nwxz ttwrtio\nwxz xapvds\nwxz zk\nyryk zk\nyryk b"
},
{
"input": "wced gnsgv\n23\ngnsgv japawpaf\njapawpaf nnvpeu\nnnvpeu a\na ddupputljq\nddupputljq qyhnvbh\nqyhnvbh pqwijl\nwced khuvs\nkhuvs bjkh\npqwijl ysacmboc\nbjkh srf\nsrf jknoz\njknoz hodf\nysacmboc xqtkoyh\nhodf rfp\nxqtkoyh bivgnwqvoe\nbivgnwqvoe nknf\nnknf wuig\nrfp e\ne bqqknq\nwuig sznhhhu\nbqqknq dhrtdld\ndhrtdld n\nsznhhhu bguylf",
"output": "wced gnsgv\nwced japawpaf\nwced nnvpeu\nwced a\nwced ddupputljq\nwced qyhnvbh\nwced pqwijl\nkhuvs pqwijl\nbjkh pqwijl\nbjkh ysacmboc\nsrf ysacmboc\njknoz ysacmboc\nhodf ysacmboc\nhodf xqtkoyh\nrfp xqtkoyh\nrfp bivgnwqvoe\nrfp nknf\nrfp wuig\ne wuig\nbqqknq wuig\nbqqknq sznhhhu\ndhrtdld sznhhhu\nn sznhhhu\nn bguylf"
},
{
"input": "qqqqqqqqqq qqqqqqqq\n3\nqqqqqqqq qqqqqqqqq\nqqqqqqqqq qqqqq\nqqqqq q",
"output": "qqqqqqqqqq qqqqqqqq\nqqqqqqqqqq qqqqqqqqq\nqqqqqqqqqq qqqqq\nqqqqqqqqqq q"
},
{
"input": "wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww",
"output": "wwwww w\nwwwwwwww w\nwwwwwwwww w\nwwwwwwwwww w\nwwwwwwwwww www\nwwww www\nww www\nww wwwwww\nww wwwwwww"
},
{
"input": "k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n",
"output": "k d\nl d\nl v\nl z\nr z\nr i\ns i\np i\nw i\nj i\nh i\nh c\nm c\nq c\nq o\nq g\nx g\nn g"
}
] | 1,642,766,841
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 57
| 62
| 0
|
if __name__ == "__main__":
vic1, vic2 = input().strip().split()
n = int(input())
for i in range(n):
print(vic1, vic2)
ded, rep = input().strip().split()
if ded == vic1: vic1 = rep
else: vic2 = rep
print(vic1, vic2)
|
Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
Input Specification:
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output Specification:
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
Demo Input:
['ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'icm codeforces\n1\ncodeforces technex\n']
Demo Output:
['ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n', 'icm codeforces\nicm technex\n']
Note:
In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
|
```python
if __name__ == "__main__":
vic1, vic2 = input().strip().split()
n = int(input())
for i in range(n):
print(vic1, vic2)
ded, rep = input().strip().split()
if ded == vic1: vic1 = rep
else: vic2 = rep
print(vic1, vic2)
```
| 3
|
|
234
|
C
|
Weather
|
PROGRAMMING
| 1,300
|
[
"dp",
"implementation"
] | null | null |
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last *n* days. Thus, he got a sequence of numbers *t*1,<=*t*2,<=...,<=*t**n*, where the *i*-th number is the temperature on the *i*-th day.
Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer *k* (1<=≤<=*k*<=≤<=*n*<=-<=1) such that *t*1<=<<=0,<=*t*2<=<<=0,<=...,<=*t**k*<=<<=0 and *t**k*<=+<=1<=><=0,<=*t**k*<=+<=2<=><=0,<=...,<=*t**n*<=><=0. In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset.
You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that.
|
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single spaces.
|
Print a single integer — the answer to the given task.
|
[
"4\n-1 1 -2 1\n",
"5\n0 -1 1 2 -5\n"
] |
[
"1\n",
"2\n"
] |
Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number.
| 0
|
[
{
"input": "4\n-1 1 -2 1",
"output": "1"
},
{
"input": "5\n0 -1 1 2 -5",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n-1 -2 -3 -4 5 6",
"output": "0"
},
{
"input": "8\n1 2 -1 0 10 2 12 13",
"output": "3"
},
{
"input": "7\n-1 -2 -3 3 -1 3 4",
"output": "1"
},
{
"input": "2\n3 -5",
"output": "2"
},
{
"input": "50\n4 -8 0 -1 -3 -9 0 -2 0 1 -1 0 7 -10 9 7 0 -10 5 0 1 -6 9 -9 3 -3 3 7 4 -8 -8 3 3 -1 0 2 -6 10 7 -1 -6 -3 -4 2 3 0 -4 0 7 -9",
"output": "26"
},
{
"input": "90\n52 -89 17 64 11 -61 92 51 42 -92 -14 -100 21 -88 73 -11 84 72 -80 -78 5 -70 -70 80 91 -89 87 -74 63 -79 -94 52 82 79 81 40 69 -15 33 -52 18 30 -39 99 84 -98 44 69 -75 0 60 -89 51 -92 83 73 16 -43 17 0 51 9 -53 86 86 -50 0 -80 3 0 86 0 -76 -45 0 -32 45 81 47 15 -62 21 4 -82 77 -67 -64 -12 0 -50",
"output": "42"
},
{
"input": "10\n-19 -29 -21 -6 29 89 -74 -22 18 -13",
"output": "3"
},
{
"input": "100\n-782 365 -283 769 -58 224 1000 983 7 595 -963 -267 -934 -187 -609 693 -316 431 859 -753 865 -421 861 -728 -793 621 -311 414 -101 -196 120 84 633 -362 989 94 206 19 -949 -629 489 376 -391 165 50 22 -209 735 565 61 -321 -256 890 34 343 -326 984 -268 -609 385 717 81 372 -391 271 -89 297 -510 797 -425 -276 573 510 560 165 -482 511 541 -491 60 168 -805 235 -657 -679 -617 -212 816 -98 901 380 103 608 -257 -643 333 8 355 743 -801",
"output": "40"
}
] | 1,620,545,844
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 60
| 6,758,400
|
a=open("input.txt","r")
b=open("output.txt","w")
c, d =int(a.readline(), list(map(int,a.readline().split())))
e = sum(x <= 0 for x in a)
length = len(a)
for x in a[:-1]:
a += (x > 0) - (0 < x)
length = min(length, e)
print(length, b)
|
Title: Weather
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last *n* days. Thus, he got a sequence of numbers *t*1,<=*t*2,<=...,<=*t**n*, where the *i*-th number is the temperature on the *i*-th day.
Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer *k* (1<=≤<=*k*<=≤<=*n*<=-<=1) such that *t*1<=<<=0,<=*t*2<=<<=0,<=...,<=*t**k*<=<<=0 and *t**k*<=+<=1<=><=0,<=*t**k*<=+<=2<=><=0,<=...,<=*t**n*<=><=0. In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset.
You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single spaces.
Output Specification:
Print a single integer — the answer to the given task.
Demo Input:
['4\n-1 1 -2 1\n', '5\n0 -1 1 2 -5\n']
Demo Output:
['1\n', '2\n']
Note:
Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number.
|
```python
a=open("input.txt","r")
b=open("output.txt","w")
c, d =int(a.readline(), list(map(int,a.readline().split())))
e = sum(x <= 0 for x in a)
length = len(a)
for x in a[:-1]:
a += (x > 0) - (0 < x)
length = min(length, e)
print(length, b)
```
| -1
|
|
250
|
A
|
Paper Work
|
PROGRAMMING
| 1,000
|
[
"greedy"
] | null | null |
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. If *a**i* is negative, then the company suffered losses on the *i*-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the *n* days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (*a**i*<=<<=0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence *a**i*, will print the minimum number of folders.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*.
|
Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them.
|
[
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] |
[
"3\n5 3 3 ",
"1\n5 "
] |
Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder.
| 500
|
[
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"input": "2\n-2 2",
"output": "1\n2 "
},
{
"input": "2\n-2 -1",
"output": "1\n2 "
},
{
"input": "12\n1 -12 -5 -8 0 -8 -1 -1 -6 12 -9 12",
"output": "4\n3 3 2 4 "
},
{
"input": "4\n1 2 0 3",
"output": "1\n4 "
},
{
"input": "4\n4 -3 3 3",
"output": "1\n4 "
},
{
"input": "4\n0 -3 4 -3",
"output": "1\n4 "
},
{
"input": "4\n-3 -2 4 -3",
"output": "2\n1 3 "
},
{
"input": "4\n-3 -2 -1 -4",
"output": "2\n2 2 "
},
{
"input": "5\n-2 -2 4 0 -1",
"output": "2\n1 4 "
},
{
"input": "5\n-5 -3 -1 2 -1",
"output": "2\n2 3 "
},
{
"input": "5\n-3 -2 -3 -2 -3",
"output": "3\n1 2 2 "
},
{
"input": "10\n0 5 2 3 10 9 4 9 9 3",
"output": "1\n10 "
},
{
"input": "10\n10 2 1 2 9 10 7 4 -4 5",
"output": "1\n10 "
},
{
"input": "10\n1 -3 1 10 -7 -6 7 0 -5 3",
"output": "2\n5 5 "
},
{
"input": "10\n6 5 -10 -4 -3 -7 5 -2 -6 -10",
"output": "4\n3 2 3 2 "
},
{
"input": "10\n-2 -4 -1 -6 -5 -5 -7 0 -7 -8",
"output": "5\n1 2 2 2 3 "
},
{
"input": "100\n48 36 10 85 15 57 100 70 14 82 15 75 67 44 40 83 12 94 80 77 92 40 39 80 11 10 2 22 71 31 93 51 22 29 98 90 33 91 66 64 87 70 46 86 62 13 85 15 37 3 49 11 21 57 26 14 5 80 33 82 9 75 26 76 50 32 48 100 62 11 97 47 67 81 86 80 51 51 44 97 2 22 18 52 43 54 65 91 94 54 22 80 23 63 44 7 52 98 80 69",
"output": "1\n100 "
},
{
"input": "100\n7 51 31 14 17 0 72 29 77 6 32 94 70 94 1 64 85 29 67 66 56 -90 38 85 51 5 69 36 62 99 99 43 43 40 68 88 62 39 45 75 50 95 51 96 69 60 65 27 63 89 23 43 49 39 92 90 1 49 22 78 13 90 97 87 5 100 60 82 50 49 0 11 87 34 67 7 35 65 20 92 89 29 73 48 41 8 14 76 91 34 13 18 42 75 36 14 78 80 74 9",
"output": "1\n100 "
},
{
"input": "100\n83 71 43 50 61 54 -45 44 36 35 44 21 34 65 23 32 73 36 70 17 46 47 10 30 48 25 84 58 63 96 44 88 24 93 26 24 70 69 90 75 20 42 63 11 0 41 54 23 95 99 17 27 43 20 46 100 65 -79 15 72 78 0 13 94 76 72 69 35 61 3 65 83 28 12 27 48 8 37 30 37 40 87 30 76 81 78 71 44 79 92 10 60 5 7 9 33 79 31 86 51",
"output": "1\n100 "
},
{
"input": "100\n78 96 4 24 -66 42 28 16 42 -48 89 0 74 19 12 86 75 21 42 100 2 43 11 -76 85 24 12 51 26 48 22 74 68 73 22 39 53 42 37 -78 100 5 9 58 10 63 19 89 76 42 10 -96 76 49 67 59 86 37 13 66 75 92 48 80 37 59 49 -4 83 1 82 25 0 31 73 40 52 3 -47 17 68 94 51 84 47 76 73 -65 83 72 56 50 62 -5 40 12 81 75 84 -6",
"output": "5\n10 30 28 20 12 "
},
{
"input": "100\n-63 20 79 73 18 82 23 -93 55 8 -31 37 33 24 30 41 70 77 14 34 84 79 -94 88 54 81 7 90 74 35 29 3 75 71 14 28 -61 63 90 79 71 97 -90 74 -33 10 27 34 46 31 9 90 100 -73 58 2 73 51 5 46 -27 -9 30 65 73 28 15 14 1 59 96 21 100 78 12 97 72 37 -28 52 12 0 -42 84 88 8 88 8 -48 39 13 -78 20 56 38 82 32 -87 45 39",
"output": "8\n1 10 26 8 16 18 10 11 "
},
{
"input": "100\n21 40 60 28 85 10 15 -3 -27 -7 26 26 9 93 -3 -65 70 88 68 -85 24 75 24 -69 53 56 44 -53 -15 -74 12 22 37 22 77 90 9 95 40 15 -76 7 -81 65 83 51 -57 59 19 78 34 40 11 17 99 75 56 67 -81 39 22 86 -78 61 19 25 53 13 -91 91 17 71 45 39 63 32 -57 83 70 26 100 -53 7 95 67 -47 84 84 28 56 94 72 48 58 21 -89 91 73 16 93",
"output": "10\n9 6 5 8 2 13 16 10 13 18 "
},
{
"input": "100\n39 -70 7 7 11 27 88 16 -3 94 94 -2 23 91 41 49 69 61 53 -99 98 54 87 44 48 73 62 80 86 -33 34 -87 56 48 4 18 92 14 -37 84 7 42 9 70 0 -78 17 68 54 -82 65 -21 59 90 72 -19 -81 8 92 88 -68 65 -42 -60 98 -39 -2 2 88 24 9 -95 17 75 12 -32 -9 85 7 88 59 14 90 69 19 -88 -73 1 2 72 15 -83 65 18 26 25 -71 3 -51 95",
"output": "13\n2 10 18 9 11 6 5 3 3 9 10 6 8 "
},
{
"input": "100\n-47 -28 -90 -35 28 32 63 77 88 3 -48 18 48 22 47 47 89 2 88 46 25 60 65 44 100 28 73 71 19 -55 44 47 30 -25 50 15 -98 5 73 -56 61 15 15 77 67 59 -64 22 17 70 67 -12 26 -81 -58 -20 1 22 34 52 -45 56 78 29 47 -11 -10 70 -57 -2 62 85 -84 -54 -67 67 85 23 6 -65 -6 -79 -13 -1 12 68 1 71 73 77 48 -48 90 70 52 100 45 38 -43 -93",
"output": "15\n2 2 26 7 10 7 2 10 3 4 2 6 2 9 8 "
},
{
"input": "100\n-34 -61 96 14 87 33 29 64 -76 7 47 -41 54 60 79 -28 -18 88 95 29 -89 -29 52 39 8 13 68 13 15 46 -34 -49 78 -73 64 -56 83 -16 45 17 40 11 -86 55 56 -35 91 81 38 -77 -41 67 16 -37 -56 -84 -42 99 -83 45 46 -56 -14 -15 79 77 -48 -87 94 46 77 18 -32 16 -18 47 67 35 89 95 36 -32 51 46 40 78 0 58 81 -47 41 5 -48 65 89 6 -79 -56 -25 74",
"output": "18\n1 8 7 5 10 3 4 8 5 4 2 5 2 4 7 15 7 3 "
},
{
"input": "100\n14 36 94 -66 24 -24 14 -87 86 94 44 88 -68 59 4 -27 -74 12 -75 92 -31 29 18 -69 -47 45 -85 67 95 -77 7 -56 -80 -46 -40 73 40 71 41 -86 50 87 94 16 43 -96 96 -63 66 24 3 90 16 42 50 41 15 -45 72 32 -94 -93 91 -31 -30 -73 -88 33 45 9 71 18 37 -26 43 -82 87 67 62 -9 29 -70 -34 99 -30 -25 -86 -91 -70 -48 24 51 53 25 90 69 -17 -53 87 -62",
"output": "20\n6 7 4 4 4 5 3 2 11 12 4 3 2 9 6 3 2 2 8 3 "
},
{
"input": "100\n-40 87 -68 72 -49 48 -62 73 95 27 80 53 76 33 -95 -53 31 18 -61 -75 84 40 35 -82 49 47 -13 22 -81 -65 -17 47 -61 21 9 -12 52 67 31 -86 -63 42 18 -25 70 45 -3 -18 94 -62 -28 16 -100 36 -96 -73 83 -65 9 -51 83 36 65 -24 77 38 81 -84 32 -34 75 -50 -92 11 -73 -17 81 -66 -61 33 -47 -50 -72 -95 -58 54 68 -46 -41 8 76 28 58 87 88 100 61 -61 75 -1",
"output": "23\n1 4 10 4 5 5 2 5 5 6 3 3 3 4 8 4 3 3 3 2 2 4 11 "
},
{
"input": "100\n-61 56 1 -37 61 -77 -6 -5 28 36 27 -32 -10 -44 -89 -26 67 100 -94 80 -18 -5 -92 94 81 -38 -76 4 -77 2 79 55 -93 54 -19 10 -35 -12 -42 -32 -23 -67 -95 -62 -16 23 -25 41 -16 -51 3 -45 -1 53 20 0 0 21 87 28 15 62 64 -21 6 45 -19 95 -23 87 15 -35 21 -88 47 -81 89 68 66 -65 95 54 18 -97 65 -7 75 -58 -54 -3 99 -95 -57 -84 98 -6 33 44 81 -56",
"output": "25\n4 3 5 2 2 5 2 4 6 4 2 2 2 2 4 3 12 5 5 6 6 3 3 2 6 "
},
{
"input": "100\n-21 61 -52 47 -25 -42 -48 -46 58 -13 75 -65 52 88 -59 68 -12 -25 33 14 -2 78 32 -41 -79 17 0 85 -39 -80 61 30 -27 -92 -100 66 -53 -11 -59 65 -5 92 -2 -85 87 -72 19 -50 -24 32 -27 -92 -100 14 72 13 67 -22 -27 -56 -84 -90 -74 -70 44 -92 70 -49 -50 11 57 -73 23 68 65 99 82 -18 -93 -34 85 45 89 -58 -80 5 -57 -98 -11 -96 28 30 29 -71 47 50 -15 30 -96 -53",
"output": "28\n1 4 2 3 5 3 6 5 4 2 3 3 3 4 3 2 6 2 2 3 3 9 2 5 3 2 7 3 "
},
{
"input": "100\n-61 15 -88 52 -75 -71 -36 29 93 99 -73 -97 -69 39 -78 80 -28 -20 -36 -89 88 -82 56 -37 -13 33 2 -6 -88 -9 8 -24 40 5 8 -33 -83 -90 -48 55 69 -12 -49 -41 -4 92 42 57 -17 -68 -41 -68 77 -17 -45 -64 -39 24 -78 -3 -49 77 3 -23 84 -36 -19 -16 -72 74 -19 -81 65 -79 -57 64 89 -29 49 69 88 -18 16 26 -86 -58 -91 69 -43 -28 86 6 -87 47 -71 18 81 -55 -42 -30",
"output": "30\n3 3 5 2 4 2 3 3 4 3 5 2 4 2 5 2 3 2 3 4 3 2 3 3 7 4 3 4 5 2 "
},
{
"input": "100\n-21 -98 -66 26 3 -5 86 99 96 -22 78 -16 20 -3 93 22 -67 -37 -27 12 -97 43 -46 -48 -58 -4 -19 26 -87 -61 67 -76 -42 57 -87 -50 -24 -79 -6 43 -68 -42 13 -1 -82 81 -32 -88 -6 -99 46 42 19 -17 89 14 -98 -24 34 -37 -17 49 76 81 -61 23 -46 -79 -48 -5 87 14 -97 -67 -31 94 -77 15 -44 38 -44 -67 -69 -84 -58 -59 -17 -54 3 -15 79 -28 -10 -26 34 -73 -37 -57 -42 -44",
"output": "33\n1 2 7 4 4 3 3 2 3 3 3 2 2 3 3 3 2 7 3 5 3 2 4 3 4 2 2 2 3 3 3 2 2 "
},
{
"input": "100\n-63 -62 -88 -14 -58 -75 -28 19 -71 60 -38 77 98 95 -49 -64 -87 -97 2 -37 -37 -41 -47 -96 -58 -42 -88 12 -90 -65 0 52 -59 87 -79 -68 -66 -90 -19 -4 86 -65 -49 -94 67 93 -61 100 68 -40 -35 -67 -4 -100 -90 -86 15 -3 -75 57 65 -91 -80 -57 51 -88 -61 -54 -13 -46 -64 53 -87 -54 -69 29 -67 -23 -96 -93 -3 -77 -10 85 55 -44 17 24 -78 -82 -33 14 85 79 84 -91 -81 54 -89 -86",
"output": "35\n2 2 2 3 6 2 3 2 2 2 3 4 3 2 2 3 4 4 2 2 3 4 2 3 2 2 3 3 2 2 2 6 2 6 3 "
},
{
"input": "100\n30 -47 -87 -49 -4 -58 -10 -10 -37 -15 -12 -85 4 24 -3 -2 57 57 -60 94 -21 82 1 -54 -39 -98 -72 57 84 -6 -41 82 93 -81 -61 -30 18 -68 -88 17 87 -6 43 -26 72 -14 -40 -75 -69 60 -91 -70 -26 -62 -13 -19 -97 -14 -59 -17 -44 -15 -65 60 -60 74 26 -6 12 -83 -49 82 -76 -96 -31 -98 -100 49 -50 -42 -43 92 -56 -79 -38 -86 -99 -37 -75 -26 -79 -12 -9 -87 -63 -62 -25 -3 -5 -92",
"output": "38\n2 2 2 2 2 2 4 5 4 2 4 4 3 4 4 2 3 2 2 2 2 2 2 5 3 3 2 3 2 3 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n-58 -18 -94 -96 -18 -2 -35 -49 47 69 96 -46 -88 -91 -9 -95 -12 -46 -12 16 44 -53 -96 71 -11 -98 -62 -27 -89 -88 -28 -11 -14 -47 67 -69 -33 -64 15 -24 67 53 -93 -10 -75 -98 -8 -97 -62 67 -52 -59 -9 -89 -39 -23 -37 -61 -83 -89 23 -47 -67 18 -38 -63 -73 -98 -65 -70 -20 13 -33 -46 -50 -30 -33 85 -93 -42 -37 48 -8 -11 -32 0 -58 -70 -27 -79 -52 82 22 -62 -100 -12 -5 -82 88 -74",
"output": "40\n2 2 2 2 5 2 2 2 4 3 2 2 2 2 3 3 4 2 2 3 2 2 2 2 3 3 2 2 2 3 2 3 2 3 3 2 2 4 2 3 "
},
{
"input": "100\n-60 -62 -19 -42 -50 -22 -90 -82 -56 40 87 -1 -30 -76 -8 -32 -57 38 -14 -39 84 -60 -28 -82 -62 -83 -37 -59 -61 -86 -13 48 18 -8 50 -27 -47 -100 -42 -88 -19 -45 30 -93 -46 3 -26 -80 -61 -13 -20 76 -95 -51 -26 -1 39 -92 -41 -76 -67 26 -23 30 79 -26 -51 -40 -29 -14 -2 -43 -30 -19 -62 -65 -1 -90 -66 -38 -50 89 -17 -53 -6 -13 -41 -54 -1 -23 -31 -88 -59 -44 -67 -11 -83 -16 -23 -71",
"output": "43\n1 2 2 2 2 4 2 2 3 3 2 2 2 2 5 2 2 2 3 3 2 3 2 3 2 3 4 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n-1 -65 76 -28 -58 -63 -86 -54 -62 -66 -39 -3 -62 -35 -2 -86 -6 -16 -85 -30 -6 -41 -88 38 -8 -78 -6 -73 -83 -12 40 -99 -78 -51 -97 -15 81 -76 -1 -78 -38 -14 -24 -2 -70 -80 -24 -28 -51 -50 61 -64 -81 -32 -59 -60 -58 -10 -24 -81 -42 -7 58 -23 -11 -14 -84 -27 -45 2 -31 -32 -20 -72 -2 -81 -31 -6 -8 -91 55 -76 -93 -65 -94 -8 -57 -20 -75 -20 -27 -37 -82 97 -37 -8 -16 49 -90 -3",
"output": "45\n2 3 2 2 2 2 2 2 2 2 2 3 2 2 3 2 3 2 2 2 2 2 2 3 2 2 2 2 3 2 2 3 2 2 2 2 3 2 2 2 2 2 3 2 3 "
},
{
"input": "100\n-75 -29 -14 -2 99 -94 -75 82 -17 -19 -61 -18 -14 -94 -17 16 -16 -4 -41 -8 -81 -26 -65 24 -7 -87 -85 -22 -74 -21 46 -31 -39 -82 -88 -20 -2 -13 -46 -1 -78 -66 -83 -50 -13 -15 -60 -56 36 -79 -99 -52 -96 -80 -97 -74 80 -90 -52 -33 -1 -78 73 -45 -3 -77 62 -4 -85 -44 -62 -74 -33 -35 -44 -14 -80 -20 -17 -83 -32 -40 -74 -13 -90 -62 -15 -16 -59 -15 -40 -50 -98 -33 -73 -25 -86 -35 -84 -41",
"output": "46\n1 2 3 3 2 2 2 3 2 2 3 2 2 3 2 2 2 2 2 2 2 2 3 2 2 3 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n-43 -90 -65 -70 -7 -49 -90 -93 -43 -80 -2 -47 -13 -5 -70 -42 -71 -68 -60 -71 -27 -84 82 -74 -75 -65 -32 -32 -50 -74 62 -96 -85 -95 -65 -51 -69 49 3 -19 -92 -61 -33 -7 -70 -51 -3 -1 -48 -48 -64 -7 -4 -46 -11 -36 -80 -69 -67 -1 -39 -40 66 -9 -40 -8 -58 -74 -27 66 -52 -26 -62 -72 -48 -25 -41 -13 -65 -82 -50 -68 -94 -52 -77 -91 -37 -18 -8 -51 -19 -22 -52 -95 35 -32 59 -41 -54 -88",
"output": "46\n2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 4 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 2 2 4 2 "
},
{
"input": "100\n-67 -100 -7 -13 -9 -78 -55 -68 -31 -18 -92 -23 -4 -99 -54 -97 -45 -24 -33 -95 -42 -20 -63 -24 -89 -25 -55 -35 -84 -30 -1 57 -88 -94 -67 -27 -91 -14 -13 -20 -7 -8 -33 -95 -1 -75 -80 -49 -15 -64 -73 -49 -87 -19 -44 -50 -19 -10 -90 -51 -74 90 -42 -18 -93 -99 -43 51 -96 95 -97 -36 -21 -13 -73 -37 -33 -22 -83 -33 -44 -84 -20 -78 -34 -70 -83 -83 -85 -17 -36 62 83 -73 -6 51 -77 -82 -83 -68",
"output": "47\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 4 2 2 2 2 2 2 2 2 2 2 4 3 2 "
},
{
"input": "100\n-30 -40 -64 -50 -13 -69 -87 -54 -7 -32 -38 30 -79 -31 57 -50 -3 -6 -13 -94 -28 -57 -95 -67 -82 -49 -83 -39 -41 -12 -73 -20 -17 -46 -92 -31 -36 -31 -80 -47 -37 -67 -41 -65 -7 -95 -85 -53 -87 -18 -52 -61 -98 -85 -6 -80 -96 -95 -72 -9 -19 -49 74 84 -60 -69 -64 -39 -82 -28 -24 -82 -13 -7 -15 -28 -26 -48 -88 -9 -36 -38 -75 -1 9 -15 -12 -47 -11 -45 -3 -10 -60 -62 -54 -60 45 -8 -43 -89",
"output": "47\n2 2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 3 2 2 2 2 3 2 "
},
{
"input": "100\n-78 -77 -84 -29 -99 -15 -60 97 -56 -9 -19 -21 -5 -29 -20 -41 -56 -15 -77 -22 -87 -75 -56 -96 -46 -24 -35 -64 63 -5 -16 -27 34 -77 84 -30 -9 -73 -58 -93 -20 -20 -69 -16 -42 -40 -44 -66 -42 -90 -47 -35 -87 -55 -37 -48 -34 -3 -40 -3 -46 -25 -80 -55 -12 -62 -46 -99 -38 -33 -72 -60 -18 -12 -52 -3 -75 -5 -48 -30 -59 -56 99 -52 -59 -72 -41 -15 -19 -19 -26 -28 -16 -23 -46 -93 -92 -38 -12 -75",
"output": "48\n1 2 2 2 3 2 2 2 2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n22 -83 -95 -61 -100 -53 -50 -19 -24 -85 -45 -43 -3 -74 -6 -24 -78 -54 -58 -52 -42 -16 -18 -56 -93 -45 -97 -67 -88 -27 83 -7 -72 -85 -24 -45 -22 -82 -83 -94 -75 -79 -22 -44 -22 -44 -42 -44 -61 85 -11 -16 -91 -12 -15 -3 -15 -82 -1 -2 -28 -24 -68 -22 -25 -46 -40 -21 -67 -90 -31 -33 -54 -83 -91 -74 -56 -67 -87 -36 -8 -100 -76 -88 -90 -45 -64 -25 -55 -15 -84 -67 -57 -73 -78 86 -28 -41 -63 -57",
"output": "48\n3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 "
},
{
"input": "100\n-13 -43 -95 -61 -62 -94 -97 -48 -16 -88 -96 -74 -26 -58 -79 -44 -72 -22 -18 -66 -8 85 -98 -3 -36 -17 -80 -82 -77 -41 -24 -86 -62 -1 -22 -29 -30 -18 -25 -90 -66 -58 -86 -81 -34 -76 -67 -72 -77 -29 -66 -67 -34 3 -16 -90 -9 -14 -28 -60 -26 -99 75 -74 -94 -55 -54 -23 -30 -34 -4 -92 -88 -46 -52 -63 -98 -6 -89 -99 -80 -100 -97 -62 -70 -97 -75 -85 -22 -2 -32 -47 -85 -44 -23 -4 -21 -30 -6 -34",
"output": "49\n1 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n-5 -37 -22 -85 -63 -46 -44 -43 -23 -77 -75 -64 -84 -46 -78 -94 -67 -19 -5 -59 -32 -92 -10 -92 -58 -73 -72 -16 99 -58 -94 -49 -60 -3 -60 -74 -12 -8 -32 -94 -63 -53 -24 -29 -6 -46 -30 -32 -87 -41 -58 -70 -53 -20 -73 -42 -54 -5 -84 -45 -11 -9 -84 -7 -68 -100 -11 -2 -87 -27 -65 -45 -17 -33 -88 -55 90 -58 -89 -13 -66 -1 -46 -90 -69 -74 -84 -90 -50 -32 -62 -37 -44 -51 -25 -94 -73 -43 -1 -44",
"output": "49\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 "
},
{
"input": "100\n-76 -48 -63 -62 -94 -37 -54 -67 -9 -52 -83 -1 -87 -36 -94 -10 -19 -55 -93 -23 -2 -87 -15 -59 -60 -87 -63 -18 -62 -92 -10 -61 -12 -89 -85 -38 -37 -3 -71 -22 -94 -96 -100 -47 -20 -93 -28 77 -35 -74 -50 -72 -38 -29 -58 -80 -24 -9 -59 -4 -93 -65 -31 -47 -36 -13 -89 -96 -99 -83 -99 -36 -45 -58 -22 -93 -51 -26 -93 -36 -85 -72 -49 -27 -69 -29 -51 -84 -35 -26 -41 -43 -45 -87 -65 -100 -45 -69 -69 -73",
"output": "50\n1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 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\n-77 -6 -71 -86 -42 -1 -40 -41 -31 -67 -75 -49 -62 -21 -2 -40 -2 -82 -90 -42 -43 -14 -72 -50 -33 -37 -58 -51 -67 -96 -63 -39 -56 -22 -17 -69 -88 -60 -18 -47 -16 -41 -32 -59 -82 -48 -22 -46 -29 -69 -21 -2 -41 -52 -83 -3 -49 -39 -31 -78 -60 -100 -12 -64 -28 -72 -43 -68 -60 -98 -21 -29 -72 -82 -5 -4 -65 -76 -60 -40 -37 -17 -77 -21 -19 -98 -39 -67 -49 -75 -7 -45 -11 -13 -45 -19 -83 -38 -14 -89",
"output": "50\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 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": "4\n1 2 3 4",
"output": "1\n4 "
},
{
"input": "4\n1 2 3 -4",
"output": "1\n4 "
},
{
"input": "4\n-4 2 1 2",
"output": "1\n4 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n2 -1",
"output": "1\n2 "
},
{
"input": "2\n-100 100",
"output": "1\n2 "
},
{
"input": "3\n-100 0 -100",
"output": "1\n3 "
},
{
"input": "5\n1 2 3 -1 -1",
"output": "1\n5 "
},
{
"input": "5\n-1 -1 2 3 4",
"output": "1\n5 "
},
{
"input": "3\n-3 -4 -5",
"output": "2\n1 2 "
},
{
"input": "4\n-3 -4 1 -3",
"output": "2\n1 3 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n-1 0",
"output": "1\n2 "
},
{
"input": "4\n0 0 0 0",
"output": "1\n4 "
},
{
"input": "3\n-1 -1 -1",
"output": "2\n1 2 "
},
{
"input": "6\n-1 -1 0 -1 -1 -1",
"output": "3\n1 3 2 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"input": "6\n0 0 -1 -1 -1 0",
"output": "2\n3 3 "
}
] | 1,695,897,339
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 2
| 92
| 0
|
n=int(input())
a=list(map(int,input().split()))[:n]
y=0
b=0
x=0
for j in range(n):
if a[j]<0:
b+=1
if b%2==0:
print(int(b/2))
else:
print(int((b+1)/2))
for i in range(n):
if a[i]<0:
y+=1
x+=1
else:
x+=1
if y==3:
print(x-1,end=" ")
y=1
x=1
if y!=1:
print(x)
|
Title: Paper Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. If *a**i* is negative, then the company suffered losses on the *i*-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the *n* days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (*a**i*<=<<=0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence *a**i*, will print the minimum number of folders.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*.
Output Specification:
Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them.
Demo Input:
['11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n', '5\n0 -1 100 -1 0\n']
Demo Output:
['3\n5 3 3 ', '1\n5 ']
Note:
Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder.
|
```python
n=int(input())
a=list(map(int,input().split()))[:n]
y=0
b=0
x=0
for j in range(n):
if a[j]<0:
b+=1
if b%2==0:
print(int(b/2))
else:
print(int((b+1)/2))
for i in range(n):
if a[i]<0:
y+=1
x+=1
else:
x+=1
if y==3:
print(x-1,end=" ")
y=1
x=1
if y!=1:
print(x)
```
| 0
|
|
447
|
B
|
DZY Loves Strings
|
PROGRAMMING
| 1,000
|
[
"greedy",
"implementation"
] | null | null |
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
|
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
|
Print a single integer — the largest possible value of the resulting string DZY could get.
|
[
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] |
[
"41\n"
] |
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
| 1,000
|
[
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314",
"output": "1762894"
},
{
"input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585",
"output": "2960349"
},
{
"input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933",
"output": "99140444"
},
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686",
"output": "301124161"
},
{
"input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495",
"output": "30125295"
},
{
"input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165",
"output": "136422"
},
{
"input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348",
"output": "2578628"
},
{
"input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338",
"output": "9168707"
},
{
"input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657",
"output": "144901921"
},
{
"input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860",
"output": "809931"
},
{
"input": "a\n0\n5 1 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": "5"
},
{
"input": "lol\n3\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",
"output": "21"
}
] | 1,645,714,213
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 24
| 31
| 0
|
def DZY_loves_strings():
s = input()
k = int(input())
w = []
h = 0
for i in input().split():
w.append(int(i))
h = max(h, int(i))
lex = "abcdefghijklmnopqrstuvwxyz"
v = 0
for i, c in enumerate(s):
v += w[lex.index(c)] * (i + 1)
a = h * (len(s) + 1)
v += a * k + (h * (k ** 2 - k)) / 2
print(int(v))
if __name__ == "__main__":
DZY_loves_strings()
pass
|
Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input Specification:
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Output Specification:
Print a single integer — the largest possible value of the resulting string DZY could get.
Demo Input:
['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n']
Demo Output:
['41\n']
Note:
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
|
```python
def DZY_loves_strings():
s = input()
k = int(input())
w = []
h = 0
for i in input().split():
w.append(int(i))
h = max(h, int(i))
lex = "abcdefghijklmnopqrstuvwxyz"
v = 0
for i, c in enumerate(s):
v += w[lex.index(c)] * (i + 1)
a = h * (len(s) + 1)
v += a * k + (h * (k ** 2 - k)) / 2
print(int(v))
if __name__ == "__main__":
DZY_loves_strings()
pass
```
| 3
|
|
96
|
A
|
Football
|
PROGRAMMING
| 900
|
[
"implementation",
"strings"
] |
A. Football
|
2
|
256
|
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
|
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
|
Print "YES" if the situation is dangerous. Otherwise, print "NO".
|
[
"001001\n",
"1000000001\n"
] |
[
"NO\n",
"YES\n"
] |
none
| 500
|
[
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,676,367,353
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 44
| 92
| 0
|
s=input()
a,b=0,0
for i in range(len(s)):
if s[i]=='1':
a+=1
b=0
if a>6:
print('YES')
break
elif s[i]=='0':
b+=1
a=0
if b>6:
print('YES')
break
else:
print('NO')
|
Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none
|
```python
s=input()
a,b=0,0
for i in range(len(s)):
if s[i]=='1':
a+=1
b=0
if a>6:
print('YES')
break
elif s[i]=='0':
b+=1
a=0
if b>6:
print('YES')
break
else:
print('NO')
```
| 3.977
|
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,626,704,104
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 124
| 6,963,200
|
if __name__ == '__main__':
r1,r2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
m1 = min(r1,d1,c1)
m2 = min(c2,d2)
f = False
i1,i2,i3,i4 = -1,-1,-1,-1
for i in range(1,m1):
for j in range(1,m2):
if i+j == r1:
cl1 = c1-i
cl2 = c2-j
if cl1+cl2 == r2 and j+cl1 == d2 and i+cl2 == d1 and i != j != cl1 != cl2:
f = True
i1 = i
i2 = j
i3 = cl1
i4 = cl2
break
else:
continue
if f:
break
if f:
print(i1,i2)
print(i3,i4)
else:
print(-1)
|
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
if __name__ == '__main__':
r1,r2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
m1 = min(r1,d1,c1)
m2 = min(c2,d2)
f = False
i1,i2,i3,i4 = -1,-1,-1,-1
for i in range(1,m1):
for j in range(1,m2):
if i+j == r1:
cl1 = c1-i
cl2 = c2-j
if cl1+cl2 == r2 and j+cl1 == d2 and i+cl2 == d1 and i != j != cl1 != cl2:
f = True
i1 = i
i2 = j
i3 = cl1
i4 = cl2
break
else:
continue
if f:
break
if f:
print(i1,i2)
print(i3,i4)
else:
print(-1)
```
| 0
|
|
552
|
B
|
Vanya and Books
|
PROGRAMMING
| 1,200
|
[
"implementation",
"math"
] | null | null |
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
|
Print the number of digits needed to number all the books.
|
[
"13\n",
"4\n"
] |
[
"17\n",
"4\n"
] |
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
| 1,000
|
[
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,588,437,270
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 55
| 155
| 0
|
"""
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
number = str(input())
digits = len(number)
number = int(number)
res = 0
curr_digit = 1
count = 1
while curr_digit <= digits:
high = '9' * curr_digit
lower = '1' + ('0' * (curr_digit - 1))
if number > int(high):
res += (int(high) - int(lower) + 1) * curr_digit
else:
res += (number - int(lower) + 1) * curr_digit
curr_digit += 1
print(res)
|
Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
|
```python
"""
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
number = str(input())
digits = len(number)
number = int(number)
res = 0
curr_digit = 1
count = 1
while curr_digit <= digits:
high = '9' * curr_digit
lower = '1' + ('0' * (curr_digit - 1))
if number > int(high):
res += (int(high) - int(lower) + 1) * curr_digit
else:
res += (number - int(lower) + 1) * curr_digit
curr_digit += 1
print(res)
```
| 3
|
|
779
|
C
|
Dishonest Sellers
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"greedy",
"sortings"
] | null | null |
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items.
|
In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week).
|
Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now.
|
[
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] |
[
"10\n",
"25\n"
] |
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
| 1,000
|
[
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
{
"input": "5 3\n28 17 20 45 45\n39 12 41 27 9",
"output": "101"
},
{
"input": "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31",
"output": "243"
},
{
"input": "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 166 114 53 144 106 141 106 191 123 44 199 35 18 84 169 46 52 129 102 155 130 63 169 116 145 154 41\n155 187 79 106 136 173 17 146 9 47 173 21 37 183 110 74 185 14 82 156 147 25 162 195 26 25 22 80 171 180 7 92 53 18 100 17 159 184 37 127 116 192 163 49 94 95 118 102 8 30",
"output": "4680"
},
{
"input": "5 2\n1 1 1 1 1\n2 2 2 2 2",
"output": "5"
},
{
"input": "5 2\n2 4 4 4 4\n3 1 1 1 1",
"output": "9"
},
{
"input": "6 3\n9 9 9 2 2 2\n6 6 6 1 1 1",
"output": "24"
},
{
"input": "5 3\n10 17 23 26 35\n7 18 18 29 32",
"output": "103"
},
{
"input": "2 1\n10 12\n5 6",
"output": "16"
}
] | 1,678,118,764
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
n, k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lst = []*n
for i in range(n):
lst.append((b[i],a[i],b[i]-a[i]))
lst.sort(reverse=True, key=lambda x: x[2])
print(lst)
cost = 0
for i in range(k):
cost += lst[i][1]
for j in range(k, n):
cost += lst[j][0]
print(cost)
|
Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items.
Input Specification:
In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week).
Output Specification:
Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now.
Demo Input:
['3 1\n5 4 6\n3 1 5\n', '5 3\n3 4 7 10 3\n4 5 5 12 5\n']
Demo Output:
['10\n', '25\n']
Note:
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.
|
```python
n, k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
lst = []*n
for i in range(n):
lst.append((b[i],a[i],b[i]-a[i]))
lst.sort(reverse=True, key=lambda x: x[2])
print(lst)
cost = 0
for i in range(k):
cost += lst[i][1]
for j in range(k, n):
cost += lst[j][0]
print(cost)
```
| 0
|
|
587
|
A
|
Duff and Weight Lifting
|
PROGRAMMING
| 1,500
|
[
"greedy"
] | null | null |
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
|
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
|
Print the minimum number of steps in a single line.
|
[
"5\n1 1 2 3 3\n",
"4\n0 1 2 3\n"
] |
[
"2\n",
"4\n"
] |
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
| 500
|
[
{
"input": "5\n1 1 2 3 3",
"output": "2"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "1\n120287",
"output": "1"
},
{
"input": "2\n28288 0",
"output": "2"
},
{
"input": "2\n95745 95745",
"output": "1"
},
{
"input": "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599",
"output": "11"
},
{
"input": "13\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743",
"output": "4"
},
{
"input": "35\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",
"output": "3"
},
{
"input": "35\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4",
"output": "31"
},
{
"input": "35\n0 0 298 0 0 0 0 0 689063 65442 0 984598 2054 43668 0 369 0 2054 0 996220 0 16327 369 0 996220 0 0 0 4693 2054 348 0 118 0 0",
"output": "16"
},
{
"input": "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 10 75252 93 7302 0 81 408441 19579 10 39 19 37748 4364 31135 47700 105818 47700 10 4142 543356 3 30647 45917 60714 8939 18 22925 7302 93 75252",
"output": "59"
}
] | 1,651,394,086
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 35
| 748
| 89,190,400
|
n=int(input())
a=[int(i) for i in input().split()]
res=0
bit=[0]*(10**6+1)
for i in a:bit[i]+=1
for i in range(10**6):
bit[i+1]+=bit[i]//2
if bit[i]&1:res+=1
print(res)
|
Title: Duff and Weight Lifting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
Output Specification:
Print the minimum number of steps in a single line.
Demo Input:
['5\n1 1 2 3 3\n', '4\n0 1 2 3\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
|
```python
n=int(input())
a=[int(i) for i in input().split()]
res=0
bit=[0]*(10**6+1)
for i in a:bit[i]+=1
for i in range(10**6):
bit[i+1]+=bit[i]//2
if bit[i]&1:res+=1
print(res)
```
| 0
|
|
282
|
A
|
Bit++
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
|
Print a single integer — the final value of *x*.
|
[
"1\n++X\n",
"2\nX++\n--X\n"
] |
[
"1\n",
"0\n"
] |
none
| 500
|
[
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++",
"output": "4"
},
{
"input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++",
"output": "-10"
},
{
"input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X",
"output": "-14"
},
{
"input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X",
"output": "3"
},
{
"input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X",
"output": "-5"
},
{
"input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X",
"output": "1"
},
{
"input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--",
"output": "1"
},
{
"input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++",
"output": "-3"
},
{
"input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X",
"output": "1"
},
{
"input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++",
"output": "8"
},
{
"input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++",
"output": "-1"
},
{
"input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--",
"output": "-5"
},
{
"input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--",
"output": "1"
},
{
"input": "1\nX--",
"output": "-1"
}
] | 1,698,993,274
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 36
| 46
| 0
|
x=0
for i in range(int(input())):
if '+' in input():
x+=1
else:
x-=1
print(x)
|
Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Output Specification:
Print a single integer — the final value of *x*.
Demo Input:
['1\n++X\n', '2\nX++\n--X\n']
Demo Output:
['1\n', '0\n']
Note:
none
|
```python
x=0
for i in range(int(input())):
if '+' in input():
x+=1
else:
x-=1
print(x)
```
| 3
|
|
266
|
B
|
Queue at the School
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null |
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
|
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
|
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
|
[
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] |
[
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] |
none
| 500
|
[
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"output": "GBBGBB"
},
{
"input": "8 3\nBBGBGBGB",
"output": "GGBGBBBB"
},
{
"input": "10 3\nBBGBBBBBBG",
"output": "GBBBBBGBBB"
},
{
"input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB",
"output": "GGGGGGGGBGGBGGBBBBBBBB"
},
{
"input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG",
"output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB"
},
{
"input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG",
"output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB"
},
{
"input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB",
"output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB"
},
{
"input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB",
"output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB"
},
{
"input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB",
"output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB"
},
{
"input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 1\nB",
"output": "B"
},
{
"input": "1 1\nG",
"output": "G"
},
{
"input": "1 50\nB",
"output": "B"
},
{
"input": "1 50\nG",
"output": "G"
},
{
"input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB",
"output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB"
},
{
"input": "6 3\nGGBBBG",
"output": "GGGBBB"
},
{
"input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG",
"output": "GGBBBBGBGBGBGGGBGBGGGBGBBB"
},
{
"input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB",
"output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB"
},
{
"input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB",
"output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB",
"output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB"
},
{
"input": "17 42\nBBGBGBGGGGGGBBGGG",
"output": "GGGGGGGGGGGBBBBBB"
},
{
"input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG",
"output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB"
},
{
"input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB",
"output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB"
},
{
"input": "2 2\nBG",
"output": "GB"
},
{
"input": "8 8\nGGGBGGBB",
"output": "GGGGGBBB"
},
{
"input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB",
"output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB"
},
{
"input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG",
"output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG",
"output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 10\nGGGGGGGGGG",
"output": "GGGGGGGGGG"
},
{
"input": "10 10\nBBBBBBBBBB",
"output": "BBBBBBBBBB"
},
{
"input": "10 10\nBGBGBGBGBG",
"output": "GGGGGBBBBB"
},
{
"input": "1 1\nB",
"output": "B"
}
] | 1,698,651,502
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 62
| 0
|
n=int(input())
p=input()
for i in range(n):
p=p.replace('BG','GB')
print(p)
|
Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Output Specification:
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
Demo Input:
['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n']
Demo Output:
['GBGGB\n', 'GGBGB\n', 'GGGB\n']
Note:
none
|
```python
n=int(input())
p=input()
for i in range(n):
p=p.replace('BG','GB')
print(p)
```
| -1
|
|
276
|
B
|
Little Girl and Game
|
PROGRAMMING
| 1,300
|
[
"games",
"greedy"
] | null | null |
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
|
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
|
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
|
[
"aba\n",
"abca\n"
] |
[
"First\n",
"Second\n"
] |
none
| 1,000
|
[
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo",
"output": "First"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz",
"output": "Second"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt",
"output": "First"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz",
"output": "First"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq",
"output": "Second"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg",
"output": "First"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj",
"output": "Second"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm",
"output": "First"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd",
"output": "First"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh",
"output": "First"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm",
"output": "Second"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq",
"output": "First"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk",
"output": "First"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq",
"output": "Second"
},
{
"input": "a",
"output": "First"
},
{
"input": "ab",
"output": "Second"
},
{
"input": "abacaba",
"output": "First"
},
{
"input": "abazaba",
"output": "First"
},
{
"input": "zz",
"output": "First"
},
{
"input": "aassddxyz",
"output": "First"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "Second"
},
{
"input": "aabc",
"output": "Second"
},
{
"input": "abcabc",
"output": "First"
},
{
"input": "aaabbbccdd",
"output": "Second"
},
{
"input": "aabbcccc",
"output": "First"
}
] | 1,690,199,692
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
# -*- coding: utf-8 -*-
"""contest
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1vkqd1IDYYeIi4VIH6yqQEhbS4qcGMzLO
"""
word = input()
turn = 0
while True:
first = sorted(word[:len(word) // 2])
first = "".join(first)
if len(word) % 2 == 0:
second = sorted(word[len(first):])
else:
second = sorted(word[len(first) + 1 :])
second = "".join(second)
print(first , second)
print(turn)
if first == second:
if turn % 2 == 0:
print("First")
break
else:
print("Second")
break
else:
word = word[1:]
turn += 1
x = 'abcdefghijklkjihgfedcba'
x = 'abcdefghiihgfedcba'
y = ''
for i in range(len(x) - 1 , -1 , -1):
y += x[i]
if x == y:
print(True)
else:
print(False)
|
Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input Specification:
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
Output Specification:
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Demo Input:
['aba\n', 'abca\n']
Demo Output:
['First\n', 'Second\n']
Note:
none
|
```python
# -*- coding: utf-8 -*-
"""contest
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1vkqd1IDYYeIi4VIH6yqQEhbS4qcGMzLO
"""
word = input()
turn = 0
while True:
first = sorted(word[:len(word) // 2])
first = "".join(first)
if len(word) % 2 == 0:
second = sorted(word[len(first):])
else:
second = sorted(word[len(first) + 1 :])
second = "".join(second)
print(first , second)
print(turn)
if first == second:
if turn % 2 == 0:
print("First")
break
else:
print("Second")
break
else:
word = word[1:]
turn += 1
x = 'abcdefghijklkjihgfedcba'
x = 'abcdefghiihgfedcba'
y = ''
for i in range(len(x) - 1 , -1 , -1):
y += x[i]
if x == y:
print(True)
else:
print(False)
```
| 0
|
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.