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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,611,649,769
| 2,147,483,647
|
PyPy 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <iostream>
using namespace std;
int op(int a, int b){
for (int j=0;j<10;j++){
if ( (a*10+j) % b == 0 )
return a*10+j;
}
return -1;
}
int main(){
int a,b,n;
cin >> a >> b >> n;
for (int i=0;i<n;i++){
if (op(a,b) == -1){
cout << -1;
return 0;
}
else a = op(a,b);
}
cout << a;
return 0;
}
|
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
#include <iostream>
using namespace std;
int op(int a, int b){
for (int j=0;j<10;j++){
if ( (a*10+j) % b == 0 )
return a*10+j;
}
return -1;
}
int main(){
int a,b,n;
cin >> a >> b >> n;
for (int i=0;i<n;i++){
if (op(a,b) == -1){
cout << -1;
return 0;
}
else a = op(a,b);
}
cout << a;
return 0;
}
```
| -1
|
|
459
|
B
|
Pashmak and Flowers
|
PROGRAMMING
| 1,300
|
[
"combinatorics",
"implementation",
"sortings"
] | null | null |
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
|
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
|
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
|
[
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] |
[
"1 1",
"4 1",
"2 4"
] |
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
| 500
|
[
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 6"
},
{
"input": "5\n1 1 1 1 1",
"output": "0 10"
},
{
"input": "5\n2 2 2 2 2",
"output": "0 10"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0 45"
},
{
"input": "3\n2 2 2",
"output": "0 3"
},
{
"input": "3\n3 3 3",
"output": "0 3"
},
{
"input": "2\n10000000 100000000",
"output": "90000000 1"
},
{
"input": "5\n5 5 5 5 5",
"output": "0 10"
},
{
"input": "5\n3 3 3 3 3",
"output": "0 10"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0 15"
},
{
"input": "2\n5 6",
"output": "1 1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0 45"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "0 45"
},
{
"input": "4\n4 4 4 4",
"output": "0 6"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0 21"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "0 55"
},
{
"input": "8\n8 8 8 8 8 8 8 8",
"output": "0 28"
},
{
"input": "2\n3 2",
"output": "1 1"
}
] | 1,697,478,609
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
int(input())
nums = [int(i) for i in input().split()]
_max = max(nums) - min(nums)
count = 0
for i in nums:
for j in nums:
diff = abs(i - j)
if diff == _max:
count += 1
print(_max, count / 2)
|
Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
Input Specification:
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
Output Specification:
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Demo Input:
['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n']
Demo Output:
['1 1', '4 1', '2 4']
Note:
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
|
```python
int(input())
nums = [int(i) for i in input().split()]
_max = max(nums) - min(nums)
count = 0
for i in nums:
for j in nums:
diff = abs(i - j)
if diff == _max:
count += 1
print(_max, count / 2)
```
| 0
|
|
334
|
A
|
Candy Bags
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
|
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
|
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
|
[
"2\n"
] |
[
"1 4\n2 3\n"
] |
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
| 500
|
[
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33"
},
{
"input": "10",
"output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51"
},
{
"input": "100",
"output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951\n51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 993..."
},
{
"input": "62",
"output": "1 3844 2 3843 3 3842 4 3841 5 3840 6 3839 7 3838 8 3837 9 3836 10 3835 11 3834 12 3833 13 3832 14 3831 15 3830 16 3829 17 3828 18 3827 19 3826 20 3825 21 3824 22 3823 23 3822 24 3821 25 3820 26 3819 27 3818 28 3817 29 3816 30 3815 31 3814\n32 3813 33 3812 34 3811 35 3810 36 3809 37 3808 38 3807 39 3806 40 3805 41 3804 42 3803 43 3802 44 3801 45 3800 46 3799 47 3798 48 3797 49 3796 50 3795 51 3794 52 3793 53 3792 54 3791 55 3790 56 3789 57 3788 58 3787 59 3786 60 3785 61 3784 62 3783\n63 3782 64 3781 65 378..."
},
{
"input": "66",
"output": "1 4356 2 4355 3 4354 4 4353 5 4352 6 4351 7 4350 8 4349 9 4348 10 4347 11 4346 12 4345 13 4344 14 4343 15 4342 16 4341 17 4340 18 4339 19 4338 20 4337 21 4336 22 4335 23 4334 24 4333 25 4332 26 4331 27 4330 28 4329 29 4328 30 4327 31 4326 32 4325 33 4324\n34 4323 35 4322 36 4321 37 4320 38 4319 39 4318 40 4317 41 4316 42 4315 43 4314 44 4313 45 4312 46 4311 47 4310 48 4309 49 4308 50 4307 51 4306 52 4305 53 4304 54 4303 55 4302 56 4301 57 4300 58 4299 59 4298 60 4297 61 4296 62 4295 63 4294 64 4293 65 4292..."
},
{
"input": "18",
"output": "1 324 2 323 3 322 4 321 5 320 6 319 7 318 8 317 9 316\n10 315 11 314 12 313 13 312 14 311 15 310 16 309 17 308 18 307\n19 306 20 305 21 304 22 303 23 302 24 301 25 300 26 299 27 298\n28 297 29 296 30 295 31 294 32 293 33 292 34 291 35 290 36 289\n37 288 38 287 39 286 40 285 41 284 42 283 43 282 44 281 45 280\n46 279 47 278 48 277 49 276 50 275 51 274 52 273 53 272 54 271\n55 270 56 269 57 268 58 267 59 266 60 265 61 264 62 263 63 262\n64 261 65 260 66 259 67 258 68 257 69 256 70 255 71 254 72 253\n73 252 7..."
},
{
"input": "68",
"output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 4612 14 4611 15 4610 16 4609 17 4608 18 4607 19 4606 20 4605 21 4604 22 4603 23 4602 24 4601 25 4600 26 4599 27 4598 28 4597 29 4596 30 4595 31 4594 32 4593 33 4592 34 4591\n35 4590 36 4589 37 4588 38 4587 39 4586 40 4585 41 4584 42 4583 43 4582 44 4581 45 4580 46 4579 47 4578 48 4577 49 4576 50 4575 51 4574 52 4573 53 4572 54 4571 55 4570 56 4569 57 4568 58 4567 59 4566 60 4565 61 4564 62 4563 63 4562 64 4561 65 4560..."
},
{
"input": "86",
"output": "1 7396 2 7395 3 7394 4 7393 5 7392 6 7391 7 7390 8 7389 9 7388 10 7387 11 7386 12 7385 13 7384 14 7383 15 7382 16 7381 17 7380 18 7379 19 7378 20 7377 21 7376 22 7375 23 7374 24 7373 25 7372 26 7371 27 7370 28 7369 29 7368 30 7367 31 7366 32 7365 33 7364 34 7363 35 7362 36 7361 37 7360 38 7359 39 7358 40 7357 41 7356 42 7355 43 7354\n44 7353 45 7352 46 7351 47 7350 48 7349 49 7348 50 7347 51 7346 52 7345 53 7344 54 7343 55 7342 56 7341 57 7340 58 7339 59 7338 60 7337 61 7336 62 7335 63 7334 64 7333 65 7332..."
},
{
"input": "96",
"output": "1 9216 2 9215 3 9214 4 9213 5 9212 6 9211 7 9210 8 9209 9 9208 10 9207 11 9206 12 9205 13 9204 14 9203 15 9202 16 9201 17 9200 18 9199 19 9198 20 9197 21 9196 22 9195 23 9194 24 9193 25 9192 26 9191 27 9190 28 9189 29 9188 30 9187 31 9186 32 9185 33 9184 34 9183 35 9182 36 9181 37 9180 38 9179 39 9178 40 9177 41 9176 42 9175 43 9174 44 9173 45 9172 46 9171 47 9170 48 9169\n49 9168 50 9167 51 9166 52 9165 53 9164 54 9163 55 9162 56 9161 57 9160 58 9159 59 9158 60 9157 61 9156 62 9155 63 9154 64 9153 65 9152..."
},
{
"input": "12",
"output": "1 144 2 143 3 142 4 141 5 140 6 139\n7 138 8 137 9 136 10 135 11 134 12 133\n13 132 14 131 15 130 16 129 17 128 18 127\n19 126 20 125 21 124 22 123 23 122 24 121\n25 120 26 119 27 118 28 117 29 116 30 115\n31 114 32 113 33 112 34 111 35 110 36 109\n37 108 38 107 39 106 40 105 41 104 42 103\n43 102 44 101 45 100 46 99 47 98 48 97\n49 96 50 95 51 94 52 93 53 92 54 91\n55 90 56 89 57 88 58 87 59 86 60 85\n61 84 62 83 63 82 64 81 65 80 66 79\n67 78 68 77 69 76 70 75 71 74 72 73"
},
{
"input": "88",
"output": "1 7744 2 7743 3 7742 4 7741 5 7740 6 7739 7 7738 8 7737 9 7736 10 7735 11 7734 12 7733 13 7732 14 7731 15 7730 16 7729 17 7728 18 7727 19 7726 20 7725 21 7724 22 7723 23 7722 24 7721 25 7720 26 7719 27 7718 28 7717 29 7716 30 7715 31 7714 32 7713 33 7712 34 7711 35 7710 36 7709 37 7708 38 7707 39 7706 40 7705 41 7704 42 7703 43 7702 44 7701\n45 7700 46 7699 47 7698 48 7697 49 7696 50 7695 51 7694 52 7693 53 7692 54 7691 55 7690 56 7689 57 7688 58 7687 59 7686 60 7685 61 7684 62 7683 63 7682 64 7681 65 7680..."
},
{
"input": "28",
"output": "1 784 2 783 3 782 4 781 5 780 6 779 7 778 8 777 9 776 10 775 11 774 12 773 13 772 14 771\n15 770 16 769 17 768 18 767 19 766 20 765 21 764 22 763 23 762 24 761 25 760 26 759 27 758 28 757\n29 756 30 755 31 754 32 753 33 752 34 751 35 750 36 749 37 748 38 747 39 746 40 745 41 744 42 743\n43 742 44 741 45 740 46 739 47 738 48 737 49 736 50 735 51 734 52 733 53 732 54 731 55 730 56 729\n57 728 58 727 59 726 60 725 61 724 62 723 63 722 64 721 65 720 66 719 67 718 68 717 69 716 70 715\n71 714 72 713 73 712 74 7..."
},
{
"input": "80",
"output": "1 6400 2 6399 3 6398 4 6397 5 6396 6 6395 7 6394 8 6393 9 6392 10 6391 11 6390 12 6389 13 6388 14 6387 15 6386 16 6385 17 6384 18 6383 19 6382 20 6381 21 6380 22 6379 23 6378 24 6377 25 6376 26 6375 27 6374 28 6373 29 6372 30 6371 31 6370 32 6369 33 6368 34 6367 35 6366 36 6365 37 6364 38 6363 39 6362 40 6361\n41 6360 42 6359 43 6358 44 6357 45 6356 46 6355 47 6354 48 6353 49 6352 50 6351 51 6350 52 6349 53 6348 54 6347 55 6346 56 6345 57 6344 58 6343 59 6342 60 6341 61 6340 62 6339 63 6338 64 6337 65 6336..."
},
{
"input": "48",
"output": "1 2304 2 2303 3 2302 4 2301 5 2300 6 2299 7 2298 8 2297 9 2296 10 2295 11 2294 12 2293 13 2292 14 2291 15 2290 16 2289 17 2288 18 2287 19 2286 20 2285 21 2284 22 2283 23 2282 24 2281\n25 2280 26 2279 27 2278 28 2277 29 2276 30 2275 31 2274 32 2273 33 2272 34 2271 35 2270 36 2269 37 2268 38 2267 39 2266 40 2265 41 2264 42 2263 43 2262 44 2261 45 2260 46 2259 47 2258 48 2257\n49 2256 50 2255 51 2254 52 2253 53 2252 54 2251 55 2250 56 2249 57 2248 58 2247 59 2246 60 2245 61 2244 62 2243 63 2242 64 2241 65 224..."
},
{
"input": "54",
"output": "1 2916 2 2915 3 2914 4 2913 5 2912 6 2911 7 2910 8 2909 9 2908 10 2907 11 2906 12 2905 13 2904 14 2903 15 2902 16 2901 17 2900 18 2899 19 2898 20 2897 21 2896 22 2895 23 2894 24 2893 25 2892 26 2891 27 2890\n28 2889 29 2888 30 2887 31 2886 32 2885 33 2884 34 2883 35 2882 36 2881 37 2880 38 2879 39 2878 40 2877 41 2876 42 2875 43 2874 44 2873 45 2872 46 2871 47 2870 48 2869 49 2868 50 2867 51 2866 52 2865 53 2864 54 2863\n55 2862 56 2861 57 2860 58 2859 59 2858 60 2857 61 2856 62 2855 63 2854 64 2853 65 285..."
},
{
"input": "58",
"output": "1 3364 2 3363 3 3362 4 3361 5 3360 6 3359 7 3358 8 3357 9 3356 10 3355 11 3354 12 3353 13 3352 14 3351 15 3350 16 3349 17 3348 18 3347 19 3346 20 3345 21 3344 22 3343 23 3342 24 3341 25 3340 26 3339 27 3338 28 3337 29 3336\n30 3335 31 3334 32 3333 33 3332 34 3331 35 3330 36 3329 37 3328 38 3327 39 3326 40 3325 41 3324 42 3323 43 3322 44 3321 45 3320 46 3319 47 3318 48 3317 49 3316 50 3315 51 3314 52 3313 53 3312 54 3311 55 3310 56 3309 57 3308 58 3307\n59 3306 60 3305 61 3304 62 3303 63 3302 64 3301 65 330..."
},
{
"input": "64",
"output": "1 4096 2 4095 3 4094 4 4093 5 4092 6 4091 7 4090 8 4089 9 4088 10 4087 11 4086 12 4085 13 4084 14 4083 15 4082 16 4081 17 4080 18 4079 19 4078 20 4077 21 4076 22 4075 23 4074 24 4073 25 4072 26 4071 27 4070 28 4069 29 4068 30 4067 31 4066 32 4065\n33 4064 34 4063 35 4062 36 4061 37 4060 38 4059 39 4058 40 4057 41 4056 42 4055 43 4054 44 4053 45 4052 46 4051 47 4050 48 4049 49 4048 50 4047 51 4046 52 4045 53 4044 54 4043 55 4042 56 4041 57 4040 58 4039 59 4038 60 4037 61 4036 62 4035 63 4034 64 4033\n65 403..."
},
{
"input": "44",
"output": "1 1936 2 1935 3 1934 4 1933 5 1932 6 1931 7 1930 8 1929 9 1928 10 1927 11 1926 12 1925 13 1924 14 1923 15 1922 16 1921 17 1920 18 1919 19 1918 20 1917 21 1916 22 1915\n23 1914 24 1913 25 1912 26 1911 27 1910 28 1909 29 1908 30 1907 31 1906 32 1905 33 1904 34 1903 35 1902 36 1901 37 1900 38 1899 39 1898 40 1897 41 1896 42 1895 43 1894 44 1893\n45 1892 46 1891 47 1890 48 1889 49 1888 50 1887 51 1886 52 1885 53 1884 54 1883 55 1882 56 1881 57 1880 58 1879 59 1878 60 1877 61 1876 62 1875 63 1874 64 1873 65 187..."
}
] | 1,624,341,140
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 21
| 280
| 3,993,600
|
n = int(input())
n_sqr = n**2
r = range(1, n**2+1)
for i in range(n_sqr//2):
print(r[i], r[n_sqr-1-i])
|
Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each brother so that all brothers got the same number of candies.
Input Specification:
The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers.
Output Specification:
Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Demo Input:
['2\n']
Demo Output:
['1 4\n2 3\n']
Note:
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
|
```python
n = int(input())
n_sqr = n**2
r = range(1, n**2+1)
for i in range(n_sqr//2):
print(r[i], r[n_sqr-1-i])
```
| 3
|
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,668,789,162
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 40
| 62
| 0
|
s = input()
temp = 'hello'
ind = 0
for i in s:
if i == temp[ind]:
ind += 1
if ind == len(temp):
break
if ind == len(temp):
print("YES")
else:
print("NO")
|
Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
s = input()
temp = 'hello'
ind = 0
for i in s:
if i == temp[ind]:
ind += 1
if ind == len(temp):
break
if ind == len(temp):
print("YES")
else:
print("NO")
```
| 3.969
|
766
|
B
|
Mahmoud and a Triangle
|
PROGRAMMING
| 1,000
|
[
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null |
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
|
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
|
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
|
[
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] |
[
"YES\n",
"NO\n"
] |
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
| 1,000
|
[
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},
{
"input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761",
"output": "YES"
},
{
"input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974",
"output": "YES"
},
{
"input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291",
"output": "NO"
},
{
"input": "3\n1 1000000000 1000000000",
"output": "YES"
},
{
"input": "4\n1 1000000000 1000000000 1000000000",
"output": "YES"
},
{
"input": "3\n1 1000000000 1",
"output": "NO"
},
{
"input": "5\n1 2 3 5 2",
"output": "YES"
},
{
"input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431",
"output": "NO"
},
{
"input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159",
"output": "YES"
},
{
"input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023",
"output": "YES"
},
{
"input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015",
"output": "YES"
},
{
"input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14",
"output": "YES"
},
{
"input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368",
"output": "NO"
},
{
"input": "3\n1 1000000000 999999999",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000",
"output": "NO"
},
{
"input": "5\n2 3 4 10 20",
"output": "YES"
},
{
"input": "6\n18 23 40 80 160 161",
"output": "YES"
},
{
"input": "4\n5 6 7 888",
"output": "YES"
},
{
"input": "9\n1 1 2 2 4 5 10 10 20",
"output": "YES"
},
{
"input": "7\n3 150 900 4 500 1500 5",
"output": "YES"
},
{
"input": "3\n2 2 3",
"output": "YES"
},
{
"input": "7\n1 2 100 200 250 1000000 2000000",
"output": "YES"
},
{
"input": "8\n2 3 5 5 5 6 6 13",
"output": "YES"
},
{
"input": "3\n2 3 4",
"output": "YES"
},
{
"input": "6\n1 1 1 4 5 100",
"output": "YES"
},
{
"input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377",
"output": "YES"
},
{
"input": "4\n2 3 4 8",
"output": "YES"
},
{
"input": "3\n5 6 7",
"output": "YES"
},
{
"input": "5\n1 4 5 6 1000000",
"output": "YES"
},
{
"input": "4\n5 6 7 20",
"output": "YES"
},
{
"input": "6\n1 1 1 1 1 65",
"output": "YES"
},
{
"input": "4\n3 4 5 100",
"output": "YES"
},
{
"input": "3\n2 4 5",
"output": "YES"
},
{
"input": "7\n1 1 1 1 1 10 1000",
"output": "YES"
},
{
"input": "4\n1 1 2 3",
"output": "NO"
},
{
"input": "11\n1 2 5 6 7 8 9 17 18 19 100",
"output": "YES"
},
{
"input": "4\n5 16 20 200",
"output": "YES"
},
{
"input": "5\n17 6 3 3 1",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "6\n1 1 1 2 3 5",
"output": "YES"
},
{
"input": "4\n2 4 6 6",
"output": "YES"
},
{
"input": "9\n1 2 4 4 4 4 7 8 20",
"output": "YES"
},
{
"input": "9\n1 1 2 5 5 5 10 10 20",
"output": "YES"
},
{
"input": "7\n3 150 600 4 1700 6000 5",
"output": "YES"
},
{
"input": "5\n5761 20966 27841 28800 29399",
"output": "YES"
},
{
"input": "9\n1 2 3 6 7 10 11 12 24",
"output": "YES"
},
{
"input": "4\n1 2 1 1",
"output": "YES"
},
{
"input": "5\n1 1 2 3 4",
"output": "YES"
}
] | 1,670,704,114
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 187
| 7,987,200
|
import math
from collections import *
def solve():
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
l = 0
for i in range(n-2):
d = (a[i]+a[i+1] + a[i+2]) / 2
if a[i]>d or a[i+1]>d or a[i+2]>d:
l = 1
print("NO")
break
if l == 0:
print("YES")
# t = int(input())
# for _ in range(t):
# solve()
solve()
|
Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
Input Specification:
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
Output Specification:
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
Demo Input:
['5\n1 5 3 2 4\n', '3\n4 1 2\n']
Demo Output:
['YES\n', 'NO\n']
Note:
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.
|
```python
import math
from collections import *
def solve():
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
l = 0
for i in range(n-2):
d = (a[i]+a[i+1] + a[i+2]) / 2
if a[i]>d or a[i+1]>d or a[i+2]>d:
l = 1
print("NO")
break
if l == 0:
print("YES")
# t = int(input())
# for _ in range(t):
# solve()
solve()
```
| 0
|
|
258
|
A
|
Little Elephant and Bits
|
PROGRAMMING
| 1,100
|
[
"greedy",
"math"
] | null | null |
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
|
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
|
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
|
[
"101\n",
"110010\n"
] |
[
"11\n",
"11010\n"
] |
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
| 500
|
[
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "111010010111",
"output": "11110010111"
},
{
"input": "11110111011100000000",
"output": "1111111011100000000"
},
{
"input": "11110010010100001110110101110011110110100111101",
"output": "1111010010100001110110101110011110110100111101"
},
{
"input": "1001011111010010100111111",
"output": "101011111010010100111111"
},
{
"input": "1111111111",
"output": "111111111"
},
{
"input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101",
"output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101"
},
{
"input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100",
"output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100"
},
{
"input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011",
"output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011"
},
{
"input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011",
"output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011"
},
{
"input": "11",
"output": "1"
},
{
"input": "111",
"output": "11"
},
{
"input": "111111",
"output": "11111"
},
{
"input": "11111",
"output": "1111"
},
{
"input": "1111",
"output": "111"
}
] | 1,670,267,323
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 37
| 124
| 0
|
s = input()
if '0' in s:
e = s.split('0',1)
if len(e) == 1:
print(e[0])
else:
print(e[0]+e[1])
else:
print(s[1:])
|
Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
Input Specification:
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
Output Specification:
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
Demo Input:
['101\n', '110010\n']
Demo Output:
['11\n', '11010\n']
Note:
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
|
```python
s = input()
if '0' in s:
e = s.split('0',1)
if len(e) == 1:
print(e[0])
else:
print(e[0]+e[1])
else:
print(s[1:])
```
| 3
|
|
427
|
A
|
Police Recruits
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
|
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
|
Print a single integer, the number of crimes which will go untreated.
|
[
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] |
[
"2\n",
"1\n",
"8\n"
] |
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
| 500
|
[
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "13"
},
{
"input": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,681,128,238
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 30
| 0
|
z = input()
a = input()
b = a.split(" ")
police = 0
tally = 0
for ins in b:
ins = int(ins)
if ins < 0:
if police == 0:
tally += ins
continue
if police > 0:
police -= ins
continue
if ins > 0:
police += ins
if tally < 0:
print(tally*-1)
else:
print(tally)
|
Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
|
```python
z = input()
a = input()
b = a.split(" ")
police = 0
tally = 0
for ins in b:
ins = int(ins)
if ins < 0:
if police == 0:
tally += ins
continue
if police > 0:
police -= ins
continue
if ins > 0:
police += ins
if tally < 0:
print(tally*-1)
else:
print(tally)
```
| 0
|
|
937
|
A
|
Olympiad
|
PROGRAMMING
| 800
|
[
"implementation",
"sortings"
] | null | null |
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score.
|
Print a single integer — the desired number of ways.
|
[
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] |
[
"3\n",
"1\n",
"1\n"
] |
There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything.
| 500
|
[
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
"input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600",
"output": "94"
},
{
"input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600",
"output": "1"
},
{
"input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12",
"output": "13"
},
{
"input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391",
"output": "33"
},
{
"input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3",
"output": "3"
},
{
"input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55",
"output": "93"
},
{
"input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13",
"output": "13"
},
{
"input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1",
"output": "1"
},
{
"input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37",
"output": "61"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 600",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "2"
},
{
"input": "4\n0 0 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "2\n0 5",
"output": "1"
},
{
"input": "5\n1 0 0 1 2",
"output": "2"
}
] | 1,575,397,740
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 21
| 124
| 0
|
n=int(input())
l=list(map(int,input().split()))
s=set(l)
if 0 in s:print(len(s)-1)
else:print(len(s))
|
Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score.
Output Specification:
Print a single integer — the desired number of ways.
Demo Input:
['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n']
Demo Output:
['3\n', '1\n', '1\n']
Note:
There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything.
|
```python
n=int(input())
l=list(map(int,input().split()))
s=set(l)
if 0 in s:print(len(s)-1)
else:print(len(s))
```
| 3
|
|
368
|
A
|
Sereja and Coat Rack
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Sereja owns a restaurant for *n* people. The restaurant hall has a coat rack with *n* hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the *i*-th hook costs *a**i* rubles. Only one person can hang clothes on one hook.
Tonight Sereja expects *m* guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a *d* ruble fine to the guest.
Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the *m* guests is visiting Sereja's restaurant tonight.
|
The first line contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100). The third line contains integer *m* (1<=≤<=*m*<=≤<=100).
|
In a single line print a single integer — the answer to the problem.
|
[
"2 1\n2 1\n2\n",
"2 1\n2 1\n10\n"
] |
[
"3\n",
"-5\n"
] |
In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.
In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5.
| 500
|
[
{
"input": "2 1\n2 1\n2",
"output": "3"
},
{
"input": "2 1\n2 1\n10",
"output": "-5"
},
{
"input": "1 1\n1\n2",
"output": "0"
},
{
"input": "3 96\n83 22 17\n19",
"output": "-1414"
},
{
"input": "8 4\n27 72 39 70 13 68 100 36\n95",
"output": "77"
},
{
"input": "2 65\n23 34\n74",
"output": "-4623"
},
{
"input": "2 48\n12 54\n69",
"output": "-3150"
},
{
"input": "5 30\n63 58 38 60 24\n42",
"output": "-867"
},
{
"input": "9 47\n17 36 91 43 89 7 41 43 65\n49",
"output": "-1448"
},
{
"input": "6 49\n91 30 71 51 7 2\n94",
"output": "-4060"
},
{
"input": "57 27\n73 51 24 86 57 17 27 58 27 58 38 72 70 62 97 23 18 13 18 97 86 42 24 30 30 66 60 33 97 56 54 63 85 35 55 73 58 70 33 64 8 84 12 36 68 49 76 39 24 43 55 12 42 76 60 26 22\n71",
"output": "2454"
},
{
"input": "35 19\n6 84 51 99 80 2 94 35 38 35 57 94 77 6 63 49 82 1 14 42 56 56 43 63 12 78 25 79 53 44 97 74 41 14 76\n73",
"output": "1098"
},
{
"input": "11 91\n18 33 13 96 70 32 41 89 86 91 98\n90",
"output": "-6522"
},
{
"input": "46 48\n54 15 52 41 45 59 36 60 93 6 65 82 4 30 76 9 93 98 50 57 62 28 68 42 30 41 14 75 2 78 16 84 14 93 25 2 93 60 71 29 28 85 76 87 99 71\n88",
"output": "382"
},
{
"input": "5 72\n4 22 64 7 64\n11",
"output": "-271"
},
{
"input": "90 24\n41 65 43 20 14 92 5 19 33 51 6 76 40 4 23 99 48 85 49 72 65 14 76 46 13 47 79 70 63 20 86 90 45 66 41 46 9 19 71 2 24 33 73 53 88 71 64 2 4 24 28 1 70 16 66 29 44 48 89 44 38 10 64 50 82 89 43 9 61 22 59 55 89 47 91 50 44 31 21 49 68 37 84 36 27 86 39 54 30 25\n49",
"output": "1306"
},
{
"input": "60 63\n58 67 45 56 19 27 12 26 56 2 50 97 85 16 65 43 76 14 43 97 49 73 27 7 74 30 5 6 27 13 76 94 66 37 37 42 15 95 57 53 37 39 83 56 16 32 31 42 26 12 38 87 91 51 63 35 94 54 17 53\n9",
"output": "86"
},
{
"input": "34 79\n55 4 35 4 57 49 25 18 14 10 29 1 81 19 59 51 56 62 65 4 77 44 10 3 62 90 49 83 54 75 21 3 24 32\n70",
"output": "-1519"
},
{
"input": "60 91\n9 20 72 4 46 82 5 93 86 14 99 90 23 39 38 11 62 35 9 62 60 94 16 70 38 70 59 1 72 65 18 16 56 16 31 40 13 89 83 55 86 11 85 75 81 16 52 42 16 80 11 99 74 89 78 33 57 90 14 9\n42",
"output": "1406"
},
{
"input": "24 68\n64 29 85 79 1 72 86 75 72 34 68 54 96 69 26 77 30 51 99 10 94 87 81 17\n50",
"output": "-312"
},
{
"input": "29 19\n80 65 22 6 27 17 17 27 67 88 82 65 41 87 22 63 22 65 10 16 3 74 25 42 46 63 24 32 7\n69",
"output": "445"
},
{
"input": "3 37\n8 8 82\n13",
"output": "-272"
},
{
"input": "31 63\n15 10 85 57 91 94 97 53 55 46 9 49 92 13 32 15 40 59 23 5 96 53 70 80 39 24 19 67 60 99 87\n97",
"output": "-2524"
},
{
"input": "34 30\n59 23 47 93 38 26 48 59 3 8 99 31 93 1 79 100 53 49 83 41 16 76 63 68 37 98 19 98 29 52 17 31 50 26\n59",
"output": "963"
},
{
"input": "21 29\n41 61 48 63 56 76 93 62 55 99 47 15 47 89 70 39 64 76 16 22 76\n16",
"output": "782"
},
{
"input": "35 86\n71 6 65 58 63 62 25 50 70 31 24 51 34 26 11 38 37 38 79 94 37 15 65 92 50 36 6 38 5 38 24 65 71 9 69\n82",
"output": "-2489"
},
{
"input": "53 75\n74 53 95 77 27 97 73 50 41 75 20 44 12 42 90 20 66 6 86 17 51 16 10 65 67 94 75 10 1 96 74 90 62 73 69 59 32 69 27 11 23 75 80 11 53 83 92 96 65 75 65 3 56\n61",
"output": "2293"
},
{
"input": "73 13\n22 23 48 78 90 6 96 95 51 44 55 82 13 73 40 29 13 63 68 9 16 9 24 60 35 5 87 20 59 46 7 67 1 68 93 88 33 57 75 48 22 84 23 32 77 84 49 24 83 19 77 21 12 83 57 91 26 25 87 78 70 44 35 78 69 69 92 97 84 29 28 27 72\n98",
"output": "3419"
},
{
"input": "4 39\n28 9 46 9\n86",
"output": "-3106"
},
{
"input": "100 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\n100",
"output": "10000"
},
{
"input": "1 100\n100\n100",
"output": "-9800"
},
{
"input": "1 1\n1\n1",
"output": "1"
},
{
"input": "5 1\n1 5 2 7 8\n3",
"output": "8"
},
{
"input": "4 44\n3 3 3 3\n1",
"output": "3"
},
{
"input": "3 1\n1 2 3\n1",
"output": "1"
}
] | 1,684,753,752
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 35
| 62
| 0
|
# https://codeforces.com/contest/368
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, d = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m >= n:
ans = sum(a) - (m - n) * d
else:
a.sort()
ans = sum(a[:m])
print(ans)
|
Title: Sereja and Coat Rack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja owns a restaurant for *n* people. The restaurant hall has a coat rack with *n* hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the *i*-th hook costs *a**i* rubles. Only one person can hang clothes on one hook.
Tonight Sereja expects *m* guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a *d* ruble fine to the guest.
Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the *m* guests is visiting Sereja's restaurant tonight.
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100). The third line contains integer *m* (1<=≤<=*m*<=≤<=100).
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['2 1\n2 1\n2\n', '2 1\n2 1\n10\n']
Demo Output:
['3\n', '-5\n']
Note:
In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.
In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 = - 5.
|
```python
# https://codeforces.com/contest/368
import sys
input = lambda: sys.stdin.readline().rstrip() # faster!
n, d = map(int, input().split())
a = list(map(int, input().split()))
m = int(input())
if m >= n:
ans = sum(a) - (m - n) * d
else:
a.sort()
ans = sum(a[:m])
print(ans)
```
| 3
|
|
844
|
A
|
Diversity
|
PROGRAMMING
| 1,000
|
[
"greedy",
"implementation",
"strings"
] | null | null |
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
|
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
|
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
|
[
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] |
[
"0\n",
"1\n",
"impossible\n"
] |
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
| 500
|
[
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26",
"output": "14"
},
{
"input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26",
"output": "12"
},
{
"input": "a\n3",
"output": "impossible"
},
{
"input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1",
"output": "0"
},
{
"input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4",
"output": "1"
},
{
"input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20",
"output": "18"
},
{
"input": "swmkwaruyv\n5",
"output": "0"
},
{
"input": "tnbqpsuhkczmejirvyfdolxwga\n22",
"output": "0"
},
{
"input": "abcde\n3",
"output": "0"
},
{
"input": "abb\n1",
"output": "0"
},
{
"input": "aaaa\n1",
"output": "0"
},
{
"input": "abcde\n2",
"output": "0"
},
{
"input": "yandex\n4",
"output": "0"
},
{
"input": "aaabbbccc\n1",
"output": "0"
},
{
"input": "abcd\n2",
"output": "0"
},
{
"input": "asdfgh\n2",
"output": "0"
},
{
"input": "aab\n1",
"output": "0"
},
{
"input": "mynameissako\n5",
"output": "0"
},
{
"input": "abcde\n1",
"output": "0"
},
{
"input": "abcd\n3",
"output": "0"
},
{
"input": "abcdef\n2",
"output": "0"
},
{
"input": "abcdefg\n4",
"output": "0"
},
{
"input": "abc\n1",
"output": "0"
},
{
"input": "asdafjsgljdllgjdgkl\n5",
"output": "0"
},
{
"input": "yaay\n3",
"output": "1"
},
{
"input": "yaay\n4",
"output": "2"
},
{
"input": "zzzzzz\n2",
"output": "1"
}
] | 1,508,265,190
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 41
| 62
| 5,529,600
|
s = input()
k = int(input())
n = 0
a = list()
for i in s:
test = False
for j in a:
if i == j:
test = True
if not test:
a.append(i)
if len(s) < k:
print('impossible')
else:
print(max(k - len(a),0))
|
Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input Specification:
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Output Specification:
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
Demo Input:
['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n']
Demo Output:
['0\n', '1\n', 'impossible\n']
Note:
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
|
```python
s = input()
k = int(input())
n = 0
a = list()
for i in s:
test = False
for j in a:
if i == j:
test = True
if not test:
a.append(i)
if len(s) < k:
print('impossible')
else:
print(max(k - len(a),0))
```
| 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,634,493,512
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 2
| 61
| 0
|
a,b=map(int,input().split())
if a%2==1:
if a>b:
print("Vladik")
else:
print("Valera")
elif b%2==0:
if b>a:
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=map(int,input().split())
if a%2==1:
if a>b:
print("Vladik")
else:
print("Valera")
elif b%2==0:
if b>a:
print("Valera")
else:
print("Vladik")
```
| 0
|
|
808
|
D
|
Array Division
|
PROGRAMMING
| 1,900
|
[
"binary search",
"data structures",
"implementation"
] | null | null |
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
|
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
|
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
|
[
"3\n1 3 2\n",
"5\n1 2 3 4 5\n",
"5\n2 2 3 4 5\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left.
| 0
|
[
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n2 2 3 4 5",
"output": "YES"
},
{
"input": "5\n72 32 17 46 82",
"output": "NO"
},
{
"input": "6\n26 10 70 11 69 57",
"output": "NO"
},
{
"input": "7\n4 7 10 7 5 5 1",
"output": "NO"
},
{
"input": "8\n9 5 5 10 4 9 5 8",
"output": "NO"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2",
"output": "YES"
},
{
"input": "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8",
"output": "NO"
},
{
"input": "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13",
"output": "NO"
},
{
"input": "20\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6",
"output": "NO"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14",
"output": "YES"
},
{
"input": "100\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53",
"output": "NO"
},
{
"input": "100\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25",
"output": "NO"
},
{
"input": "100\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19",
"output": "NO"
},
{
"input": "100\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80",
"output": "NO"
},
{
"input": "6\n1 4 3 100 100 6",
"output": "YES"
},
{
"input": "6\n6 100 100 3 4 1",
"output": "YES"
},
{
"input": "6\n4 2 3 7 1 1",
"output": "YES"
},
{
"input": "4\n6 1 4 5",
"output": "NO"
},
{
"input": "3\n228 114 114",
"output": "YES"
},
{
"input": "3\n229 232 444",
"output": "NO"
},
{
"input": "3\n322 324 555",
"output": "NO"
},
{
"input": "3\n69 34 5",
"output": "NO"
},
{
"input": "6\n5 4 1 2 2 2",
"output": "YES"
},
{
"input": "3\n545 237 546",
"output": "NO"
},
{
"input": "5\n2 3 1 1 1",
"output": "YES"
},
{
"input": "6\n2 2 10 2 2 2",
"output": "YES"
},
{
"input": "5\n5 4 6 5 6",
"output": "NO"
},
{
"input": "5\n6 1 1 1 1",
"output": "NO"
},
{
"input": "2\n1 3",
"output": "NO"
},
{
"input": "5\n5 2 2 3 4",
"output": "YES"
},
{
"input": "2\n2 2",
"output": "YES"
},
{
"input": "5\n1 2 6 1 2",
"output": "YES"
},
{
"input": "5\n1 1 8 5 1",
"output": "YES"
},
{
"input": "10\n73 67 16 51 56 71 37 49 90 6",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "5\n8 2 7 5 4",
"output": "YES"
},
{
"input": "1\n2",
"output": "NO"
},
{
"input": "16\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2",
"output": "YES"
},
{
"input": "4\n8 2 2 4",
"output": "YES"
},
{
"input": "19\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3",
"output": "NO"
},
{
"input": "11\n7 2 1 8 8 2 4 10 8 7 1",
"output": "YES"
},
{
"input": "6\n10 20 30 40 99 1",
"output": "YES"
},
{
"input": "10\n3 7 9 2 10 1 9 6 4 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "2\n9 3",
"output": "NO"
},
{
"input": "7\n1 2 3 12 1 2 3",
"output": "YES"
},
{
"input": "6\n2 4 4 5 8 5",
"output": "YES"
},
{
"input": "18\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4",
"output": "YES"
},
{
"input": "20\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9",
"output": "NO"
},
{
"input": "12\n3 8 10 2 4 4 6 9 5 10 10 3",
"output": "YES"
},
{
"input": "11\n9 2 7 7 7 3 7 5 4 10 7",
"output": "NO"
},
{
"input": "5\n1 1 4 1 1",
"output": "YES"
},
{
"input": "2\n4 4",
"output": "YES"
},
{
"input": "2\n7 1",
"output": "NO"
},
{
"input": "5\n10 5 6 7 6",
"output": "YES"
},
{
"input": "11\n4 3 10 3 7 8 4 9 2 1 1",
"output": "YES"
},
{
"input": "6\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "NO"
},
{
"input": "8\n1 5 6 8 3 1 7 3",
"output": "YES"
},
{
"input": "20\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8",
"output": "YES"
},
{
"input": "11\n2 4 8 3 4 7 9 10 5 3 3",
"output": "YES"
},
{
"input": "7\n6 4 2 24 6 4 2",
"output": "YES"
},
{
"input": "17\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5",
"output": "NO"
},
{
"input": "7\n7 10 1 2 6 2 2",
"output": "NO"
},
{
"input": "5\n10 10 40 10 10",
"output": "YES"
},
{
"input": "3\n4 3 13",
"output": "NO"
},
{
"input": "5\n5 2 10 2 1",
"output": "YES"
},
{
"input": "7\n7 4 5 62 20 20 6",
"output": "YES"
},
{
"input": "6\n1 5 2 20 10 2",
"output": "YES"
},
{
"input": "2\n5 6",
"output": "NO"
},
{
"input": "14\n5 2 9 7 5 8 3 2 2 4 9 1 3 10",
"output": "YES"
},
{
"input": "5\n1 2 3 4 2",
"output": "YES"
},
{
"input": "5\n2 2 2 5 5",
"output": "NO"
},
{
"input": "11\n1 1 1 1 1 10 1 1 1 1 1",
"output": "YES"
},
{
"input": "9\n8 4 13 19 11 1 8 2 8",
"output": "YES"
},
{
"input": "6\n14 16 14 14 15 11",
"output": "YES"
},
{
"input": "9\n14 19 1 13 11 3 1 1 7",
"output": "YES"
},
{
"input": "6\n16 13 3 7 4 15",
"output": "YES"
},
{
"input": "4\n11 7 12 14",
"output": "NO"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "5\n2 1 3 6 4",
"output": "YES"
},
{
"input": "5\n3 4 8 11 2",
"output": "YES"
},
{
"input": "5\n1 2 10 3 4",
"output": "YES"
},
{
"input": "6\n8 15 12 14 15 4",
"output": "YES"
},
{
"input": "5\n1 2 4 4 5",
"output": "YES"
},
{
"input": "3\n2 4 2",
"output": "YES"
},
{
"input": "5\n2 3 1 6 4",
"output": "YES"
},
{
"input": "7\n1 2 3 12 3 2 1",
"output": "YES"
},
{
"input": "3\n3 4 13",
"output": "NO"
},
{
"input": "6\n1 1 1 1 1000000000 1000000000",
"output": "YES"
},
{
"input": "6\n19 6 5 13 6 13",
"output": "YES"
},
{
"input": "8\n2 2 2 5 1 2 3 3",
"output": "YES"
}
] | 1,565,187,757
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 115
| 327
| 15,462,400
|
def possible(a):
if len(a)==1:
return False
if len(a)==2:
return a[0]==a[1]
total = sum(a)
vals = set([a[0]])
running = a[0]
for el in a[1:]:
running += el
vals.add(el)
if running == total-running:
return True
if (running - (total-running))%2==0 and (running - (total-running))//2 in vals:
return True
return False
n = int(input())
a = list(map(int, input().split()))
if possible(a) or possible(a[::-1]):
print("YES")
else:
print("NO")
|
Title: Array Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has an array *a* consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2... *a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Output Specification:
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
Demo Input:
['3\n1 3 2\n', '5\n1 2 3 4 5\n', '5\n2 2 3 4 5\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left.
|
```python
def possible(a):
if len(a)==1:
return False
if len(a)==2:
return a[0]==a[1]
total = sum(a)
vals = set([a[0]])
running = a[0]
for el in a[1:]:
running += el
vals.add(el)
if running == total-running:
return True
if (running - (total-running))%2==0 and (running - (total-running))//2 in vals:
return True
return False
n = int(input())
a = list(map(int, input().split()))
if possible(a) or possible(a[::-1]):
print("YES")
else:
print("NO")
```
| 3
|
|
104
|
A
|
Blackjack
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Blackjack
|
2
|
256
|
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
|
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
|
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
|
[
"12\n",
"20\n",
"10\n"
] |
[
"4",
"15",
"0"
] |
In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points.
| 500
|
[
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
},
{
"input": "22",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "9",
"output": "0"
},
{
"input": "13",
"output": "4"
},
{
"input": "14",
"output": "4"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "4"
},
{
"input": "19",
"output": "4"
},
{
"input": "21",
"output": "4"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "0"
}
] | 1,626,073,614
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 25
| 154
| 6,758,400
|
n = int(input())
reqNumber = n - 10
if reqNumber in [2,3,4,5,6,7,8,9] :
print(4)
elif reqNumber == 10:
print(15)
elif reqNumber == 11:
print(4)
elif reqNumber == 1 :
print(4)
else :
print(0)
|
Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
Input Specification:
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Output Specification:
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
Demo Input:
['12\n', '20\n', '10\n']
Demo Output:
['4', '15', '0']
Note:
In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points.
|
```python
n = int(input())
reqNumber = n - 10
if reqNumber in [2,3,4,5,6,7,8,9] :
print(4)
elif reqNumber == 10:
print(15)
elif reqNumber == 11:
print(4)
elif reqNumber == 1 :
print(4)
else :
print(0)
```
| 3.948911
|
935
|
A
|
Fafa and his Company
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
|
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
|
Print a single integer representing the answer to the problem.
|
[
"2\n",
"10\n"
] |
[
"1\n",
"3\n"
] |
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
| 500
|
[
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,663,272,435
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
n=int(input())
s=0
for i in range(1,n-1):
if (n-i)%i==0:
s+=1
print(s)
|
Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
|
```python
n=int(input())
s=0
for i in range(1,n-1):
if (n-i)%i==0:
s+=1
print(s)
```
| 0
|
|
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,678,300,347
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 30
| 0
|
print(4, n-4)
|
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
print(4, n-4)
```
| -1
|
|
17
|
B
|
Hierarchy
|
PROGRAMMING
| 1,500
|
[
"dfs and similar",
"dsu",
"greedy",
"shortest paths"
] |
B. Hierarchy
|
2
|
64
|
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: «employee *a**i* is ready to become a supervisor of employee *b**i* at extra cost *c**i*». The qualification *q**j* of each employee is known, and for each application the following is true: *q**a**i*<=><=*q**b**i*.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
|
The first input line contains integer *n* (1<=≤<=*n*<=≤<=1000) — amount of employees in the company. The following line contains *n* space-separated numbers *q**j* (0<=≤<=*q**j*<=≤<=106)— the employees' qualifications. The following line contains number *m* (0<=≤<=*m*<=≤<=10000) — amount of received applications. The following *m* lines contain the applications themselves, each of them in the form of three space-separated numbers: *a**i*, *b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, 0<=≤<=*c**i*<=≤<=106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application *q**a**i*<=><=*q**b**i*.
|
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
|
[
"4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5\n",
"3\n1 2 3\n2\n3 1 2\n3 1 3\n"
] |
[
"11\n",
"-1\n"
] |
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
| 0
|
[
{
"input": "4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5",
"output": "11"
},
{
"input": "3\n1 2 3\n2\n3 1 2\n3 1 3",
"output": "-1"
},
{
"input": "1\n2\n0",
"output": "0"
},
{
"input": "2\n5 3\n4\n1 2 0\n1 2 5\n1 2 0\n1 2 7",
"output": "0"
},
{
"input": "3\n9 4 5\n5\n3 2 4\n1 2 4\n3 2 8\n1 3 5\n3 2 5",
"output": "9"
},
{
"input": "3\n2 5 9\n5\n3 1 7\n2 1 1\n2 1 6\n2 1 2\n3 1 5",
"output": "-1"
},
{
"input": "3\n6 2 9\n5\n1 2 10\n3 1 4\n1 2 5\n1 2 2\n3 1 4",
"output": "6"
},
{
"input": "4\n10 6 7 4\n5\n1 3 1\n3 4 1\n3 2 2\n1 2 6\n1 4 7",
"output": "4"
},
{
"input": "4\n2 7 0 6\n8\n4 3 5\n2 3 7\n4 3 1\n2 1 9\n1 3 1\n1 3 3\n2 3 1\n1 3 2",
"output": "-1"
},
{
"input": "5\n6 8 5 9 0\n8\n4 2 2\n2 3 10\n2 3 6\n4 5 4\n1 3 1\n4 3 4\n3 5 1\n2 3 8",
"output": "-1"
},
{
"input": "5\n10 9 5 0 3\n9\n1 5 1\n1 4 7\n1 4 0\n1 4 6\n3 4 6\n2 3 1\n1 2 2\n1 2 9\n2 3 9",
"output": "4"
},
{
"input": "5\n3 9 2 1 8\n9\n2 5 10\n1 3 8\n3 4 9\n5 4 2\n2 1 4\n5 1 4\n2 4 2\n1 4 7\n5 1 2",
"output": "22"
},
{
"input": "5\n6 10 7 8 5\n10\n3 1 5\n2 4 1\n2 3 2\n4 5 9\n3 5 0\n4 1 9\n4 5 2\n1 5 8\n2 3 7\n1 5 1",
"output": "8"
},
{
"input": "7\n10 0 4 7 3 8 6\n10\n3 2 4\n6 4 3\n6 5 1\n1 2 1\n6 7 6\n7 3 9\n1 6 3\n3 2 1\n6 4 4\n1 4 4",
"output": "23"
},
{
"input": "6\n10 2 4 3 1 6\n10\n1 4 7\n1 6 9\n6 4 1\n4 2 5\n4 5 7\n6 3 10\n3 2 3\n3 4 3\n6 5 2\n1 3 2",
"output": "17"
},
{
"input": "1\n10\n0",
"output": "0"
},
{
"input": "2\n10 5\n0",
"output": "-1"
},
{
"input": "2\n1000000 999999\n1\n1 2 1000000",
"output": "1000000"
},
{
"input": "4\n3 2 2 1\n5\n1 2 1\n1 3 1\n1 4 500\n2 4 1\n3 4 2",
"output": "3"
}
] | 1,639,556,259
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 62
| 0
|
import sys
def reverse_graph(graph: dict):
r = {}
for src in graph:
for (dst, c) in graph[src].items():
if dst in r:
r[dst][src] = c
else:
r[dst] = {src: c}
return r
def get_cycle(n: int, g: dict, visited: set = None, cycle: list = None):
if visited is None:
visited = set()
if cycle is None:
cycle = []
visited.add(n)
cycle += [n]
if n not in g:
return cycle
for e in g[n]:
if e not in visited:
cycle = get_cycle(e, g, visited, cycle)
return cycle
def merge_cycles(cycle, rev_graph, g, rg):
all_in_edges = []
min_internal = None
min_internal_weight = sys.maxsize
# find minimal internal edge weight
for n in cycle:
for e in rev_graph[n]:
if e in cycle:
if min_internal is None or rev_graph[n][e] < min_internal_weight:
min_internal = (n, e)
min_internal_weight = rev_graph[n][e]
continue
else:
all_in_edges.append((n, e))
# find the incoming edge with minimum modified cost
min_external = None
min_modified_weight = 0
for s, t in all_in_edges:
u, v = rg[s].popitem()
rg[s][u] = v
w = rev_graph[s][t] - (v - min_internal_weight)
if min_external is None or min_modified_weight > w:
min_external = (s, t)
min_modified_weight = w
u, w = rg[min_external[0]].popitem()
rem = (min_external[0], u)
rg[min_external[0]].clear()
if min_external[1] in rg:
rg[min_external[1]][min_external[0]] = w
else:
rg[min_external[1]] = {min_external[0]: w}
if rem[1] in g:
if rem[0] in g[rem[1]]:
del g[rem[1]][rem[0]]
if min_external[1] in g:
g[min_external[1]][min_external[0]] = w
else:
g[min_external[1]] = {min_external[0]: w}
def mst(root: int, graph: dict):
reversed_graph = reverse_graph(graph)
if root in reversed_graph:
reversed_graph[root] = {}
g = {}
for n in reversed_graph:
if len(reversed_graph[n]) == 0:
continue
minimum = sys.maxsize
s, d = None, None
for e in reversed_graph[n]:
if reversed_graph[n][e] < minimum:
minimum = reversed_graph[n][e]
s, d = n, e
if d in g:
g[d][s] = reversed_graph[s][d]
else:
g[d] = {s: reversed_graph[s][d]}
cycles = []
visited = set()
for n in g:
if n not in visited:
cycle = get_cycle(n, g, visited)
cycles.append(cycle)
rg = reverse_graph(g)
for cycle in cycles:
if root in cycle:
continue
merge_cycles(cycle, reversed_graph, g, rg)
return g
def read_graph(edges: list) -> dict:
graph = {}
for edge in edges:
if edge[0] - 1 not in graph.keys():
node_neighbors = {edge[1] - 1: edge[2]}
graph.update({edge[0] - 1: node_neighbors})
else:
graph[edge[0] - 1].update({edge[1] - 1: edge[2]})
return graph
def task4(n: int, qualifications: list, statements: list) -> int:
"""
Method for solving a startup problem
Parameters:
----------
n: int
Number of company employees
qualifications: list
Staff qualifications
statements: list
List of statements
Returns:
-------
Minimum cost of creating a hierarchy
"""
if len(qualifications) == 1:
return 0
root = qualifications.index(max(qualifications))
graph = read_graph(statements)
h = mst(root, graph)
visited_nodes = set(list(h.keys()) + [key for dct in h.values() for key in dct.keys()])
return sum(h[s][t] for s in h for t in h[s]) if n == len(visited_nodes) else -1
n = int(input())
q = list(map(int,input().split()))
m = int(input())
s = []
for i in range(0,m):
s.append(list(map(int,input().split())))
print(task4(n,q,s))
|
Title: Hierarchy
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: «employee *a**i* is ready to become a supervisor of employee *b**i* at extra cost *c**i*». The qualification *q**j* of each employee is known, and for each application the following is true: *q**a**i*<=><=*q**b**i*.
Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=1000) — amount of employees in the company. The following line contains *n* space-separated numbers *q**j* (0<=≤<=*q**j*<=≤<=106)— the employees' qualifications. The following line contains number *m* (0<=≤<=*m*<=≤<=10000) — amount of received applications. The following *m* lines contain the applications themselves, each of them in the form of three space-separated numbers: *a**i*, *b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, 0<=≤<=*c**i*<=≤<=106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application *q**a**i*<=><=*q**b**i*.
Output Specification:
Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.
Demo Input:
['4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5\n', '3\n1 2 3\n2\n3 1 2\n3 1 3\n']
Demo Output:
['11\n', '-1\n']
Note:
In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.
|
```python
import sys
def reverse_graph(graph: dict):
r = {}
for src in graph:
for (dst, c) in graph[src].items():
if dst in r:
r[dst][src] = c
else:
r[dst] = {src: c}
return r
def get_cycle(n: int, g: dict, visited: set = None, cycle: list = None):
if visited is None:
visited = set()
if cycle is None:
cycle = []
visited.add(n)
cycle += [n]
if n not in g:
return cycle
for e in g[n]:
if e not in visited:
cycle = get_cycle(e, g, visited, cycle)
return cycle
def merge_cycles(cycle, rev_graph, g, rg):
all_in_edges = []
min_internal = None
min_internal_weight = sys.maxsize
# find minimal internal edge weight
for n in cycle:
for e in rev_graph[n]:
if e in cycle:
if min_internal is None or rev_graph[n][e] < min_internal_weight:
min_internal = (n, e)
min_internal_weight = rev_graph[n][e]
continue
else:
all_in_edges.append((n, e))
# find the incoming edge with minimum modified cost
min_external = None
min_modified_weight = 0
for s, t in all_in_edges:
u, v = rg[s].popitem()
rg[s][u] = v
w = rev_graph[s][t] - (v - min_internal_weight)
if min_external is None or min_modified_weight > w:
min_external = (s, t)
min_modified_weight = w
u, w = rg[min_external[0]].popitem()
rem = (min_external[0], u)
rg[min_external[0]].clear()
if min_external[1] in rg:
rg[min_external[1]][min_external[0]] = w
else:
rg[min_external[1]] = {min_external[0]: w}
if rem[1] in g:
if rem[0] in g[rem[1]]:
del g[rem[1]][rem[0]]
if min_external[1] in g:
g[min_external[1]][min_external[0]] = w
else:
g[min_external[1]] = {min_external[0]: w}
def mst(root: int, graph: dict):
reversed_graph = reverse_graph(graph)
if root in reversed_graph:
reversed_graph[root] = {}
g = {}
for n in reversed_graph:
if len(reversed_graph[n]) == 0:
continue
minimum = sys.maxsize
s, d = None, None
for e in reversed_graph[n]:
if reversed_graph[n][e] < minimum:
minimum = reversed_graph[n][e]
s, d = n, e
if d in g:
g[d][s] = reversed_graph[s][d]
else:
g[d] = {s: reversed_graph[s][d]}
cycles = []
visited = set()
for n in g:
if n not in visited:
cycle = get_cycle(n, g, visited)
cycles.append(cycle)
rg = reverse_graph(g)
for cycle in cycles:
if root in cycle:
continue
merge_cycles(cycle, reversed_graph, g, rg)
return g
def read_graph(edges: list) -> dict:
graph = {}
for edge in edges:
if edge[0] - 1 not in graph.keys():
node_neighbors = {edge[1] - 1: edge[2]}
graph.update({edge[0] - 1: node_neighbors})
else:
graph[edge[0] - 1].update({edge[1] - 1: edge[2]})
return graph
def task4(n: int, qualifications: list, statements: list) -> int:
"""
Method for solving a startup problem
Parameters:
----------
n: int
Number of company employees
qualifications: list
Staff qualifications
statements: list
List of statements
Returns:
-------
Minimum cost of creating a hierarchy
"""
if len(qualifications) == 1:
return 0
root = qualifications.index(max(qualifications))
graph = read_graph(statements)
h = mst(root, graph)
visited_nodes = set(list(h.keys()) + [key for dct in h.values() for key in dct.keys()])
return sum(h[s][t] for s in h for t in h[s]) if n == len(visited_nodes) else -1
n = int(input())
q = list(map(int,input().split()))
m = int(input())
s = []
for i in range(0,m):
s.append(list(map(int,input().split())))
print(task4(n,q,s))
```
| 0
|
652
|
C
|
Foe Pairs
|
PROGRAMMING
| 1,800
|
[
"combinatorics",
"sortings",
"two pointers"
] | null | null |
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x*,<=*y*) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: *p*<==<=[1,<=3,<=2,<=4] and foe pairs are {(3,<=2),<=(4,<=2)}. The interval (1,<=3) is incorrect because it contains a foe pair (3,<=2). The interval (1,<=4) is also incorrect because it contains two foe pairs (3,<=2) and (4,<=2). But the interval (1,<=2) is correct because it doesn't contain any foe pair.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the length of the permutation *p* and the number of foe pairs.
The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*.
Each of the next *m* lines contains two integers (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the *i*-th foe pair. Note a foe pair can appear multiple times in the given list.
|
Print the only integer *c* — the number of different intervals (*x*,<=*y*) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
|
[
"4 2\n1 3 2 4\n3 2\n2 4\n",
"9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n"
] |
[
"5\n",
"20\n"
] |
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
| 0
|
[
{
"input": "4 2\n1 3 2 4\n3 2\n2 4",
"output": "5"
},
{
"input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7",
"output": "20"
},
{
"input": "2 1\n1 2\n1 2",
"output": "2"
},
{
"input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1",
"output": "39"
},
{
"input": "50 10\n41 15 17 1 5 31 7 38 30 39 43 35 2 26 20 42 48 25 19 32 50 4 8 10 44 12 9 18 13 36 28 6 27 23 40 24 3 14 29 11 49 47 45 46 34 21 37 16 22 33\n13 48\n24 12\n2 32\n36 7\n19 20\n9 45\n35 47\n10 16\n4 49\n46 2",
"output": "608"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43\n58 26\n10 52\n26 75\n51 9\n49 33\n55 6\n52 62\n82 53\n90 24\n12 7",
"output": "1589"
},
{
"input": "3 8\n1 2 3\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n2 3",
"output": "3"
},
{
"input": "3 4\n1 2 3\n1 3\n1 2\n1 3\n2 3",
"output": "3"
}
] | 1,660,722,775
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 0
| 61
| 0
|
import sys
# import random
# from collections import Counter, defaultdict, deque
# from functools import lru_cache, reduce
# from itertools import accumulate,product
# from heapq import nsmallest, nlargest, heapify, heappop, heappush
# input = sys.stdin.buffer.readline
input = sys.stdin.readline
def mp():return list(map(int,input().split()))
def it():return int(input())
import math
def solve():
n,m=mp()
nums=mp()
ans=0
record=[0]*(n+1)
edge=[0]*(n+1)
for i in range(n):
record[nums[i]]=i
for i in range(m):
x,y=mp()
x,y=record[x],record[y]
if x>y:x,y=y,x
edge[y]=max(edge[y],x)
ptr=0
for i in range(n):
ptr=max(ptr,edge[i])
ans+=i-ptr
print(ans)
return
if __name__ == '__main__':
# t=it()
# for _ in range(t):
# solve()
# n=it()
# n,m,k=mp()
solve()
|
Title: Foe Pairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x*,<=*y*) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: *p*<==<=[1,<=3,<=2,<=4] and foe pairs are {(3,<=2),<=(4,<=2)}. The interval (1,<=3) is incorrect because it contains a foe pair (3,<=2). The interval (1,<=4) is also incorrect because it contains two foe pairs (3,<=2) and (4,<=2). But the interval (1,<=2) is correct because it doesn't contain any foe pair.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the length of the permutation *p* and the number of foe pairs.
The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*.
Each of the next *m* lines contains two integers (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — the *i*-th foe pair. Note a foe pair can appear multiple times in the given list.
Output Specification:
Print the only integer *c* — the number of different intervals (*x*,<=*y*) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['4 2\n1 3 2 4\n3 2\n2 4\n', '9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n']
Demo Output:
['5\n', '20\n']
Note:
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
|
```python
import sys
# import random
# from collections import Counter, defaultdict, deque
# from functools import lru_cache, reduce
# from itertools import accumulate,product
# from heapq import nsmallest, nlargest, heapify, heappop, heappush
# input = sys.stdin.buffer.readline
input = sys.stdin.readline
def mp():return list(map(int,input().split()))
def it():return int(input())
import math
def solve():
n,m=mp()
nums=mp()
ans=0
record=[0]*(n+1)
edge=[0]*(n+1)
for i in range(n):
record[nums[i]]=i
for i in range(m):
x,y=mp()
x,y=record[x],record[y]
if x>y:x,y=y,x
edge[y]=max(edge[y],x)
ptr=0
for i in range(n):
ptr=max(ptr,edge[i])
ans+=i-ptr
print(ans)
return
if __name__ == '__main__':
# t=it()
# for _ in range(t):
# solve()
# n=it()
# n,m,k=mp()
solve()
```
| 0
|
|
18
|
C
|
Stripe
|
PROGRAMMING
| 1,200
|
[
"data structures",
"implementation"
] |
C. Stripe
|
2
|
64
|
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
|
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
|
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
|
[
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] |
[
"3\n",
"0\n",
"1\n"
] |
none
| 0
|
[
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "10\n0 -1 2 2 -1 1 0 0 0 2",
"output": "0"
},
{
"input": "10\n-1 -1 1 -1 0 1 0 1 1 1",
"output": "1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "9"
},
{
"input": "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3",
"output": "3"
},
{
"input": "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3",
"output": "0"
},
{
"input": "10\n3 -1 -3 -1 3 -2 0 3 1 -2",
"output": "0"
},
{
"input": "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2",
"output": "1"
},
{
"input": "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2",
"output": "6"
},
{
"input": "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n10000",
"output": "0"
},
{
"input": "1\n-10000",
"output": "0"
}
] | 1,578,180,795
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 218
| 0
|
n=int(input())
l=list(map(int,input().split()))
ls=[0]
x=0
for i in range(n):
x+=l[i]
ls.append(x)
count=0
for i in range(1,n):
if (ls[n]-ls[i])==0:
count+=1
print(count)
|
Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output Specification:
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
Demo Input:
['9\n1 5 -6 7 9 -16 0 -2 2\n', '3\n1 1 1\n', '2\n0 0\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
none
|
```python
n=int(input())
l=list(map(int,input().split()))
ls=[0]
x=0
for i in range(n):
x+=l[i]
ls.append(x)
count=0
for i in range(1,n):
if (ls[n]-ls[i])==0:
count+=1
print(count)
```
| 0
|
588
|
B
|
Duff in Love
|
PROGRAMMING
| 1,300
|
[
"math"
] | null | null |
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.
|
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
|
Print the answer in one line.
|
[
"10\n",
"12\n"
] |
[
"10\n",
"6\n"
] |
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
| 1,000
|
[
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input": "31",
"output": "31"
},
{
"input": "97",
"output": "97"
},
{
"input": "1000000000000",
"output": "10"
},
{
"input": "15",
"output": "15"
},
{
"input": "894",
"output": "894"
},
{
"input": "271",
"output": "271"
},
{
"input": "2457",
"output": "273"
},
{
"input": "2829",
"output": "2829"
},
{
"input": "5000",
"output": "10"
},
{
"input": "20",
"output": "10"
},
{
"input": "68",
"output": "34"
},
{
"input": "3096",
"output": "258"
},
{
"input": "1024",
"output": "2"
},
{
"input": "1048576",
"output": "2"
},
{
"input": "413933789280",
"output": "25870861830"
},
{
"input": "817634153013",
"output": "817634153013"
},
{
"input": "56517269141",
"output": "56517269141"
},
{
"input": "30707328551",
"output": "30707328551"
},
{
"input": "279564127218",
"output": "10354226934"
},
{
"input": "491159577042",
"output": "18191095446"
},
{
"input": "734337660466",
"output": "734337660466"
},
{
"input": "808453785117",
"output": "808453785117"
},
{
"input": "55926835837",
"output": "55926835837"
},
{
"input": "294809951965",
"output": "294809951965"
},
{
"input": "537988035389",
"output": "76855433627"
},
{
"input": "822722434952",
"output": "205680608738"
},
{
"input": "699511759613",
"output": "699511759613"
},
{
"input": "942689843037",
"output": "104743315893"
},
{
"input": "663634158717",
"output": "663634158717"
},
{
"input": "213612977250",
"output": "11730"
},
{
"input": "999999999989",
"output": "999999999989"
},
{
"input": "999999999988",
"output": "499999999994"
},
{
"input": "87178291200",
"output": "30030"
},
{
"input": "927668721948",
"output": "463834360974"
},
{
"input": "562436815639",
"output": "37927"
},
{
"input": "302981118597",
"output": "35853"
},
{
"input": "5",
"output": "5"
},
{
"input": "9",
"output": "3"
},
{
"input": "36",
"output": "6"
},
{
"input": "2231",
"output": "2231"
},
{
"input": "27648",
"output": "6"
},
{
"input": "40320",
"output": "210"
},
{
"input": "648000",
"output": "30"
},
{
"input": "999966000289",
"output": "999983"
},
{
"input": "999985999949",
"output": "999985999949"
},
{
"input": "991921850317",
"output": "9973"
}
] | 1,575,478,207
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 9
| 2,000
| 0
|
n=int(input())
for i in range(2,n+1):
while n%(i*i)==0:
n//=i
print(n)
|
Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.
Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.
Input Specification:
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Output Specification:
Print the answer in one line.
Demo Input:
['10\n', '12\n']
Demo Output:
['10\n', '6\n']
Note:
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
|
```python
n=int(input())
for i in range(2,n+1):
while n%(i*i)==0:
n//=i
print(n)
```
| 0
|
|
985
|
C
|
Liebig's Barrels
|
PROGRAMMING
| 1,500
|
[
"greedy"
] | null | null |
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
|
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
|
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
|
[
"4 2 1\n2 2 1 2 3 2 2 3\n",
"2 1 0\n10 10\n",
"1 2 1\n5 2\n",
"3 2 1\n1 2 3 4 5 6\n"
] |
[
"7\n",
"20\n",
"2\n",
"0\n"
] |
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
| 0
|
[
{
"input": "4 2 1\n2 2 1 2 3 2 2 3",
"output": "7"
},
{
"input": "2 1 0\n10 10",
"output": "20"
},
{
"input": "1 2 1\n5 2",
"output": "2"
},
{
"input": "3 2 1\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "10 3 189\n267 697 667 4 52 128 85 616 142 344 413 660 962 194 618 329 266 593 558 447 89 983 964 716 32 890 267 164 654 71",
"output": "0"
},
{
"input": "10 3 453\n277 706 727 812 692 686 196 507 911 40 498 704 573 381 463 759 704 381 693 640 326 405 47 834 962 521 463 740 520 494",
"output": "2979"
},
{
"input": "10 3 795\n398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104",
"output": "5045"
},
{
"input": "6 2 29\n1 2 3 3 4 5 5 6 7 7 8 9",
"output": "28"
},
{
"input": "2 1 2\n1 2",
"output": "3"
}
] | 1,527,154,002
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 171
| 7,884,800
|
def binarySearchCount(arr,n,key):
left = 0
right = n
mid=0
while (left < right):
mid = left + (right-left)//2
if (arr[mid] == key):
while (mid+1<n and arr[mid+1] == key):
mid+=1
break
elif (arr[mid] > key):
right = mid
else:
left = mid + 1
while (arr[mid] > key):
mid-=1
return mid
n,k,l=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)
s=binarySearchCount(a,n*k,a[0]+l)
v=0
temp=s//k
i=0
count=0
if s > k or n==1 or k==1:
while i<temp:
v+=a[i]
i+=k
count+=1
for i in range(n-count):
v+=a[s-i]
print(v)
|
Title: Liebig's Barrels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *m*<==<=*n*·*k* wooden staves. The *i*-th stave has length *a**i*. You have to assemble *n* barrels consisting of *k* staves each, you can use any *k* staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume *v**j* of barrel *j* be equal to the length of the minimal stave in it.
You want to assemble exactly *n* barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed *l*, i.e. |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
Input Specification:
The first line contains three space-separated integers *n*, *k* and *l* (1<=≤<=*n*,<=*k*<=≤<=105, 1<=≤<=*n*·*k*<=≤<=105, 0<=≤<=*l*<=≤<=109).
The second line contains *m*<==<=*n*·*k* space-separated integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — lengths of staves.
Output Specification:
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly *n* barrels satisfying the condition |*v**x*<=-<=*v**y*|<=≤<=*l* for any 1<=≤<=*x*<=≤<=*n* and 1<=≤<=*y*<=≤<=*n*.
Demo Input:
['4 2 1\n2 2 1 2 3 2 2 3\n', '2 1 0\n10 10\n', '1 2 1\n5 2\n', '3 2 1\n1 2 3 4 5 6\n']
Demo Output:
['7\n', '20\n', '2\n', '0\n']
Note:
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
|
```python
def binarySearchCount(arr,n,key):
left = 0
right = n
mid=0
while (left < right):
mid = left + (right-left)//2
if (arr[mid] == key):
while (mid+1<n and arr[mid+1] == key):
mid+=1
break
elif (arr[mid] > key):
right = mid
else:
left = mid + 1
while (arr[mid] > key):
mid-=1
return mid
n,k,l=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)
s=binarySearchCount(a,n*k,a[0]+l)
v=0
temp=s//k
i=0
count=0
if s > k or n==1 or k==1:
while i<temp:
v+=a[i]
i+=k
count+=1
for i in range(n-count):
v+=a[s-i]
print(v)
```
| 0
|
|
327
|
B
|
Hungry Sequence
|
PROGRAMMING
| 1,200
|
[
"math"
] | null | null |
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in increasing order. That is an inequality *a**i*<=<<=*a**j* holds for any two indices *i*,<=*j* (*i*<=<<=*j*). - For any two indices *i* and *j* (*i*<=<<=*j*), *a**j* must not be divisible by *a**i*.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with *n* elements.
|
The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105).
|
Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
|
[
"3\n",
"5\n"
] |
[
"2 9 15\n",
"11 14 20 27 31\n"
] |
none
| 500
|
[
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3..."
},
{
"input": "100000",
"output": "300000 300001 300002 300003 300004 300005 300006 300007 300008 300009 300010 300011 300012 300013 300014 300015 300016 300017 300018 300019 300020 300021 300022 300023 300024 300025 300026 300027 300028 300029 300030 300031 300032 300033 300034 300035 300036 300037 300038 300039 300040 300041 300042 300043 300044 300045 300046 300047 300048 300049 300050 300051 300052 300053 300054 300055 300056 300057 300058 300059 300060 300061 300062 300063 300064 300065 300066 300067 300068 300069 300070 300071 300072 ..."
},
{
"input": "46550",
"output": "139650 139651 139652 139653 139654 139655 139656 139657 139658 139659 139660 139661 139662 139663 139664 139665 139666 139667 139668 139669 139670 139671 139672 139673 139674 139675 139676 139677 139678 139679 139680 139681 139682 139683 139684 139685 139686 139687 139688 139689 139690 139691 139692 139693 139694 139695 139696 139697 139698 139699 139700 139701 139702 139703 139704 139705 139706 139707 139708 139709 139710 139711 139712 139713 139714 139715 139716 139717 139718 139719 139720 139721 139722 ..."
},
{
"input": "61324",
"output": "183972 183973 183974 183975 183976 183977 183978 183979 183980 183981 183982 183983 183984 183985 183986 183987 183988 183989 183990 183991 183992 183993 183994 183995 183996 183997 183998 183999 184000 184001 184002 184003 184004 184005 184006 184007 184008 184009 184010 184011 184012 184013 184014 184015 184016 184017 184018 184019 184020 184021 184022 184023 184024 184025 184026 184027 184028 184029 184030 184031 184032 184033 184034 184035 184036 184037 184038 184039 184040 184041 184042 184043 184044 ..."
},
{
"input": "13176",
"output": "39528 39529 39530 39531 39532 39533 39534 39535 39536 39537 39538 39539 39540 39541 39542 39543 39544 39545 39546 39547 39548 39549 39550 39551 39552 39553 39554 39555 39556 39557 39558 39559 39560 39561 39562 39563 39564 39565 39566 39567 39568 39569 39570 39571 39572 39573 39574 39575 39576 39577 39578 39579 39580 39581 39582 39583 39584 39585 39586 39587 39588 39589 39590 39591 39592 39593 39594 39595 39596 39597 39598 39599 39600 39601 39602 39603 39604 39605 39606 39607 39608 39609 39610 39611 39612 3..."
},
{
"input": "73274",
"output": "219822 219823 219824 219825 219826 219827 219828 219829 219830 219831 219832 219833 219834 219835 219836 219837 219838 219839 219840 219841 219842 219843 219844 219845 219846 219847 219848 219849 219850 219851 219852 219853 219854 219855 219856 219857 219858 219859 219860 219861 219862 219863 219864 219865 219866 219867 219868 219869 219870 219871 219872 219873 219874 219875 219876 219877 219878 219879 219880 219881 219882 219883 219884 219885 219886 219887 219888 219889 219890 219891 219892 219893 219894 ..."
},
{
"input": "86947",
"output": "260841 260842 260843 260844 260845 260846 260847 260848 260849 260850 260851 260852 260853 260854 260855 260856 260857 260858 260859 260860 260861 260862 260863 260864 260865 260866 260867 260868 260869 260870 260871 260872 260873 260874 260875 260876 260877 260878 260879 260880 260881 260882 260883 260884 260885 260886 260887 260888 260889 260890 260891 260892 260893 260894 260895 260896 260897 260898 260899 260900 260901 260902 260903 260904 260905 260906 260907 260908 260909 260910 260911 260912 260913 ..."
},
{
"input": "26342",
"output": "79026 79027 79028 79029 79030 79031 79032 79033 79034 79035 79036 79037 79038 79039 79040 79041 79042 79043 79044 79045 79046 79047 79048 79049 79050 79051 79052 79053 79054 79055 79056 79057 79058 79059 79060 79061 79062 79063 79064 79065 79066 79067 79068 79069 79070 79071 79072 79073 79074 79075 79076 79077 79078 79079 79080 79081 79082 79083 79084 79085 79086 79087 79088 79089 79090 79091 79092 79093 79094 79095 79096 79097 79098 79099 79100 79101 79102 79103 79104 79105 79106 79107 79108 79109 79110 7..."
},
{
"input": "22345",
"output": "67035 67036 67037 67038 67039 67040 67041 67042 67043 67044 67045 67046 67047 67048 67049 67050 67051 67052 67053 67054 67055 67056 67057 67058 67059 67060 67061 67062 67063 67064 67065 67066 67067 67068 67069 67070 67071 67072 67073 67074 67075 67076 67077 67078 67079 67080 67081 67082 67083 67084 67085 67086 67087 67088 67089 67090 67091 67092 67093 67094 67095 67096 67097 67098 67099 67100 67101 67102 67103 67104 67105 67106 67107 67108 67109 67110 67111 67112 67113 67114 67115 67116 67117 67118 67119 6..."
},
{
"input": "19639",
"output": "58917 58918 58919 58920 58921 58922 58923 58924 58925 58926 58927 58928 58929 58930 58931 58932 58933 58934 58935 58936 58937 58938 58939 58940 58941 58942 58943 58944 58945 58946 58947 58948 58949 58950 58951 58952 58953 58954 58955 58956 58957 58958 58959 58960 58961 58962 58963 58964 58965 58966 58967 58968 58969 58970 58971 58972 58973 58974 58975 58976 58977 58978 58979 58980 58981 58982 58983 58984 58985 58986 58987 58988 58989 58990 58991 58992 58993 58994 58995 58996 58997 58998 58999 59000 59001 5..."
},
{
"input": "12337",
"output": "37011 37012 37013 37014 37015 37016 37017 37018 37019 37020 37021 37022 37023 37024 37025 37026 37027 37028 37029 37030 37031 37032 37033 37034 37035 37036 37037 37038 37039 37040 37041 37042 37043 37044 37045 37046 37047 37048 37049 37050 37051 37052 37053 37054 37055 37056 37057 37058 37059 37060 37061 37062 37063 37064 37065 37066 37067 37068 37069 37070 37071 37072 37073 37074 37075 37076 37077 37078 37079 37080 37081 37082 37083 37084 37085 37086 37087 37088 37089 37090 37091 37092 37093 37094 37095 3..."
},
{
"input": "67989",
"output": "203967 203968 203969 203970 203971 203972 203973 203974 203975 203976 203977 203978 203979 203980 203981 203982 203983 203984 203985 203986 203987 203988 203989 203990 203991 203992 203993 203994 203995 203996 203997 203998 203999 204000 204001 204002 204003 204004 204005 204006 204007 204008 204009 204010 204011 204012 204013 204014 204015 204016 204017 204018 204019 204020 204021 204022 204023 204024 204025 204026 204027 204028 204029 204030 204031 204032 204033 204034 204035 204036 204037 204038 204039 ..."
},
{
"input": "57610",
"output": "172830 172831 172832 172833 172834 172835 172836 172837 172838 172839 172840 172841 172842 172843 172844 172845 172846 172847 172848 172849 172850 172851 172852 172853 172854 172855 172856 172857 172858 172859 172860 172861 172862 172863 172864 172865 172866 172867 172868 172869 172870 172871 172872 172873 172874 172875 172876 172877 172878 172879 172880 172881 172882 172883 172884 172885 172886 172887 172888 172889 172890 172891 172892 172893 172894 172895 172896 172897 172898 172899 172900 172901 172902 ..."
},
{
"input": "63287",
"output": "189861 189862 189863 189864 189865 189866 189867 189868 189869 189870 189871 189872 189873 189874 189875 189876 189877 189878 189879 189880 189881 189882 189883 189884 189885 189886 189887 189888 189889 189890 189891 189892 189893 189894 189895 189896 189897 189898 189899 189900 189901 189902 189903 189904 189905 189906 189907 189908 189909 189910 189911 189912 189913 189914 189915 189916 189917 189918 189919 189920 189921 189922 189923 189924 189925 189926 189927 189928 189929 189930 189931 189932 189933 ..."
},
{
"input": "952",
"output": "2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2..."
},
{
"input": "77840",
"output": "233520 233521 233522 233523 233524 233525 233526 233527 233528 233529 233530 233531 233532 233533 233534 233535 233536 233537 233538 233539 233540 233541 233542 233543 233544 233545 233546 233547 233548 233549 233550 233551 233552 233553 233554 233555 233556 233557 233558 233559 233560 233561 233562 233563 233564 233565 233566 233567 233568 233569 233570 233571 233572 233573 233574 233575 233576 233577 233578 233579 233580 233581 233582 233583 233584 233585 233586 233587 233588 233589 233590 233591 233592 ..."
},
{
"input": "42157",
"output": "126471 126472 126473 126474 126475 126476 126477 126478 126479 126480 126481 126482 126483 126484 126485 126486 126487 126488 126489 126490 126491 126492 126493 126494 126495 126496 126497 126498 126499 126500 126501 126502 126503 126504 126505 126506 126507 126508 126509 126510 126511 126512 126513 126514 126515 126516 126517 126518 126519 126520 126521 126522 126523 126524 126525 126526 126527 126528 126529 126530 126531 126532 126533 126534 126535 126536 126537 126538 126539 126540 126541 126542 126543 ..."
},
{
"input": "46375",
"output": "139125 139126 139127 139128 139129 139130 139131 139132 139133 139134 139135 139136 139137 139138 139139 139140 139141 139142 139143 139144 139145 139146 139147 139148 139149 139150 139151 139152 139153 139154 139155 139156 139157 139158 139159 139160 139161 139162 139163 139164 139165 139166 139167 139168 139169 139170 139171 139172 139173 139174 139175 139176 139177 139178 139179 139180 139181 139182 139183 139184 139185 139186 139187 139188 139189 139190 139191 139192 139193 139194 139195 139196 139197 ..."
},
{
"input": "55142",
"output": "165426 165427 165428 165429 165430 165431 165432 165433 165434 165435 165436 165437 165438 165439 165440 165441 165442 165443 165444 165445 165446 165447 165448 165449 165450 165451 165452 165453 165454 165455 165456 165457 165458 165459 165460 165461 165462 165463 165464 165465 165466 165467 165468 165469 165470 165471 165472 165473 165474 165475 165476 165477 165478 165479 165480 165481 165482 165483 165484 165485 165486 165487 165488 165489 165490 165491 165492 165493 165494 165495 165496 165497 165498 ..."
},
{
"input": "60299",
"output": "180897 180898 180899 180900 180901 180902 180903 180904 180905 180906 180907 180908 180909 180910 180911 180912 180913 180914 180915 180916 180917 180918 180919 180920 180921 180922 180923 180924 180925 180926 180927 180928 180929 180930 180931 180932 180933 180934 180935 180936 180937 180938 180939 180940 180941 180942 180943 180944 180945 180946 180947 180948 180949 180950 180951 180952 180953 180954 180955 180956 180957 180958 180959 180960 180961 180962 180963 180964 180965 180966 180967 180968 180969 ..."
},
{
"input": "28862",
"output": "86586 86587 86588 86589 86590 86591 86592 86593 86594 86595 86596 86597 86598 86599 86600 86601 86602 86603 86604 86605 86606 86607 86608 86609 86610 86611 86612 86613 86614 86615 86616 86617 86618 86619 86620 86621 86622 86623 86624 86625 86626 86627 86628 86629 86630 86631 86632 86633 86634 86635 86636 86637 86638 86639 86640 86641 86642 86643 86644 86645 86646 86647 86648 86649 86650 86651 86652 86653 86654 86655 86656 86657 86658 86659 86660 86661 86662 86663 86664 86665 86666 86667 86668 86669 86670 8..."
},
{
"input": "48251",
"output": "144753 144754 144755 144756 144757 144758 144759 144760 144761 144762 144763 144764 144765 144766 144767 144768 144769 144770 144771 144772 144773 144774 144775 144776 144777 144778 144779 144780 144781 144782 144783 144784 144785 144786 144787 144788 144789 144790 144791 144792 144793 144794 144795 144796 144797 144798 144799 144800 144801 144802 144803 144804 144805 144806 144807 144808 144809 144810 144811 144812 144813 144814 144815 144816 144817 144818 144819 144820 144821 144822 144823 144824 144825 ..."
},
{
"input": "2",
"output": "6 7"
},
{
"input": "4",
"output": "12 13 14 15"
}
] | 1,655,744,160
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 3
| 1,000
| 0
|
l=[11,14,20,27,31]
n=int(input())
s=[]
if n<=5:
s=l[:n]
else:
s=l
c=0
d=n-5
e=31
while(c!=d):
e+=1
if e%11!=0 and e%14!=0 and e%20!=0 and e%27!=0 and e%31!=0:
f=0
for i in s:
if e%i!=0:
f+=1
if f==len(s):
s.append(e)
c+=1
for i in s:
print(i, end=" ")
|
Title: Hungry Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in increasing order. That is an inequality *a**i*<=<<=*a**j* holds for any two indices *i*,<=*j* (*i*<=<<=*j*). - For any two indices *i* and *j* (*i*<=<<=*j*), *a**j* must not be divisible by *a**i*.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with *n* elements.
Input Specification:
The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105).
Output Specification:
Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
Demo Input:
['3\n', '5\n']
Demo Output:
['2 9 15\n', '11 14 20 27 31\n']
Note:
none
|
```python
l=[11,14,20,27,31]
n=int(input())
s=[]
if n<=5:
s=l[:n]
else:
s=l
c=0
d=n-5
e=31
while(c!=d):
e+=1
if e%11!=0 and e%14!=0 and e%20!=0 and e%27!=0 and e%31!=0:
f=0
for i in s:
if e%i!=0:
f+=1
if f==len(s):
s.append(e)
c+=1
for i in s:
print(i, end=" ")
```
| 0
|
|
651
|
A
|
Joysticks
|
PROGRAMMING
| 1,100
|
[
"dp",
"greedy",
"implementation",
"math"
] | null | null |
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
|
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
|
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
|
[
"3 5\n",
"4 4\n"
] |
[
"6\n",
"5\n"
] |
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
| 500
|
[
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 8",
"output": "13"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "24 15",
"output": "36"
},
{
"input": "19 30",
"output": "47"
},
{
"input": "15 31",
"output": "44"
},
{
"input": "14 15",
"output": "27"
},
{
"input": "58 33",
"output": "89"
},
{
"input": "15 25",
"output": "38"
},
{
"input": "59 45",
"output": "102"
},
{
"input": "3 73",
"output": "74"
},
{
"input": "48 1",
"output": "47"
},
{
"input": "100 25",
"output": "122"
},
{
"input": "40 49",
"output": "86"
},
{
"input": "85 73",
"output": "155"
},
{
"input": "29 1",
"output": "28"
},
{
"input": "74 25",
"output": "97"
},
{
"input": "24 57",
"output": "78"
},
{
"input": "23 12",
"output": "33"
},
{
"input": "2 99",
"output": "99"
},
{
"input": "98 2",
"output": "97"
},
{
"input": "2 97",
"output": "97"
},
{
"input": "30 54",
"output": "81"
},
{
"input": "32 53",
"output": "82"
},
{
"input": "32 54",
"output": "84"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 2",
"output": "3"
}
] | 1,569,006,051
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 6
| 124
| 0
|
def main():
a, b = [int(v) for v in input().split()]
c= 0
while a>0 and b>0:
c+=1
if a>b:
b+=1
a-=2
else:
b-=2
a+=1
print(c)
if __name__ == "__main__":
main()
|
Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
Input Specification:
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output Specification:
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
Demo Input:
['3 5\n', '4 4\n']
Demo Output:
['6\n', '5\n']
Note:
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
|
```python
def main():
a, b = [int(v) for v in input().split()]
c= 0
while a>0 and b>0:
c+=1
if a>b:
b+=1
a-=2
else:
b-=2
a+=1
print(c)
if __name__ == "__main__":
main()
```
| 0
|
|
913
|
B
|
Christmas Spruce
|
PROGRAMMING
| 1,200
|
[
"implementation",
"trees"
] | null | null |
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a parent.
Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.
The definition of a rooted tree can be found [here](https://goo.gl/1dqvzz).
|
The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*).
Vertex 1 is the root. It's guaranteed that the root has at least 2 children.
|
Print "Yes" if the tree is a spruce and "No" otherwise.
|
[
"4\n1\n1\n1\n",
"7\n1\n1\n1\n2\n2\n2\n",
"8\n1\n1\n1\n1\n3\n3\n3\n"
] |
[
"Yes\n",
"No\n",
"Yes\n"
] |
The first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-width: 100.0%;max-height: 100.0%;"/>
It is not a spruce, because the non-leaf vertex 1 has only 2 leaf children.
The third example:
<img class="tex-graphics" src="https://espresso.codeforces.com/cf84a9e1585707f4ab06eff8eb1120a49b5e1ef7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 750
|
[
{
"input": "4\n1\n1\n1",
"output": "Yes"
},
{
"input": "7\n1\n1\n1\n2\n2\n2",
"output": "No"
},
{
"input": "8\n1\n1\n1\n1\n3\n3\n3",
"output": "Yes"
},
{
"input": "3\n1\n1",
"output": "No"
},
{
"input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10",
"output": "No"
},
{
"input": "7\n1\n2\n2\n1\n1\n1",
"output": "No"
},
{
"input": "7\n1\n1\n1\n1\n2\n2",
"output": "No"
},
{
"input": "8\n1\n1\n1\n1\n5\n5\n5",
"output": "Yes"
},
{
"input": "9\n1\n1\n1\n1\n2\n6\n6\n6",
"output": "No"
},
{
"input": "12\n1\n1\n1\n2\n5\n5\n5\n5\n1\n2\n2",
"output": "No"
},
{
"input": "20\n1\n1\n1\n1\n2\n2\n2\n3\n3\n3\n4\n4\n4\n5\n5\n5\n1\n1\n1",
"output": "Yes"
},
{
"input": "7\n1\n1\n1\n3\n3\n3",
"output": "No"
}
] | 1,690,438,982
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 46
| 0
|
vert = int(input())
vocab = {}
list = []
list_t = []
for i in range(1,vert ):
list.append([i,int(input())])
user_tipiks = []
list_ind = []
list_used_ind = []
count_feed_vert = len(list)
tupik_vetv = 1
for i in range(0,len(list)):
ind = list[i][0]
if ind == 1:
continue
list_ind.append(ind)
item = list[i][1]
if item != 1 and item not in user_tipiks:
user_tipiks.append(item)
tupik_vetv += 1
for i in range(0,len(list)):
item = list[i][1]
if item in list_ind and item not in list_used_ind:
list_used_ind.append(item)
count_feed_vert-=1
tupik_vetv = tupik_vetv*3
if(count_feed_vert == tupik_vetv):
print("Yes")
else:
print("No")
|
Title: Christmas Spruce
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a parent.
Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.
The definition of a rooted tree can be found [here](https://goo.gl/1dqvzz).
Input Specification:
The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*).
Vertex 1 is the root. It's guaranteed that the root has at least 2 children.
Output Specification:
Print "Yes" if the tree is a spruce and "No" otherwise.
Demo Input:
['4\n1\n1\n1\n', '7\n1\n1\n1\n2\n2\n2\n', '8\n1\n1\n1\n1\n3\n3\n3\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n']
Note:
The first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-width: 100.0%;max-height: 100.0%;"/>
It is not a spruce, because the non-leaf vertex 1 has only 2 leaf children.
The third example:
<img class="tex-graphics" src="https://espresso.codeforces.com/cf84a9e1585707f4ab06eff8eb1120a49b5e1ef7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
vert = int(input())
vocab = {}
list = []
list_t = []
for i in range(1,vert ):
list.append([i,int(input())])
user_tipiks = []
list_ind = []
list_used_ind = []
count_feed_vert = len(list)
tupik_vetv = 1
for i in range(0,len(list)):
ind = list[i][0]
if ind == 1:
continue
list_ind.append(ind)
item = list[i][1]
if item != 1 and item not in user_tipiks:
user_tipiks.append(item)
tupik_vetv += 1
for i in range(0,len(list)):
item = list[i][1]
if item in list_ind and item not in list_used_ind:
list_used_ind.append(item)
count_feed_vert-=1
tupik_vetv = tupik_vetv*3
if(count_feed_vert == tupik_vetv):
print("Yes")
else:
print("No")
```
| 0
|
|
143
|
A
|
Help Vasilisa the Wise 2
|
PROGRAMMING
| 1,000
|
[
"brute force",
"math"
] | null | null |
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
|
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
|
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
|
[
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] |
[
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] |
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
| 500
|
[
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
},
{
"input": "12 17\n10 19\n13 16",
"output": "-1"
},
{
"input": "11 11\n17 5\n12 10",
"output": "9 2\n8 3"
},
{
"input": "12 11\n11 12\n16 7",
"output": "-1"
},
{
"input": "5 9\n7 7\n8 6",
"output": "3 2\n4 5"
},
{
"input": "10 7\n4 13\n11 6",
"output": "-1"
},
{
"input": "18 10\n16 12\n12 16",
"output": "-1"
},
{
"input": "13 6\n10 9\n6 13",
"output": "-1"
},
{
"input": "14 16\n16 14\n18 12",
"output": "-1"
},
{
"input": "16 10\n16 10\n12 14",
"output": "-1"
},
{
"input": "11 9\n12 8\n11 9",
"output": "-1"
},
{
"input": "5 14\n10 9\n10 9",
"output": "-1"
},
{
"input": "2 4\n1 5\n3 3",
"output": "-1"
},
{
"input": "17 16\n14 19\n18 15",
"output": "-1"
},
{
"input": "12 12\n14 10\n16 8",
"output": "9 3\n5 7"
},
{
"input": "15 11\n16 10\n9 17",
"output": "7 8\n9 2"
},
{
"input": "8 10\n9 9\n13 5",
"output": "6 2\n3 7"
},
{
"input": "13 7\n10 10\n5 15",
"output": "4 9\n6 1"
},
{
"input": "14 11\n9 16\n16 9",
"output": "-1"
},
{
"input": "12 8\n14 6\n8 12",
"output": "-1"
},
{
"input": "10 6\n6 10\n4 12",
"output": "-1"
},
{
"input": "10 8\n10 8\n4 14",
"output": "-1"
},
{
"input": "14 13\n9 18\n14 13",
"output": "-1"
},
{
"input": "9 14\n8 15\n8 15",
"output": "-1"
},
{
"input": "3 8\n2 9\n6 5",
"output": "-1"
},
{
"input": "14 17\n18 13\n15 16",
"output": "-1"
},
{
"input": "16 14\n15 15\n17 13",
"output": "9 7\n6 8"
},
{
"input": "14 11\n16 9\n13 12",
"output": "9 5\n7 4"
},
{
"input": "13 10\n11 12\n7 16",
"output": "4 9\n7 3"
},
{
"input": "14 8\n11 11\n13 9",
"output": "8 6\n3 5"
},
{
"input": "12 11\n13 10\n10 13",
"output": "-1"
},
{
"input": "6 5\n2 9\n5 6",
"output": "-1"
},
{
"input": "7 8\n8 7\n12 3",
"output": "-1"
},
{
"input": "7 11\n7 11\n6 12",
"output": "-1"
},
{
"input": "8 5\n11 2\n8 5",
"output": "-1"
},
{
"input": "10 16\n14 12\n14 12",
"output": "-1"
},
{
"input": "7 9\n4 12\n5 11",
"output": "-1"
},
{
"input": "11 13\n19 5\n12 12",
"output": "-1"
},
{
"input": "8 12\n5 15\n11 9",
"output": "2 6\n3 9"
},
{
"input": "16 5\n13 8\n10 11",
"output": "9 7\n4 1"
},
{
"input": "3 14\n8 9\n10 7",
"output": "2 1\n6 8"
},
{
"input": "12 14\n11 15\n9 17",
"output": "3 9\n8 6"
},
{
"input": "13 7\n9 11\n14 6",
"output": "8 5\n1 6"
},
{
"input": "13 8\n15 6\n11 10",
"output": "9 4\n6 2"
},
{
"input": "9 6\n5 10\n3 12",
"output": "1 8\n4 2"
},
{
"input": "12 7\n5 14\n8 11",
"output": "3 9\n2 5"
},
{
"input": "9 12\n3 17\n10 10",
"output": "-1"
},
{
"input": "3 8\n4 6\n5 5",
"output": "-1"
}
] | 1,610,075,930
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 186
| 307,200
|
r,r2 = [int(x) for x in input().split()]
c,c2 = [int(x) for x in input().split()]
d,d2 = [int(x) for x in input().split()]
res = []
for x in range(1,10):
for y in range(1,10):
for z in range(1,10):
for k in range(1,10):
if x!=y and x!=z and x!=k and y!=z and y!=k and x+y==r and z+k==r2 and x+z==c and y+k==c2:
res = [x,y,z,k]
break
print(res[0],res[1])
print(res[2],res[3])
|
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
r,r2 = [int(x) for x in input().split()]
c,c2 = [int(x) for x in input().split()]
d,d2 = [int(x) for x in input().split()]
res = []
for x in range(1,10):
for y in range(1,10):
for z in range(1,10):
for k in range(1,10):
if x!=y and x!=z and x!=k and y!=z and y!=k and x+y==r and z+k==r2 and x+z==c and y+k==c2:
res = [x,y,z,k]
break
print(res[0],res[1])
print(res[2],res[3])
```
| 0
|
|
214
|
A
|
System of Equations
|
PROGRAMMING
| 800
|
[
"brute force"
] | null | null |
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
|
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
|
On a single line print the answer to the problem.
|
[
"9 3\n",
"14 28\n",
"4 20\n"
] |
[
"1\n",
"1\n",
"0\n"
] |
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
| 500
|
[
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,667,490,038
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 54
| 124
| 0
|
def solve(n, m):
valid_pairs_count = 0
valid_pairs = {}
a = 0
while (a ** 2) <= n:
b = n - (a ** 2)
if int(b) == b: # checks to see if b is an integer
valid_pairs[(a, b)] = True
a += 1
b = 0
while (b ** 2) <= m:
a = m - (b ** 2)
if int(a) == a:
if (a, b) in valid_pairs:
valid_pairs_count += 1
b += 1
return valid_pairs_count
if __name__ == "__main__":
n, m = [int(_) for _ in input().split(sep=" ")]
result = solve(n, m)
print(result)
|
Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
|
```python
def solve(n, m):
valid_pairs_count = 0
valid_pairs = {}
a = 0
while (a ** 2) <= n:
b = n - (a ** 2)
if int(b) == b: # checks to see if b is an integer
valid_pairs[(a, b)] = True
a += 1
b = 0
while (b ** 2) <= m:
a = m - (b ** 2)
if int(a) == a:
if (a, b) in valid_pairs:
valid_pairs_count += 1
b += 1
return valid_pairs_count
if __name__ == "__main__":
n, m = [int(_) for _ in input().split(sep=" ")]
result = solve(n, m)
print(result)
```
| 3
|
|
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,645,420,224
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 12
| 93
| 4,812,800
|
n,k=map(int,input().split())
a=[int(x)for x in input().split()]
cur=1
for i in range(n-1):
if cur>=n-1:print('NO');break
cur += a[cur-1]
if cur==k:
print('YES');break
|
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,k=map(int,input().split())
a=[int(x)for x in input().split()]
cur=1
for i in range(n-1):
if cur>=n-1:print('NO');break
cur += a[cur-1]
if cur==k:
print('YES');break
```
| 0
|
|
999
|
B
|
Reversing Encryption
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.
|
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
|
Print a string $s$ such that the above algorithm results in $t$.
|
[
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] |
[
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] |
The first example is described in the problem statement.
| 0
|
[
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\njfyy",
"output": "yyjf"
},
{
"input": "6\nkrdych",
"output": "hcyrkd"
},
{
"input": "60\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj",
"output": "jqprcbfgsxwgjhmkehcoiwwltuxjzokamzpalobnfespcvmoecqigyuutueu"
},
{
"input": "64\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy",
"output": "ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh"
},
{
"input": "97\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacygakhxoubibxtqkpyyhzjipylujgrc",
"output": "crgjulypijzhyypkqtxbibuoxhkagycauuqgchyaokulsbfbnsazfrkcgibxucwgwdalcelhuoqdibceswtjiabubmhdmrqnq"
},
{
"input": "100\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf",
"output": "fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi"
},
{
"input": "96\nqtbcksuvxonzbkokhqlgkrvimzqmqnrvqlihrmksldyydacbtckfphenxszcnzhfjmpeykrvshgiboivkvabhrpphgavvprz",
"output": "zrpvvaghpprhbavkviobighsvrkyepmjfhznczsxnehpfkctvrnqmqzmkokbvuctqbksxonzhqlgkrviqlihrmksldyydacb"
},
{
"input": "90\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "89\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
},
{
"input": "99\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "100\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"output": "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
},
{
"input": "60\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwnwwwwwwwwwwhwwwxwwwwwwwwwfhwwwwawwwwww"
},
{
"input": "90\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc",
"output": "cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc"
},
{
"input": "97\nfwffffffffffffffffffffffffrffffffffffffffzfffffffffffffffftfcfffffffqffffffffffffffffffffffyfffff",
"output": "fffffyffffffffffffffffffffffqfffffffcftffffffffffffffffzffffffffffffffrffffffffffffffffffffffffwf"
},
{
"input": "100\ndjjjjjjjjjjgjjjjjjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjjjjajjjjjjajjjjjjrjjjjjjjjjjjjrjjtjjjjjjjjjjjjjojjj",
"output": "jjjojjjjjjjjjjjjjtjjrjjjjjjjjjjjjrjjjjjjajjjjjjajjjjjjjjjjjjjjdjjjgjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjj"
}
] | 1,613,939,704
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 62
| 0
|
n=int(input())
s=input()
for i in range(2, n+1):
if n%i==0:
z=str()
for j in range(i-1, -1, -1):
z=z+s[j]
for j in range(i, n):
z=z+s[j]
s=z
print(s)
|
Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.
Input Specification:
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Output Specification:
Print a string $s$ such that the above algorithm results in $t$.
Demo Input:
['10\nrocesfedoc\n', '16\nplmaetwoxesisiht\n', '1\nz\n']
Demo Output:
['codeforces\n', 'thisisexampletwo\n', 'z\n']
Note:
The first example is described in the problem statement.
|
```python
n=int(input())
s=input()
for i in range(2, n+1):
if n%i==0:
z=str()
for j in range(i-1, -1, -1):
z=z+s[j]
for j in range(i, n):
z=z+s[j]
s=z
print(s)
```
| 3
|
|
515
|
B
|
Drazil and His Happy Friends
|
PROGRAMMING
| 1,300
|
[
"brute force",
"dsu",
"meet-in-the-middle",
"number theory"
] | null | null |
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, *i* starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
|
The first line contains two integer *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains integer *b* (0<=≤<=*b*<=≤<=*n*), denoting the number of happy boys among friends of Drazil, and then follow *b* distinct integers *x*1,<=*x*2,<=...,<=*x**b* (0<=≤<=*x**i*<=<<=*n*), denoting the list of indices of happy boys.
The third line conatins integer *g* (0<=≤<=*g*<=≤<=*m*), denoting the number of happy girls among friends of Drazil, and then follow *g* distinct integers *y*1,<=*y*2,<=... ,<=*y**g* (0<=≤<=*y**j*<=<<=*m*), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
|
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
|
[
"2 3\n0\n1 0\n",
"2 4\n1 0\n1 2\n",
"2 3\n1 0\n1 1\n"
] |
[
"Yes\n",
"No\n",
"Yes\n"
] |
By <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/169ade208e6eb4f9263c57aaff716529d59c3288.png" style="max-width: 100.0%;max-height: 100.0%;"/> we define the remainder of integer division of *i* by *k*.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. - On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. - On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. - On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
| 1,000
|
[
{
"input": "2 3\n0\n1 0",
"output": "Yes"
},
{
"input": "2 4\n1 0\n1 2",
"output": "No"
},
{
"input": "2 3\n1 0\n1 1",
"output": "Yes"
},
{
"input": "16 88\n6 5 14 2 0 12 7\n30 21 64 35 79 74 39 63 44 81 73 0 27 33 69 12 86 46 20 25 55 52 7 58 23 5 60 32 41 50 82",
"output": "Yes"
},
{
"input": "52 91\n13 26 1 3 43 17 19 32 46 33 48 23 37 50\n25 78 26 1 40 2 67 42 4 56 30 70 84 32 20 85 59 8 86 34 73 23 10 88 24 11",
"output": "No"
},
{
"input": "26 52\n8 0 14 16 17 7 9 10 11\n15 39 15 2 41 42 30 17 18 31 6 21 35 48 50 51",
"output": "No"
},
{
"input": "50 50\n0\n0",
"output": "No"
},
{
"input": "27 31\n4 25 5 19 20\n26 5 28 17 2 1 0 26 23 12 29 6 4 25 19 15 13 20 24 8 27 22 30 3 10 9 7",
"output": "Yes"
},
{
"input": "55 79\n5 51 27 36 45 53\n30 15 28 0 5 38 3 34 30 35 1 32 12 27 42 39 69 33 10 63 16 29 76 19 60 70 67 31 78 68 45",
"output": "Yes"
},
{
"input": "79 23\n35 31 62 14 9 46 18 68 69 42 13 50 77 23 76 5 53 40 16 32 74 54 38 25 45 39 26 37 66 78 3 48 10 17 56 59\n13 16 0 8 6 18 14 21 11 20 4 15 13 22",
"output": "Yes"
},
{
"input": "7 72\n1 4\n3 49 32 28",
"output": "Yes"
},
{
"input": "100 50\n31 52 54 8 60 61 62 63 64 16 19 21 73 25 76 77 79 30 81 32 33 34 37 88 39 40 91 42 94 95 96 98\n18 0 1 3 5 6 7 9 15 18 20 22 24 28 35 36 43 47 49",
"output": "No"
},
{
"input": "98 49\n33 0 51 52 6 57 10 12 63 15 16 19 20 21 72 73 74 76 77 78 30 31 81 33 83 37 38 39 40 92 44 45 95 97\n15 4 5 7 9 11 13 17 18 22 26 35 36 41 42 47",
"output": "No"
},
{
"input": "50 50\n14 7 8 12 16 18 22 23 24 28 30 35 40 46 49\n35 0 1 2 3 4 5 6 9 10 11 13 14 15 17 19 20 21 25 26 27 29 31 32 33 34 36 37 38 39 41 43 44 45 47 48",
"output": "No"
},
{
"input": "30 44\n3 8 26 28\n6 2 30 38 26 8 6",
"output": "No"
},
{
"input": "69 72\n18 58 46 52 43 1 55 16 7 4 38 68 14 32 53 41 29 2 59\n21 22 43 55 13 70 4 7 31 10 23 56 44 62 17 50 53 5 41 11 65 32",
"output": "No"
},
{
"input": "76 28\n10 24 13 61 45 29 57 41 21 37 11\n2 12 9",
"output": "No"
},
{
"input": "65 75\n15 25 60 12 62 37 22 47 52 3 63 58 13 14 49 34\n18 70 10 2 52 22 47 72 57 38 48 13 73 3 19 4 74 49 34",
"output": "No"
},
{
"input": "6 54\n1 5\n14 13 49 31 37 44 2 15 51 52 22 28 10 35 47",
"output": "No"
},
{
"input": "96 36\n34 84 24 0 48 85 13 61 37 62 38 86 75 3 16 64 40 28 76 53 5 17 42 6 7 91 67 55 68 92 57 11 71 35 59\n9 1 14 15 17 18 30 6 8 35",
"output": "No"
},
{
"input": "40 40\n23 0 2 3 4 5 7 11 15 16 17 18 19 22 25 28 29 30 31 32 34 35 36 37\n16 1 6 8 9 10 12 13 14 20 21 23 24 26 27 38 39",
"output": "No"
},
{
"input": "66 66\n24 2 35 3 36 4 5 10 45 14 48 18 51 19 21 55 22 23 24 25 26 63 31 65 32\n21 0 1 37 6 40 7 8 42 45 13 15 16 50 53 23 24 60 28 62 63 31",
"output": "No"
},
{
"input": "20 20\n9 0 3 4 6 7 8 10 12 13\n10 1 2 5 9 11 14 15 16 18 19",
"output": "No"
},
{
"input": "75 30\n18 46 47 32 33 3 34 35 21 51 7 9 54 39 72 42 59 29 14\n8 0 17 5 6 23 26 27 13",
"output": "No"
},
{
"input": "100 50\n30 50 54 7 8 59 60 61 62 63 64 15 16 18 19 20 22 73 27 79 83 86 87 89 42 93 94 45 46 97 98\n20 1 2 3 5 6 17 21 24 25 26 28 30 31 32 34 35 38 40 41 49",
"output": "Yes"
},
{
"input": "98 98\n43 49 1 51 3 53 4 55 56 8 9 10 60 11 12 61 64 16 65 17 19 20 21 72 24 74 25 77 78 31 34 35 36 37 87 88 89 42 92 43 44 94 46 96\n34 50 2 52 5 54 9 62 63 15 18 68 70 22 72 75 26 27 77 30 81 82 83 35 36 37 87 88 89 90 41 93 95 96 48",
"output": "No"
},
{
"input": "100 100\n45 50 1 4 5 55 7 8 10 60 61 62 63 14 65 66 17 18 20 21 22 24 25 27 78 28 29 30 31 82 83 33 84 36 37 38 39 40 41 42 44 45 46 48 98 49\n34 50 1 2 52 3 54 56 7 9 59 61 14 16 67 18 69 22 73 24 76 79 81 82 84 35 36 38 39 90 43 44 45 47 49",
"output": "No"
},
{
"input": "76 72\n29 4 64 68 20 8 12 50 42 46 0 70 11 37 75 47 45 29 17 19 73 9 41 31 35 67 65 39 51 55\n25 60 32 48 42 8 6 9 7 31 19 25 5 33 51 61 67 55 49 27 29 53 39 65 35 13",
"output": "Yes"
},
{
"input": "39 87\n16 18 15 30 33 21 9 3 31 16 10 34 20 35 8 26 23\n36 33 75 81 24 42 54 78 39 57 60 30 36 63 4 76 25 1 40 73 22 58 49 85 31 74 59 20 44 83 65 23 41 71 47 14 35",
"output": "Yes"
},
{
"input": "36 100\n10 0 32 4 5 33 30 18 14 35 7\n29 60 32 20 4 16 69 5 38 50 46 74 94 18 82 2 66 22 42 55 51 91 67 75 35 95 43 79 3 27",
"output": "Yes"
},
{
"input": "90 25\n26 55 30 35 20 15 26 6 1 41 81 76 46 57 17 12 67 77 27 47 62 8 43 63 3 48 19\n9 10 16 21 7 17 12 13 19 9",
"output": "Yes"
},
{
"input": "66 66\n26 0 54 6 37 43 13 25 38 2 32 56 20 50 39 27 51 9 64 4 16 17 65 11 5 47 23\n15 6 24 43 49 25 20 14 63 27 3 58 52 53 11 41",
"output": "No"
},
{
"input": "24 60\n4 0 2 19 23\n15 12 24 49 2 14 3 52 28 5 6 19 32 33 34 35",
"output": "Yes"
},
{
"input": "80 40\n27 0 41 44 45 6 47 8 10 52 13 14 16 17 18 59 21 62 23 64 26 68 29 32 75 37 78 39\n13 2 3 9 11 15 20 25 27 30 31 33 34 36",
"output": "Yes"
},
{
"input": "66 99\n23 33 35 36 38 8 10 44 11 45 46 47 50 19 54 22 55 23 58 59 27 61 30 65\n32 33 67 69 4 70 38 6 39 7 74 42 9 43 12 13 14 15 81 82 84 85 20 87 89 90 24 58 59 27 95 97 31",
"output": "Yes"
},
{
"input": "100 40\n25 61 42 2 3 25 46 66 68 69 49 9 10 50 91 72 92 33 73 53 14 15 55 96 36 39\n12 0 22 3 23 4 6 27 11 35 37 38 39",
"output": "Yes"
},
{
"input": "90 30\n27 15 16 2 32 78 49 64 65 50 6 66 21 22 82 23 39 84 85 10 86 56 27 87 13 58 44 74\n7 19 4 20 24 25 12 27",
"output": "No"
},
{
"input": "75 75\n33 30 74 57 23 19 42 71 11 44 29 58 43 48 61 63 13 27 50 17 18 70 64 39 12 32 36 10 40 51 49 1 54 73\n8 43 23 0 7 63 47 74 28",
"output": "No"
},
{
"input": "98 98\n23 6 81 90 28 38 51 23 69 13 95 15 16 88 58 10 26 42 44 54 92 27 45 39\n18 20 70 38 82 72 61 37 78 74 23 15 56 59 35 93 64 28 57",
"output": "No"
},
{
"input": "75 75\n19 48 3 5 67 23 8 70 45 63 36 38 56 15 10 37 52 11 9 27\n21 13 9 45 28 59 36 30 43 5 38 27 40 50 17 41 71 8 51 63 1 33",
"output": "No"
},
{
"input": "3 20\n0\n1 19",
"output": "Yes"
},
{
"input": "41 2\n1 33\n0",
"output": "Yes"
},
{
"input": "50 49\n1 49\n0",
"output": "Yes"
},
{
"input": "3 50\n0\n1 49",
"output": "Yes"
},
{
"input": "100 100\n50 0 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\n49 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",
"output": "No"
},
{
"input": "100 100\n50 0 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\n50 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",
"output": "Yes"
},
{
"input": "91 98\n78 0 1 2 3 4 5 7 8 9 10 11 12 14 15 16 17 18 19 21 22 23 24 25 26 28 29 30 31 32 33 35 36 37 38 39 40 42 43 44 45 46 47 49 50 51 52 53 54 56 57 58 59 60 61 63 64 65 66 67 68 70 71 72 73 74 75 77 78 79 80 81 82 84 85 86 87 88 89\n84 0 1 2 3 4 5 7 8 9 10 11 12 14 15 16 17 18 19 21 22 23 24 25 26 28 29 30 31 32 33 35 36 37 38 39 40 42 43 44 45 46 47 49 50 51 52 53 54 56 57 58 59 60 61 63 64 65 66 67 68 70 71 72 73 74 75 77 78 79 80 81 82 84 85 86 87 88 89 91 92 93 94 95 96",
"output": "No"
},
{
"input": "99 84\n66 0 2 3 5 6 8 9 11 12 14 15 17 18 20 21 23 24 26 27 29 30 32 33 35 36 38 39 41 42 44 45 47 48 50 51 53 54 56 57 59 60 62 63 65 66 68 69 71 72 74 75 77 78 80 81 83 84 86 87 89 90 92 93 95 96 98\n56 0 2 3 5 6 8 9 11 12 14 15 17 18 20 21 23 24 26 27 29 30 32 33 35 36 38 39 41 42 44 45 47 48 50 51 53 54 56 57 59 60 62 63 65 66 68 69 71 72 74 75 77 78 80 81 83",
"output": "No"
},
{
"input": "75 90\n60 0 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 22 23 24 25 27 28 29 30 32 33 34 35 37 38 39 40 42 43 44 45 47 48 49 50 52 53 54 55 57 58 59 60 62 63 64 65 67 68 69 70 72 73 74\n72 0 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 22 23 24 25 27 28 29 30 32 33 34 35 37 38 39 40 42 43 44 45 47 48 49 50 52 53 54 55 57 58 59 60 62 63 64 65 67 68 69 70 72 73 74 75 77 78 79 80 82 83 84 85 87 88 89",
"output": "No"
},
{
"input": "5 7\n1 0\n1 0",
"output": "Yes"
},
{
"input": "100 1\n1 99\n0",
"output": "Yes"
},
{
"input": "4 1\n1 3\n0",
"output": "Yes"
},
{
"input": "4 5\n3 0 1 3\n4 0 1 3 4",
"output": "Yes"
},
{
"input": "100 99\n1 99\n0",
"output": "Yes"
},
{
"input": "2 3\n1 0\n2 0 2",
"output": "Yes"
}
] | 1,599,329,127
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 56
| 140
| 1,331,200
|
n, m = [int(p) for p in input().split()]
arrb = [int(p) for p in input().split()]
arrg = [int(p) for p in input().split()]
arrb.pop(0)
arrg.pop(0)
cb = [False]*n
cg = [False]*m
for i in arrb:
cb[i] = True
for i in arrg:
cg[i] = True
i = 0
while i < 10**5:
b = cb[i%n]
g = cg[i%m]
if b and g:
i += 1
continue
elif b and not g:
cg[i%m] = True
elif not b and g:
cb[i%n] = True
else:
i += 1
continue
i += 1
if all(cb) and all(cg):
print('Yes')
else:
print('No')
|
Title: Drazil and His Happy Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are *n* boys and *m* girls among his friends. Let's number them from 0 to *n*<=-<=1 and 0 to *m*<=-<=1 separately. In *i*-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, *i* starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
Input Specification:
The first line contains two integer *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains integer *b* (0<=≤<=*b*<=≤<=*n*), denoting the number of happy boys among friends of Drazil, and then follow *b* distinct integers *x*1,<=*x*2,<=...,<=*x**b* (0<=≤<=*x**i*<=<<=*n*), denoting the list of indices of happy boys.
The third line conatins integer *g* (0<=≤<=*g*<=≤<=*m*), denoting the number of happy girls among friends of Drazil, and then follow *g* distinct integers *y*1,<=*y*2,<=... ,<=*y**g* (0<=≤<=*y**j*<=<<=*m*), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
Output Specification:
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
Demo Input:
['2 3\n0\n1 0\n', '2 4\n1 0\n1 2\n', '2 3\n1 0\n1 1\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n']
Note:
By <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/169ade208e6eb4f9263c57aaff716529d59c3288.png" style="max-width: 100.0%;max-height: 100.0%;"/> we define the remainder of integer division of *i* by *k*.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. - On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. - On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. - On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. - On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
|
```python
n, m = [int(p) for p in input().split()]
arrb = [int(p) for p in input().split()]
arrg = [int(p) for p in input().split()]
arrb.pop(0)
arrg.pop(0)
cb = [False]*n
cg = [False]*m
for i in arrb:
cb[i] = True
for i in arrg:
cg[i] = True
i = 0
while i < 10**5:
b = cb[i%n]
g = cg[i%m]
if b and g:
i += 1
continue
elif b and not g:
cg[i%m] = True
elif not b and g:
cb[i%n] = True
else:
i += 1
continue
i += 1
if all(cb) and all(cg):
print('Yes')
else:
print('No')
```
| 3
|
|
4
|
C
|
Registration System
|
PROGRAMMING
| 1,300
|
[
"data structures",
"hashing",
"implementation"
] |
C. Registration system
|
5
|
64
|
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
|
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
|
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
|
[
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] |
[
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] |
none
| 0
|
[
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
},
{
"input": "3\nb\nb\nb",
"output": "OK\nb1\nb2"
},
{
"input": "2\nc\ncn",
"output": "OK\nOK"
},
{
"input": "3\nvhn\nvhn\nh",
"output": "OK\nvhn1\nOK"
},
{
"input": "4\nd\nhd\nd\nh",
"output": "OK\nOK\nd1\nOK"
},
{
"input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp",
"output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9"
},
{
"input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh",
"output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7"
},
{
"input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj",
"output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4"
},
{
"input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzz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CEEDED
|
TESTS
| 6
| 5,000
| 1,126,400
|
a = int(input())
x1 = input()
dataBase = ["OK"]
repeats = [x1]
for i in range(a-1):
x = input()
c=0
int(c)
for j in range(len(repeats)):
if x == repeats[j]:
c+=1
c = str(c)
repeats.append(x)
x+=c
if c == "0" :
dataBase.append("OK")
else:
dataBase.append(x)
for i in range(len(dataBase)):
print(dataBase[i])
|
Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Output Specification:
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
Demo Input:
['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n']
Demo Output:
['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n']
Note:
none
|
```python
a = int(input())
x1 = input()
dataBase = ["OK"]
repeats = [x1]
for i in range(a-1):
x = input()
c=0
int(c)
for j in range(len(repeats)):
if x == repeats[j]:
c+=1
c = str(c)
repeats.append(x)
x+=c
if c == "0" :
dataBase.append("OK")
else:
dataBase.append(x)
for i in range(len(dataBase)):
print(dataBase[i])
```
| 0
|
817
|
C
|
Really Big Numbers
|
PROGRAMMING
| 1,600
|
[
"binary search",
"brute force",
"dp",
"math"
] | null | null |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
|
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
|
Print one integer — the quantity of really big numbers that are not greater than *n*.
|
[
"12 1\n",
"25 20\n",
"10 9\n"
] |
[
"3\n",
"0\n",
"1\n"
] |
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9).
| 0
|
[
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input": "10000 1000",
"output": "8991"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 100000000000000000",
"output": "899999999999999991"
},
{
"input": "1000000000000000000 10000000000000000",
"output": "989999999999999991"
},
{
"input": "1000000000000000000 1000000000000000",
"output": "998999999999999991"
},
{
"input": "1000000000000000000 100000000000000",
"output": "999899999999999991"
},
{
"input": "1000000000000000000 200000000000000000",
"output": "799999999999999991"
},
{
"input": "10 5",
"output": "1"
},
{
"input": "20 5",
"output": "11"
},
{
"input": "20 9",
"output": "11"
},
{
"input": "100 9",
"output": "91"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "130 118",
"output": "1"
},
{
"input": "190 181",
"output": "0"
},
{
"input": "1999 1971",
"output": "10"
},
{
"input": "100 99",
"output": "1"
},
{
"input": "6909094398 719694282",
"output": "6189400069"
},
{
"input": "260 258",
"output": "0"
},
{
"input": "35 19",
"output": "6"
},
{
"input": "100 87",
"output": "1"
},
{
"input": "91 89",
"output": "0"
},
{
"input": "109 89",
"output": "10"
},
{
"input": "109 91",
"output": "10"
},
{
"input": "20331 11580",
"output": "8732"
},
{
"input": "405487470 255750281",
"output": "149737161"
},
{
"input": "17382 12863",
"output": "4493"
},
{
"input": "19725 14457",
"output": "5246"
},
{
"input": "24848 15384",
"output": "9449"
},
{
"input": "25727 15982",
"output": "9728"
},
{
"input": "109 90",
"output": "10"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "1"
},
{
"input": "1000000000000000000 999999999999999998",
"output": "1"
},
{
"input": "1009 980",
"output": "10"
},
{
"input": "999999999999999999 999999999999999838",
"output": "0"
},
{
"input": "1000000000000000000 99999999999999800",
"output": "900000000000000061"
},
{
"input": "8785369357 3377262261",
"output": "5408107058"
},
{
"input": "110 109",
"output": "0"
},
{
"input": "999 777",
"output": "200"
},
{
"input": "327170000015578 77230000029054",
"output": "249939999986479"
},
{
"input": "12515000022229 1791000022317",
"output": "10723999999880"
},
{
"input": "9999999999999 9999999999882",
"output": "10"
},
{
"input": "213 196",
"output": "14"
},
{
"input": "92 82",
"output": "0"
},
{
"input": "148 136",
"output": "0"
},
{
"input": "8 9",
"output": "0"
},
{
"input": "309 299",
"output": "0"
},
{
"input": "9999 9963",
"output": "10"
},
{
"input": "82 81",
"output": "0"
},
{
"input": "9999999 9999936",
"output": "10"
},
{
"input": "171 155",
"output": "2"
},
{
"input": "999 972",
"output": "10"
},
{
"input": "999999999999 999999999891",
"output": "10"
},
{
"input": "9 9",
"output": "0"
},
{
"input": "6900 6885",
"output": "1"
},
{
"input": "96 57",
"output": "27"
},
{
"input": "5 4",
"output": "0"
},
{
"input": "17386 5814",
"output": "11557"
},
{
"input": "493679757404593 316259583979965",
"output": "177420173424564"
},
{
"input": "18474 9478",
"output": "8975"
},
{
"input": "270091571496186 250931112649966",
"output": "19160458846177"
},
{
"input": "565751690089037 381448507916936",
"output": "184303182172038"
},
{
"input": "19 10",
"output": "0"
}
] | 1,497,543,367
| 4,267
|
Python 3
|
OK
|
TESTS
| 68
| 62
| 0
|
def f(x):
ans = x
while x > 0:
ans -= x % 10
x //= 10
return ans
n, s = map(int, input().split())
if f(n) < s:
print(0)
exit(0)
l, r = 1, n
while l < r:
m = (l + r) // 2
if f(m) >= s:
r = (m // 10) * 10
else:
l = m + 1
print(n - l + 1)
|
Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input Specification:
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Output Specification:
Print one integer — the quantity of really big numbers that are not greater than *n*.
Demo Input:
['12 1\n', '25 20\n', '10 9\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9).
|
```python
def f(x):
ans = x
while x > 0:
ans -= x % 10
x //= 10
return ans
n, s = map(int, input().split())
if f(n) < s:
print(0)
exit(0)
l, r = 1, n
while l < r:
m = (l + r) // 2
if f(m) >= s:
r = (m // 10) * 10
else:
l = m + 1
print(n - l + 1)
```
| 3
|
|
807
|
A
|
Is it rated?
|
PROGRAMMING
| 900
|
[
"implementation",
"sortings"
] | null | null |
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
|
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
|
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
|
[
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] |
[
"rated\n",
"unrated\n",
"maybe\n"
] |
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
| 500
|
[
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n1 1\n1 1",
"output": "maybe"
},
{
"input": "2\n4126 4126\n4126 4126",
"output": "maybe"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423",
"output": "rated"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110",
"output": "unrated"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143",
"output": "maybe"
},
{
"input": "2\n3936 3936\n2967 2967",
"output": "maybe"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 1\n1 2",
"output": "rated"
},
{
"input": "2\n2967 2967\n3936 3936",
"output": "unrated"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300",
"output": "unrated"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n3 2\n3 2",
"output": "rated"
},
{
"input": "3\n5 5\n4 4\n3 4",
"output": "rated"
},
{
"input": "3\n200 200\n200 200\n300 300",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699",
"output": "maybe"
},
{
"input": "2\n10 10\n8 8",
"output": "maybe"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80",
"output": "unrated"
},
{
"input": "2\n1 2\n2 1",
"output": "rated"
},
{
"input": "3\n5 5\n4 3\n3 3",
"output": "rated"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450",
"output": "rated"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700",
"output": "unrated"
},
{
"input": "2\n1600 1600\n1400 1400",
"output": "maybe"
},
{
"input": "2\n3 1\n9 8",
"output": "rated"
},
{
"input": "2\n2 1\n1 1",
"output": "rated"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670",
"output": "unrated"
},
{
"input": "2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n10 11\n5 4",
"output": "rated"
},
{
"input": "2\n15 14\n13 12",
"output": "rated"
},
{
"input": "2\n2 1\n2 2",
"output": "rated"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106",
"output": "unrated"
},
{
"input": "3\n4 5\n3 3\n2 2",
"output": "rated"
},
{
"input": "2\n10 9\n10 10",
"output": "rated"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100",
"output": "rated"
},
{
"input": "2\n3 3\n5 5",
"output": "unrated"
},
{
"input": "2\n1500 1500\n3000 2000",
"output": "rated"
},
{
"input": "2\n5 6\n5 5",
"output": "rated"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500",
"output": "rated"
},
{
"input": "2\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n1 2\n1 1",
"output": "rated"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n15 14\n14 13",
"output": "rated"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900",
"output": "unrated"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884",
"output": "rated"
},
{
"input": "2\n100 99\n100 100",
"output": "rated"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n100 101\n100 100\n100 100",
"output": "rated"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890",
"output": "rated"
},
{
"input": "2\n2 3\n1 1",
"output": "rated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n3 2\n2 2",
"output": "rated"
},
{
"input": "2\n3 2\n3 3",
"output": "rated"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n3 2\n3 3\n3 3",
"output": "rated"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "3\n1000 1000\n500 500\n400 300",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000",
"output": "unrated"
},
{
"input": "2\n1 1\n2 3",
"output": "rated"
},
{
"input": "2\n6 2\n6 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246",
"output": "unrated"
},
{
"input": "2\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699",
"output": "maybe"
},
{
"input": "2\n20 30\n10 5",
"output": "rated"
},
{
"input": "3\n1 1\n2 2\n1 1",
"output": "unrated"
},
{
"input": "2\n1 2\n3 3",
"output": "rated"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 2\n2 1",
"output": "rated"
},
{
"input": "2\n100 100\n90 89",
"output": "rated"
},
{
"input": "2\n1000 900\n2000 2000",
"output": "rated"
},
{
"input": "2\n50 10\n10 50",
"output": "rated"
},
{
"input": "2\n200 200\n100 100",
"output": "maybe"
},
{
"input": "3\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "3\n1000 1000\n300 300\n100 100",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4",
"output": "unrated"
},
{
"input": "2\n5 3\n6 3",
"output": "rated"
},
{
"input": "2\n1200 1100\n1200 1000",
"output": "rated"
},
{
"input": "2\n5 5\n4 4",
"output": "maybe"
},
{
"input": "2\n5 5\n3 3",
"output": "maybe"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100",
"output": "unrated"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6",
"output": "maybe"
},
{
"input": "3\n1000 1000\n300 300\n10 10",
"output": "maybe"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n3 3\n1 1",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n1000 1000\n700 700",
"output": "maybe"
},
{
"input": "2\n4 3\n5 3",
"output": "rated"
},
{
"input": "2\n1000 1000\n1100 1100",
"output": "unrated"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n1 2\n1 3",
"output": "rated"
},
{
"input": "2\n3 3\n1 2",
"output": "rated"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "2\n10 10\n1 2",
"output": "rated"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900",
"output": "unrated"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699",
"output": "unrated"
},
{
"input": "2\n100 100\n110 110",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n3 3\n3 2\n4 4",
"output": "rated"
},
{
"input": "3\n5 2\n4 4\n3 3",
"output": "rated"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n1 1\n3 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n3 4",
"output": "rated"
},
{
"input": "3\n1 2\n2 2\n3 3",
"output": "rated"
},
{
"input": "3\n1 2\n1 2\n1 2",
"output": "rated"
},
{
"input": "2\n2 1\n2 1",
"output": "rated"
},
{
"input": "2\n1 2\n3 4",
"output": "rated"
},
{
"input": "2\n3 2\n2 3",
"output": "rated"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1 1\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n2 2",
"output": "unrated"
},
{
"input": "2\n10 12\n8 8",
"output": "rated"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500",
"output": "unrated"
},
{
"input": "2\n1 2\n2 2",
"output": "rated"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100",
"output": "rated"
},
{
"input": "2\n10 12\n10 10",
"output": "rated"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300",
"output": "maybe"
},
{
"input": "3\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "3\n2 6\n3 5\n4 4",
"output": "rated"
},
{
"input": "2\n5 6\n4 6",
"output": "rated"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8",
"output": "unrated"
},
{
"input": "2\n4 4\n3 3",
"output": "maybe"
}
] | 1,598,376,402
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 150
| 124
| 307,200
|
n = int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
ans = 'maybe'
for i in range(n):
if a[i][0] != a[i][1]:
ans = 'rated'
break
else:
for i in range(n-1):
if a[i][0] < a[i+1][0]:
ans = 'unrated'
break
print(ans)
|
Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
Output Specification:
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
Demo Input:
['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n']
Demo Output:
['rated\n', 'unrated\n', 'maybe\n']
Note:
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
|
```python
n = int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
ans = 'maybe'
for i in range(n):
if a[i][0] != a[i][1]:
ans = 'rated'
break
else:
for i in range(n-1):
if a[i][0] < a[i+1][0]:
ans = 'unrated'
break
print(ans)
```
| 3
|
|
570
|
A
|
Elections
|
PROGRAMMING
| 1,100
|
[
"implementation"
] | null | null |
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
|
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*.
It is guaranteed that the total number of people in all the cities does not exceed 109.
|
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
|
[
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] |
[
"2",
"1"
] |
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
| 500
|
[
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{
"input": "2 2\n1 2\n2 1",
"output": "1"
},
{
"input": "2 2\n2 1\n2 1",
"output": "1"
},
{
"input": "2 2\n1 2\n1 2",
"output": "2"
},
{
"input": "3 3\n0 0 0\n1 1 1\n2 2 2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 2 3 4 5\n2 3 4 5 6\n3 4 5 6 7\n4 5 6 7 8\n5 6 7 8 9",
"output": "5"
},
{
"input": "4 4\n1 3 1 3\n3 1 3 1\n2 0 0 2\n0 1 1 0",
"output": "1"
},
{
"input": "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0",
"output": "1"
},
{
"input": "4 4\n1 4 1 300\n3 1 2 1\n5 0 0 2\n0 1 10 100",
"output": "1"
},
{
"input": "5 5\n15 45 15 300 10\n53 15 25 51 10\n5 50 50 2 10\n1000 1 10 100 10\n10 10 10 10 10",
"output": "1"
},
{
"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": "1"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "1 100\n859\n441\n272\n47\n355\n345\n612\n569\n545\n599\n410\n31\n720\n303\n58\n537\n561\n730\n288\n275\n446\n955\n195\n282\n153\n455\n996\n121\n267\n702\n769\n560\n353\n89\n990\n282\n801\n335\n573\n258\n722\n768\n324\n41\n249\n125\n557\n303\n664\n945\n156\n884\n985\n816\n433\n65\n976\n963\n85\n647\n46\n877\n665\n523\n714\n182\n377\n549\n994\n385\n184\n724\n447\n99\n766\n353\n494\n747\n324\n436\n915\n472\n879\n582\n928\n84\n627\n156\n972\n651\n159\n372\n70\n903\n590\n480\n184\n540\n270\n892",
"output": "1"
},
{
"input": "100 1\n439 158 619 538 187 153 973 781 610 475 94 947 449 531 220 51 788 118 189 501 54 434 465 902 280 635 688 214 737 327 682 690 683 519 261 923 254 388 529 659 662 276 376 735 976 664 521 285 42 147 187 259 407 977 879 465 522 17 550 701 114 921 577 265 668 812 232 267 135 371 586 201 608 373 771 358 101 412 195 582 199 758 507 882 16 484 11 712 916 699 783 618 405 124 904 257 606 610 230 718",
"output": "54"
},
{
"input": "1 99\n511\n642\n251\n30\n494\n128\n189\n324\n884\n656\n120\n616\n959\n328\n411\n933\n895\n350\n1\n838\n996\n761\n619\n131\n824\n751\n707\n688\n915\n115\n244\n476\n293\n986\n29\n787\n607\n259\n756\n864\n394\n465\n303\n387\n521\n582\n485\n355\n299\n997\n683\n472\n424\n948\n339\n383\n285\n957\n591\n203\n866\n79\n835\n980\n344\n493\n361\n159\n160\n947\n46\n362\n63\n553\n793\n754\n429\n494\n523\n227\n805\n313\n409\n243\n927\n350\n479\n971\n825\n460\n544\n235\n660\n327\n216\n729\n147\n671\n738",
"output": "1"
},
{
"input": "99 1\n50 287 266 159 551 198 689 418 809 43 691 367 160 664 86 805 461 55 127 950 576 351 721 493 972 560 934 885 492 92 321 759 767 989 883 7 127 413 404 604 80 645 666 874 371 718 893 158 722 198 563 293 134 255 742 913 252 378 859 721 502 251 839 284 133 209 962 514 773 124 205 903 785 859 911 93 861 786 747 213 690 69 942 697 211 203 284 961 351 137 962 952 408 249 238 850 944 40 346",
"output": "34"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2",
"output": "100"
},
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 1\n0 0",
"output": "1"
},
{
"input": "2 2\n0 0\n0 0",
"output": "1"
},
{
"input": "2 2\n1 2\n0 0",
"output": "1"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 0",
"output": "1"
},
{
"input": "2 3\n0 0\n0 0\n0 1",
"output": "1"
},
{
"input": "3 2\n1 1 3\n0 0 0",
"output": "1"
},
{
"input": "3 4\n1 10 3\n0 0 0\n0 0 0\n0 0 0",
"output": "1"
},
{
"input": "2 4\n2 1\n1 2\n0 0\n1 2",
"output": "1"
},
{
"input": "2 2\n0 1\n0 1",
"output": "2"
},
{
"input": "2 3\n1 2\n0 0\n2 1",
"output": "1"
},
{
"input": "2 2\n0 0\n4 5",
"output": "1"
},
{
"input": "3 2\n10 15 20\n0 0 0",
"output": "1"
},
{
"input": "3 4\n0 0 0\n0 0 0\n0 0 0\n1 2 3",
"output": "1"
},
{
"input": "3 3\n0 0 0\n0 0 0\n0 0 1",
"output": "1"
},
{
"input": "3 3\n0 0 0\n1 2 3\n1 3 2",
"output": "1"
},
{
"input": "3 1\n0 0 0",
"output": "1"
},
{
"input": "3 3\n0 0 1\n0 0 0\n0 0 0",
"output": "1"
}
] | 1,472,980,234
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 62
| 62
| 102,400
|
lineInput = list(map(int,str(input()).split()))
m = lineInput[0]
n = lineInput[1]
city = [0] * 110
for i in range(0,n):
cnt = list(map(int,str(input()).split()))
winner = 0
for j in range(0,m):
if(cnt[j] > cnt[winner]):
winner = j
city[winner] += 1
answer = int(0)
for i in range(0,m):
if(city[i] > city[answer]):
answer = i
answer += 1
print(answer)
|
Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.
At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
Input Specification:
The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes the number of votes for candidate *j* in city *i*.
It is guaranteed that the total number of people in all the cities does not exceed 109.
Output Specification:
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
Demo Input:
['3 3\n1 2 3\n2 3 1\n1 2 1\n', '3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n']
Demo Output:
['2', '1']
Note:
Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
|
```python
lineInput = list(map(int,str(input()).split()))
m = lineInput[0]
n = lineInput[1]
city = [0] * 110
for i in range(0,n):
cnt = list(map(int,str(input()).split()))
winner = 0
for j in range(0,m):
if(cnt[j] > cnt[winner]):
winner = j
city[winner] += 1
answer = int(0)
for i in range(0,m):
if(city[i] > city[answer]):
answer = i
answer += 1
print(answer)
```
| 3
|
|
3
|
C
|
Tic-tac-toe
|
PROGRAMMING
| 1,800
|
[
"brute force",
"games",
"implementation"
] |
C. Tic-tac-toe
|
1
|
64
|
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw.
|
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
|
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
|
[
"X0X\n.0.\n.X.\n"
] |
[
"second\n"
] |
none
| 0
|
[
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
"input": "X.X\nX.0\n0.0",
"output": "first"
},
{
"input": "XXX\nX00\nX00",
"output": "the first player won"
},
{
"input": "000\nX.X\nX.X",
"output": "illegal"
},
{
"input": "XXX\n0.0\n0..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX0X",
"output": "the first player won"
},
{
"input": "XX.\nX0X\nX..",
"output": "illegal"
},
{
"input": "X0X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "XX0\n0..\n000",
"output": "illegal"
},
{
"input": "XXX\n0..\n.0.",
"output": "the first player won"
},
{
"input": "XXX\nX..\n.00",
"output": "illegal"
},
{
"input": "X00\n0.0\nXX0",
"output": "illegal"
},
{
"input": "0.0\n0XX\n..0",
"output": "illegal"
},
{
"input": ".00\nX.X\n0..",
"output": "illegal"
},
{
"input": "..0\n.00\n.0X",
"output": "illegal"
},
{
"input": "..0\n0..\n00X",
"output": "illegal"
},
{
"input": "..0\n.XX\nX..",
"output": "illegal"
},
{
"input": "0.X\n0X0\n.00",
"output": "illegal"
},
{
"input": "..X\n0X0\n0X.",
"output": "first"
},
{
"input": "0X0\nX..\nX.0",
"output": "first"
},
{
"input": ".0.\nX.X\n0..",
"output": "first"
},
{
"input": "0X0\n00X\n.00",
"output": "illegal"
},
{
"input": ".0.\n.X0\nX..",
"output": "first"
},
{
"input": "00X\n0.X\n00X",
"output": "illegal"
},
{
"input": "00X\n0XX\n0X.",
"output": "the second player won"
},
{
"input": "X00\n..0\nX.X",
"output": "first"
},
{
"input": "X00\nX00\n.X0",
"output": "illegal"
},
{
"input": "X0X\n.X0\n0..",
"output": "first"
},
{
"input": "..0\nXXX\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n.0.",
"output": "illegal"
},
{
"input": "0..\n000\nX0X",
"output": "illegal"
},
{
"input": ".00\n0X.\n0.0",
"output": "illegal"
},
{
"input": "X..\nX00\n0.0",
"output": "illegal"
},
{
"input": ".X0\nXX0\nX.X",
"output": "illegal"
},
{
"input": "X.X\n0.0\nX..",
"output": "second"
},
{
"input": "00X\n.00\n..0",
"output": "illegal"
},
{
"input": "..0\n0.X\n00.",
"output": "illegal"
},
{
"input": "0.X\nX0X\n.X0",
"output": "illegal"
},
{
"input": "0X.\n.X.\n0X0",
"output": "illegal"
},
{
"input": "00.\nX0.\n..X",
"output": "illegal"
},
{
"input": "..X\n.00\nXX.",
"output": "second"
},
{
"input": ".00\n.0.\n.X.",
"output": "illegal"
},
{
"input": "XX0\nX.0\nXX0",
"output": "illegal"
},
{
"input": "00.\n00.\nX.X",
"output": "illegal"
},
{
"input": "X00\nX.0\nX.0",
"output": "illegal"
},
{
"input": "0X.\n0XX\n000",
"output": "illegal"
},
{
"input": "00.\n00.\n.X.",
"output": "illegal"
},
{
"input": "X0X\n00.\n0.X",
"output": "illegal"
},
{
"input": "XX0\nXXX\n0X0",
"output": "illegal"
},
{
"input": "XX0\n..X\nXX0",
"output": "illegal"
},
{
"input": "0X.\n..X\nX..",
"output": "illegal"
},
{
"input": "...\nX0.\nXX0",
"output": "second"
},
{
"input": "..X\n.0.\n0..",
"output": "illegal"
},
{
"input": "00X\nXX.\n00X",
"output": "first"
},
{
"input": "..0\nXX0\n..X",
"output": "second"
},
{
"input": ".0.\n.00\nX00",
"output": "illegal"
},
{
"input": "X00\n.XX\n00.",
"output": "illegal"
},
{
"input": ".00\n0.X\n000",
"output": "illegal"
},
{
"input": "X0.\n..0\nX.0",
"output": "illegal"
},
{
"input": "X0X\n.XX\n00.",
"output": "second"
},
{
"input": "0X.\n00.\n.X.",
"output": "illegal"
},
{
"input": ".0.\n...\n0.0",
"output": "illegal"
},
{
"input": "..X\nX00\n0.0",
"output": "illegal"
},
{
"input": "0XX\n...\nX0.",
"output": "second"
},
{
"input": "X.X\n0X.\n.0X",
"output": "illegal"
},
{
"input": "XX0\nX.X\n00.",
"output": "second"
},
{
"input": ".0X\n.00\n00.",
"output": "illegal"
},
{
"input": ".XX\nXXX\n0..",
"output": "illegal"
},
{
"input": "XX0\n.X0\n.0.",
"output": "first"
},
{
"input": "X00\n0.X\nX..",
"output": "first"
},
{
"input": "X..\n.X0\nX0.",
"output": "second"
},
{
"input": ".0X\nX..\nXXX",
"output": "illegal"
},
{
"input": "X0X\nXXX\nX.X",
"output": "illegal"
},
{
"input": ".00\nX0.\n00X",
"output": "illegal"
},
{
"input": "0XX\n.X0\n0.0",
"output": "illegal"
},
{
"input": "00X\nXXX\n..0",
"output": "the first player won"
},
{
"input": "X0X\n...\n.X.",
"output": "illegal"
},
{
"input": ".X0\n...\n0X.",
"output": "first"
},
{
"input": "X..\n0X0\nX.0",
"output": "first"
},
{
"input": "..0\n.00\nX.0",
"output": "illegal"
},
{
"input": ".XX\n.0.\nX0X",
"output": "illegal"
},
{
"input": "00.\n0XX\n..0",
"output": "illegal"
},
{
"input": ".0.\n00.\n00.",
"output": "illegal"
},
{
"input": "00.\n000\nX.X",
"output": "illegal"
},
{
"input": "0X0\n.X0\n.X.",
"output": "illegal"
},
{
"input": "00X\n0..\n0..",
"output": "illegal"
},
{
"input": ".X.\n.X0\nX.0",
"output": "second"
},
{
"input": ".0.\n0X0\nX0X",
"output": "illegal"
},
{
"input": "...\nX.0\n0..",
"output": "illegal"
},
{
"input": "..0\nXX.\n00X",
"output": "first"
},
{
"input": "0.X\n.0X\nX00",
"output": "illegal"
},
{
"input": "..X\n0X.\n.0.",
"output": "first"
},
{
"input": "..X\nX.0\n.0X",
"output": "second"
},
{
"input": "X0.\n.0X\nX0X",
"output": "illegal"
},
{
"input": "...\n.0.\n.X0",
"output": "illegal"
},
{
"input": ".X0\nXX0\n0..",
"output": "first"
},
{
"input": "0X.\n...\nX..",
"output": "second"
},
{
"input": ".0.\n0.0\n0.X",
"output": "illegal"
},
{
"input": "XX.\n.X0\n.0X",
"output": "illegal"
},
{
"input": ".0.\nX0X\nX00",
"output": "illegal"
},
{
"input": "0X.\n.X0\nX..",
"output": "second"
},
{
"input": "..0\n0X.\n000",
"output": "illegal"
},
{
"input": "0.0\nX.X\nXX.",
"output": "illegal"
},
{
"input": ".X.\n.XX\nX0.",
"output": "illegal"
},
{
"input": "X.X\n.XX\n0X.",
"output": "illegal"
},
{
"input": "X.0\n0XX\n..0",
"output": "first"
},
{
"input": "X.0\n0XX\n.X0",
"output": "second"
},
{
"input": "X00\n0XX\n.X0",
"output": "first"
},
{
"input": "X00\n0XX\nXX0",
"output": "draw"
},
{
"input": "X00\n0XX\n0X0",
"output": "illegal"
},
{
"input": "XXX\nXXX\nXXX",
"output": "illegal"
},
{
"input": "000\n000\n000",
"output": "illegal"
},
{
"input": "XX0\n00X\nXX0",
"output": "draw"
},
{
"input": "X00\n00X\nXX0",
"output": "illegal"
},
{
"input": "X.0\n00.\nXXX",
"output": "the first player won"
},
{
"input": "X..\nX0.\nX0.",
"output": "the first player won"
},
{
"input": ".XX\n000\nXX0",
"output": "the second player won"
},
{
"input": "X0.\nX.X\nX00",
"output": "the first player won"
},
{
"input": "00X\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XXX\n.00\nX0.",
"output": "the first player won"
},
{
"input": "XX0\n000\nXX.",
"output": "the second player won"
},
{
"input": ".X0\n0.0\nXXX",
"output": "the first player won"
},
{
"input": "0XX\nX00\n0XX",
"output": "draw"
},
{
"input": "0XX\nX0X\n00X",
"output": "the first player won"
},
{
"input": "XX0\n0XX\n0X0",
"output": "the first player won"
},
{
"input": "0X0\nX0X\nX0X",
"output": "draw"
},
{
"input": "X0X\n0XX\n00X",
"output": "the first player won"
},
{
"input": "0XX\nX0.\nX00",
"output": "the second player won"
},
{
"input": "X.0\n0X0\nXX0",
"output": "the second player won"
},
{
"input": "X0X\nX0X\n0X0",
"output": "draw"
},
{
"input": "X.0\n00X\n0XX",
"output": "the second player won"
},
{
"input": "00X\nX0X\n.X0",
"output": "the second player won"
},
{
"input": "X0X\n.00\nX0X",
"output": "the second player won"
},
{
"input": "0XX\nX00\nX0X",
"output": "draw"
},
{
"input": "000\nX0X\n.XX",
"output": "the second player won"
},
{
"input": "0.0\n0.X\nXXX",
"output": "the first player won"
},
{
"input": "X.0\nX0.\n0X.",
"output": "the second player won"
},
{
"input": "X0X\n0X0\n..X",
"output": "the first player won"
},
{
"input": "0X0\nXX0\n.X.",
"output": "the first player won"
},
{
"input": "X0.\n.X.\n0.X",
"output": "the first player won"
},
{
"input": "0XX\nX00\n.X0",
"output": "the second player won"
},
{
"input": "0.0\nXXX\n0.X",
"output": "the first player won"
},
{
"input": ".0X\n.X.\nX.0",
"output": "the first player won"
},
{
"input": "XXX\nX.0\n0.0",
"output": "the first player won"
},
{
"input": "XX0\nX..\nX00",
"output": "the first player won"
},
{
"input": "XXX\n00X\n00X",
"output": "the first player won"
},
{
"input": "X00\n00X\nXXX",
"output": "the first player won"
},
{
"input": "0X0\nX0X\n0X.",
"output": "the second player won"
},
{
"input": "XX0\nX00\n0X.",
"output": "the second player won"
},
{
"input": "..X\n0X0\nX..",
"output": "the first player won"
},
{
"input": "X0.\n00.\nXXX",
"output": "the first player won"
},
{
"input": "0.X\nX00\nXX0",
"output": "the second player won"
},
{
"input": "X0.\n0X.\n..X",
"output": "the first player won"
},
{
"input": "00X\nX0.\nXX0",
"output": "the second player won"
},
{
"input": "XX.\n000\n0XX",
"output": "the second player won"
},
{
"input": "..X\n0.X\n.0X",
"output": "the first player won"
},
{
"input": "X00\n.0X\n0XX",
"output": "the second player won"
},
{
"input": "00X\n0X.\nXX.",
"output": "the first player won"
},
{
"input": "X00\nXX.\n0.X",
"output": "the first player won"
},
{
"input": "XXX\n00X\n0X0",
"output": "the first player won"
},
{
"input": "X00\nXX0\n0XX",
"output": "the first player won"
},
{
"input": "0X0\nX00\nXXX",
"output": "the first player won"
},
{
"input": "XX0\nX00\n.X0",
"output": "the second player won"
}
] | 1,690,647,386
| 2,147,483,647
|
PyPy 3-64
|
RUNTIME_ERROR
|
TESTS
| 0
| 156
| 2,867,200
|
cx = 0
c0 = 0
wx = 0
w0 = 0
b = [' '] * 9
def ch(c, i):
return (b[i] == c and b[i + 3] == c and b[i + 6] == c) or (b[i * 3 + 0] == c and b[i * 3 + 1] == c and b[i * 3 + 2] == c) or (b[0] == c and b[4] == c and b[8] == c) or (b[2] == c and b[4] == c and b[6] == c)
for i in range(9):
b[i] = input()
if b[i] == 'X':
cx += 1
elif b[i] == '0':
c0 += 1
for i in range(3):
wx += ch('X', i)
w0 += ch('0', i)
if (w0 > 0 and cx != c0) or (cx != c0 and cx != c0 + 1) or (wx > 0 and cx != c0 + 1) or (w0 > 0 and wx > 0):
print("illegal")
elif wx:
print("the first player won")
elif w0:
print("the second player won")
elif cx + c0 == 9:
print("draw")
elif cx == c0:
print("first")
else:
print("second")
|
Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=×<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal — if the given board layout can't appear during a valid game; - the first player won — if in the given board layout the first player has just won; - the second player won — if in the given board layout the second player has just won; - draw — if the given board layout has just let to a draw.
Input Specification:
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Output Specification:
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
Demo Input:
['X0X\n.0.\n.X.\n']
Demo Output:
['second\n']
Note:
none
|
```python
cx = 0
c0 = 0
wx = 0
w0 = 0
b = [' '] * 9
def ch(c, i):
return (b[i] == c and b[i + 3] == c and b[i + 6] == c) or (b[i * 3 + 0] == c and b[i * 3 + 1] == c and b[i * 3 + 2] == c) or (b[0] == c and b[4] == c and b[8] == c) or (b[2] == c and b[4] == c and b[6] == c)
for i in range(9):
b[i] = input()
if b[i] == 'X':
cx += 1
elif b[i] == '0':
c0 += 1
for i in range(3):
wx += ch('X', i)
w0 += ch('0', i)
if (w0 > 0 and cx != c0) or (cx != c0 and cx != c0 + 1) or (wx > 0 and cx != c0 + 1) or (w0 > 0 and wx > 0):
print("illegal")
elif wx:
print("the first player won")
elif w0:
print("the second player won")
elif cx + c0 == 9:
print("draw")
elif cx == c0:
print("first")
else:
print("second")
```
| -1
|
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,924,308
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 30
| 0
|
def notSameColor(s):
l = list(s)
cnt =0
for i in range(len(l)-1):
if l[i+1]==l[i]:
cnt +=1
return cnt
print(notSameColor(input()))
|
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
def notSameColor(s):
l = list(s)
cnt =0
for i in range(len(l)-1):
if l[i+1]==l[i]:
cnt +=1
return cnt
print(notSameColor(input()))
```
| 0
|
|
80
|
A
|
Panoramix's Prediction
|
PROGRAMMING
| 800
|
[
"brute force"
] |
A. Panoramix's Prediction
|
2
|
256
|
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
|
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
|
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
|
[
"3 5\n",
"7 11\n",
"7 9\n"
] |
[
"YES",
"YES",
"NO"
] |
none
| 500
|
[
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,687,972,524
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 13
| 122
| 0
|
a=input('')
n=int(a.split(' ')[0])
m=int(a.split(' ')[1])
c=n+1
for i in range(2,c):
if c%i!=0:
continue
else:
c+=1
if c==m:
print('YES')
else:
print('NO')
|
Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none
|
```python
a=input('')
n=int(a.split(' ')[0])
m=int(a.split(' ')[1])
c=n+1
for i in range(2,c):
if c%i!=0:
continue
else:
c+=1
if c==m:
print('YES')
else:
print('NO')
```
| 0
|
735
|
B
|
Urbanization
|
PROGRAMMING
| 1,100
|
[
"greedy",
"number theory",
"sortings"
] | null | null |
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second for *n*2 people. Of course, each of *n* candidates can settle in only one of the cities. Thus, first some subset of candidates of size *n*1 settle in the first city and then some subset of size *n*2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth *a**i* among all its residents divided by the number of them (*n*1 or *n*2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities.
|
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), the *i*-th of them is equal to the wealth of the *i*-th candidate.
|
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
|
[
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] |
[
"6.00000000\n",
"6.50000000\n"
] |
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class="lower-index">4</sub>) / 2 + *a*<sub class="lower-index">2</sub> = (3 + 2) / 2 + 4 = 6.5
| 1,000
|
[
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 100000 100000",
"output": "47052.10714286"
},
{
"input": "100 9 6\n109 711 40 95 935 48 228 253 308 726 816 534 252 8 966 363 162 508 84 83 807 506 748 178 45 30 106 108 764 698 825 198 336 353 158 790 64 262 403 334 577 571 742 541 946 602 279 621 910 776 421 886 29 133 114 394 762 965 339 263 750 530 49 80 124 31 322 292 27 590 960 278 111 932 849 491 561 744 469 511 106 271 156 160 836 363 149 473 457 543 976 809 490 29 85 626 265 88 995 946",
"output": "1849.66666667"
},
{
"input": "69 6 63\n53475 22876 79144 6335 33763 79104 65441 45527 65847 94406 74670 43529 75330 19403 67629 56187 57949 23071 64910 54409 55348 18056 855 24961 50565 6622 26467 33989 22660 79469 41246 13965 79706 14422 16075 93378 81313 48173 13470 97348 2346 27452 59427 29925 29847 73823 32021 10988 24609 98855 90919 45939 17203 8439 43007 40138 55693 30314 71734 33458 66850 4011 20089 20546 92090 50842 78859 62756 40177",
"output": "135712.88888889"
},
{
"input": "69 6 9\n2612 17461 69001 33130 10662 85485 88195 45974 16712 81365 67119 87797 15559 20197 74716 92979 97268 49466 68603 48351 99905 35606 54242 98603 68232 54398 82637 49647 38979 46171 54680 23334 15892 92186 69670 29711 67999 2220 32317 717 70667 68262 86760 55720 97158 61122 7251 138 21022 27197 12691 59331 13576 66999 38332 13574 83484 66646 17704 33065 98583 80259 64631 16745 69431 40747 82089 82788 32739",
"output": "183129.44444444"
}
] | 1,614,342,549
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 37
| 171
| 10,649,600
|
n,n1,n2=map(int,input().split())
n1,n2=min(n1,n2),max(n1,n2)
l=sorted(list(map(int,input().split())))
l.reverse()
print(sum(l[:n1])/n1+sum(l[n1:n1+n2])/n2)
|
Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second for *n*2 people. Of course, each of *n* candidates can settle in only one of the cities. Thus, first some subset of candidates of size *n*1 settle in the first city and then some subset of size *n*2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth *a**i* among all its residents divided by the number of them (*n*1 or *n*2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities.
Input Specification:
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), the *i*-th of them is equal to the wealth of the *i*-th candidate.
Output Specification:
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['2 1 1\n1 5\n', '4 2 1\n1 4 2 3\n']
Demo Output:
['6.00000000\n', '6.50000000\n']
Note:
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class="lower-index">4</sub>) / 2 + *a*<sub class="lower-index">2</sub> = (3 + 2) / 2 + 4 = 6.5
|
```python
n,n1,n2=map(int,input().split())
n1,n2=min(n1,n2),max(n1,n2)
l=sorted(list(map(int,input().split())))
l.reverse()
print(sum(l[:n1])/n1+sum(l[n1:n1+n2])/n2)
```
| 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,102,806
| 6,506
|
Python 3
|
WRONG_ANSWER
|
PRETESTS
| 8
| 77
| 5,120,000
|
import collections
s, k = input().split()
arr = list(map(int,list(s[1:])))
n = 0;
def cor(n,arr):
for i in range(0,n):
if arr[-(i+1)]!=0:
return False
return True
if len(s)<int(k):
print(len(s)-1)
else:
for i in range(len(arr)-1,-1,-1):
if arr[i]!=0:
arr.pop(i)
n+=1
if len(arr)>=int(k) and cor(int(k),arr):
break
if len(arr)<int(k):
n = len(s)-1
break
print(n)
|
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
import collections
s, k = input().split()
arr = list(map(int,list(s[1:])))
n = 0;
def cor(n,arr):
for i in range(0,n):
if arr[-(i+1)]!=0:
return False
return True
if len(s)<int(k):
print(len(s)-1)
else:
for i in range(len(arr)-1,-1,-1):
if arr[i]!=0:
arr.pop(i)
n+=1
if len(arr)>=int(k) and cor(int(k),arr):
break
if len(arr)<int(k):
n = len(s)-1
break
print(n)
```
| 0
|
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the 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,694,605,737
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 31
| 0
|
s=list(map(int, input().split(" ")))
n=s[0]
m=s[1]
a=s[2]
print((int(n/a)+1)*(int(m/a)+1))
|
Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each 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
s=list(map(int, input().split(" ")))
n=s[0]
m=s[1]
a=s[2]
print((int(n/a)+1)*(int(m/a)+1))
```
| 0
|
525
|
B
|
Pasha and String
|
PROGRAMMING
| 1,400
|
[
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null |
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days.
|
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day.
|
In the first line of the output print what Pasha's string *s* will look like after *m* days.
|
[
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] |
[
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] |
none
| 750
|
[
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"output": "wyjldgqxlc"
},
{
"input": "keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs\n2\n5 12",
"output": "keiccyobhhphsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlniqumqnfavs"
},
{
"input": "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 34 16 25 14 45 35 38 46 48 49 27 49 38 10 49 5 7 3 3 41 25 24 34 37 33 17 50 48 11 40 43 48 10 9 50 18 39 32 13 26 40 37 16 45 50 27 3 7 31",
"output": "xjcxggxvfbbruliyyxkjzikdebnfyftxsorcaxqyxbtkfhbdvigasnababsxfekiwvqsauwsayfumblsaztbweukdfqrzmwumuwy"
}
] | 1,622,030,531
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 26
| 2,000
| 15,052,800
|
def reverse(lis, i, j):
n = (j - i + 1)
while(i <= j):
lis[i], lis[j] = lis[j], lis[i]
j -= 1
i += 1
return lis
s = input()
lis = list(s)
nn = len(s)
m = int(input())
arr = list(map(int, input().split()))
dic = {}
for i in arr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
for i in dic:
if dic[i] & 1 != 0:
#print(i - 1, nn - i)
reverse(lis, i - 1, nn - i)
for i in lis:
print(i, end = '')
|
Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days.
Input Specification:
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day.
Output Specification:
In the first line of the output print what Pasha's string *s* will look like after *m* days.
Demo Input:
['abcdef\n1\n2\n', 'vwxyz\n2\n2 2\n', 'abcdef\n3\n1 2 3\n']
Demo Output:
['aedcbf\n', 'vwxyz\n', 'fbdcea\n']
Note:
none
|
```python
def reverse(lis, i, j):
n = (j - i + 1)
while(i <= j):
lis[i], lis[j] = lis[j], lis[i]
j -= 1
i += 1
return lis
s = input()
lis = list(s)
nn = len(s)
m = int(input())
arr = list(map(int, input().split()))
dic = {}
for i in arr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
for i in dic:
if dic[i] & 1 != 0:
#print(i - 1, nn - i)
reverse(lis, i - 1, nn - i)
for i in lis:
print(i, end = '')
```
| 0
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of color *i*<=+<=1 for all *i* from 1 to *k*<=-<=1. Now he wonders how many different ways this can happen.
|
The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000).
The total number of balls doesn't exceed 1000.
|
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007.
|
[
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] |
[
"3\n",
"1680\n"
] |
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
| 0
|
[
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n381\n126\n39\n19\n20\n3\n1\n20\n45\n2",
"output": "902382672"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "13\n67\n75\n76\n80\n69\n86\n75\n86\n81\n84\n73\n72\n76",
"output": "232242896"
},
{
"input": "25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33",
"output": "362689152"
},
{
"input": "47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n21\n25\n28\n24\n21\n21\n17\n28\n20\n20\n31\n19",
"output": "295545118"
},
{
"input": "3\n343\n317\n337",
"output": "691446102"
},
{
"input": "1\n5",
"output": "1"
}
] | 1,533,046,157
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 27
| 171
| 0
|
import math
MOD = 1000000007
MAXN = 1005
def fac(n, k):
res = 1
for i in range(n + 1 - k, n + 1):
res *= i
return res
k = int(input())
sum = 0
ans = 1
for i in range(0, k):
num = int(input())
sum += num
ans = ans * fac(sum - 1, num - 1) // fac(num - 1, num - 1)
print (ans % MOD)
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of color *i*<=+<=1 for all *i* from 1 to *k*<=-<=1. Now he wonders how many different ways this can happen.
Input Specification:
The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000).
The total number of balls doesn't exceed 1000.
Output Specification:
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007.
Demo Input:
['3\n2\n2\n1\n', '4\n1\n2\n3\n4\n']
Demo Output:
['3\n', '1680\n']
Note:
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
|
```python
import math
MOD = 1000000007
MAXN = 1005
def fac(n, k):
res = 1
for i in range(n + 1 - k, n + 1):
res *= i
return res
k = int(input())
sum = 0
ans = 1
for i in range(0, k):
num = int(input())
sum += num
ans = ans * fac(sum - 1, num - 1) // fac(num - 1, num - 1)
print (ans % MOD)
```
| 3
|
|
145
|
A
|
Lucky Conversion
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation"
] | null | null |
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types:
- replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*.
Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task.
|
The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
|
Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*.
|
[
"47\n74\n",
"774\n744\n",
"777\n444\n"
] |
[
"1\n",
"1\n",
"3\n"
] |
In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites.
| 500
|
[
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774474447474774\n4477774777444444444777447",
"output": "8"
},
{
"input": "7\n4",
"output": "1"
},
{
"input": "4\n7",
"output": "1"
},
{
"input": "7777777777\n7777777774",
"output": "1"
},
{
"input": "47777777777\n77777777774",
"output": "1"
},
{
"input": "47747477747744447774774444444777444747474747777774\n44777444774477447777444774477777477774444477447777",
"output": "14"
},
{
"input": "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447",
"output": "13"
},
{
"input": "4447744774744774744747744774474474444447477477444747477444\n7477477444744774744744774774744474744447744774744477744477",
"output": "14"
},
{
"input": "44747744777777444\n47774747747744777",
"output": "6"
},
{
"input": "44447774444474477747774774477777474774744744477444447777477477744747477774744444744777777777747777477447744774744444747477744744\n77777474477477747774777777474474477444474777477747747777477747747744474474747774747747444777474444744744444477477777747744747477",
"output": "37"
},
{
"input": "774774747744474477447477777447477747477474777477744744747444774474477477747474477447774444774744777\n744477444747477447477777774477447444447747477747477747774477474447474477477474444777444444447474747",
"output": "27"
},
{
"input": "4747447477\n4747444744",
"output": "3"
},
{
"input": "47744447444\n74477447744",
"output": "4"
},
{
"input": "447444777744\n777747744477",
"output": "6"
},
{
"input": "474777477774444\n774747777774477",
"output": "4"
},
{
"input": "47744474447747744777777447\n44744747477474777744777477",
"output": "7"
},
{
"input": "77447447444777777744744747744747774747477774777774447447777474477477774774777\n74777777444744447447474474477747747444444447447774444444747777444747474777447",
"output": "28"
},
{
"input": "7\n7",
"output": "0"
},
{
"input": "444\n444",
"output": "0"
},
{
"input": "77747\n47474",
"output": "3"
}
] | 1,617,813,459
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 51
| 248
| 1,945,600
|
a = list(input())
b = list(input())
a_copy = a[:]
a_copy.sort()
b_copy = b[:]
b_copy.sort()
replace_counter = 0
swap_counter = 0
for i in range(len(a_copy)):
if(a_copy[i] != b_copy[i]):
replace_counter += 1
for i in range(len(a)):
if (a[i] != b[i]):
swap_counter += 1
swap_counter = (swap_counter - replace_counter) // 2
print(replace_counter + swap_counter)
|
Title: Lucky Conversion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits. Petya can perform operations of two types:
- replace any one digit from string *a* by its opposite (i.e., replace 4 by 7 and 7 by 4); - swap any pair of digits in string *a*.
Petya is interested in the minimum number of operations that are needed to make string *a* equal to string *b*. Help him with the task.
Input Specification:
The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Output Specification:
Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*.
Demo Input:
['47\n74\n', '774\n744\n', '777\n444\n']
Demo Output:
['1\n', '1\n', '3\n']
Note:
In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites.
|
```python
a = list(input())
b = list(input())
a_copy = a[:]
a_copy.sort()
b_copy = b[:]
b_copy.sort()
replace_counter = 0
swap_counter = 0
for i in range(len(a_copy)):
if(a_copy[i] != b_copy[i]):
replace_counter += 1
for i in range(len(a)):
if (a[i] != b[i]):
swap_counter += 1
swap_counter = (swap_counter - replace_counter) // 2
print(replace_counter + swap_counter)
```
| 3
|
|
855
|
A
|
Tom Riddle's Diary
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation",
"strings"
] | null | null |
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
|
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
|
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
|
[
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] |
[
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] |
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES".
| 500
|
[
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,646,909,372
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 55
| 46
| 0
|
memory=dict()
for _ in [0]*int(input()):
s=input()
try:memory[s]+=1;print('YES')
except:memory[s]=0;print('NO')
|
Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES".
|
```python
memory=dict()
for _ in [0]*int(input()):
s=input()
try:memory[s]+=1;print('YES')
except:memory[s]=0;print('NO')
```
| 3
|
|
441
|
A
|
Valera and Antique Items
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.
Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
|
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
|
In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
|
[
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] |
[
"3\n1 2 3\n",
"0\n\n"
] |
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
| 500
|
[
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 1000000",
"output": "0"
},
{
"input": "1 1000000\n1 561774",
"output": "1\n1"
},
{
"input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "2\n1 2"
},
{
"input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000",
"output": "0"
},
{
"input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236",
"output": "3\n1 2 3"
},
{
"input": "1 50001\n1 50000",
"output": "1\n1"
}
] | 1,661,021,671
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 15
| 0
|
n, valera = map(int, input().split())
amn = 0
nums = []
for j in range (n):
lots, *price = map(int, input().split())
for i in range (price):
if valera > i:
amn += 1
nums += j + 1
break
print (amn)
for y in nums:
print (y + ' ', end='')
|
Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.
Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
Input Specification:
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
Output Specification:
In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
Demo Input:
['3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n', '3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n']
Demo Output:
['3\n1 2 3\n', '0\n\n']
Note:
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
|
```python
n, valera = map(int, input().split())
amn = 0
nums = []
for j in range (n):
lots, *price = map(int, input().split())
for i in range (price):
if valera > i:
amn += 1
nums += j + 1
break
print (amn)
for y in nums:
print (y + ' ', end='')
```
| -1
|
|
104
|
A
|
Blackjack
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Blackjack
|
2
|
256
|
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
|
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
|
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
|
[
"12\n",
"20\n",
"10\n"
] |
[
"4",
"15",
"0"
] |
In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points.
| 500
|
[
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
},
{
"input": "22",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "9",
"output": "0"
},
{
"input": "13",
"output": "4"
},
{
"input": "14",
"output": "4"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "4"
},
{
"input": "19",
"output": "4"
},
{
"input": "21",
"output": "4"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "0"
}
] | 1,545,760,108
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 25
| 218
| 0
|
c = int(input())
c = c-10
if (c >= 1 and c < 10) or (c is 11):
print(4)
elif c is 10:
print(15)
else:
print(0)
|
Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
Input Specification:
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Output Specification:
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
Demo Input:
['12\n', '20\n', '10\n']
Demo Output:
['4', '15', '0']
Note:
In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points.
|
```python
c = int(input())
c = c-10
if (c >= 1 and c < 10) or (c is 11):
print(4)
elif c is 10:
print(15)
else:
print(0)
```
| 3.9455
|
999
|
B
|
Reversing Encryption
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.
|
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
|
Print a string $s$ such that the above algorithm results in $t$.
|
[
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] |
[
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] |
The first example is described in the problem statement.
| 0
|
[
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\njfyy",
"output": "yyjf"
},
{
"input": "6\nkrdych",
"output": "hcyrkd"
},
{
"input": "60\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj",
"output": "jqprcbfgsxwgjhmkehcoiwwltuxjzokamzpalobnfespcvmoecqigyuutueu"
},
{
"input": "64\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy",
"output": "ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh"
},
{
"input": "97\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacygakhxoubibxtqkpyyhzjipylujgrc",
"output": "crgjulypijzhyypkqtxbibuoxhkagycauuqgchyaokulsbfbnsazfrkcgibxucwgwdalcelhuoqdibceswtjiabubmhdmrqnq"
},
{
"input": "100\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf",
"output": "fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi"
},
{
"input": "96\nqtbcksuvxonzbkokhqlgkrvimzqmqnrvqlihrmksldyydacbtckfphenxszcnzhfjmpeykrvshgiboivkvabhrpphgavvprz",
"output": "zrpvvaghpprhbavkviobighsvrkyepmjfhznczsxnehpfkctvrnqmqzmkokbvuctqbksxonzhqlgkrviqlihrmksldyydacb"
},
{
"input": "90\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "89\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
},
{
"input": "99\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "100\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"output": "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
},
{
"input": "60\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwnwwwwwwwwwwhwwwxwwwwwwwwwfhwwwwawwwwww"
},
{
"input": "90\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc",
"output": "cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc"
},
{
"input": "97\nfwffffffffffffffffffffffffrffffffffffffffzfffffffffffffffftfcfffffffqffffffffffffffffffffffyfffff",
"output": "fffffyffffffffffffffffffffffqfffffffcftffffffffffffffffzffffffffffffffrffffffffffffffffffffffffwf"
},
{
"input": "100\ndjjjjjjjjjjgjjjjjjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjjjjajjjjjjajjjjjjrjjjjjjjjjjjjrjjtjjjjjjjjjjjjjojjj",
"output": "jjjojjjjjjjjjjjjjtjjrjjjjjjjjjjjjrjjjjjjajjjjjjajjjjjjjjjjjjjjdjjjgjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjj"
}
] | 1,641,105,044
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 46
| 0
|
length = int(input())
string = input()
def find_divisors(length):
divisors = sorted([i for i in range(1, (length // 2) + 2) if length % i == 0])
divisors.append(length)
return divisors[1:]
def decode(divisors, string):
string_list = [i for i in string]
for i in divisors:
string_list[:i] = string_list[:i][::-1]
return ''.join(string_list)
divisors = find_divisors(length)
decoded_string = decode(divisors, string)
print(decoded_string)
|
Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.
Input Specification:
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Output Specification:
Print a string $s$ such that the above algorithm results in $t$.
Demo Input:
['10\nrocesfedoc\n', '16\nplmaetwoxesisiht\n', '1\nz\n']
Demo Output:
['codeforces\n', 'thisisexampletwo\n', 'z\n']
Note:
The first example is described in the problem statement.
|
```python
length = int(input())
string = input()
def find_divisors(length):
divisors = sorted([i for i in range(1, (length // 2) + 2) if length % i == 0])
divisors.append(length)
return divisors[1:]
def decode(divisors, string):
string_list = [i for i in string]
for i in divisors:
string_list[:i] = string_list[:i][::-1]
return ''.join(string_list)
divisors = find_divisors(length)
decoded_string = decode(divisors, string)
print(decoded_string)
```
| 0
|
|
962
|
D
|
Merge Equals
|
PROGRAMMING
| 1,600
|
[
"data structures",
"implementation"
] | null | null |
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two occurrences, and the right one is replaced by the sum of this two values (that is, $2 \cdot x$).
Determine how the array will look after described operations are performed.
For example, consider the given array looks like $[3, 4, 1, 2, 2, 1, 1]$. It will be changed in the following way: $[3, 4, 1, 2, 2, 1, 1]~\rightarrow~[3, 4, 2, 2, 2, 1]~\rightarrow~[3, 4, 4, 2, 1]~\rightarrow~[3, 8, 2, 1]$.
If the given array is look like $[1, 1, 3, 1, 1]$ it will be changed in the following way: $[1, 1, 3, 1, 1]~\rightarrow~[2, 3, 1, 1]~\rightarrow~[2, 3, 2]~\rightarrow~[3, 4]$.
|
The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of elements in the array.
The second line contains a sequence from $n$ elements $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{9}$) — the elements of the array.
|
In the first line print an integer $k$ — the number of elements in the array after all the performed operations. In the second line print $k$ integers — the elements of the array after all the performed operations.
|
[
"7\n3 4 1 2 2 1 1\n",
"5\n1 1 3 1 1\n",
"5\n10 40 20 50 30\n"
] |
[
"4\n3 8 2 1 \n",
"2\n3 4 \n",
"5\n10 40 20 50 30 \n"
] |
The first two examples were considered in the statement.
In the third example all integers in the given array are distinct, so it will not change.
| 0
|
[
{
"input": "7\n3 4 1 2 2 1 1",
"output": "4\n3 8 2 1 "
},
{
"input": "5\n1 1 3 1 1",
"output": "2\n3 4 "
},
{
"input": "5\n10 40 20 50 30",
"output": "5\n10 40 20 50 30 "
},
{
"input": "100\n10 10 15 12 15 13 15 12 10 10 15 11 13 14 13 14 10 13 12 10 14 12 13 11 14 15 12 11 11 15 12 12 11 14 14 14 15 10 10 15 15 13 13 15 10 12 14 10 12 13 11 15 11 13 14 12 10 12 11 14 13 15 13 15 13 14 14 11 12 13 11 14 10 10 15 10 15 12 15 12 13 10 11 13 15 11 10 12 10 12 14 14 13 12 14 10 12 13 11 13",
"output": "12\n88 240 15 44 160 192 208 224 20 24 11 26 "
},
{
"input": "2\n1000000000 1000000000",
"output": "1\n2000000000 "
},
{
"input": "3\n500000000 500000000 1000000000",
"output": "1\n2000000000 "
},
{
"input": "9\n8 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913",
"output": "2\n8 4294967304 "
},
{
"input": "34\n967614464 967614464 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "2\n1935228928 32000000000 "
}
] | 1,553,605,087
| 2,147,483,647
|
PyPy 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define push push_back
#define pop pop_back
// #define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define itr iterator
#define f first
#define s second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll ans,i,j,ind,n;
ll a[150001];
map <ll,ll> mp;
int main(){
fast
cin>>n;
for (i=0;i<n;i++){
cin>>a[i];
while(1){
// cout<<a[i]<<" "<<mp[a[i]]<<endl;
if (mp[a[i]]==0){mp[a[i]]=i+1;break;}
ind=mp[a[i]]-1;
mp[a[i]]=0;
a[i]=2*a[i];
a[ind]=-1;
++ans;
// cout<<a[i]<<"ET"<<endl;
}
}
cout<<n-ans<<endl;
for (j=0;j<n;j++){
if (a[j]>0)
cout<<a[j]<<" ";
}
cout<<"\n";
return 0;
}
|
Title: Merge Equals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $x$ that occurs in the array $2$ or more times. Take the first two occurrences of $x$ in this array (the two leftmost occurrences). Remove the left of these two occurrences, and the right one is replaced by the sum of this two values (that is, $2 \cdot x$).
Determine how the array will look after described operations are performed.
For example, consider the given array looks like $[3, 4, 1, 2, 2, 1, 1]$. It will be changed in the following way: $[3, 4, 1, 2, 2, 1, 1]~\rightarrow~[3, 4, 2, 2, 2, 1]~\rightarrow~[3, 4, 4, 2, 1]~\rightarrow~[3, 8, 2, 1]$.
If the given array is look like $[1, 1, 3, 1, 1]$ it will be changed in the following way: $[1, 1, 3, 1, 1]~\rightarrow~[2, 3, 1, 1]~\rightarrow~[2, 3, 2]~\rightarrow~[3, 4]$.
Input Specification:
The first line contains a single integer $n$ ($2 \le n \le 150\,000$) — the number of elements in the array.
The second line contains a sequence from $n$ elements $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{9}$) — the elements of the array.
Output Specification:
In the first line print an integer $k$ — the number of elements in the array after all the performed operations. In the second line print $k$ integers — the elements of the array after all the performed operations.
Demo Input:
['7\n3 4 1 2 2 1 1\n', '5\n1 1 3 1 1\n', '5\n10 40 20 50 30\n']
Demo Output:
['4\n3 8 2 1 \n', '2\n3 4 \n', '5\n10 40 20 50 30 \n']
Note:
The first two examples were considered in the statement.
In the third example all integers in the given array are distinct, so it will not change.
|
```python
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define push push_back
#define pop pop_back
// #define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define itr iterator
#define f first
#define s second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll ans,i,j,ind,n;
ll a[150001];
map <ll,ll> mp;
int main(){
fast
cin>>n;
for (i=0;i<n;i++){
cin>>a[i];
while(1){
// cout<<a[i]<<" "<<mp[a[i]]<<endl;
if (mp[a[i]]==0){mp[a[i]]=i+1;break;}
ind=mp[a[i]]-1;
mp[a[i]]=0;
a[i]=2*a[i];
a[ind]=-1;
++ans;
// cout<<a[i]<<"ET"<<endl;
}
}
cout<<n-ans<<endl;
for (j=0;j<n;j++){
if (a[j]>0)
cout<<a[j]<<" ";
}
cout<<"\n";
return 0;
}
```
| -1
|
|
305
|
E
|
Playing with String
|
PROGRAMMING
| 2,300
|
[
"games"
] | null | null |
Two people play the following string game. Initially the players have got some string *s*. The players move in turns, the player who cannot make a move loses.
Before the game began, the string is written on a piece of paper, one letter per cell.
A player's move is the sequence of actions:
1. The player chooses one of the available pieces of paper with some string written on it. Let's denote it is *t*. Note that initially, only one piece of paper is available. 1. The player chooses in the string *t*<==<=*t*1*t*2... *t*|*t*| character in position *i* (1<=≤<=*i*<=≤<=|*t*|) such that for some positive integer *l* (0<=<<=*i*<=-<=*l*; *i*<=+<=*l*<=≤<=|*t*|) the following equations hold: *t**i*<=-<=1<==<=*t**i*<=+<=1, *t**i*<=-<=2<==<=*t**i*<=+<=2, ..., *t**i*<=-<=*l*<==<=*t**i*<=+<=*l*. 1. Player cuts the cell with the chosen character. As a result of the operation, he gets three new pieces of paper, the first one will contain string *t*1*t*2... *t**i*<=-<=1, the second one will contain a string consisting of a single character *t**i*, the third one contains string *t**i*<=+<=1*t**i*<=+<=2... *t*|*t*|.
Your task is to determine the winner provided that both players play optimally well. If the first player wins, find the position of character that is optimal to cut in his first move. If there are multiple positions, print the minimal possible one.
|
The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that string *s* only contains lowercase English letters.
|
If the second player wins, print in the single line "Second" (without the quotes). Otherwise, print in the first line "First" (without the quotes), and in the second line print the minimal possible winning move — integer *i* (1<=≤<=*i*<=≤<=|*s*|).
|
[
"abacaba\n",
"abcde\n"
] |
[
"First\n2\n",
"Second\n"
] |
In the first sample the first player has multiple winning moves. But the minimum one is to cut the character in position 2.
In the second sample the first player has no available moves.
| 2,500
|
[
{
"input": "abacaba",
"output": "First\n2"
},
{
"input": "abcde",
"output": "Second"
},
{
"input": "aaaaa",
"output": "First\n3"
},
{
"input": "aaabbbbbbbbabaaabbaabbbbabbabaabaabbbaabbbbbbabbbabaabaaabaaaabbaaabbbbaabbbaaabababbbbabbabbabaaaaabababbbaabbbaabababaaabababbaaaaaaaabbbbabbabbbababbababbbaabbbbbbbabaababaaabababbabbaabbbbbaabaabaabbbabbabbbbabaabbabaaaabbbbaabaaabbaabbabbaaabbbbaaaaaaabbbbbbbbbbabaaabaabababaabababbbbbbbabaababababbbaababaaaabbaababaaabbaaaabbabbabaaaaaabbabbbbbababbabbabbaaababbbaaababbb",
"output": "Second"
},
{
"input": "abbabbaaababbbbbbabbbbaabbabaababaababbbabbbaaaaaabbabbabbaabbbbaaaabbabaababbbabbaabaabbbaabaaaabbbbbabbbbbaababbabaabaababbbbbbbaaaababbabbaababbabaabbbbbabbbbaabaaabbbababaaabbbbabaaaabbbbbbbbbabbbbababababbbbaabbababaaabbabbaaaabaaabbbbabbbaaaabbabbaabaaaabaaaaabaaabbbbaaabababaaabbbaabbababbaaabbbbaabaabbbaaaaaabbaaabbaabbbaaabbbbbabbbbaabababbbababaaabbbaabbbbbaababaaabaabbbbba",
"output": "First\n4"
},
{
"input": "hwlyeasmdahtbvvguqxrbkzzbladwolhqwnelgatnbcwxpcbzdsuriybdopjiljwyjldjvbcgwdlyrrsbpjkkembkxhsqraqzbtartvbptgsbcibfxqgiosreccmvkfvcxvxxejxtthxnaqhkmzihkjcehlubhdsyhpacwfqetifotriilokxgrjsfpwemrgiyjsbxpvvfiycbxzwcuhivdxvjgyaandwncxqkkrvhfwdnhxnbzilfpkbchsjrer",
"output": "Second"
},
{
"input": "gggggggggggggg",
"output": "First\n5"
},
{
"input": "tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogog",
"output": "First\n6"
}
] | 1,371,123,563
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 78
| 0
|
s = input()
d = [0 for i in s]
n = 0
m = 0
for i in range(1, len(s) - 1):
if s[i - 1] == s[i + 1]:
d[i] = d[i - 1] + 1
d[i - 1] = 0
for i in d:
if 1 <= i % 5 <= 2:
n ^= 1
elif i % 5 == 3:
m ^= 1
if n == m == 0:
print('Second')
else:
print('First')
for i in range(1, len(s) - 1):
if m == 0 and d[i] <= 2 or m == n and d[i] >= 3:
print(i - d[i] + 2)
break
if n == 0 and d[i] >= 3:
print(i - d[i] + 3)
break
|
Title: Playing with String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two people play the following string game. Initially the players have got some string *s*. The players move in turns, the player who cannot make a move loses.
Before the game began, the string is written on a piece of paper, one letter per cell.
A player's move is the sequence of actions:
1. The player chooses one of the available pieces of paper with some string written on it. Let's denote it is *t*. Note that initially, only one piece of paper is available. 1. The player chooses in the string *t*<==<=*t*1*t*2... *t*|*t*| character in position *i* (1<=≤<=*i*<=≤<=|*t*|) such that for some positive integer *l* (0<=<<=*i*<=-<=*l*; *i*<=+<=*l*<=≤<=|*t*|) the following equations hold: *t**i*<=-<=1<==<=*t**i*<=+<=1, *t**i*<=-<=2<==<=*t**i*<=+<=2, ..., *t**i*<=-<=*l*<==<=*t**i*<=+<=*l*. 1. Player cuts the cell with the chosen character. As a result of the operation, he gets three new pieces of paper, the first one will contain string *t*1*t*2... *t**i*<=-<=1, the second one will contain a string consisting of a single character *t**i*, the third one contains string *t**i*<=+<=1*t**i*<=+<=2... *t*|*t*|.
Your task is to determine the winner provided that both players play optimally well. If the first player wins, find the position of character that is optimal to cut in his first move. If there are multiple positions, print the minimal possible one.
Input Specification:
The first line contains string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that string *s* only contains lowercase English letters.
Output Specification:
If the second player wins, print in the single line "Second" (without the quotes). Otherwise, print in the first line "First" (without the quotes), and in the second line print the minimal possible winning move — integer *i* (1<=≤<=*i*<=≤<=|*s*|).
Demo Input:
['abacaba\n', 'abcde\n']
Demo Output:
['First\n2\n', 'Second\n']
Note:
In the first sample the first player has multiple winning moves. But the minimum one is to cut the character in position 2.
In the second sample the first player has no available moves.
|
```python
s = input()
d = [0 for i in s]
n = 0
m = 0
for i in range(1, len(s) - 1):
if s[i - 1] == s[i + 1]:
d[i] = d[i - 1] + 1
d[i - 1] = 0
for i in d:
if 1 <= i % 5 <= 2:
n ^= 1
elif i % 5 == 3:
m ^= 1
if n == m == 0:
print('Second')
else:
print('First')
for i in range(1, len(s) - 1):
if m == 0 and d[i] <= 2 or m == n and d[i] >= 3:
print(i - d[i] + 2)
break
if n == 0 and d[i] >= 3:
print(i - d[i] + 3)
break
```
| 0
|
|
75
|
C
|
Modified GCD
|
PROGRAMMING
| 1,600
|
[
"binary search",
"number theory"
] |
C. Modified GCD
|
2
|
256
|
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
|
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
|
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
|
[
"9 27\n3\n1 5\n10 11\n9 11\n"
] |
[
"3\n-1\n9\n"
] |
none
| 1,500
|
[
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input": "84 36\n1\n18 32",
"output": "-1"
},
{
"input": "90 36\n16\n13 15\n5 28\n11 30\n26 35\n2 8\n19 36\n3 17\n5 14\n4 26\n22 33\n16 33\n18 27\n4 17\n1 2\n29 31\n18 36",
"output": "-1\n18\n18\n-1\n6\n-1\n9\n9\n18\n-1\n18\n18\n9\n2\n-1\n18"
},
{
"input": "84 90\n18\n10 75\n2 40\n30 56\n49 62\n19 33\n5 79\n61 83\n13 56\n73 78\n1 18\n23 35\n14 72\n22 33\n1 21\n8 38\n54 82\n6 80\n57 75",
"output": "-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n-1\n6\n-1\n-1\n6\n-1"
},
{
"input": "84 100\n16\n10 64\n3 61\n19 51\n42 67\n51 68\n12 40\n10 47\n52 53\n37 67\n2 26\n23 47\n17 75\n49 52\n3 83\n63 81\n8 43",
"output": "-1\n4\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n4\n-1\n-1\n-1\n4\n-1\n-1"
},
{
"input": "36 60\n2\n17 25\n16 20",
"output": "-1\n-1"
},
{
"input": "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57",
"output": "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "90 36\n8\n1 19\n10 12\n14 28\n21 24\n8 8\n33 34\n10 26\n15 21",
"output": "18\n-1\n18\n-1\n-1\n-1\n18\n18"
},
{
"input": "48 80\n19\n1 1\n16 16\n1 16\n16 48\n16 80\n16 1000000000\n1000000000 1000000000\n1 1000000000\n500000000 1000000000\n15 17\n17 17\n15 15\n8 8\n8 15\n8 16\n8 17\n7 17\n7 15\n9 15",
"output": "1\n16\n16\n16\n16\n16\n-1\n16\n-1\n16\n-1\n-1\n8\n8\n16\n16\n16\n8\n-1"
},
{
"input": "31607 999002449\n18\n31607 31607\n31606 31608\n31607 31608\n31606 31607\n31606 31606\n31608 31608\n1 31607\n1 31606\n1 31608\n1 1000000000\n31607 1000000000\n31606 1000000000\n31608 1000000000\n1000000000 1000000000\n1 1\n2 31606\n2 31607\n2 31608",
"output": "31607\n31607\n31607\n31607\n-1\n-1\n31607\n1\n31607\n31607\n31607\n31607\n-1\n-1\n1\n-1\n31607\n31607"
},
{
"input": "999999937 999999929\n12\n999999929 999999937\n1 1\n1 1000000000\n2 1000000000\n1 2\n999999937 999999937\n999999929 999999929\n2 2\n3 3\n1 100\n1 999999937\n1 999999929",
"output": "-1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1"
}
] | 1,679,571,378
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 4
| 2,000
| 0
|
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
a, b = map(int, input().split())
n = int(input())
for _ in range(n):
low, high = map(int, input().split())
if (gcd(a, b) < low):
print('-1')
else:
g = 1
for i in range(2, a + 1):
if a % i == 0 and b % i == 0:
g = i
break
d = gcd(a, b)
while d > high:
d = gcd(a // g, b)
print(d)
|
Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor *d* between two integers *a* and *b* that is in a given range from *low* to *high* (inclusive), i.e. *low*<=≤<=*d*<=≤<=*high*. It is possible that there is no common divisor in the given range.
You will be given the two integers *a* and *b*, then *n* queries. Each query is a range from *low* to *high* and you have to answer each query.
Input Specification:
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=≤<=109).
Output Specification:
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Demo Input:
['9 27\n3\n1 5\n10 11\n9 11\n']
Demo Output:
['3\n-1\n9\n']
Note:
none
|
```python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
a, b = map(int, input().split())
n = int(input())
for _ in range(n):
low, high = map(int, input().split())
if (gcd(a, b) < low):
print('-1')
else:
g = 1
for i in range(2, a + 1):
if a % i == 0 and b % i == 0:
g = i
break
d = gcd(a, b)
while d > high:
d = gcd(a // g, b)
print(d)
```
| 0
|
930
|
D
|
Game with Tokens
|
PROGRAMMING
| 2,500
|
[
"data structures",
"games",
"implementation"
] | null | null |
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*.
The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or right. Black player can choose directions for each token independently.
After a turn of the white player the white token can not be in a point where a black token is located. There are no other constraints on locations of the tokens: positions of black tokens can coincide, after a turn of the black player and initially the white token can be in the same point with some black point. If at some moment the white player can't make a move, he loses. If the white player makes 10100500 moves, he wins.
You are to solve the following problem. You are given initial positions of all black tokens. It is guaranteed that initially all these positions are distinct. In how many places can the white token be located initially so that if both players play optimally, the black player wins?
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of black points.
The (*i*<=+<=1)-th line contains two integers *x**i*, *y**i* (<=-<=105<=≤<=*x**i*,<=*y**i*,<=<=≤<=105) — the coordinates of the point where the *i*-th black token is initially located.
It is guaranteed that initial positions of black tokens are distinct.
|
Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins.
|
[
"4\n-2 -1\n0 1\n0 -3\n2 -1\n",
"4\n-2 0\n-1 1\n0 -2\n1 -1\n",
"16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2\n"
] |
[
"4\n",
"2\n",
"4\n"
] |
In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/5054b8d2df2fac92c92f96fae82d21c365d12983.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example: <img class="tex-graphics" src="https://espresso.codeforces.com/eb795dd6abb95cfafb1d1cb7d8c8798825dcc180.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the third example the white tokens should be located in the inner square 2 × 2, to make the black player win. <img class="tex-graphics" src="https://espresso.codeforces.com/6dfd863f649b92860dfd6b446ea004abc01b71a6.png" style="max-width: 100.0%;max-height: 100.0%;"/>
| 2,000
|
[
{
"input": "4\n-2 -1\n0 1\n0 -3\n2 -1",
"output": "4"
},
{
"input": "4\n-2 0\n-1 1\n0 -2\n1 -1",
"output": "2"
},
{
"input": "16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2",
"output": "4"
},
{
"input": "1\n1 2",
"output": "0"
},
{
"input": "4\n0 99999\n-99999 0\n99999 0\n0 -99999",
"output": "9999800001"
},
{
"input": "10\n-1 3\n-1 7\n-8 -4\n5 14\n-6 -7\n11 -8\n-11 0\n5 -1\n9 4\n-2 -14",
"output": "110"
},
{
"input": "50\n-15 -80\n-80 21\n90 38\n-100 27\n-64 -75\n-10 59\n38 44\n-31 -91\n97 76\n87 43\n5 43\n-73 74\n-45 42\n31 -100\n-87 19\n-21 -13\n-71 38\n-54 -39\n-89 -32\n-18 99\n-44 -78\n9 76\n-69 -40\n-29 23\n-88 42\n-95 86\n45 15\n-39 100\n17 -33\n5 -48\n-4 -22\n-19 54\n-13 -64\n-86 68\n-52 -95\n-73 -29\n-24 -93\n-60 96\n41 57\n55 43\n-64 15\n-43 9\n29 88\n44 -2\n67 -94\n-20 -81\n-75 -74\n-80 -44\n-49 -7\n39 -59",
"output": "17145"
},
{
"input": "2\n-3 0\n3 2",
"output": "0"
},
{
"input": "3\n-5 3\n4 -5\n-3 2",
"output": "0"
},
{
"input": "4\n-5 1\n0 -3\n-1 4\n5 -5",
"output": "0"
},
{
"input": "4\n-1 4\n-3 2\n-2 1\n-5 3",
"output": "0"
},
{
"input": "5\n-3 -5\n5 2\n-4 1\n-2 0\n1 2",
"output": "0"
},
{
"input": "5\n2 3\n1 -1\n0 2\n0 5\n3 2",
"output": "0"
},
{
"input": "6\n-1 2\n5 -4\n0 4\n3 0\n-4 -1\n-3 -2",
"output": "3"
},
{
"input": "6\n-3 4\n-1 -3\n1 -4\n1 -1\n-5 -1\n1 4",
"output": "0"
},
{
"input": "7\n0 4\n0 3\n-1 3\n4 3\n1 3\n-4 4\n5 4",
"output": "0"
},
{
"input": "7\n4 4\n2 3\n5 -2\n-1 1\n2 2\n-2 -2\n-1 2",
"output": "0"
},
{
"input": "8\n2 -4\n-4 -2\n-3 3\n-3 -1\n4 -4\n2 3\n4 -5\n0 0",
"output": "4"
},
{
"input": "8\n4 -4\n5 -5\n3 2\n-2 5\n-4 -2\n2 5\n-5 5\n5 4",
"output": "2"
},
{
"input": "9\n4 -5\n-4 -3\n4 -4\n1 0\n5 -1\n-3 1\n5 -4\n2 -4\n4 -3",
"output": "4"
},
{
"input": "9\n-2 0\n-4 -4\n0 4\n2 2\n-3 -2\n1 3\n-5 5\n-3 -3\n-1 1",
"output": "5"
},
{
"input": "10\n-1 -2\n-5 2\n-5 0\n-1 0\n4 0\n4 5\n0 -3\n-3 -3\n-5 5\n3 -4",
"output": "2"
},
{
"input": "10\n2 -3\n-3 3\n-1 -1\n3 -5\n5 -3\n0 5\n-4 -4\n2 -4\n-2 -5\n-2 4",
"output": "11"
},
{
"input": "10\n2 -4\n0 -3\n3 2\n-1 3\n1 -1\n4 -5\n-4 2\n1 0\n-2 -5\n-2 2",
"output": "3"
},
{
"input": "10\n-4 -2\n-1 0\n1 -3\n2 5\n3 1\n3 -3\n2 4\n-2 -1\n-3 3\n5 2",
"output": "7"
},
{
"input": "10\n2 0\n1 2\n4 0\n3 -1\n4 3\n-5 4\n-4 -1\n1 -1\n2 -1\n-5 -4",
"output": "3"
},
{
"input": "10\n3 4\n-2 -3\n-2 5\n-2 1\n5 4\n2 -1\n5 -4\n0 1\n4 4\n3 -1",
"output": "6"
},
{
"input": "10\n-1 3\n2 3\n3 2\n-4 -3\n-2 -5\n5 -5\n-4 -4\n0 1\n4 -1\n3 3",
"output": "11"
},
{
"input": "10\n1 -3\n0 4\n-1 3\n-2 3\n4 1\n-1 5\n5 4\n-5 5\n-4 -2\n-5 1",
"output": "5"
},
{
"input": "10\n5 -1\n-2 5\n-5 -1\n-3 -3\n-5 -4\n-3 -2\n-1 -4\n2 5\n4 -5\n1 -4",
"output": "5"
},
{
"input": "10\n-1 0\n5 -1\n-4 1\n-3 0\n-5 -1\n-3 -4\n3 3\n-2 2\n-3 -2\n3 -1",
"output": "2"
},
{
"input": "20\n-16 24\n9 13\n-1 -3\n5 7\n-20 17\n21 5\n-10 8\n0 -14\n17 -5\n7 1\n-6 16\n-18 -9\n-7 -8\n-13 -23\n4 4\n10 -3\n2 -5\n-18 24\n19 -19\n12 -25",
"output": "268"
},
{
"input": "20\n-4 23\n-10 3\n20 25\n24 -23\n1 18\n-23 -24\n-20 -6\n7 22\n11 -18\n-25 -19\n7 -6\n-9 22\n-24 -2\n-9 -17\n-1 12\n-20 -21\n-19 -24\n10 -20\n20 8\n25 -14",
"output": "312"
},
{
"input": "20\n21 20\n23 -21\n-22 24\n-18 -2\n-6 -15\n-20 -10\n-15 21\n-18 5\n13 10\n-11 15\n-6 -1\n17 6\n-13 -23\n8 -9\n-24 21\n8 11\n21 9\n22 12\n-2 -21\n-12 -10",
"output": "459"
},
{
"input": "20\n-5 -7\n-17 22\n13 -4\n19 8\n2 6\n-4 1\n7 -15\n-5 -15\n-14 -13\n14 8\n-13 -23\n8 4\n-13 18\n-17 3\n9 3\n7 -11\n6 -16\n-15 9\n-24 -17\n-20 -18",
"output": "227"
},
{
"input": "20\n-9 5\n-25 -4\n14 -22\n-17 23\n-20 -8\n19 22\n23 -3\n-23 -11\n-2 -15\n22 -4\n-10 -16\n16 22\n9 9\n-18 16\n-25 6\n8 -10\n-2 -17\n-12 6\n20 -10\n17 -6",
"output": "529"
},
{
"input": "20\n-13 15\n1 14\n-12 7\n-18 -15\n-19 -11\n-7 6\n7 -15\n4 18\n-4 10\n-23 16\n-8 -15\n-3 14\n-8 1\n17 19\n15 19\n-3 -12\n-25 16\n-7 -1\n-14 1\n18 3",
"output": "295"
},
{
"input": "20\n-17 7\n0 -21\n15 -10\n-5 12\n18 -12\n-19 11\n24 -19\n-25 -1\n-5 -25\n20 -23\n-4 9\n7 -15\n8 -9\n23 -15\n-2 5\n10 -4\n12 -24\n25 2\n5 -6\n2 25",
"output": "577"
},
{
"input": "20\n17 23\n-7 8\n3 9\n9 -22\n-9 -14\n-18 -10\n-4 2\n10 -3\n-9 19\n-7 9\n-22 4\n6 14\n-9 -18\n2 0\n-17 4\n6 20\n24 13\n22 4\n-14 -1\n-6 -14",
"output": "454"
},
{
"input": "20\n-10 16\n24 18\n-1 -22\n1 4\n4 -19\n-22 8\n-20 -20\n25 24\n-4 8\n7 -11\n-17 -14\n25 -12\n24 23\n-18 15\n23 -1\n-11 -14\n-4 -6\n-14 18\n-10 18\n2 -17",
"output": "487"
},
{
"input": "20\n11 1\n-15 23\n5 24\n7 -13\n-13 -13\n-25 20\n22 -16\n-23 -2\n11 -21\n12 1\n2 3\n-3 -17\n4 21\n-17 12\n13 -14\n1 4\n23 -22\n-18 9\n14 5\n-23 -3",
"output": "502"
}
] | 1,632,748,661
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 62
| 795
| 121,548,800
|
#FB HACKERCUP
import os,sys,math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from _builtin_ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
def so(): return int(input())
def st(): return input()
def mj(): return map(int,input().strip().split(" "))
def msj(): return map(str,input().strip().split(" "))
def le(): return list(map(int,input().split()))
def lebe():return list(map(int, input()))
# def dmain():
# sys.setrecursionlimit(1000000)
# threading.stack_size(1024000)
# thread = threading.Thread(target=main)
# thread.start()
def joro(L):
return(''.join(map(str, L)))
def cheems(c,d):
a=1
while(d!=0):
if(d%2==1):
a*=c
c=c*c
d=d//2
return a
def decimalToBinary(n): return bin(n).replace("0b","")
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
# def npr(n, r):
# return factorial(n) // factorial(n - r) if n >= r else 0
# def ncr(n, r):
# return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0
def lower_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer # min index where x is not less than num
def upper_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer # max index where x is not greater than num
def tir(a,b,c):
if(0==c):
return 1
if(len(a)<=b):
return 0
if(c!=-1):
return (tir(a,1+b,c+a[b]) or tir(a,b+1,c-a[b]) or tir(a,1+b,c))
else:
return (tir(a,1+b,a[b]) or tir(a,b+1,-a[b]) or tir(a,1+b,-1))
def abs(x):
return x if x >= 0 else -x
doi=int(1e9+7)
boi=int(1e9-7)
koi=int(5+2e6)
moi=int(4e6+5+100)
def binary_search(li, val, lb, ub):
# print(lb, ub, li)
ans = -1
while (lb <= ub):
mid = (lb + ub) // 2
# print('mid is',mid, li[mid])
if li[mid] > val:
ub = mid - 1
elif val > li[mid]:
lb = mid + 1
else:
ans = mid # return index
break
return ans
def kadane(x): # maximum sum contiguous subarray
sum_so_far = 0
current_sum = 0
for i in x:
current_sum += i
if current_sum < 0:
current_sum = 0
else:
sum_so_far = max(sum_so_far, current_sum)
return sum_so_far
def wubu(m):
import math as my
d=0
while(not m%2):
m=m//2
d=1+d
for i in range(3,int(my.sqrt(m))+1,2):
while(not m%i):
m=m//i
d=1+d
return int(m>1)+d
def pref(li):
pref_sum = [0]
for i in li:
pref_sum.append(pref_sum[-1] + i)
return pref_sum
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
li = []
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, len(prime)):
if prime[p]:
li.append(p)
return li
def primefactors(n):
import math as my
factors = []
while (n % 2 == 0):
factors.append(2)
n //= 2
for i in range(3, int(my.sqrt(n)) + 1, 2): # only odd factors left
while n % i == 0:
factors.append(i)
n //= i
if n > 2: # incase of prime
factors.append(n)
return factors
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def tr(n):
return n*(n+1)//2
def bro(q,r,c):
bec,pot,h=0,0,0
ds=[]
bs=[]
es=[]
for i in range(c):
while(h<len(r) and r[h]<=q[i][0]):
pot=0
ds.clear()
bs.clear()
h=1+h
for i in range(c):
ds.append(q[i][1])
es.append(q[i][1])
ds=list(set(ds))
for i in ds:
bs.append(es.count(i))
print(bs)
for i in range(c):
if(q[i][0]>r[h-1]):
bec=bec+pot-bs[i]
pot=1+pot
return bec
def iu():
import sys
input = sys.stdin.readline
import math as my
import bisect as by
m=so()
bec=0
A=[0]*moi
B=[0]*moi
C=[0]*moi
D=[0]*moi
E=[0]*moi
F=[0]*moi
for i in range(koi*2+1):
A[i]=sys.maxsize
B[i]=-sys.maxsize
for i in range(1,m+1):
p,q=mj()
r=p+q+koi
s=p-q
A[r]=min(A[r],s)
B[r]=max(B[r],s)
for i in range(2):
C[i]=A[i]
D[i]=B[i]
for i in range(2,1+2*koi):
C[i]=min(C[i-2],A[i])
D[i]=max(B[i],D[i-2])
for i in range(2*koi-2,2*koi+1):
E[i]=A[i]
F[i]=B[i]
for i in range(2*koi-2,-1,-1):
E[i]=min(E[2+i],A[i])
F[i]=max(B[i],F[2+i])
for i in range(1,2*koi+1,1):
se=min(D[i-1],F[1+i])-max(C[i-1],E[1+i])
bec=max(0,se//2)+bec
print(bec)
def main():
for i in range(1):
iu()
# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
main()
#dmain()
# Comment Read()
|
Title: Game with Tokens
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates *x* and *y*.
The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or right. Black player can choose directions for each token independently.
After a turn of the white player the white token can not be in a point where a black token is located. There are no other constraints on locations of the tokens: positions of black tokens can coincide, after a turn of the black player and initially the white token can be in the same point with some black point. If at some moment the white player can't make a move, he loses. If the white player makes 10100500 moves, he wins.
You are to solve the following problem. You are given initial positions of all black tokens. It is guaranteed that initially all these positions are distinct. In how many places can the white token be located initially so that if both players play optimally, the black player wins?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of black points.
The (*i*<=+<=1)-th line contains two integers *x**i*, *y**i* (<=-<=105<=≤<=*x**i*,<=*y**i*,<=<=≤<=105) — the coordinates of the point where the *i*-th black token is initially located.
It is guaranteed that initial positions of black tokens are distinct.
Output Specification:
Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins.
Demo Input:
['4\n-2 -1\n0 1\n0 -3\n2 -1\n', '4\n-2 0\n-1 1\n0 -2\n1 -1\n', '16\n2 1\n1 2\n-1 1\n0 1\n0 0\n1 1\n2 -1\n2 0\n1 0\n-1 -1\n1 -1\n2 2\n0 -1\n-1 0\n0 2\n-1 2\n']
Demo Output:
['4\n', '2\n', '4\n']
Note:
In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/5054b8d2df2fac92c92f96fae82d21c365d12983.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The second example: <img class="tex-graphics" src="https://espresso.codeforces.com/eb795dd6abb95cfafb1d1cb7d8c8798825dcc180.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the third example the white tokens should be located in the inner square 2 × 2, to make the black player win. <img class="tex-graphics" src="https://espresso.codeforces.com/6dfd863f649b92860dfd6b446ea004abc01b71a6.png" style="max-width: 100.0%;max-height: 100.0%;"/>
|
```python
#FB HACKERCUP
import os,sys,math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from _builtin_ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound
def so(): return int(input())
def st(): return input()
def mj(): return map(int,input().strip().split(" "))
def msj(): return map(str,input().strip().split(" "))
def le(): return list(map(int,input().split()))
def lebe():return list(map(int, input()))
# def dmain():
# sys.setrecursionlimit(1000000)
# threading.stack_size(1024000)
# thread = threading.Thread(target=main)
# thread.start()
def joro(L):
return(''.join(map(str, L)))
def cheems(c,d):
a=1
while(d!=0):
if(d%2==1):
a*=c
c=c*c
d=d//2
return a
def decimalToBinary(n): return bin(n).replace("0b","")
def isprime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
# def npr(n, r):
# return factorial(n) // factorial(n - r) if n >= r else 0
# def ncr(n, r):
# return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0
def lower_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer # min index where x is not less than num
def upper_bound(li, num):
answer = -1
start = 0
end = len(li) - 1
while (start <= end):
middle = (end + start) // 2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer # max index where x is not greater than num
def tir(a,b,c):
if(0==c):
return 1
if(len(a)<=b):
return 0
if(c!=-1):
return (tir(a,1+b,c+a[b]) or tir(a,b+1,c-a[b]) or tir(a,1+b,c))
else:
return (tir(a,1+b,a[b]) or tir(a,b+1,-a[b]) or tir(a,1+b,-1))
def abs(x):
return x if x >= 0 else -x
doi=int(1e9+7)
boi=int(1e9-7)
koi=int(5+2e6)
moi=int(4e6+5+100)
def binary_search(li, val, lb, ub):
# print(lb, ub, li)
ans = -1
while (lb <= ub):
mid = (lb + ub) // 2
# print('mid is',mid, li[mid])
if li[mid] > val:
ub = mid - 1
elif val > li[mid]:
lb = mid + 1
else:
ans = mid # return index
break
return ans
def kadane(x): # maximum sum contiguous subarray
sum_so_far = 0
current_sum = 0
for i in x:
current_sum += i
if current_sum < 0:
current_sum = 0
else:
sum_so_far = max(sum_so_far, current_sum)
return sum_so_far
def wubu(m):
import math as my
d=0
while(not m%2):
m=m//2
d=1+d
for i in range(3,int(my.sqrt(m))+1,2):
while(not m%i):
m=m//i
d=1+d
return int(m>1)+d
def pref(li):
pref_sum = [0]
for i in li:
pref_sum.append(pref_sum[-1] + i)
return pref_sum
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
li = []
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, len(prime)):
if prime[p]:
li.append(p)
return li
def primefactors(n):
import math as my
factors = []
while (n % 2 == 0):
factors.append(2)
n //= 2
for i in range(3, int(my.sqrt(n)) + 1, 2): # only odd factors left
while n % i == 0:
factors.append(i)
n //= i
if n > 2: # incase of prime
factors.append(n)
return factors
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def tr(n):
return n*(n+1)//2
def bro(q,r,c):
bec,pot,h=0,0,0
ds=[]
bs=[]
es=[]
for i in range(c):
while(h<len(r) and r[h]<=q[i][0]):
pot=0
ds.clear()
bs.clear()
h=1+h
for i in range(c):
ds.append(q[i][1])
es.append(q[i][1])
ds=list(set(ds))
for i in ds:
bs.append(es.count(i))
print(bs)
for i in range(c):
if(q[i][0]>r[h-1]):
bec=bec+pot-bs[i]
pot=1+pot
return bec
def iu():
import sys
input = sys.stdin.readline
import math as my
import bisect as by
m=so()
bec=0
A=[0]*moi
B=[0]*moi
C=[0]*moi
D=[0]*moi
E=[0]*moi
F=[0]*moi
for i in range(koi*2+1):
A[i]=sys.maxsize
B[i]=-sys.maxsize
for i in range(1,m+1):
p,q=mj()
r=p+q+koi
s=p-q
A[r]=min(A[r],s)
B[r]=max(B[r],s)
for i in range(2):
C[i]=A[i]
D[i]=B[i]
for i in range(2,1+2*koi):
C[i]=min(C[i-2],A[i])
D[i]=max(B[i],D[i-2])
for i in range(2*koi-2,2*koi+1):
E[i]=A[i]
F[i]=B[i]
for i in range(2*koi-2,-1,-1):
E[i]=min(E[2+i],A[i])
F[i]=max(B[i],F[2+i])
for i in range(1,2*koi+1,1):
se=min(D[i-1],F[1+i])-max(C[i-1],E[1+i])
bec=max(0,se//2)+bec
print(bec)
def main():
for i in range(1):
iu()
# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
main()
#dmain()
# Comment Read()
```
| 3
|
|
976
|
A
|
Minimum Binary Number
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
|
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
|
Print one string — the minimum correct string that you can obtain from the given one.
|
[
"4\n1001\n",
"1\n1\n"
] |
[
"100\n",
"1\n"
] |
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use.
| 0
|
[
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "1"
},
{
"input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111",
"output": "10"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "8\n10101010",
"output": "10000"
},
{
"input": "2\n10",
"output": "10"
},
{
"input": "3\n111",
"output": "1"
},
{
"input": "5\n11100",
"output": "100"
},
{
"input": "2\n11",
"output": "1"
},
{
"input": "3\n110",
"output": "10"
},
{
"input": "50\n10010010000000000000000000000000000000001000000000",
"output": "10000000000000000000000000000000000000000000000"
}
] | 1,525,437,646
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 7,065,600
|
a = input()
if (a == '0'):
print(a)
else:
print('1' + a.count('0') * '0')
|
Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10").
Let *val*(*s*) be such a number that *s* is its binary representation.
Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=<<=*val*(*b*).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
Input Specification:
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Output Specification:
Print one string — the minimum correct string that you can obtain from the given one.
Demo Input:
['4\n1001\n', '1\n1\n']
Demo Output:
['100\n', '1\n']
Note:
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100".
In the second example you can't obtain smaller answer no matter what operations you use.
|
```python
a = input()
if (a == '0'):
print(a)
else:
print('1' + a.count('0') * '0')
```
| 0
|
|
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,606,661,164
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 76
| 124
| 0
|
a,b,c,d=list(map(int,input().split()))
print(-1 if d-a-b+c<=0 or a<c or b<c else d-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,d=list(map(int,input().split()))
print(-1 if d-a-b+c<=0 or a<c or b<c else d-a-b+c)
```
| 3
|
|
343
|
B
|
Alternating Current
|
PROGRAMMING
| 1,600
|
[
"data structures",
"greedy",
"implementation"
] | null | null |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.
The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):
Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.
To understand the problem better please read the notes to the test samples.
|
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
|
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
|
[
"-++-\n",
"+-\n",
"++\n",
"-\n"
] |
[
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] |
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:
In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:
In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
| 1,000
|
[
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
"output": "Yes"
},
{
"input": "+",
"output": "No"
},
{
"input": "-+",
"output": "No"
},
{
"input": "--",
"output": "Yes"
},
{
"input": "+++",
"output": "No"
},
{
"input": "--+",
"output": "No"
},
{
"input": "++--++",
"output": "Yes"
},
{
"input": "+-++-+",
"output": "Yes"
},
{
"input": "+-+--+",
"output": "No"
},
{
"input": "--++-+",
"output": "No"
},
{
"input": "-+-+--",
"output": "No"
},
{
"input": "+-+++-",
"output": "No"
},
{
"input": "-+-+-+",
"output": "No"
},
{
"input": "-++-+--++--+-++-",
"output": "Yes"
},
{
"input": "+-----+-++---+------+++-++++",
"output": "No"
},
{
"input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-",
"output": "No"
},
{
"input": "-+-----++++--++-+-++",
"output": "Yes"
},
{
"input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+",
"output": "Yes"
},
{
"input": "-+-+-++-+-+-",
"output": "Yes"
},
{
"input": "-+-++-+-",
"output": "Yes"
},
{
"input": "-+-++-+-+-",
"output": "No"
},
{
"input": "++-+-+-+-+--+",
"output": "No"
},
{
"input": "+++---",
"output": "No"
},
{
"input": "+-+-+-+-+--+-+-+-+-++--++--+",
"output": "Yes"
},
{
"input": "+-+-++",
"output": "No"
},
{
"input": "-++--+--+++-+-+-+-+-",
"output": "No"
},
{
"input": "+---+-+-",
"output": "No"
},
{
"input": "+-+--+-+",
"output": "Yes"
},
{
"input": "+++---+++---",
"output": "No"
},
{
"input": "-+++++",
"output": "No"
},
{
"input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-",
"output": "Yes"
},
{
"input": "-+++--",
"output": "No"
},
{
"input": "+---+",
"output": "No"
},
{
"input": "-++",
"output": "No"
},
{
"input": "-+--+-",
"output": "Yes"
},
{
"input": "+---++--++",
"output": "No"
},
{
"input": "+++-",
"output": "No"
},
{
"input": "--+++",
"output": "No"
},
{
"input": "++-+",
"output": "No"
}
] | 1,602,432,838
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 62
| 280
| 5,017,600
|
s = input()
ss = []
for i in s:
if len(ss) > 0 and ss[-1] == i:
ss.pop()
else:
ss.append(i)
if len(ss) == 0:
print("Yes")
else:
print("No")
|
Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.
The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):
Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.
To understand the problem better please read the notes to the test samples.
Input Specification:
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Output Specification:
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
Demo Input:
['-++-\n', '+-\n', '++\n', '-\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n', 'No\n']
Note:
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:
In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:
In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
|
```python
s = input()
ss = []
for i in s:
if len(ss) > 0 and ss[-1] == i:
ss.pop()
else:
ss.append(i)
if len(ss) == 0:
print("Yes")
else:
print("No")
```
| 3
|
|
253
|
B
|
Physics Practical
|
PROGRAMMING
| 1,400
|
[
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null |
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
|
The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
|
Print a single integer — the minimum number of results Vasya will have to remove.
|
[
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] |
[
"2\n",
"0\n"
] |
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
| 1,000
|
[
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 1 24",
"output": "5"
},
{
"input": "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45",
"output": "0"
},
{
"input": "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18",
"output": "15"
},
{
"input": "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 28 13 8 5 9 2 3 2 29 13 1 2 18 29 28 4 13 3 14 9 20 26 1 19 13 7 8 22 7 5 13 14 10 23",
"output": "29"
},
{
"input": "10\n135 188 160 167 179 192 195 192 193 191",
"output": "0"
},
{
"input": "15\n2 19 19 22 15 24 6 36 20 3 18 27 20 1 10",
"output": "6"
},
{
"input": "25\n8 1 2 1 2 5 3 4 2 6 3 3 4 1 6 1 6 1 4 5 2 9 1 2 1",
"output": "13"
},
{
"input": "40\n4784 4824 4707 4343 4376 4585 4917 4848 3748 4554 3390 4944 4845 3922 4617 4606 4815 4698 4595 4942 4327 4983 4833 4507 3721 4863 4633 4553 4991 4922 4733 4396 4747 4724 4886 4226 4025 4928 4990 4792",
"output": "0"
},
{
"input": "60\n1219 19 647 1321 21 242 677 901 10 165 434 978 448 163 919 517 1085 10 516 920 653 1363 62 98 629 928 998 1335 1448 85 357 432 1298 561 663 182 2095 801 59 208 765 1653 642 645 1378 221 911 749 347 849 43 1804 62 73 613 143 860 297 278 148",
"output": "37"
},
{
"input": "100\n4204 4719 4688 3104 4012 4927 4696 4614 4826 4792 3891 4672 4914 4740 4968 3879 4424 4755 3856 3837 4965 4939 4030 4941 4504 4668 4908 4608 3660 4822 4846 3945 4539 4819 4895 3746 4324 4233 4135 4956 4983 4546 4673 4617 3533 4851 4868 4838 4998 4769 4899 4578 3841 4974 4627 4990 4524 4939 4469 4233 4434 4339 4446 4979 4354 4912 4558 4609 4436 3883 4379 4927 4824 4819 4984 4660 4874 3732 4853 4268 4761 4402 4642 4577 4635 4564 4113 4896 4943 4122 4413 4597 3768 4731 4669 4958 4548 4263 4657 3651",
"output": "0"
},
{
"input": "100\n1354 1797 588 3046 1290 745 217 907 113 381 523 935 791 415 92 1597 1739 1774 240 27 1262 2498 52 1339 1031 1355 2036 230 489 7 69 877 530 2664 1230 940 2712 2651 3410 480 332 699 957 2257 1877 1940 452 1652 1216 3144 236 165 1109 888 1649 346 24 183 1061 1226 2694 3225 2021 1145 907 1671 1599 3395 942 1959 555 1281 675 1125 1386 732 1081 326 256 26 1009 1772 2687 1173 491 709 390 992 519 203 1029 1381 846 1515 705 2859 282 147 1824 299",
"output": "63"
},
{
"input": "100\n2794 2201 4935 564 2876 4472 4196 2571 2260 1479 1451 3497 245 2805 4834 3872 4294 1299 937 2983 1458 3278 1098 2990 4447 4337 4388 947 3708 3382 3694 4562 3827 2312 3760 1181 2830 1256 1054 1583 2094 931 86 2526 998 3420 2248 3461 3662 1715 5 4123 1051 545 3704 1084 1916 695 794 121 1000 1611 3674 1910 4795 2805 825 2392 3551 1148 3738 4650 791 288 1064 2011 2991 2116 2179 3333 1303 498 1610 3092 1935 3450 3524 2624 1596 2801 2290 2297 2327 1602 4779 3135 1231 4203 3283 3580",
"output": "51"
},
{
"input": "2\n1 5",
"output": "1"
}
] | 1,614,400,454
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 216
| 2,150,400
|
from collections import Counter as cc
inp = open("input.txt","r+")
f = inp.readlines()
for i in range(len(f)):
f[i].replace("\n","")
n = int(f[0])
l = list(map(int, f[1].split()))
d = dict(cc(l))
g = sorted(list(d.items()), key = lambda x:x[0])
# print(g)
start = 0
end = len(g)-1
ans=0
while start<end:
if g[start][0]*2>=g[end][0]:
break
else:
if g[start][1]<g[end][1]:
start+=1
ans+=g[start][1]
else:
end-=1
ans+=g[end][1]
outp = open("output.txt","w+")
outp.write(str(ans))
|
Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=≤<=2·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces.
Output Specification:
Print a single integer — the minimum number of results Vasya will have to remove.
Demo Input:
['6\n4 5 3 8 3 7\n', '4\n4 3 2 4\n']
Demo Output:
['2\n', '0\n']
Note:
In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one will be 4.
|
```python
from collections import Counter as cc
inp = open("input.txt","r+")
f = inp.readlines()
for i in range(len(f)):
f[i].replace("\n","")
n = int(f[0])
l = list(map(int, f[1].split()))
d = dict(cc(l))
g = sorted(list(d.items()), key = lambda x:x[0])
# print(g)
start = 0
end = len(g)-1
ans=0
while start<end:
if g[start][0]*2>=g[end][0]:
break
else:
if g[start][1]<g[end][1]:
start+=1
ans+=g[start][1]
else:
end-=1
ans+=g[end][1]
outp = open("output.txt","w+")
outp.write(str(ans))
```
| -1
|
|
126
|
B
|
Password
|
PROGRAMMING
| 1,700
|
[
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
|
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
|
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
|
[
"fixprefixsuffix\n",
"abcdabc\n"
] |
[
"fix",
"Just a legend"
] |
none
| 1,000
|
[
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ghbdtn",
"output": "Just a legend"
},
{
"input": "a",
"output": "Just a legend"
},
{
"input": "aa",
"output": "Just a legend"
},
{
"input": "ab",
"output": "Just a legend"
},
{
"input": "aaa",
"output": "a"
},
{
"input": "aba",
"output": "Just a legend"
},
{
"input": "aab",
"output": "Just a legend"
},
{
"input": "abb",
"output": "Just a legend"
},
{
"input": "abc",
"output": "Just a legend"
},
{
"input": "aaabaabaaaaab",
"output": "Just a legend"
},
{
"input": "aabaaabaaaaab",
"output": "aab"
},
{
"input": "aaabaaaabab",
"output": "Just a legend"
},
{
"input": "abcabcabcabcabc",
"output": "abcabcabc"
},
{
"input": "aaaaabaaaa",
"output": "aaaa"
},
{
"input": "aaaabaaaaaaa",
"output": "aaaa"
},
{
"input": "ghghghgxghghghg",
"output": "ghghg"
},
{
"input": "kincenvizh",
"output": "Just a legend"
},
{
"input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw",
"output": "Just a legend"
},
{
"input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx",
"output": "Just a legend"
},
{
"input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb",
"output": "nfbdzgdlbjhrlvfryyjb"
},
{
"input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp",
"output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp"
},
{
"input": "abcazabca",
"output": "a"
}
] | 1,651,942,179
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 1
| 124
| 3,276,800
|
from string import ascii_lowercase as lc
s=input()
n=len(s)
dt1=dict()
dt2=dict()
dt3=dict()
for i in range(26):
dt1[lc[i]]=i+1
dt2[lc[i]]=(i+1)*2
dt3[lc[i]]=(i+1)*3
l1,l2,l3=[],[],[]
cl1,cl2,cl3=[dt1[s[0]]**2+0],[dt2[s[0]]**3+0],[dt3[s[0]]+0]
for i in range(n):
l1.append(dt1[s[i]]**2)
l2.append(dt2[s[i]]**3)
l3.append(dt3[s[i]])
if i>0:
cl1.append(l1[-1]+cl1[-1])
cl2.append(l2[-1]+cl2[-1])
cl3.append(l3[-1]+cl3[-1])
s1=''
for i in range(n):
s1+=s[-1-i]
rl1,rl2,rl3=[],[],[]
rcl1,rcl2,rcl3=[dt1[s1[0]]**2+0],[dt2[s1[0]]**3+0],[dt3[s1[0]]+0]
for i in range(n):
rl1.append(dt1[s1[i]]**2)
rl2.append(dt2[s1[i]]**3)
rl3.append(dt3[s1[i]])
if i>0:
rcl1.append(rl1[-1]+rcl1[-1])
rcl2.append(rl2[-1]+rcl2[-1])
rcl3.append(rl3[-1]+rcl3[-1])
s1=''
j=0
for i in range(n):
if (cl1[i]==rcl1[i] and cl2[i]==rcl2[i]
and cl3[i]==rcl3[i]):
s1=cl1[i]
s2,s3=cl2[i],cl3[i]
j=i+1
break
ans=''
for i in range(1,n-j-1):
if (cl1[i+j]-cl1[i]==s1 and cl2[i+j]-cl2[i]==s2
and cl3[i+j]-cl3[i]==s3):
ans=s[:j]
break
if ans=='':
ans='just a legend'
print(ans)
|
Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
Input Specification:
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output Specification:
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
Demo Input:
['fixprefixsuffix\n', 'abcdabc\n']
Demo Output:
['fix', 'Just a legend']
Note:
none
|
```python
from string import ascii_lowercase as lc
s=input()
n=len(s)
dt1=dict()
dt2=dict()
dt3=dict()
for i in range(26):
dt1[lc[i]]=i+1
dt2[lc[i]]=(i+1)*2
dt3[lc[i]]=(i+1)*3
l1,l2,l3=[],[],[]
cl1,cl2,cl3=[dt1[s[0]]**2+0],[dt2[s[0]]**3+0],[dt3[s[0]]+0]
for i in range(n):
l1.append(dt1[s[i]]**2)
l2.append(dt2[s[i]]**3)
l3.append(dt3[s[i]])
if i>0:
cl1.append(l1[-1]+cl1[-1])
cl2.append(l2[-1]+cl2[-1])
cl3.append(l3[-1]+cl3[-1])
s1=''
for i in range(n):
s1+=s[-1-i]
rl1,rl2,rl3=[],[],[]
rcl1,rcl2,rcl3=[dt1[s1[0]]**2+0],[dt2[s1[0]]**3+0],[dt3[s1[0]]+0]
for i in range(n):
rl1.append(dt1[s1[i]]**2)
rl2.append(dt2[s1[i]]**3)
rl3.append(dt3[s1[i]])
if i>0:
rcl1.append(rl1[-1]+rcl1[-1])
rcl2.append(rl2[-1]+rcl2[-1])
rcl3.append(rl3[-1]+rcl3[-1])
s1=''
j=0
for i in range(n):
if (cl1[i]==rcl1[i] and cl2[i]==rcl2[i]
and cl3[i]==rcl3[i]):
s1=cl1[i]
s2,s3=cl2[i],cl3[i]
j=i+1
break
ans=''
for i in range(1,n-j-1):
if (cl1[i+j]-cl1[i]==s1 and cl2[i+j]-cl2[i]==s2
and cl3[i+j]-cl3[i]==s3):
ans=s[:j]
break
if ans=='':
ans='just a legend'
print(ans)
```
| 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,405,259,264
| 2,864
|
Python 3
|
OK
|
TESTS
| 24
| 77
| 0
|
st=input()
k=int(input())
w=list(map(int,input().split()))
w2={chr(ord('a')+i):w[i] for i in range(26)}
m=max(w)
print(sum([w2[st[i]]*(i+1) for i in range(len(st))])+sum([i*m for i in range(len(st)+1,len(st)+1+k)]))
|
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
st=input()
k=int(input())
w=list(map(int,input().split()))
w2={chr(ord('a')+i):w[i] for i in range(26)}
m=max(w)
print(sum([w2[st[i]]*(i+1) for i in range(len(st))])+sum([i*m for i in range(len(st)+1,len(st)+1+k)]))
```
| 3
|
|
514
|
A
|
Chewbaсca and Number
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation"
] | null | null |
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
|
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
|
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
|
[
"27\n",
"4545\n"
] |
[
"22\n",
"4444\n"
] |
none
| 500
|
[
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 1,699,808,370
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 31
| 0
|
n=list(input())
index=0
for i in n:
if i>='5':
if index:n[index]=str(9-int(i))
index+=1
print(*n,sep='')
|
Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Output Specification:
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
Demo Input:
['27\n', '4545\n']
Demo Output:
['22\n', '4444\n']
Note:
none
|
```python
n=list(input())
index=0
for i in n:
if i>='5':
if index:n[index]=str(9-int(i))
index+=1
print(*n,sep='')
```
| 0
|
|
478
|
C
|
Table Decorations
|
PROGRAMMING
| 1,800
|
[
"greedy"
] | null | null |
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner.
|
The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
|
Print a single integer *t* — the maximum number of tables that can be decorated in the required manner.
|
[
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] |
[
"4\n",
"1\n",
"2\n"
] |
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.
| 1,500
|
[
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "100 99 56",
"output": "85"
},
{
"input": "1000 1000 1002",
"output": "1000"
},
{
"input": "0 1 1000000000",
"output": "1"
},
{
"input": "500000000 1000000000 500000000",
"output": "666666666"
},
{
"input": "1000000000 2000000000 1000000000",
"output": "1333333333"
},
{
"input": "2000000000 2000000000 2000000000",
"output": "2000000000"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "1 2000000000 1000000000",
"output": "1000000000"
},
{
"input": "1585222789 1889821127 2000000000",
"output": "1825014638"
},
{
"input": "10000 7500 7500",
"output": "8333"
},
{
"input": "150000 75000 75000",
"output": "100000"
},
{
"input": "999288131 55884921 109298382",
"output": "165183303"
},
{
"input": "100500 100500 3",
"output": "67001"
},
{
"input": "1463615122 1988383731 837331500",
"output": "1429776784"
},
{
"input": "1938 8999 1882",
"output": "3820"
},
{
"input": "45 33 76",
"output": "51"
},
{
"input": "100000 1 2",
"output": "3"
},
{
"input": "198488 50 18",
"output": "68"
},
{
"input": "82728372 939848 100139442",
"output": "61269220"
},
{
"input": "99 5747 5298",
"output": "3714"
},
{
"input": "3 5 2",
"output": "3"
},
{
"input": "7511 7512 7513",
"output": "7512"
},
{
"input": "1234567890 123456789 987654321",
"output": "781893000"
},
{
"input": "500000000 2000000000 500000000",
"output": "1000000000"
},
{
"input": "500000002 2000000000 500000001",
"output": "1000000001"
},
{
"input": "520000000 1000000033 501000000",
"output": "673666677"
},
{
"input": "10000 1000 100000",
"output": "11000"
},
{
"input": "2000000000 500000000 499999999",
"output": "999999999"
},
{
"input": "1999999999 500000000 500000000",
"output": "999999999"
},
{
"input": "1 1 9",
"output": "2"
},
{
"input": "3 0 0",
"output": "0"
},
{
"input": "6 1 1",
"output": "2"
},
{
"input": "2000000000 1999999999 1999999999",
"output": "1999999999"
},
{
"input": "3 4 9",
"output": "5"
},
{
"input": "3 3 6",
"output": "4"
}
] | 1,668,599,366
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 42
| 77
| 0
|
r,g,b = map(int,input().split())
print(min(r+g,r+b,b+g,(r+b+g)//3))
|
Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values *r*, *g* and *b* will find the maximum number *t* of tables, that can be decorated in the required manner.
Input Specification:
The single line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Output Specification:
Print a single integer *t* — the maximum number of tables that can be decorated in the required manner.
Demo Input:
['5 4 3\n', '1 1 1\n', '2 3 3\n']
Demo Output:
['4\n', '1\n', '2\n']
Note:
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.
|
```python
r,g,b = map(int,input().split())
print(min(r+g,r+b,b+g,(r+b+g)//3))
```
| 3
|
|
879
|
A
|
Borya's Diagnosis
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor *i* goes to work on the *s**i*-th day and works every *d**i* day. So, he works on days *s**i*,<=*s**i*<=+<=*d**i*,<=*s**i*<=+<=2*d**i*,<=....
The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?
|
First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000).
|
Output a single integer — the minimum day at which Borya can visit the last doctor.
|
[
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] |
[
"4\n",
"11\n"
] |
In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11.
| 500
|
[
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
{
"input": "6\n1 3\n2 5\n4 7\n7 5\n6 8\n8 8",
"output": "16"
},
{
"input": "10\n4 10\n8 7\n6 5\n2 1\n2 3\n8 8\n2 4\n2 2\n6 7\n7 9",
"output": "34"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "1\n1000 1000",
"output": "1000"
},
{
"input": "42\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\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\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "83"
},
{
"input": "2\n5 5\n5 1",
"output": "6"
},
{
"input": "2\n5 5\n5 5",
"output": "10"
},
{
"input": "2\n1 1\n1 1",
"output": "2"
},
{
"input": "2\n1 6\n7 1",
"output": "7"
},
{
"input": "2\n4 3\n4 5",
"output": "9"
},
{
"input": "2\n1 2\n1 3",
"output": "4"
},
{
"input": "3\n2 3\n5 1\n2 1",
"output": "6"
},
{
"input": "2\n2 1\n6 3",
"output": "6"
},
{
"input": "3\n10 1\n4 4\n12 1",
"output": "13"
},
{
"input": "2\n2 2\n10 2",
"output": "10"
},
{
"input": "2\n1 1\n1000 2",
"output": "1000"
},
{
"input": "14\n1000 1\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1",
"output": "13001"
},
{
"input": "2\n2 4\n2 1",
"output": "3"
},
{
"input": "3\n1 100\n100 3\n200 1",
"output": "200"
},
{
"input": "7\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1",
"output": "6001"
},
{
"input": "2\n5 5\n15 5",
"output": "15"
},
{
"input": "2\n2 2\n2 4",
"output": "6"
},
{
"input": "2\n1 1\n10 1",
"output": "10"
},
{
"input": "2\n10 1\n100 1",
"output": "100"
},
{
"input": "15\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1",
"output": "14001"
},
{
"input": "3\n2 1\n1 3\n4 7",
"output": "11"
},
{
"input": "2\n5 5\n100 5",
"output": "100"
},
{
"input": "2\n1 10\n2 30",
"output": "2"
},
{
"input": "4\n2 2\n2 2\n2 2\n2 2",
"output": "8"
},
{
"input": "1\n10 10",
"output": "10"
}
] | 1,548,411,327
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 51
| 124
| 0
|
n = int(input())
cur = 0
for i in range(n):
s, d = map(int, input().split())
q = max(0, cur - s + d) // d
cur = q * d + s
print(cur)
|
Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.
Doctors have a strange working schedule. The doctor *i* goes to work on the *s**i*-th day and works every *d**i* day. So, he works on days *s**i*,<=*s**i*<=+<=*d**i*,<=*s**i*<=+<=2*d**i*,<=....
The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?
Input Specification:
First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000).
Output Specification:
Output a single integer — the minimum day at which Borya can visit the last doctor.
Demo Input:
['3\n2 2\n1 2\n2 2\n', '2\n10 1\n6 5\n']
Demo Output:
['4\n', '11\n']
Note:
In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11.
|
```python
n = int(input())
cur = 0
for i in range(n):
s, d = map(int, input().split())
q = max(0, cur - s + d) // d
cur = q * d + s
print(cur)
```
| 3
|
|
8
|
B
|
Obsession with Robots
|
PROGRAMMING
| 1,400
|
[
"constructive algorithms",
"graphs",
"implementation"
] |
B. Obsession with Robots
|
2
|
64
|
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
|
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
|
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
|
[
"LLUUUR\n",
"RRUULLDD\n"
] |
[
"OK\n",
"BUG\n"
] |
none
| 0
|
[
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"output": "OK"
},
{
"input": "LD",
"output": "OK"
},
{
"input": "RUL",
"output": "BUG"
},
{
"input": "ULD",
"output": "BUG"
},
{
"input": "DDR",
"output": "OK"
},
{
"input": "RRDD",
"output": "OK"
},
{
"input": "RRLR",
"output": "BUG"
},
{
"input": "RRDL",
"output": "BUG"
},
{
"input": "LRUD",
"output": "BUG"
},
{
"input": "RDRLL",
"output": "BUG"
},
{
"input": "DRDRD",
"output": "OK"
},
{
"input": "ULURL",
"output": "BUG"
},
{
"input": "LUUDU",
"output": "BUG"
},
{
"input": "RDLUR",
"output": "BUG"
},
{
"input": "DLDLDDRR",
"output": "OK"
},
{
"input": "RDRDDD",
"output": "OK"
},
{
"input": "UULLDLUR",
"output": "BUG"
},
{
"input": "LULU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "LLDDLDLLDDDLLLDLLLLLUU",
"output": "OK"
},
{
"input": "URRRRRURRURUURRRRRDDDDLDDDRDDDDLLDLL",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "UL",
"output": "OK"
},
{
"input": "UDR",
"output": "BUG"
},
{
"input": "DDDR",
"output": "OK"
},
{
"input": "UUUDU",
"output": "BUG"
},
{
"input": "LULULL",
"output": "OK"
},
{
"input": "DLURUUU",
"output": "BUG"
},
{
"input": "UURUURRUUU",
"output": "OK"
},
{
"input": "DDDDRDDLDDDDDDDRDDLD",
"output": "OK"
},
{
"input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU",
"output": "BUG"
},
{
"input": "RURRRRLURRRURRUURRRRRRRRDDULULRRURRRDRRRRRRRRRRLDR",
"output": "BUG"
},
{
"input": "RLRRRRRDRRDRRRRDLRRRRRRRDLRLDDLRRRRLDLDRDRRRRDRDRDRDLRRURRLRRRRDRRRRRRRRLDDRLRRDRRRRRRRDRDRLDRDDDRDR",
"output": "BUG"
},
{
"input": "DDUL",
"output": "BUG"
},
{
"input": "UUULLLLRDD",
"output": "BUG"
},
{
"input": "LLLLLLLLRRRRDDDDDDDUUUUUU",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDUUUUUUUUUUUURRRRRRRRRRRRRLLLLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "DLUR",
"output": "BUG"
},
{
"input": "UUUURDLLLL",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRURLLLLLLLLLLLL",
"output": "BUG"
},
{
"input": "LLLLLLLLLLLLLLLLLLLLLLLLLLRUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "BUG"
},
{
"input": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDLDRRR",
"output": "BUG"
},
{
"input": "RRUULLD",
"output": "BUG"
},
{
"input": "LUUUULLLLDDDDRRRD",
"output": "BUG"
},
{
"input": "DDDDLLLDDDRRRUURRRR",
"output": "BUG"
},
{
"input": "DDDDDDDLLDDRRURRRRRRR",
"output": "BUG"
},
{
"input": "DDDDDDDDDDLLLLLLLLLLLDDDDDDDDDDDRRRRRRRRRRRUUUUUUUUUURRRRRRRRRR",
"output": "BUG"
},
{
"input": "DDDLLLLLLLDDDDDDDRRRRRRRUUUUUURRR",
"output": "BUG"
},
{
"input": "RRRUUULLLDD",
"output": "BUG"
},
{
"input": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLDDDDRRRRUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BUG"
},
{
"input": "RRRRRRRRRRRDDDDDDDDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLUUUUUUUUUUU",
"output": "BUG"
}
] | 1,680,434,813
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 0
|
def robots(s):
visited = set()
p = [0, 0]
for i in s:
if i == 'R': p[0] += 1
elif i == 'L': p[0] -= 1
elif i == 'U': p[1] += 1
elif i == 'D': p[1] -= 1
if str(p) in visited: return ("BUG")
visited.add(str([p[0]-1, p[1]]))
visited.add(str([p[0]+1, p[1]]))
visited.add(str([p[0], p[1]-1]))
visited.add(str([p[0], p[1]+1]))
return ("OK")
s = input()
print(robots(s))
|
Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
Input Specification:
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
Output Specification:
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
Demo Input:
['LLUUUR\n', 'RRUULLDD\n']
Demo Output:
['OK\n', 'BUG\n']
Note:
none
|
```python
def robots(s):
visited = set()
p = [0, 0]
for i in s:
if i == 'R': p[0] += 1
elif i == 'L': p[0] -= 1
elif i == 'U': p[1] += 1
elif i == 'D': p[1] -= 1
if str(p) in visited: return ("BUG")
visited.add(str([p[0]-1, p[1]]))
visited.add(str([p[0]+1, p[1]]))
visited.add(str([p[0], p[1]-1]))
visited.add(str([p[0], p[1]+1]))
return ("OK")
s = input()
print(robots(s))
```
| 0
|
681
|
A
|
A Good Contest
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
|
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
|
[
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] |
[
"YES",
"NO"
] |
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
| 500
|
[
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155",
"output": "NO"
},
{
"input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968",
"output": "NO"
},
{
"input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290",
"output": "NO"
},
{
"input": "1\na 2400 2401",
"output": "YES"
},
{
"input": "1\nfucker 4000 4000",
"output": "NO"
},
{
"input": "1\nJora 2400 2401",
"output": "YES"
},
{
"input": "1\nACA 2400 2420",
"output": "YES"
},
{
"input": "1\nAca 2400 2420",
"output": "YES"
},
{
"input": "1\nSub_d 2401 2402",
"output": "YES"
},
{
"input": "2\nHack 2400 2401\nDum 1243 555",
"output": "YES"
},
{
"input": "1\nXXX 2400 2500",
"output": "YES"
},
{
"input": "1\nfucker 2400 2401",
"output": "YES"
},
{
"input": "1\nX 2400 2500",
"output": "YES"
},
{
"input": "1\nvineet 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2500",
"output": "YES"
},
{
"input": "1\naaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nhoge 2400 2401",
"output": "YES"
},
{
"input": "1\nInfinity 2400 2468",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2401",
"output": "YES"
},
{
"input": "1\nFuck 2400 2401",
"output": "YES"
},
{
"input": "1\nfuck 2400 2401",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "YES"
},
{
"input": "1\nalex 2400 2401",
"output": "YES"
},
{
"input": "1\nA 2400 2401",
"output": "YES"
},
{
"input": "1\na 2400 2455",
"output": "YES"
},
{
"input": "1\nlol 2400 2401",
"output": "YES"
},
{
"input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214",
"output": "YES"
},
{
"input": "1\naaaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2500",
"output": "YES"
},
{
"input": "1\nds 2400 2410",
"output": "YES"
},
{
"input": "1\nas 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2401",
"output": "YES"
},
{
"input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537",
"output": "YES"
},
{
"input": "1\ncaonima 2400 2401",
"output": "YES"
},
{
"input": "1\narr 2400 2500",
"output": "YES"
},
{
"input": "1\nx 2400 2401",
"output": "YES"
},
{
"input": "1\narrr 2400 2500",
"output": "YES"
},
{
"input": "1\nabc 2400 2405",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2537",
"output": "YES"
},
{
"input": "1\nHELLO 2400 2401",
"output": "YES"
},
{
"input": "1\neatmore 2400 2500",
"output": "YES"
},
{
"input": "1\nb 2400 2401",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nApplejack 2400 2410",
"output": "YES"
},
{
"input": "1\nabacaba 2400 2451",
"output": "YES"
},
{
"input": "1\nrekt_n00b 2500 2600",
"output": "YES"
}
] | 1,561,213,214
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 60
| 109
| 0
|
n = int(input())
flag = 'NO'
for i in range(n):
text, f, s = input().split()
if int(s) > int(f) >= 2400:
flag = 'YES'
print(flag)
|
Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
Output Specification:
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
Demo Input:
['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
|
```python
n = int(input())
flag = 'NO'
for i in range(n):
text, f, s = input().split()
if int(s) > int(f) >= 2400:
flag = 'YES'
print(flag)
```
| 3
|
|
443
|
A
|
Anton and Letters
|
PROGRAMMING
| 800
|
[
"constructive algorithms",
"implementation"
] | null | null |
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
|
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
|
Print a single number — the number of distinct letters in Anton's set.
|
[
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] |
[
"3\n",
"2\n",
"0\n"
] |
none
| 500
|
[
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"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, 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, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,693,950,888
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
print(len(set(list(input().split())[1:-1])))
|
Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none
|
```python
print(len(set(list(input().split())[1:-1])))
```
| 0
|
|
691
|
A
|
Fashion in Berland
|
PROGRAMMING
| 1,000
|
[
"implementation"
] | null | null |
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
|
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
|
[
"3\n1 0 1\n",
"3\n1 0 0\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 0
|
[
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
},
{
"input": "3\n0 1 1",
"output": "YES"
},
{
"input": "3\n0 1 0",
"output": "NO"
},
{
"input": "2\n0 1",
"output": "YES"
},
{
"input": "2\n1 0",
"output": "YES"
},
{
"input": "2\n0 0",
"output": "NO"
},
{
"input": "2\n1 1",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "1\n0",
"output": "NO"
},
{
"input": "10\n1 0 1 1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5\n1 1 1 1 0",
"output": "YES"
},
{
"input": "4\n1 0 1 0",
"output": "NO"
},
{
"input": "4\n1 1 0 0",
"output": "NO"
},
{
"input": "10\n0 0 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "94\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "64\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "34\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "10\n1 1 0 1 1 1 0 1 1 1",
"output": "NO"
}
] | 1,523,693,238
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 77
| 7,065,600
|
n = input()
list = [int(x) for x in input().split()]
print(list)
result = True
k = list[0]
for i in range(1, len(list)):
if list[i] == list[i-1]:
result = False
break
if result:
print('YES')
else:
print('NO')
|
Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
Output Specification:
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
Demo Input:
['3\n1 0 1\n', '3\n1 0 0\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none
|
```python
n = input()
list = [int(x) for x in input().split()]
print(list)
result = True
k = list[0]
for i in range(1, len(list)):
if list[i] == list[i-1]:
result = False
break
if result:
print('YES')
else:
print('NO')
```
| 0
|
|
798
|
A
|
Mike and palindrome
|
PROGRAMMING
| 1,000
|
[
"brute force",
"constructive algorithms",
"strings"
] | null | null |
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
|
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
|
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
|
[
"abccaa\n",
"abbcca\n",
"abcda\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
none
| 500
|
[
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input": "gqrk",
"output": "NO"
},
{
"input": "glxlg",
"output": "YES"
},
{
"input": "czhfc",
"output": "YES"
},
{
"input": "broon",
"output": "NO"
},
{
"input": "rmggmr",
"output": "NO"
},
{
"input": "wvxxzw",
"output": "YES"
},
{
"input": "ukvciu",
"output": "NO"
},
{
"input": "vrnwnrv",
"output": "YES"
},
{
"input": "vlkjkav",
"output": "YES"
},
{
"input": "guayhmg",
"output": "NO"
},
{
"input": "lkvhhvkl",
"output": "NO"
},
{
"input": "ffdsslff",
"output": "YES"
},
{
"input": "galjjtyw",
"output": "NO"
},
{
"input": "uosgwgsou",
"output": "YES"
},
{
"input": "qjwmjmljq",
"output": "YES"
},
{
"input": "ustrvrodf",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "qjfyjjyfjq",
"output": "NO"
},
{
"input": "ysxibbixsq",
"output": "YES"
},
{
"input": "howfslfwmh",
"output": "NO"
},
{
"input": "ekhajrjahke",
"output": "YES"
},
{
"input": "ucnolsloncw",
"output": "YES"
},
{
"input": "jrzsfrrkrtj",
"output": "NO"
},
{
"input": "typayzzyapyt",
"output": "NO"
},
{
"input": "uwdhkzokhdwu",
"output": "YES"
},
{
"input": "xokxpyyuafij",
"output": "NO"
},
{
"input": "eusneioiensue",
"output": "YES"
},
{
"input": "fuxpuajabpxuf",
"output": "YES"
},
{
"input": "guvggtfhlgruy",
"output": "NO"
},
{
"input": "cojhkhxxhkhjoc",
"output": "NO"
},
{
"input": "mhifbmmmmbmihm",
"output": "YES"
},
{
"input": "kxfqqncnebpami",
"output": "NO"
},
{
"input": "scfwrjevejrwfcs",
"output": "YES"
},
{
"input": "thdaonpepdoadht",
"output": "YES"
},
{
"input": "jsfzcbnhsccuqsj",
"output": "NO"
},
{
"input": "nn",
"output": "NO"
},
{
"input": "nm",
"output": "YES"
},
{
"input": "jdj",
"output": "YES"
},
{
"input": "bbcaa",
"output": "NO"
},
{
"input": "abcde",
"output": "NO"
},
{
"input": "abcdf",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "abecd",
"output": "NO"
},
{
"input": "abccacb",
"output": "NO"
},
{
"input": "aabc",
"output": "NO"
},
{
"input": "anpqb",
"output": "NO"
},
{
"input": "c",
"output": "YES"
},
{
"input": "abcdefg",
"output": "NO"
},
{
"input": "aanbb",
"output": "NO"
},
{
"input": "aabbb",
"output": "NO"
},
{
"input": "aaabbab",
"output": "NO"
},
{
"input": "ab",
"output": "YES"
},
{
"input": "aabbc",
"output": "NO"
},
{
"input": "ecabd",
"output": "NO"
},
{
"input": "abcdrty",
"output": "NO"
},
{
"input": "abcdmnp",
"output": "NO"
},
{
"input": "bbbbbb",
"output": "NO"
},
{
"input": "abcxuio",
"output": "NO"
},
{
"input": "abcdabcde",
"output": "NO"
},
{
"input": "abcxpoi",
"output": "NO"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "aacbb",
"output": "NO"
},
{
"input": "abcedca",
"output": "NO"
},
{
"input": "abcdd",
"output": "NO"
},
{
"input": "abbcs",
"output": "NO"
},
{
"input": "aaabccc",
"output": "NO"
},
{
"input": "paxkxbq",
"output": "NO"
},
{
"input": "z",
"output": "YES"
},
{
"input": "b",
"output": "YES"
},
{
"input": "abcdefghi",
"output": "NO"
},
{
"input": "abcqr",
"output": "NO"
},
{
"input": "abcdc",
"output": "NO"
},
{
"input": "abcb",
"output": "NO"
},
{
"input": "aabcd",
"output": "NO"
},
{
"input": "abbba",
"output": "YES"
},
{
"input": "aaabbb",
"output": "NO"
},
{
"input": "bb",
"output": "NO"
},
{
"input": "aaacbbb",
"output": "NO"
},
{
"input": "abbzcca",
"output": "NO"
},
{
"input": "abxab",
"output": "NO"
},
{
"input": "bbb",
"output": "YES"
},
{
"input": "abcrtyu",
"output": "NO"
},
{
"input": "cbacb",
"output": "NO"
},
{
"input": "acbb",
"output": "NO"
},
{
"input": "ww",
"output": "NO"
},
{
"input": "aaaaaa",
"output": "NO"
},
{
"input": "jizzz",
"output": "NO"
},
{
"input": "aaakcba",
"output": "NO"
},
{
"input": "acbak",
"output": "NO"
},
{
"input": "bddeffd",
"output": "NO"
},
{
"input": "aaa",
"output": "YES"
},
{
"input": "afghqwe",
"output": "NO"
},
{
"input": "abcdfga",
"output": "NO"
}
] | 1,637,732,392
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 7
| 31
| 0
|
n=input()
l=len(n)
s=0
for i in range(l):
if n[i]!=n[l-i-1]:
s+=1
if s<=2 and s>=1:
print("YES")
else:
print("NO")
|
Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input Specification:
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Output Specification:
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Demo Input:
['abccaa\n', 'abbcca\n', 'abcda\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none
|
```python
n=input()
l=len(n)
s=0
for i in range(l):
if n[i]!=n[l-i-1]:
s+=1
if s<=2 and s>=1:
print("YES")
else:
print("NO")
```
| 0
|
|
629
|
B
|
Far Relative’s Problem
|
PROGRAMMING
| 1,100
|
[
"brute force"
] | null | null |
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.
Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive.
|
Print the maximum number of people that may come to Famil Door's party.
|
[
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
] |
[
"2\n",
"4\n"
] |
In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
| 1,000
|
[
{
"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128",
"output": "2"
},
{
"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200",
"output": "4"
},
{
"input": "1\nF 68 307",
"output": "0"
},
{
"input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\nM 330 363\nF 154 231\nF 216 352\nF 357 365\nM 279 292\nF 353 359\nF 82 183\nM 78 297\nM 231 314\nM 107 264\nF 34 318\nM 44 244\nF 42 339\nM 253 307\nM 128 192\nF 119 328\nM 135 249\nF 303 358\nF 348 352\nF 8 364\nF 126 303\nM 226 346\nF 110 300\nF 47 303\nF 201 311\nF 287 288\nM 270 352\nM 227 351\nF 8 111\nF 39 229\nM 163 315\nF 269 335\nF 147 351\nF 96 143\nM 97 99\nM 177 295",
"output": "22"
},
{
"input": "2\nF 1 1\nM 1 1",
"output": "2"
},
{
"input": "4\nM 1 2\nM 2 3\nF 3 4\nF 4 5",
"output": "2"
},
{
"input": "1\nF 1 2",
"output": "0"
},
{
"input": "18\nF 3 4\nF 3 4\nF 3 4\nF 3 4\nF 5 6\nF 5 6\nM 3 4\nM 3 4\nM 5 6\nM 5 6\nM 5 6\nM 5 6\nF 7 8\nF 7 8\nF 7 8\nM 7 8\nM 7 8\nM 7 8",
"output": "6"
},
{
"input": "2\nM 1 1\nF 1 1",
"output": "2"
},
{
"input": "3\nM 1 1\nF 1 1\nM 1 1",
"output": "2"
}
] | 1,489,481,431
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 76
| 546
| 5,017,600
|
n = int(input())
gender = []
fromdate = []
todate = []
for k in range(n):
a, b, c = input().split()
gender.append(a)
fromdate.append(int(b))
todate.append(int(c))
minimum = min(fromdate)
maximum = max(todate)
#print("min = {} max = {}".format(minimum,maximum))
ans = 0
for i in range(minimum, maximum + 1):
male = 0
women = 0
for j in range(n):
if fromdate[j] <= i and todate[j] >= i:
if gender[j] == 'M':
male += 1
else:
women += 1
count = min(male, women) * 2
#print(count)
if count > ans:
ans = count
print(ans)
|
Title: Far Relative’s Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.
Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=366), providing that the *i*-th friend can come to the party from day *a**i* to day *b**i* inclusive.
Output Specification:
Print the maximum number of people that may come to Famil Door's party.
Demo Input:
['4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n', '6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
|
```python
n = int(input())
gender = []
fromdate = []
todate = []
for k in range(n):
a, b, c = input().split()
gender.append(a)
fromdate.append(int(b))
todate.append(int(c))
minimum = min(fromdate)
maximum = max(todate)
#print("min = {} max = {}".format(minimum,maximum))
ans = 0
for i in range(minimum, maximum + 1):
male = 0
women = 0
for j in range(n):
if fromdate[j] <= i and todate[j] >= i:
if gender[j] == 'M':
male += 1
else:
women += 1
count = min(male, women) * 2
#print(count)
if count > ans:
ans = count
print(ans)
```
| 3
|
|
771
|
A
|
Bear and Friendship Condition
|
PROGRAMMING
| 1,500
|
[
"dfs and similar",
"dsu",
"graphs"
] | null | null |
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
|
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
|
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
|
[
"4 3\n1 3\n3 4\n1 4\n",
"4 4\n3 1\n2 3\n3 4\n1 2\n",
"10 4\n4 3\n5 10\n8 9\n1 2\n",
"3 2\n1 2\n2 3\n"
] |
[
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] |
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
| 250
|
[
{
"input": "4 3\n1 3\n3 4\n1 4",
"output": "YES"
},
{
"input": "4 4\n3 1\n2 3\n3 4\n1 2",
"output": "NO"
},
{
"input": "10 4\n4 3\n5 10\n8 9\n1 2",
"output": "YES"
},
{
"input": "3 2\n1 2\n2 3",
"output": "NO"
},
{
"input": "3 0",
"output": "YES"
},
{
"input": "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8",
"output": "YES"
},
{
"input": "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11",
"output": "NO"
},
{
"input": "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69",
"output": "NO"
},
{
"input": "3 1\n1 2",
"output": "YES"
},
{
"input": "3 2\n3 2\n1 3",
"output": "NO"
},
{
"input": "3 3\n2 3\n1 2\n1 3",
"output": "YES"
},
{
"input": "4 2\n4 1\n2 1",
"output": "NO"
},
{
"input": "4 3\n3 1\n2 1\n3 2",
"output": "YES"
},
{
"input": "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2",
"output": "NO"
},
{
"input": "10 5\n9 5\n1 2\n6 8\n6 3\n10 6",
"output": "NO"
},
{
"input": "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8",
"output": "NO"
},
{
"input": "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3",
"output": "NO"
},
{
"input": "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762",
"output": "YES"
},
{
"input": "150000 0",
"output": "YES"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n1 4",
"output": "NO"
},
{
"input": "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7",
"output": "NO"
},
{
"input": "5 4\n1 2\n2 5\n3 4\n4 5",
"output": "NO"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3",
"output": "NO"
},
{
"input": "3 2\n1 2\n1 3",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n2 4\n3 4",
"output": "NO"
},
{
"input": "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n3 4",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n2 4",
"output": "NO"
},
{
"input": "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1",
"output": "NO"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "NO"
},
{
"input": "150000 3\n150000 149999\n149998 149999\n149998 150000",
"output": "YES"
},
{
"input": "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10",
"output": "NO"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "NO"
},
{
"input": "5 4\n1 2\n1 3\n1 4\n1 5",
"output": "NO"
},
{
"input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n3 4",
"output": "NO"
},
{
"input": "4 4\n1 2\n1 3\n4 2\n4 3",
"output": "NO"
},
{
"input": "5 5\n1 4\n5 3\n5 1\n2 3\n4 5",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n2 3\n1 4\n2 4",
"output": "NO"
},
{
"input": "4 5\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "NO"
},
{
"input": "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6",
"output": "NO"
},
{
"input": "1000 4\n100 132\n100 164\n196 132\n196 164",
"output": "NO"
}
] | 1,630,293,735
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 9
| 1,000
| 110,182,400
|
from sys import stdin
from collections import deque
def main():
input = stdin.readline
n,m = [int(i) for i in input().split()]
graph = {i+1:set() for i in range(n)}
for _ in range(m):
a,b = [int(i) for i in input().split()]
graph[a].add(b)
graph[b].add(a)
INF = 10**10
seen = set()
for i in range(1,n+1):
que = deque([(i, INF, INF)])
seen.add((i, INF, INF))
while que:
cur, prev, pprev = que.popleft()
# print(cur,prev,pprev)
if pprev != INF and pprev not in graph[cur]:
print("NO")
exit()
for nxt in graph[cur]:
t = (nxt, cur, prev)
if t in seen or nxt == prev:
continue
seen.add(t)
que.append(t)
print("YES")
if __name__ == '__main__':
main()
|
Title: Bear and Friendship Condition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
Input Specification:
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends.
The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
Output Specification:
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
Demo Input:
['4 3\n1 3\n3 4\n1 4\n', '4 4\n3 1\n2 3\n3 4\n1 2\n', '10 4\n4 3\n5 10\n8 9\n1 2\n', '3 2\n1 2\n2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
|
```python
from sys import stdin
from collections import deque
def main():
input = stdin.readline
n,m = [int(i) for i in input().split()]
graph = {i+1:set() for i in range(n)}
for _ in range(m):
a,b = [int(i) for i in input().split()]
graph[a].add(b)
graph[b].add(a)
INF = 10**10
seen = set()
for i in range(1,n+1):
que = deque([(i, INF, INF)])
seen.add((i, INF, INF))
while que:
cur, prev, pprev = que.popleft()
# print(cur,prev,pprev)
if pprev != INF and pprev not in graph[cur]:
print("NO")
exit()
for nxt in graph[cur]:
t = (nxt, cur, prev)
if t in seen or nxt == prev:
continue
seen.add(t)
que.append(t)
print("YES")
if __name__ == '__main__':
main()
```
| 0
|
|
601
|
A
|
The Two Routes
|
PROGRAMMING
| 1,600
|
[
"graphs",
"shortest paths"
] | null | null |
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.
A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads.
You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously.
Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
|
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*).
You may assume that there is at most one railway connecting any two towns.
|
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
|
[
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] |
[
"2\n",
"-1\n",
"3\n"
] |
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time.
In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
| 500
|
[
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "-1"
},
{
"input": "2 0",
"output": "-1"
},
{
"input": "20 0",
"output": "-1"
},
{
"input": "381 0",
"output": "-1"
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "-1"
},
{
"input": "3 0",
"output": "-1"
},
{
"input": "3 1\n1 3",
"output": "2"
},
{
"input": "3 2\n2 3\n3 1",
"output": "-1"
},
{
"input": "4 1\n1 4",
"output": "2"
},
{
"input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3",
"output": "2"
},
{
"input": "20 1\n20 1",
"output": "2"
},
{
"input": "21 1\n21 1",
"output": "2"
},
{
"input": "100 1\n100 1",
"output": "2"
},
{
"input": "400 1\n1 400",
"output": "2"
},
{
"input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2",
"output": "2"
}
] | 1,690,044,953
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 11
| 46
| 0
|
import math
def main():
n, m = map(int, input().split())
graph = [[False] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
graph[a][b] = True
graph[b][a] = True
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
for j in range(1, i):
if graph[i][j]:
dp[i] = min(dp[i], dp[j] + 1)
dp[j] = min(dp[j], dp[i] + 1)
train_time = dp[-1]
if math.isinf(train_time):
print(-1)
return
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
for j in range(1, i):
if not graph[i][j]:
dp[i] = min(dp[i], dp[j] + 1)
dp[j] = min(dp[j], dp[i] + 1)
bus_time = dp[-1]
if math.isinf(bus_time):
print(-1)
return
print(max(train_time, bus_time))
main()
|
Title: The Two Routes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.
A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads.
You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously.
Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*).
You may assume that there is at most one railway connecting any two towns.
Output Specification:
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
Demo Input:
['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n']
Demo Output:
['2\n', '-1\n', '3\n']
Note:
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time.
In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.
|
```python
import math
def main():
n, m = map(int, input().split())
graph = [[False] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
graph[a][b] = True
graph[b][a] = True
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
for j in range(1, i):
if graph[i][j]:
dp[i] = min(dp[i], dp[j] + 1)
dp[j] = min(dp[j], dp[i] + 1)
train_time = dp[-1]
if math.isinf(train_time):
print(-1)
return
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
for j in range(1, i):
if not graph[i][j]:
dp[i] = min(dp[i], dp[j] + 1)
dp[j] = min(dp[j], dp[i] + 1)
bus_time = dp[-1]
if math.isinf(bus_time):
print(-1)
return
print(max(train_time, bus_time))
main()
```
| 0
|
|
678
|
D
|
Iterated Linear Function
|
PROGRAMMING
| 1,700
|
[
"math",
"number theory"
] | null | null |
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7.
|
The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement.
Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
|
Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7.
|
[
"3 4 1 1\n",
"3 4 2 1\n",
"3 4 3 1\n"
] |
[
"7\n",
"25\n",
"79\n"
] |
none
| 0
|
[
{
"input": "3 4 1 1",
"output": "7"
},
{
"input": "3 4 2 1",
"output": "25"
},
{
"input": "3 4 3 1",
"output": "79"
},
{
"input": "1 1 1 1",
"output": "2"
},
{
"input": "3 10 723 6",
"output": "443623217"
},
{
"input": "14 81 51 82",
"output": "908370438"
},
{
"input": "826504481 101791432 76 486624528",
"output": "621999403"
},
{
"input": "475965351 844435993 96338 972382431",
"output": "83709654"
},
{
"input": "528774798 650132512 6406119 36569714",
"output": "505858307"
},
{
"input": "632656975 851906850 1 310973933",
"output": "230360736"
},
{
"input": "1 1 352875518515340737 1",
"output": "45212126"
},
{
"input": "978837295 606974665 846646545585165081 745145208",
"output": "154788991"
},
{
"input": "277677243 142088706 8846851 253942280",
"output": "221036825"
},
{
"input": "1 192783664 1000000000000000000 596438713",
"output": "42838179"
},
{
"input": "1 1000000000 1000000000000000000 1",
"output": "999999665"
},
{
"input": "1 1000000000 1000000000000000000 1000000000",
"output": "999999657"
},
{
"input": "1 100000000 10000000000000 1000000000",
"output": "48993"
},
{
"input": "1 1171281 1000000000000000000 100",
"output": "57392869"
},
{
"input": "1 1000000000 100000000000000000 1000000000",
"output": "899999965"
},
{
"input": "1 100000000 100000000000000000 10000",
"output": "490010000"
},
{
"input": "1 100000456 10000000000000000 54165",
"output": "129054389"
},
{
"input": "1 1000000000 10000000000000 1",
"output": "490001"
},
{
"input": "1 100000000 10000000000000000 10000",
"output": "49010000"
},
{
"input": "1 1000000000 10000000000 12",
"output": "502"
},
{
"input": "1 999999999 999999999999999999 12345678",
"output": "12345294"
},
{
"input": "1 1000000 1000000000000000000 100000",
"output": "49100000"
},
{
"input": "1 1000000000 1000000000000 12",
"output": "49012"
},
{
"input": "1 10000 1000000000000000000 5",
"output": "490005"
},
{
"input": "1 10000 1000000000000000000 10000",
"output": "500000"
},
{
"input": "1 1000000000 10000000000000 12",
"output": "490012"
},
{
"input": "1 1000000000 1000000000000000 12",
"output": "49000012"
},
{
"input": "1 1000000000 1000000000000000000 12",
"output": "999999676"
},
{
"input": "1 10000000 100000000000000000 100000",
"output": "49100000"
},
{
"input": "114514 114514 114514 114514",
"output": "623380685"
},
{
"input": "2 1 1000000006 1",
"output": "1"
},
{
"input": "1 1234 10 9",
"output": "12349"
}
] | 1,615,326,218
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<tuple>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<string.h>
#include<assert.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll oo = 1e18;
const ll MOD = 1e9 + 7;
ll a, b, n, x;
ll binpow(ll a, ll b) {
a %= MOD;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int main(){
cin >> a >> b >> n >> x;
}
|
Title: Iterated Linear Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=><=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7.
Input Specification:
The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement.
Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output Specification:
Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7.
Demo Input:
['3 4 1 1\n', '3 4 2 1\n', '3 4 3 1\n']
Demo Output:
['7\n', '25\n', '79\n']
Note:
none
|
```python
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<tuple>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<string.h>
#include<assert.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll oo = 1e18;
const ll MOD = 1e9 + 7;
ll a, b, n, x;
ll binpow(ll a, ll b) {
a %= MOD;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
int main(){
cin >> a >> b >> n >> x;
}
```
| -1
|
|
769
|
B
|
News About Credit
|
PROGRAMMING
| 1,200
|
[
"*special",
"greedy",
"two pointers"
] | null | null |
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send per day. The student can't send messages to himself.
In early morning Polycarp knew important news that the programming credit will be tomorrow. For this reason it is necessary to urgently inform all groupmates about this news using private messages.
Your task is to make a plan of using private messages, so that:
- the student *i* sends no more than *a**i* messages (for all *i* from 1 to *n*); - all students knew the news about the credit (initially only Polycarp knew it); - the student can inform the other student only if he knows it himself.
Let's consider that all students are numerated by distinct numbers from 1 to *n*, and Polycarp always has the number 1.
In that task you shouldn't minimize the number of messages, the moment of time, when all knew about credit or some other parameters. Find any way how to use private messages which satisfies requirements above.
|
The first line contains the positive integer *n* (2<=≤<=*n*<=≤<=100) — the number of students.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has the number 1.
|
Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer *k* — the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to the student number *t*. All messages should be printed in chronological order. It means that the student, who is sending the message, must already know this news. It is assumed that students can receive repeated messages with news of the credit.
If there are several answers, it is acceptable to print any of them.
|
[
"4\n1 2 1 0\n",
"6\n2 0 1 3 2 0\n",
"3\n0 2 2\n"
] |
[
"3\n1 2\n2 4\n2 3\n",
"6\n1 3\n3 4\n1 2\n4 5\n5 6\n4 6\n",
"-1\n"
] |
In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit.
| 1,000
|
[
{
"input": "4\n1 2 1 0",
"output": "3\n1 2\n2 3\n2 4"
},
{
"input": "6\n2 0 1 3 2 0",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6"
},
{
"input": "3\n0 2 2",
"output": "-1"
},
{
"input": "2\n0 0",
"output": "-1"
},
{
"input": "2\n1 0",
"output": "1\n1 2"
},
{
"input": "2\n0 1",
"output": "-1"
},
{
"input": "2\n1 1",
"output": "1\n1 2"
},
{
"input": "3\n1 1 0",
"output": "2\n1 2\n2 3"
},
{
"input": "3\n0 1 1",
"output": "-1"
},
{
"input": "3\n1 0 0",
"output": "-1"
},
{
"input": "3\n2 0 0",
"output": "2\n1 2\n1 3"
},
{
"input": "3\n1 0 1",
"output": "2\n1 3\n3 2"
},
{
"input": "3\n1 1 1",
"output": "2\n1 2\n2 3"
},
{
"input": "40\n3 3 2 1 0 0 0 4 5 4 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 2 3 2 0 1 0 0 2 0 3 0 1 0",
"output": "-1"
},
{
"input": "100\n1 0 0 2 0 2 0 0 2 0 0 2 0 0 2 2 2 1 1 2 1 2 2 2 1 2 0 1 0 1 0 2 2 2 0 1 2 0 0 2 0 2 0 1 1 0 1 0 2 0 0 2 1 2 1 2 2 2 2 1 0 2 0 0 1 0 2 0 0 2 0 1 0 2 1 1 2 2 2 2 0 0 2 0 2 1 0 0 0 1 0 2 2 2 0 1 0 1 1 0",
"output": "99\n1 4\n4 6\n4 9\n6 12\n6 15\n9 16\n9 17\n12 20\n12 22\n15 23\n15 24\n16 26\n16 32\n17 33\n17 34\n20 37\n20 40\n22 42\n22 49\n23 52\n23 54\n24 56\n24 57\n26 58\n26 59\n32 62\n32 67\n33 70\n33 74\n34 77\n34 78\n37 79\n37 80\n40 83\n40 85\n42 92\n42 93\n49 94\n49 18\n52 19\n52 21\n54 25\n54 28\n56 30\n56 36\n57 44\n57 45\n58 47\n58 53\n59 55\n59 60\n62 65\n62 72\n67 75\n67 76\n70 86\n70 90\n74 96\n74 98\n77 99\n77 2\n78 3\n78 5\n79 7\n79 8\n80 10\n80 11\n83 13\n83 14\n85 27\n85 29\n92 31\n92 35\n93 38\n93 3..."
},
{
"input": "4\n2 0 0 0",
"output": "-1"
},
{
"input": "4\n2 0 0 1",
"output": "3\n1 4\n1 2\n4 3"
},
{
"input": "4\n2 0 1 0",
"output": "3\n1 3\n1 2\n3 4"
},
{
"input": "4\n2 1 0 0",
"output": "3\n1 2\n1 3\n2 4"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "100\n99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n..."
},
{
"input": "100\n98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "-1"
},
{
"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 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 77\n..."
},
{
"input": "100\n1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99\n1 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 7..."
},
{
"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 0",
"output": "99\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n..."
},
{
"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": "99\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n..."
},
{
"input": "100\n1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99\n1 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n2 25\n2 26\n2 27\n2 28\n2 29\n2 30\n2 31\n2 32\n2 33\n2 34\n2 35\n2 36\n2 37\n2 38\n2 39\n2 40\n2 41\n2 42\n2 43\n2 44\n2 45\n2 46\n2 47\n2 48\n2 49\n2 50\n2 51\n2 52\n2 53\n2 54\n2 55\n2 56\n2 57\n2 58\n2 59\n2 60\n2 61\n2 62\n2 63\n2 64\n2 65\n2 66\n2 67\n2 68\n2 69\n2 70\n2 71\n2 72\n2 73\n2 74\n2 75\n2 76\n2 77\n2 78\n2 79\n2 80\n2 81\n2 82\n2 83\n2 84\n2 85\n2 86\n2 87\n..."
},
{
"input": "100\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99\n1 55\n55 2\n55 3\n55 4\n55 5\n55 6\n55 7\n55 8\n55 9\n55 10\n55 11\n55 12\n55 13\n55 14\n55 15\n55 16\n55 17\n55 18\n55 19\n55 20\n55 21\n55 22\n55 23\n55 24\n55 25\n55 26\n55 27\n55 28\n55 29\n55 30\n55 31\n55 32\n55 33\n55 34\n55 35\n55 36\n55 37\n55 38\n55 39\n55 40\n55 41\n55 42\n55 43\n55 44\n55 45\n55 46\n55 47\n55 48\n55 49\n55 50\n55 51\n55 52\n55 53\n55 54\n55 56\n55 57\n55 58\n55 59\n55 60\n55 61\n55 62\n55 63\n55 64\n55 65\n55 66\n55 67\n55 68\n55 69\n55 70\n55 71\n55 72\n55 73\n55 74\n55 75..."
},
{
"input": "2\n0 1",
"output": "-1"
},
{
"input": "5\n0 0 1 1 2",
"output": "-1"
},
{
"input": "7\n2 0 0 0 1 0 3",
"output": "6\n1 7\n1 5\n7 2\n7 3\n7 4\n5 6"
},
{
"input": "10\n3 0 0 0 0 2 0 1 0 3",
"output": "9\n1 10\n1 6\n1 8\n10 2\n10 3\n10 4\n6 5\n6 7\n8 9"
},
{
"input": "20\n0 2 0 0 2 0 0 2 2 0 0 2 0 2 1 0 1 3 1 1",
"output": "-1"
},
{
"input": "30\n2 0 2 2 0 2 2 0 0 0 3 0 1 1 2 0 0 2 2 0 1 0 3 0 1 0 2 0 0 1",
"output": "29\n1 11\n1 23\n11 3\n11 4\n11 6\n23 7\n23 15\n23 18\n3 19\n3 27\n4 13\n4 14\n6 21\n6 25\n7 30\n7 2\n15 5\n15 8\n18 9\n18 10\n19 12\n19 16\n27 17\n27 20\n13 22\n14 24\n21 26\n25 28\n30 29"
},
{
"input": "31\n2 0 0 4 0 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 3 0 4 3 0 2 0 0 0 3 4",
"output": "30\n1 4\n1 23\n4 31\n4 14\n4 21\n4 24\n23 30\n23 15\n23 26\n23 2\n31 3\n31 5\n31 6\n31 7\n14 8\n14 9\n14 10\n21 11\n21 12\n21 13\n24 16\n24 17\n24 18\n30 19\n30 20\n30 22\n15 25\n15 27\n26 28\n26 29"
},
{
"input": "39\n2 0 3 0 0 2 0 0 2 1 1 0 0 3 3 0 2 0 2 3 0 0 3 0 3 2 0 0 3 0 0 0 3 0 0 0 0 0 0",
"output": "38\n1 3\n1 14\n3 15\n3 20\n3 23\n14 25\n14 29\n14 33\n15 6\n15 9\n15 17\n20 19\n20 26\n20 10\n23 11\n23 2\n23 4\n25 5\n25 7\n25 8\n29 12\n29 13\n29 16\n33 18\n33 21\n33 22\n6 24\n6 27\n9 28\n9 30\n17 31\n17 32\n19 34\n19 35\n26 36\n26 37\n10 38\n11 39"
},
{
"input": "58\n4 2 1 3 5 3 0 0 1 0 3 0 2 1 0 0 0 4 0 0 0 0 0 1 2 3 4 0 1 1 0 0 1 0 0 0 2 0 0 0 0 2 2 0 2 0 0 4 0 2 0 0 0 0 0 1 0 0",
"output": "57\n1 5\n1 18\n1 27\n1 48\n5 4\n5 6\n5 11\n5 26\n5 2\n18 13\n18 25\n18 37\n18 42\n27 43\n27 45\n27 50\n27 3\n48 9\n48 14\n48 24\n48 29\n4 30\n4 33\n4 56\n6 7\n6 8\n6 10\n11 12\n11 15\n11 16\n26 17\n26 19\n26 20\n2 21\n2 22\n13 23\n13 28\n25 31\n25 32\n37 34\n37 35\n42 36\n42 38\n43 39\n43 40\n45 41\n45 44\n50 46\n50 47\n3 49\n9 51\n14 52\n24 53\n29 54\n30 55\n33 57\n56 58"
},
{
"input": "65\n3 0 0 0 0 3 0 0 0 0 0 4 2 0 0 0 0 0 0 0 0 8 0 0 0 0 0 6 7 0 3 0 0 0 0 4 0 3 0 0 0 0 1 0 0 5 0 0 0 0 3 0 0 4 0 0 0 0 0 1 0 0 0 0 7",
"output": "64\n1 22\n1 29\n1 65\n22 28\n22 46\n22 12\n22 36\n22 54\n22 6\n22 31\n22 38\n29 51\n29 13\n29 43\n29 60\n29 2\n29 3\n29 4\n65 5\n65 7\n65 8\n65 9\n65 10\n65 11\n65 14\n28 15\n28 16\n28 17\n28 18\n28 19\n28 20\n46 21\n46 23\n46 24\n46 25\n46 26\n12 27\n12 30\n12 32\n12 33\n36 34\n36 35\n36 37\n36 39\n54 40\n54 41\n54 42\n54 44\n6 45\n6 47\n6 48\n31 49\n31 50\n31 52\n38 53\n38 55\n38 56\n51 57\n51 58\n51 59\n13 61\n13 62\n43 63\n60 64"
},
{
"input": "77\n7 0 0 0 0 0 0 0 0 8 0 0 0 0 3 0 0 0 0 9 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 2 6 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 7 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 8",
"output": "76\n1 20\n1 63\n1 10\n1 37\n1 77\n1 24\n1 60\n20 44\n20 15\n20 43\n20 55\n20 2\n20 3\n20 4\n20 5\n20 6\n63 7\n63 8\n63 9\n63 11\n63 12\n63 13\n63 14\n63 16\n63 17\n10 18\n10 19\n10 21\n10 22\n10 23\n10 25\n10 26\n10 27\n37 28\n37 29\n37 30\n37 31\n37 32\n37 33\n37 34\n37 35\n77 36\n77 38\n77 39\n77 40\n77 41\n77 42\n77 45\n77 46\n24 47\n24 48\n24 49\n24 50\n24 51\n24 52\n24 53\n60 54\n60 56\n60 57\n60 58\n60 59\n60 61\n60 62\n44 64\n44 65\n44 66\n44 67\n44 68\n44 69\n15 70\n15 71\n15 72\n43 73\n43 74\n55 7..."
},
{
"input": "80\n2 3 0 2 2 1 3 3 3 0 0 0 1 0 1 0 3 1 0 2 0 2 3 0 2 3 0 3 0 0 0 3 0 0 0 2 3 0 0 2 0 0 0 0 0 3 2 0 0 3 0 3 0 3 0 3 1 2 0 0 0 0 0 0 0 1 0 3 0 0 0 1 0 2 0 2 0 0 0 0",
"output": "79\n1 2\n1 7\n2 8\n2 9\n2 17\n7 23\n7 26\n7 28\n8 32\n8 37\n8 46\n9 50\n9 52\n9 54\n17 56\n17 68\n17 4\n23 5\n23 20\n23 22\n26 25\n26 36\n26 40\n28 47\n28 58\n28 74\n32 76\n32 6\n32 13\n37 15\n37 18\n37 57\n46 66\n46 72\n46 3\n50 10\n50 11\n50 12\n52 14\n52 16\n52 19\n54 21\n54 24\n54 27\n56 29\n56 30\n56 31\n68 33\n68 34\n68 35\n4 38\n4 39\n5 41\n5 42\n20 43\n20 44\n22 45\n22 48\n25 49\n25 51\n36 53\n36 55\n40 59\n40 60\n47 61\n47 62\n58 63\n58 64\n74 65\n74 67\n76 69\n76 70\n6 71\n13 73\n15 75\n18 77\n57..."
},
{
"input": "90\n2 0 0 0 0 1 2 0 1 1 0 1 0 4 0 1 1 0 1 0 1 0 1 1 2 0 0 1 2 3 0 1 1 0 0 1 1 0 0 2 0 2 2 1 0 1 0 0 2 0 1 4 2 0 1 2 2 0 1 0 0 5 0 0 3 0 1 2 0 0 0 0 2 3 0 0 3 3 0 3 3 0 0 0 1 0 1 2 2 2",
"output": "89\n1 62\n1 14\n62 52\n62 30\n62 65\n62 74\n62 77\n14 78\n14 80\n14 81\n14 7\n52 25\n52 29\n52 40\n52 42\n30 43\n30 49\n30 53\n65 56\n65 57\n65 68\n74 73\n74 88\n74 89\n77 90\n77 6\n77 9\n78 10\n78 12\n78 16\n80 17\n80 19\n80 21\n81 23\n81 24\n81 28\n7 32\n7 33\n25 36\n25 37\n29 44\n29 46\n40 51\n40 55\n42 59\n42 67\n43 85\n43 87\n49 2\n49 3\n53 4\n53 5\n56 8\n56 11\n57 13\n57 15\n68 18\n68 20\n73 22\n73 26\n88 27\n88 31\n89 34\n89 35\n90 38\n90 39\n6 41\n9 45\n10 47\n12 48\n16 50\n17 54\n19 58\n21 60\n23 ..."
},
{
"input": "99\n1 2 1 0 2 1 2 0 1 2 1 1 2 1 0 2 0 0 1 2 0 1 1 1 0 0 1 1 2 3 1 0 0 0 1 1 0 0 1 2 1 0 2 0 0 2 0 1 0 2 1 1 0 0 3 1 0 2 2 2 2 1 0 2 0 1 1 0 3 2 0 0 1 1 2 0 0 2 0 0 1 2 3 0 3 0 0 3 0 3 0 1 2 1 0 1 0 1 1",
"output": "98\n1 30\n30 55\n30 69\n30 83\n55 85\n55 88\n55 90\n69 2\n69 5\n69 7\n83 10\n83 13\n83 16\n85 20\n85 29\n85 40\n88 43\n88 46\n88 50\n90 58\n90 59\n90 60\n2 61\n2 64\n5 70\n5 75\n7 78\n7 82\n10 93\n10 3\n13 6\n13 9\n16 11\n16 12\n20 14\n20 19\n29 22\n29 23\n40 24\n40 27\n43 28\n43 31\n46 35\n46 36\n50 39\n50 41\n58 48\n58 51\n59 52\n59 56\n60 62\n60 66\n61 67\n61 73\n64 74\n64 81\n70 92\n70 94\n75 96\n75 98\n78 99\n78 4\n82 8\n82 15\n93 17\n93 18\n3 21\n6 25\n9 26\n11 32\n12 33\n14 34\n19 37\n22 38\n23 42\n..."
},
{
"input": "100\n18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 13 0 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0",
"output": "99\n1 26\n1 99\n1 38\n1 62\n1 32\n1 71\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n26 14\n26 15\n26 16\n26 17\n26 18\n26 19\n26 20\n26 21\n26 22\n26 23\n26 24\n26 25\n26 27\n26 28\n26 29\n26 30\n99 31\n99 33\n99 34\n99 35\n99 36\n99 37\n99 39\n99 40\n99 41\n99 42\n99 43\n99 44\n99 45\n99 46\n99 47\n99 48\n38 49\n38 50\n38 51\n38 52\n38 53\n38 54\n38 55\n38 56\n38 57\n38 58\n38 59\n38 60\n38 61\n38 63\n38 64\n62 65\n62 66\n62 67\n62 68\n62 69\n62 70\n62 72\n62 73\n62 74\n62 75\n62 76\n6..."
},
{
"input": "100\n3 2 1 0 1 0 0 0 2 3 2 1 0 0 0 3 1 1 3 0 1 1 1 3 0 2 2 2 0 1 1 1 0 0 1 0 2 1 1 2 1 0 0 0 1 1 0 3 0 0 0 4 1 2 0 0 0 1 0 3 2 0 0 2 0 3 0 1 4 2 1 0 0 1 1 0 1 0 0 4 0 1 0 1 0 1 1 0 0 0 0 1 2 0 0 0 3 3 0 2",
"output": "99\n1 52\n1 69\n1 80\n52 10\n52 16\n52 19\n52 24\n69 48\n69 60\n69 66\n69 97\n80 98\n80 2\n80 9\n80 11\n10 26\n10 27\n10 28\n16 37\n16 40\n16 54\n19 61\n19 64\n19 70\n24 93\n24 100\n24 3\n48 5\n48 12\n48 17\n60 18\n60 21\n60 22\n66 23\n66 30\n66 31\n97 32\n97 35\n97 38\n98 39\n98 41\n98 45\n2 46\n2 53\n9 58\n9 68\n11 71\n11 74\n26 75\n26 77\n27 82\n27 84\n28 86\n28 87\n37 92\n37 4\n40 6\n40 7\n54 8\n54 13\n61 14\n61 15\n64 20\n64 25\n70 29\n70 33\n93 34\n93 36\n100 42\n100 43\n3 44\n5 47\n12 49\n17 50\n18 ..."
},
{
"input": "100\n66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 0",
"output": "99\n1 97\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n97 67\n97 68\n97 69\n97 70\n97 71\n97 72\n97 73\n97 74\n97 75\n97 76\n97 77\n97 78\n97 79\n97 80\n97 81\n97 82\n97 83\n..."
},
{
"input": "20\n0 0 3 0 0 0 3 4 2 0 2 0 0 0 0 1 0 1 0 1",
"output": "-1"
},
{
"input": "60\n3 0 0 1 0 0 0 0 3 1 3 4 0 0 0 3 0 0 0 2 0 3 4 1 3 3 0 2 0 4 1 5 3 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 1 0 1 0 3 0 0",
"output": "-1"
},
{
"input": "80\n4 0 0 0 0 0 0 3 0 3 0 0 0 4 3 0 1 0 2 0 0 0 5 0 5 0 0 0 0 4 0 3 0 0 0 1 0 0 2 0 5 2 0 0 4 4 0 3 0 0 0 0 0 0 0 2 5 0 2 0 0 0 0 0 0 0 0 0 0 3 0 0 3 5 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "100\n2 0 0 2 0 0 0 0 0 2 0 0 0 5 0 0 0 0 0 0 0 1 0 7 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 6 0 7 4 0 0 0 0 5 0 0 0 0 0 0 7 4 0 0 0 0 0 0 7 7 0 0 0 0 0 2 0 0 0 0 0 0 0 0 4 7 7 0 0 0",
"output": "-1"
},
{
"input": "100\n1 0 0 0 1 2 3 2 1 0 1 2 3 1 3 1 0 0 1 1 0 0 2 1 2 1 3 3 1 0 0 1 0 2 2 0 3 0 1 1 1 2 0 2 0 1 0 2 0 1 2 2 0 0 0 0 1 0 0 0 1 1 4 0 2 0 1 0 2 0 2 2 2 1 1 0 0 2 0 3 1 0 0 1 1 0 1 0 2 3 2 0 1 2 0 0 0 0 0 1",
"output": "99\n1 63\n63 7\n63 13\n63 15\n63 27\n7 28\n7 37\n7 80\n13 90\n13 6\n13 8\n15 12\n15 23\n15 25\n27 34\n27 35\n27 42\n28 44\n28 48\n28 51\n37 52\n37 65\n37 69\n80 71\n80 72\n80 73\n90 78\n90 89\n90 91\n6 94\n6 5\n8 9\n8 11\n12 14\n12 16\n23 19\n23 20\n25 24\n25 26\n34 29\n34 32\n35 39\n35 40\n42 41\n42 46\n44 50\n44 57\n48 61\n48 62\n51 67\n51 74\n52 75\n52 81\n65 84\n65 85\n69 87\n69 93\n71 100\n71 2\n72 3\n72 4\n73 10\n73 17\n78 18\n78 21\n89 22\n89 30\n91 31\n91 33\n94 36\n94 38\n5 43\n9 45\n11 47\n14 49\n..."
},
{
"input": "100\n5 0 0 1 1 0 0 0 1 0 0 0 0 0 5 0 2 1 0 1 0 6 0 0 0 3 0 0 0 0 0 0 0 0 1 0 3 0 0 0 0 0 0 4 0 0 3 1 1 0 0 4 0 0 0 0 0 0 3 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 2 1 0 5 1 0 8 0 1 0 0 10 4 0 0 0 6 4 0 0 0 0 1",
"output": "99\n1 89\n1 84\n1 22\n1 94\n1 15\n89 81\n89 44\n89 52\n89 90\n89 95\n89 26\n89 37\n89 47\n89 59\n89 61\n84 62\n84 17\n84 60\n84 75\n84 78\n84 4\n84 5\n84 9\n22 18\n22 20\n22 35\n22 48\n22 49\n22 79\n94 82\n94 86\n94 100\n94 2\n94 3\n94 6\n15 7\n15 8\n15 10\n15 11\n15 12\n81 13\n81 14\n81 16\n81 19\n81 21\n44 23\n44 24\n44 25\n44 27\n52 28\n52 29\n52 30\n52 31\n90 32\n90 33\n90 34\n90 36\n95 38\n95 39\n95 40\n95 41\n26 42\n26 43\n26 45\n37 46\n37 50\n37 51\n47 53\n47 54\n47 55\n59 56\n59 57\n59 58\n61 63\n6..."
},
{
"input": "100\n47 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 4 0 1 0 2 0 0 1 0 0 0 0 0 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0",
"output": "99\n1 47\n1 12\n1 66\n1 33\n1 93\n1 37\n1 81\n1 25\n1 35\n1 40\n1 46\n1 61\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 34\n1 36\n1 38\n1 39\n1 41\n1 42\n47 43\n47 44\n47 45\n47 48\n47 49\n47 50\n47 51\n47 52\n47 53\n47 54\n47 55\n47 56\n47 57\n47 58\n47 59\n47 60\n47 62\n47 63\n12 64\n12 65\n12 67\n12 68\n12 69\n12 70\n12 71\n12 72\n12 73\n66 74\n66 75\n66 76\n66 77\n66 78\n66 79\n66..."
},
{
"input": "100\n1 0 2 1 1 1 0 0 0 3 2 1 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 2 1 0 2 1 1 1 0 0 1 2 1 3 1 1 0 0 2 1 0 1 1 1 2 1 2 0 3 1 2 0 1 1 2 2 1 1 1 1 1 2 0 0 2 1 1 0 1 2 1 1 1 1 1 0 1 1 1 0 3 0 0 2 2 0 0 0 2 1 2 0",
"output": "99\n1 10\n10 42\n10 57\n10 89\n42 3\n42 11\n42 30\n57 33\n57 40\n57 47\n89 53\n89 55\n89 59\n3 63\n3 64\n11 70\n11 73\n30 78\n30 92\n33 93\n33 97\n40 99\n40 4\n47 5\n47 6\n53 12\n53 13\n55 14\n55 16\n59 18\n59 19\n63 20\n63 22\n64 23\n64 24\n70 26\n70 27\n73 28\n73 29\n78 31\n78 34\n92 35\n92 36\n93 39\n93 41\n97 43\n97 44\n99 48\n99 50\n4 51\n5 52\n6 54\n12 58\n13 61\n14 62\n16 65\n18 66\n19 67\n20 68\n22 69\n23 74\n24 75\n26 77\n27 79\n28 80\n29 81\n31 82\n34 83\n35 85\n36 86\n39 87\n41 98\n43 2\n44 7\n4..."
},
{
"input": "100\n83 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 0",
"output": "99\n1 99\n1 83\n1 22\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n99 84\n99 85\n99 ..."
},
{
"input": "100\n1 1 0 1 0 1 1 1 2 1 0 1 1 0 1 2 1 1 1 1 2 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 2 2 2 2 1 1 0 1 2 1 1 0 1 1 0 1 0 1 1 0 0 1 1 1 1 1 1 2 0 2 1 2 1 1 0 0 1 1 1 1 0 2 4 2 1 1 1 0 1 2 1 1 1 0 2 1 2",
"output": "99\n1 86\n86 9\n86 16\n86 21\n86 44\n9 45\n9 46\n16 47\n16 52\n21 71\n21 73\n44 75\n44 85\n45 87\n45 93\n46 98\n46 100\n47 2\n47 4\n52 6\n52 7\n71 8\n71 10\n73 12\n73 13\n75 15\n75 17\n85 18\n85 19\n87 20\n87 22\n93 23\n93 25\n98 27\n98 28\n100 29\n100 30\n2 31\n4 32\n6 33\n7 34\n8 35\n10 36\n12 37\n13 38\n15 39\n17 41\n18 42\n19 48\n20 49\n22 51\n23 53\n25 54\n27 56\n28 57\n29 59\n30 61\n31 62\n32 65\n33 66\n34 67\n35 68\n36 69\n37 70\n38 74\n39 76\n41 77\n42 80\n48 81\n49 82\n51 83\n53 88\n54 89\n56 90\n..."
},
{
"input": "100\n99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n1 25\n1 26\n1 27\n1 28\n1 29\n1 30\n1 31\n1 32\n1 33\n1 34\n1 35\n1 36\n1 37\n1 38\n1 39\n1 40\n1 41\n1 42\n1 43\n1 44\n1 45\n1 46\n1 47\n1 48\n1 49\n1 50\n1 51\n1 52\n1 53\n1 54\n1 55\n1 56\n1 57\n1 58\n1 59\n1 60\n1 61\n1 62\n1 63\n1 64\n1 65\n1 66\n1 67\n1 68\n1 69\n1 70\n1 71\n1 72\n1 73\n1 74\n1 75\n1 76\n1 77\n1 78\n1 79\n1 80\n1 81\n1 82\n1 83\n1 84\n1 85\n1 86\n1 87\n..."
},
{
"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 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 52\n52 53\n53 54\n54 55\n55 56\n56 57\n57 58\n58 59\n59 60\n60 61\n61 62\n62 63\n63 64\n64 65\n65 66\n66 67\n67 68\n68 69\n69 70\n70 71\n71 72\n72 73\n73 74\n74 75\n75 76\n76 77\n..."
},
{
"input": "2\n0 100",
"output": "-1"
},
{
"input": "2\n100 0",
"output": "1\n1 2"
},
{
"input": "2\n100 100",
"output": "1\n1 2"
}
] | 1,546,334,404
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 60
| 140
| 0
|
n = int(input())
call = list(map(int, input().split()))
cp = []
ans = []
for i in range(1, n):
x = call[i]
cp.append([x, i + 1])
cp.sort(reverse=True)
l = [[call[0], 1]]
j = 0
while len(cp) > 0 and len(l) > 0 and j < len(cp):
s = l[0]
x = s[0]
p = s[1]
for i in range(j, min(j + x, len(cp))):
ans.append([str(p), str(cp[i][1])])
l.append(cp[i])
j = min(j + x, len(cp))
l.remove(l[0])
if j < len(cp):
print(-1)
else:
print(len(ans))
for i in range(len(ans)):
print(' '.join(ans[i]))
|
Title: News About Credit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send per day. The student can't send messages to himself.
In early morning Polycarp knew important news that the programming credit will be tomorrow. For this reason it is necessary to urgently inform all groupmates about this news using private messages.
Your task is to make a plan of using private messages, so that:
- the student *i* sends no more than *a**i* messages (for all *i* from 1 to *n*); - all students knew the news about the credit (initially only Polycarp knew it); - the student can inform the other student only if he knows it himself.
Let's consider that all students are numerated by distinct numbers from 1 to *n*, and Polycarp always has the number 1.
In that task you shouldn't minimize the number of messages, the moment of time, when all knew about credit or some other parameters. Find any way how to use private messages which satisfies requirements above.
Input Specification:
The first line contains the positive integer *n* (2<=≤<=*n*<=≤<=100) — the number of students.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has the number 1.
Output Specification:
Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer *k* — the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to the student number *t*. All messages should be printed in chronological order. It means that the student, who is sending the message, must already know this news. It is assumed that students can receive repeated messages with news of the credit.
If there are several answers, it is acceptable to print any of them.
Demo Input:
['4\n1 2 1 0\n', '6\n2 0 1 3 2 0\n', '3\n0 2 2\n']
Demo Output:
['3\n1 2\n2 4\n2 3\n', '6\n1 3\n3 4\n1 2\n4 5\n5 6\n4 6\n', '-1\n']
Note:
In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit.
|
```python
n = int(input())
call = list(map(int, input().split()))
cp = []
ans = []
for i in range(1, n):
x = call[i]
cp.append([x, i + 1])
cp.sort(reverse=True)
l = [[call[0], 1]]
j = 0
while len(cp) > 0 and len(l) > 0 and j < len(cp):
s = l[0]
x = s[0]
p = s[1]
for i in range(j, min(j + x, len(cp))):
ans.append([str(p), str(cp[i][1])])
l.append(cp[i])
j = min(j + x, len(cp))
l.remove(l[0])
if j < len(cp):
print(-1)
else:
print(len(ans))
for i in range(len(ans)):
print(' '.join(ans[i]))
```
| 3
|
|
1,005
|
A
|
Tanya and Stairways
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ steps, she will pronounce the numbers $1, 2, 3, 1, 2, 3, 4$.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
|
The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya.
The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with $x$ steps, she will pronounce the numbers $1, 2, \dots, x$ in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
|
In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
|
[
"7\n1 2 3 1 2 3 4\n",
"4\n1 1 1 1\n",
"5\n1 2 3 4 5\n",
"5\n1 2 1 2 1\n"
] |
[
"2\n3 4 ",
"4\n1 1 1 1 ",
"1\n5 ",
"3\n2 2 1 "
] |
none
| 0
|
[
{
"input": "7\n1 2 3 1 2 3 4",
"output": "2\n3 4 "
},
{
"input": "4\n1 1 1 1",
"output": "4\n1 1 1 1 "
},
{
"input": "5\n1 2 3 4 5",
"output": "1\n5 "
},
{
"input": "5\n1 2 1 2 1",
"output": "3\n2 2 1 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "48\n1 2 3 4 1 2 3 1 1 2 3 1 2 3 4 1 1 2 3 4 1 2 3 4 1 2 3 4 1 1 2 1 2 1 2 1 1 2 1 2 1 2 3 1 2 1 2 1",
"output": "20\n4 3 1 3 4 1 4 4 4 1 2 2 2 1 2 2 3 2 2 1 "
},
{
"input": "2\n1 2",
"output": "1\n2 "
},
{
"input": "3\n1 1 2",
"output": "2\n1 2 "
},
{
"input": "4\n1 1 2 3",
"output": "2\n1 3 "
},
{
"input": "8\n1 2 3 1 2 3 4 5",
"output": "2\n3 5 "
},
{
"input": "5\n1 1 1 2 3",
"output": "3\n1 1 3 "
}
] | 1,637,832,748
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 16
| 62
| 0
|
n = int(input())
li = list(map(int, input().split()))
count = 1
newli = []
for i in range(1,n):
if li[i]<li[i-1]:
count +=1
newli.append(li[i-1])
if li[i]==li[i-1]:
count +=1
newli.append(li[i-1])
newli.append(li[-1])
print(count)
print(" ".join([str(x) for x in newli]))
|
Title: Tanya and Stairways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ steps, she will pronounce the numbers $1, 2, 3, 1, 2, 3, 4$.
You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Input Specification:
The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya.
The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with $x$ steps, she will pronounce the numbers $1, 2, \dots, x$ in that order.
The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.
Output Specification:
In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
Demo Input:
['7\n1 2 3 1 2 3 4\n', '4\n1 1 1 1\n', '5\n1 2 3 4 5\n', '5\n1 2 1 2 1\n']
Demo Output:
['2\n3 4 ', '4\n1 1 1 1 ', '1\n5 ', '3\n2 2 1 ']
Note:
none
|
```python
n = int(input())
li = list(map(int, input().split()))
count = 1
newli = []
for i in range(1,n):
if li[i]<li[i-1]:
count +=1
newli.append(li[i-1])
if li[i]==li[i-1]:
count +=1
newli.append(li[i-1])
newli.append(li[-1])
print(count)
print(" ".join([str(x) for x in newli]))
```
| 3
|
|
631
|
B
|
Print Check
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"implementation"
] | null | null |
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size *n*<=×<=*m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row *r**i* in color *a**i*; 1. Paint all cells in column *c**i* in color *a**i*.
If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*.
Your program has to print the resulting table after *k* operation.
|
The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next *k* lines contains the description of exactly one query:
- 1 *r**i* *a**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=109), means that row *r**i* is painted in color *a**i*; - 2 *c**i* *a**i* (1<=≤<=*c**i*<=≤<=*m*, 1<=≤<=*a**i*<=≤<=109), means that column *c**i* is painted in color *a**i*.
|
Print *n* lines containing *m* integers each — the resulting table after all operations are applied.
|
[
"3 3 3\n1 1 3\n2 2 1\n1 2 2\n",
"5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n"
] |
[
"3 1 3 \n2 2 2 \n0 1 0 \n",
"1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n"
] |
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
| 1,000
|
[
{
"input": "3 3 3\n1 1 3\n2 2 1\n1 2 2",
"output": "3 1 3 \n2 2 2 \n0 1 0 "
},
{
"input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1",
"output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 "
},
{
"input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1",
"output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 "
},
{
"input": "4 6 8\n1 2 1\n2 2 2\n2 5 2\n1 1 1\n1 4 1\n1 3 2\n2 1 1\n2 6 1",
"output": "1 1 1 1 1 1 \n1 2 1 1 2 1 \n1 2 2 2 2 1 \n1 1 1 1 1 1 "
},
{
"input": "2 2 3\n1 1 1\n1 2 1\n2 1 2",
"output": "2 1 \n2 1 "
},
{
"input": "1 2 4\n1 1 1\n2 1 2\n2 2 3\n1 1 4",
"output": "4 4 "
},
{
"input": "2 1 5\n1 1 7\n1 2 77\n2 1 777\n1 1 77\n1 2 7",
"output": "77 \n7 "
},
{
"input": "2 1 1\n1 2 1000000000",
"output": "0 \n1000000000 "
},
{
"input": "1 2 1\n2 2 1000000000",
"output": "0 1000000000 "
},
{
"input": "160 600 1\n1 132 589472344",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "600 160 1\n1 124 542622711",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "10 1 1\n2 1 1000000000",
"output": "1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 \n1000000000 "
},
{
"input": "1 10 1\n1 1 1000000000",
"output": "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 "
},
{
"input": "5000 20 15\n2 13 447246914\n2 10 89345638\n2 6 393683717\n2 1 62225152\n2 12 990340161\n2 4 227462932\n1 4011 327145900\n1 1915 981331082\n1 802 437883065\n2 11 205232924\n2 15 303578182\n1 2667 835309719\n2 3 550440583\n1 3852 766318960\n2 5 204700467",
"output": "62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 204700467 393683717 0 0 0 89345638 205232924 990340161 447246914 0 303578182 0 0 0 0 0 \n62225152 0 550440583 227462932 ..."
},
{
"input": "20 5000 15\n1 14 94104058\n1 3 170575572\n1 12 613859505\n2 4797 363375206\n1 10 554079405\n2 4481 223609505\n2 4974 385117513\n1 7 363246561\n2 2503 128936152\n1 2 152944073\n1 14 25797327\n1 20 258831369\n1 10 453164078\n2 2159 753235825\n2 1823 827844660",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "1 1 1\n1 1 1",
"output": "1 "
},
{
"input": "1 1 1\n1 1 1000000000",
"output": "1000000000 "
},
{
"input": "1 1 2\n1 1 123\n1 1 321",
"output": "321 "
},
{
"input": "1 1 2\n1 1 321\n1 1 123",
"output": "123 "
}
] | 1,582,505,857
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 10
| 1,000
| 1,126,400
|
n, m, k = map(int, input().split())
ary = [[0 for i in range(m)]for j in range(n)]
for i in range(k):
x, r, a = map(int, input().split())
if x == 1:
for j in range(m):
ary[r-1][j] = a
else:
for j in range(n):
ary[j][r-1] = a
for i in range(n):
iar = map(str, ary[i])
print (" ".join(iar))
|
Title: Print Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
Printer works with a rectangular sheet of paper of size *n*<=×<=*m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0.
Your program has to support two operations:
1. Paint all cells in row *r**i* in color *a**i*; 1. Paint all cells in column *c**i* in color *a**i*.
If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*.
Your program has to print the resulting table after *k* operation.
Input Specification:
The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next *k* lines contains the description of exactly one query:
- 1 *r**i* *a**i* (1<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=109), means that row *r**i* is painted in color *a**i*; - 2 *c**i* *a**i* (1<=≤<=*c**i*<=≤<=*m*, 1<=≤<=*a**i*<=≤<=109), means that column *c**i* is painted in color *a**i*.
Output Specification:
Print *n* lines containing *m* integers each — the resulting table after all operations are applied.
Demo Input:
['3 3 3\n1 1 3\n2 2 1\n1 2 2\n', '5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n']
Demo Output:
['3 1 3 \n2 2 2 \n0 1 0 \n', '1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n']
Note:
The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
|
```python
n, m, k = map(int, input().split())
ary = [[0 for i in range(m)]for j in range(n)]
for i in range(k):
x, r, a = map(int, input().split())
if x == 1:
for j in range(m):
ary[r-1][j] = a
else:
for j in range(n):
ary[j][r-1] = a
for i in range(n):
iar = map(str, ary[i])
print (" ".join(iar))
```
| 0
|
|
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,649,615,359
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 61
| 92
| 0
|
n=int(input(''))
l=list(map(int,input().split()))
c,bc,bk=[],[],[]
for i in range(0,n,3):
c.append(l[i])
for j in range(1,n,3):
bc.append(l[j])
for k in range(2,n,3):
bk.append(l[k])
t=[sum(c),sum(bc),sum(bk)]
m=t.index(max(t))
if m==0:
print('chest')
elif m==1:
print('biceps')
else:
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
n=int(input(''))
l=list(map(int,input().split()))
c,bc,bk=[],[],[]
for i in range(0,n,3):
c.append(l[i])
for j in range(1,n,3):
bc.append(l[j])
for k in range(2,n,3):
bk.append(l[k])
t=[sum(c),sum(bc),sum(bk)]
m=t.index(max(t))
if m==0:
print('chest')
elif m==1:
print('biceps')
else:
print('back')
```
| 3
|
|
313
|
B
|
Ilya and Queries
|
PROGRAMMING
| 1,100
|
[
"dp",
"implementation"
] | null | null |
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
|
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
|
Print *m* integers — the answers to the queries in the order in which they are given in the input.
|
[
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] |
[
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] |
none
| 1,000
|
[
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3",
"output": "0\n0\n1\n1\n0"
},
{
"input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5",
"output": "2\n1\n1\n1\n1\n1\n1"
},
{
"input": "#..#\n1\n1 4",
"output": "1"
},
{
"input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4",
"output": "2\n2\n3\n2\n1\n4\n0"
},
{
"input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0"
},
{
"input": "###..#...#\n2\n2 4\n1 2",
"output": "1\n1"
},
{
"input": "..\n1\n1 2",
"output": "1"
},
{
"input": "##\n1\n1 2",
"output": "1"
},
{
"input": ".#\n1\n1 2",
"output": "0"
},
{
"input": "#.\n1\n1 2",
"output": "0"
},
{
"input": "...\n2\n1 2\n1 2",
"output": "1\n1"
}
] | 1,695,285,387
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 1
| 124
| 2,048,000
|
s = input()
out = 0
dp = [0]
for i in range(1,len(s)):
if s[i] == s[i-1]:
out +=1
dp.append(out)
m=int(input())
for i in range(m):
left,right = map(int, input().split())
print(dp[right-1] - dp[left-1])
|
Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input Specification:
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the answers to the queries in the order in which they are given in the input.
Demo Input:
['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n']
Demo Output:
['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n']
Note:
none
|
```python
s = input()
out = 0
dp = [0]
for i in range(1,len(s)):
if s[i] == s[i-1]:
out +=1
dp.append(out)
m=int(input())
for i in range(m):
left,right = map(int, input().split())
print(dp[right-1] - dp[left-1])
```
| -1
|
|
901
|
B
|
GCD of Polynomials
|
PROGRAMMING
| 2,200
|
[
"constructive algorithms",
"math"
] | null | null |
Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way:
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, denotes the degree of polynomial *P*(*x*). is called the remainder of division of polynomial by polynomial , it is also denoted as .
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials . If the polynomial is zero, the result is , otherwise the result is the value the algorithm returns for pair . On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer *n*. You have to build two polynomials with degrees not greater than *n*, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of *x*) are equal to one, and the described Euclid's algorithm performs exactly *n* steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair to pair .
|
You are given a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of steps of the algorithm you need to reach.
|
Print two polynomials in the following format.
In the first line print a single integer *m* (0<=≤<=*m*<=≤<=*n*) — the degree of the polynomial.
In the second line print *m*<=+<=1 integers between <=-<=1 and 1 — the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly *n* steps when called using these polynomials.
If there is no answer for the given *n*, print -1.
If there are multiple answer, print any of them.
|
[
"1\n",
"2\n"
] |
[
"1\n0 1\n0\n1\n",
"2\n-1 0 1\n1\n0 1\n"
] |
In the second example you can print polynomials *x*<sup class="upper-index">2</sup> - 1 and *x*. The sequence of transitions is
There are two steps in it.
| 1,000
|
[
{
"input": "1",
"output": "1\n0 1\n0\n1"
},
{
"input": "2",
"output": "2\n-1 0 1\n1\n0 1"
},
{
"input": "3",
"output": "3\n0 0 0 1\n2\n-1 0 1"
},
{
"input": "4",
"output": "4\n1 0 -1 0 1\n3\n0 0 0 1"
},
{
"input": "5",
"output": "5\n0 1 0 0 0 1\n4\n1 0 -1 0 1"
},
{
"input": "6",
"output": "6\n1 0 0 0 1 0 1\n5\n0 1 0 0 0 1"
},
{
"input": "7",
"output": "7\n0 0 0 0 0 0 0 1\n6\n1 0 0 0 1 0 1"
},
{
"input": "8",
"output": "8\n-1 0 0 0 -1 0 -1 0 1\n7\n0 0 0 0 0 0 0 1"
},
{
"input": "9",
"output": "9\n0 -1 0 0 0 -1 0 0 0 1\n8\n-1 0 0 0 -1 0 -1 0 1"
},
{
"input": "10",
"output": "10\n1 0 -1 0 1 0 0 0 -1 0 1\n9\n0 -1 0 0 0 -1 0 0 0 1"
},
{
"input": "11",
"output": "11\n0 0 0 -1 0 0 0 0 0 0 0 1\n10\n1 0 -1 0 1 0 0 0 -1 0 1"
},
{
"input": "12",
"output": "12\n1 0 -1 0 0 0 0 0 -1 0 1 0 1\n11\n0 0 0 -1 0 0 0 0 0 0 0 1"
},
{
"input": "13",
"output": "13\n0 1 0 0 0 0 0 0 0 -1 0 0 0 1\n12\n1 0 -1 0 0 0 0 0 -1 0 1 0 1"
},
{
"input": "14",
"output": "14\n1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1\n13\n0 1 0 0 0 0 0 0 0 -1 0 0 0 1"
},
{
"input": "15",
"output": "15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n14\n1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1"
},
{
"input": "16",
"output": "16\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1\n15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1"
},
{
"input": "17",
"output": "17\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1\n16\n-1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1"
},
{
"input": "18",
"output": "18\n1 0 -1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1\n17\n0 -1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1"
},
{
"input": "19",
"output": "19\n0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n18\n1 0 -1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1"
},
{
"input": "20",
"output": "20\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1\n19\n0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1"
},
{
"input": "21",
"output": "21\n0 -1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1\n20\n-1 0 1 0 -1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1"
},
{
"input": "22",
"output": "22\n-1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1\n21\n0 -1 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1"
},
{
"input": "23",
"output": "23\n0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n22\n-1 0 0 0 -1 0 -1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1"
},
{
"input": "24",
"output": "24\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1\n23\n0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1"
},
{
"input": "25",
"output": "25\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1\n24\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1"
},
{
"input": "26",
"output": "26\n1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 -1 0 0 0 -1 0 1\n25\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1"
},
{
"input": "27",
"output": "27\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n26\n1 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 -1 0 0 0 -1 0 1"
},
{
"input": "28",
"output": "28\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1\n27\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1"
},
{
"input": "29",
"output": "29\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1\n28\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1"
},
{
"input": "30",
"output": "30\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1\n29\n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1"
},
{
"input": "31",
"output": "31\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 1\n30\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 1 0 1"
},
{
"input": "32",
"output": "32\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1\n31\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 1"
},
{
"input": "33",
"output": "33\n0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1\n32\n-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 -1 0 1"
},
{
"input": "34",
"output": "34\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1\n33\n0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 1"
},
{
"input": "35",
"output": "35\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1\n34\n1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 -1 0 1 0 1 0 0 0 -1 0 1"
},
{
"input": "36",
"output": "36\n-1 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1\n35\n0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1"
},
{
"input": "37",
"output": "37\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1\n36\n-1 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 0 0 1 0 -1 0 0 0 0 0 1 0 -1 0 1"
},
{
"input": "38",
"output": "38\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1\n37\n0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1"
},
{
"input": "39",
"output": "39\n0 0 0 0 0 0 0 -1 0 0 0 0 0 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 1\n38\n-1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1"
},
{
"input": "40",
"output": "40\n1 0 0 0 1 0 1 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 -1 0 1\n39\n0 0 0 0 0 0 0 -1 0 0 0 0 0 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 1"
},
{
"input": "41",
"output": "41\n0 1 0 0 0 1 0 0 0 -1 0 0 0 0 0 0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0 0 0 0 0 0 1 0 0 0 1 0 1\n149\n0 1 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 ..."
}
] | 1,513,703,401
| 5,701
|
Python 3
|
COMPILATION_ERROR
|
PRETESTS
| 0
| 0
| 0
|
n = input()
a = [0, 1]
b = [1, 0]
for x in xrange(n-1):
c = [0, 0]
c[0] = a[0] + b[0]
c[1] = a[1] + b[1]
a = b
b = c
print 1
print b[1], b[0]
print 1
print a[1], a[0]
|
Title: GCD of Polynomials
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Suppose you have two polynomials and . Then polynomial can be uniquely represented in the following way:
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, denotes the degree of polynomial *P*(*x*). is called the remainder of division of polynomial by polynomial , it is also denoted as .
Since there is a way to divide polynomials with remainder, we can define Euclid's algorithm of finding the greatest common divisor of two polynomials. The algorithm takes two polynomials . If the polynomial is zero, the result is , otherwise the result is the value the algorithm returns for pair . On each step the degree of the second argument decreases, so the algorithm works in finite number of steps. But how large that number could be? You are to answer this question.
You are given an integer *n*. You have to build two polynomials with degrees not greater than *n*, such that their coefficients are integers not exceeding 1 by their absolute value, the leading coefficients (ones with the greatest power of *x*) are equal to one, and the described Euclid's algorithm performs exactly *n* steps finding their greatest common divisor. Moreover, the degree of the first polynomial should be greater than the degree of the second. By a step of the algorithm we mean the transition from pair to pair .
Input Specification:
You are given a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of steps of the algorithm you need to reach.
Output Specification:
Print two polynomials in the following format.
In the first line print a single integer *m* (0<=≤<=*m*<=≤<=*n*) — the degree of the polynomial.
In the second line print *m*<=+<=1 integers between <=-<=1 and 1 — the coefficients of the polynomial, from constant to leading.
The degree of the first polynomial should be greater than the degree of the second polynomial, the leading coefficients should be equal to 1. Euclid's algorithm should perform exactly *n* steps when called using these polynomials.
If there is no answer for the given *n*, print -1.
If there are multiple answer, print any of them.
Demo Input:
['1\n', '2\n']
Demo Output:
['1\n0 1\n0\n1\n', '2\n-1 0 1\n1\n0 1\n']
Note:
In the second example you can print polynomials *x*<sup class="upper-index">2</sup> - 1 and *x*. The sequence of transitions is
There are two steps in it.
|
```python
n = input()
a = [0, 1]
b = [1, 0]
for x in xrange(n-1):
c = [0, 0]
c[0] = a[0] + b[0]
c[1] = a[1] + b[1]
a = b
b = c
print 1
print b[1], b[0]
print 1
print a[1], a[0]
```
| -1
|
|
221
|
A
|
Little Elephant and Function
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] | null | null |
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
|
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
|
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists.
|
[
"1\n",
"2\n"
] |
[
"1 ",
"2 1 "
] |
none
| 500
|
[
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"input": "7",
"output": "7 1 2 3 4 5 6 "
},
{
"input": "1000",
"output": "1000 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..."
},
{
"input": "999",
"output": "999 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "998",
"output": "998 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "997",
"output": "997 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "900",
"output": "900 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "101",
"output": "101 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": "3",
"output": "3 1 2 "
},
{
"input": "67",
"output": "67 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 "
},
{
"input": "779",
"output": "779 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "971",
"output": "971 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "683",
"output": "683 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "99",
"output": "99 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 "
},
{
"input": "811",
"output": "811 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "875",
"output": "875 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "291",
"output": "291 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "419",
"output": "419 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "779",
"output": "779 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "195",
"output": "195 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "907",
"output": "907 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "21",
"output": "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
},
{
"input": "22",
"output": "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
},
{
"input": "23",
"output": "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "24",
"output": "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 "
},
{
"input": "25",
"output": "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "
}
] | 1,621,970,804
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 2
| 154
| 0
|
x = int(input())
def solve(x):
if x == 1:
print(1)
elif x == 2:
print("2 1")
else:
x = [z for z in range(1, x)]
print(x, *x)
solve(x)
|
Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows:
- If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*).
The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation.
Output Specification:
In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists.
Demo Input:
['1\n', '2\n']
Demo Output:
['1 ', '2 1 ']
Note:
none
|
```python
x = int(input())
def solve(x):
if x == 1:
print(1)
elif x == 2:
print("2 1")
else:
x = [z for z in range(1, x)]
print(x, *x)
solve(x)
```
| 0
|
|
4
|
A
|
Watermelon
|
PROGRAMMING
| 800
|
[
"brute force",
"math"
] |
A. Watermelon
|
1
|
64
|
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
|
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
|
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
|
[
"8\n"
] |
[
"YES\n"
] |
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
| 0
|
[
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,692,190,731
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
number = int(input())
if number > 2 and number % 2 == 0:
return "YES"
else:
return "NO"
|
Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
|
```python
number = int(input())
if number > 2 and number % 2 == 0:
return "YES"
else:
return "NO"
```
| -1
|
115
|
A
|
Party
|
PROGRAMMING
| 900
|
[
"dfs and similar",
"graphs",
"trees"
] | null | null |
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
|
Print a single integer denoting the minimum number of groups that will be formed in the party.
|
[
"5\n-1\n1\n2\n1\n-1\n"
] |
[
"3\n"
] |
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5
| 500
|
[
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,698,417,265
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 11
| 186
| 4,096,000
|
test=int(input())
res=[]
for i in range (test):
n=int(input())
if n==-1: res.append(0)
else: res.append(n)
for i in range (test):
if res[i]!=0: res[i]=res[res[i]-1]+1
print(max(res)+1)
|
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
test=int(input())
res=[]
for i in range (test):
n=int(input())
if n==-1: res.append(0)
else: res.append(n)
for i in range (test):
if res[i]!=0: res[i]=res[res[i]-1]+1
print(max(res)+1)
```
| 0
|
|
821
|
C
|
Okabe and Boxes
|
PROGRAMMING
| 1,500
|
[
"data structures",
"greedy",
"trees"
] | null | null |
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.
That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.
Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.
|
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack.
It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.
|
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
|
[
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] |
[
"1\n",
"2\n"
] |
In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
| 1,500
|
[
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremove",
"output": "2"
},
{
"input": "2\nadd 1\nremove\nadd 2\nremove",
"output": "0"
},
{
"input": "1\nadd 1\nremove",
"output": "0"
},
{
"input": "15\nadd 12\nadd 7\nadd 10\nadd 11\nadd 5\nadd 2\nadd 1\nadd 6\nadd 8\nremove\nremove\nadd 15\nadd 4\nadd 13\nadd 9\nadd 3\nadd 14\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "2"
},
{
"input": "14\nadd 7\nadd 2\nadd 13\nadd 5\nadd 12\nadd 6\nadd 4\nadd 1\nadd 14\nremove\nadd 10\nremove\nadd 9\nadd 8\nadd 11\nadd 3\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "3"
},
{
"input": "11\nadd 10\nadd 9\nadd 11\nadd 1\nadd 5\nadd 6\nremove\nadd 3\nadd 8\nadd 2\nadd 4\nremove\nremove\nremove\nremove\nremove\nadd 7\nremove\nremove\nremove\nremove\nremove",
"output": "2"
},
{
"input": "3\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove",
"output": "0"
},
{
"input": "4\nadd 1\nadd 3\nadd 4\nremove\nadd 2\nremove\nremove\nremove",
"output": "1"
},
{
"input": "6\nadd 3\nadd 4\nadd 5\nadd 1\nadd 6\nremove\nadd 2\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "16\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "2\nadd 2\nadd 1\nremove\nremove",
"output": "0"
},
{
"input": "17\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "18\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "4\nadd 1\nadd 2\nremove\nremove\nadd 4\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "19\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nadd 19\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "5\nadd 4\nadd 3\nadd 1\nremove\nadd 2\nremove\nremove\nadd 5\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 4\nadd 6\nadd 1\nadd 5\nadd 7\nremove\nadd 2\nremove\nadd 3\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "8\nadd 1\nadd 2\nadd 3\nadd 7\nadd 8\nremove\nremove\nremove\nadd 6\nadd 5\nadd 4\nremove\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "4\nadd 1\nadd 4\nremove\nadd 3\nadd 2\nremove\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 1\nadd 2\nadd 3\nadd 5\nadd 7\nremove\nremove\nremove\nadd 4\nremove\nremove\nadd 6\nremove\nremove",
"output": "1"
},
{
"input": "4\nadd 4\nadd 1\nadd 2\nremove\nremove\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "5\nadd 1\nadd 3\nadd 4\nadd 5\nremove\nadd 2\nremove\nremove\nremove\nremove",
"output": "1"
},
{
"input": "5\nadd 2\nadd 1\nremove\nremove\nadd 5\nadd 3\nremove\nadd 4\nremove\nremove",
"output": "0"
},
{
"input": "9\nadd 3\nadd 2\nadd 1\nadd 4\nadd 6\nadd 9\nremove\nremove\nremove\nremove\nadd 5\nremove\nremove\nadd 8\nadd 7\nremove\nremove\nremove",
"output": "1"
},
{
"input": "10\nadd 9\nadd 10\nadd 4\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove\nremove\nadd 8\nadd 7\nadd 5\nadd 6\nremove\nremove\nremove\nremove\nremove\nremove",
"output": "1"
}
] | 1,611,993,529
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 8
| 3,000
| 7,680,000
|
t = int(input())
ans = 0
curr = 1
lst = []
for i in range(2*t):
s = input().split()
if s[0]=="add":
n = int(s[1])
lst.append(n)
else:
if lst[-1]==curr:
curr += 1
lst.pop()
else:
lst.sort(reverse = True)
lst.pop()
ans += 1
curr += 1
print(ans)
|
Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.
That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.
Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.
Input Specification:
The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack.
It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.
Output Specification:
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
Demo Input:
['3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n', '7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.
|
```python
t = int(input())
ans = 0
curr = 1
lst = []
for i in range(2*t):
s = input().split()
if s[0]=="add":
n = int(s[1])
lst.append(n)
else:
if lst[-1]==curr:
curr += 1
lst.pop()
else:
lst.sort(reverse = True)
lst.pop()
ans += 1
curr += 1
print(ans)
```
| 0
|
|
749
|
A
|
Bachgold Problem
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation",
"math",
"number theory"
] | null | null |
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
|
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
|
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
|
[
"5\n",
"6\n"
] |
[
"2\n2 3\n",
"3\n2 2 2\n"
] |
none
| 500
|
[
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\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 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 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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "100000",
"output": "50000\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 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 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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "7",
"output": "3\n2 2 3"
},
{
"input": "4",
"output": "2\n2 2"
},
{
"input": "8",
"output": "4\n2 2 2 2"
},
{
"input": "9",
"output": "4\n2 2 2 3"
},
{
"input": "99995",
"output": "49997\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 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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 2 ..."
},
{
"input": "14",
"output": "7\n2 2 2 2 2 2 2"
},
{
"input": "15",
"output": "7\n2 2 2 2 2 2 3"
},
{
"input": "53",
"output": "26\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 3"
},
{
"input": "57",
"output": "28\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 3"
},
{
"input": "61",
"output": "30\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 3"
},
{
"input": "774",
"output": "387\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 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 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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ..."
},
{
"input": "202",
"output": "101\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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| 1,641,485,037
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 15
| 0
|
n=int(input())
if n%2==0 : s='2 '*(n//2)
else : s='2 '*((n-3)//2)+'3'
print(s)
|
Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*.
Input Specification:
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
Output Specification:
The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
Demo Input:
['5\n', '6\n']
Demo Output:
['2\n2 3\n', '3\n2 2 2\n']
Note:
none
|
```python
n=int(input())
if n%2==0 : s='2 '*(n//2)
else : s='2 '*((n-3)//2)+'3'
print(s)
```
| 0
|
|
735
|
B
|
Urbanization
|
PROGRAMMING
| 1,100
|
[
"greedy",
"number theory",
"sortings"
] | null | null |
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second for *n*2 people. Of course, each of *n* candidates can settle in only one of the cities. Thus, first some subset of candidates of size *n*1 settle in the first city and then some subset of size *n*2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth *a**i* among all its residents divided by the number of them (*n*1 or *n*2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities.
|
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), the *i*-th of them is equal to the wealth of the *i*-th candidate.
|
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
|
[
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] |
[
"6.00000000\n",
"6.50000000\n"
] |
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class="lower-index">4</sub>) / 2 + *a*<sub class="lower-index">2</sub> = (3 + 2) / 2 + 4 = 6.5
| 1,000
|
[
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 100000 100000",
"output": "47052.10714286"
},
{
"input": "100 9 6\n109 711 40 95 935 48 228 253 308 726 816 534 252 8 966 363 162 508 84 83 807 506 748 178 45 30 106 108 764 698 825 198 336 353 158 790 64 262 403 334 577 571 742 541 946 602 279 621 910 776 421 886 29 133 114 394 762 965 339 263 750 530 49 80 124 31 322 292 27 590 960 278 111 932 849 491 561 744 469 511 106 271 156 160 836 363 149 473 457 543 976 809 490 29 85 626 265 88 995 946",
"output": "1849.66666667"
},
{
"input": "69 6 63\n53475 22876 79144 6335 33763 79104 65441 45527 65847 94406 74670 43529 75330 19403 67629 56187 57949 23071 64910 54409 55348 18056 855 24961 50565 6622 26467 33989 22660 79469 41246 13965 79706 14422 16075 93378 81313 48173 13470 97348 2346 27452 59427 29925 29847 73823 32021 10988 24609 98855 90919 45939 17203 8439 43007 40138 55693 30314 71734 33458 66850 4011 20089 20546 92090 50842 78859 62756 40177",
"output": "135712.88888889"
},
{
"input": "69 6 9\n2612 17461 69001 33130 10662 85485 88195 45974 16712 81365 67119 87797 15559 20197 74716 92979 97268 49466 68603 48351 99905 35606 54242 98603 68232 54398 82637 49647 38979 46171 54680 23334 15892 92186 69670 29711 67999 2220 32317 717 70667 68262 86760 55720 97158 61122 7251 138 21022 27197 12691 59331 13576 66999 38332 13574 83484 66646 17704 33065 98583 80259 64631 16745 69431 40747 82089 82788 32739",
"output": "183129.44444444"
}
] | 1,632,338,841
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 77
| 6,963,200
|
# بسم الله الرحمن الرحيم
def main():
n, n1, n2 = [int(i) for i in input().split()]
wealthes = [int(i) for i in input().split()]
sorted_wealthes = sorted(wealthes)
# print(sorted_wealthes)
max_mean1 = 0
max_mean2 = 0
if n1 <= n2:
# start fill n1 with people hav maxis wealthes
sum = 0
for i in range(n-1, n-n1-1, -1):
sum += sorted_wealthes[i]
max_mean1 = sum / n1
sum = 0
for i in range(n-n1-1, n-n2-1-1, -1):
sum += sorted_wealthes[i]
max_mean2 = sum / n2
else:
# start fill n2 with people hav maxis wealthes
sum = 0
for i in range(n-1, n-n2-1, -1): # [4]
sum += sorted_wealthes[i]
max_mean2 = sum / n2
# then continue fill n1 with people hav maxis wealthes after those on n2
sum = 0
for i in range(n-n2-1, n-n1-1-1, -1): # [2, 1]
sum += sorted_wealthes[i]
max_mean1 = sum / n1
print(max_mean1+max_mean2)
if __name__=='__main__':
main()
|
Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second for *n*2 people. Of course, each of *n* candidates can settle in only one of the cities. Thus, first some subset of candidates of size *n*1 settle in the first city and then some subset of size *n*2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.
To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth *a**i* among all its residents divided by the number of them (*n*1 or *n*2 depending on the city). The division should be done in real numbers without any rounding.
Please, help authorities find the optimal way to pick residents for two cities.
Input Specification:
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), the *i*-th of them is equal to the wealth of the *i*-th candidate.
Output Specification:
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['2 1 1\n1 5\n', '4 2 1\n1 4 2 3\n']
Demo Output:
['6.00000000\n', '6.50000000\n']
Note:
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class="lower-index">4</sub>) / 2 + *a*<sub class="lower-index">2</sub> = (3 + 2) / 2 + 4 = 6.5
|
```python
# بسم الله الرحمن الرحيم
def main():
n, n1, n2 = [int(i) for i in input().split()]
wealthes = [int(i) for i in input().split()]
sorted_wealthes = sorted(wealthes)
# print(sorted_wealthes)
max_mean1 = 0
max_mean2 = 0
if n1 <= n2:
# start fill n1 with people hav maxis wealthes
sum = 0
for i in range(n-1, n-n1-1, -1):
sum += sorted_wealthes[i]
max_mean1 = sum / n1
sum = 0
for i in range(n-n1-1, n-n2-1-1, -1):
sum += sorted_wealthes[i]
max_mean2 = sum / n2
else:
# start fill n2 with people hav maxis wealthes
sum = 0
for i in range(n-1, n-n2-1, -1): # [4]
sum += sorted_wealthes[i]
max_mean2 = sum / n2
# then continue fill n1 with people hav maxis wealthes after those on n2
sum = 0
for i in range(n-n2-1, n-n1-1-1, -1): # [2, 1]
sum += sorted_wealthes[i]
max_mean1 = sum / n1
print(max_mean1+max_mean2)
if __name__=='__main__':
main()
```
| 0
|
|
448
|
A
|
Rewards
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
|
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
|
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
|
[
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] |
[
"YES\n",
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n1",
"output": "NO"
},
{
"input": "1 10 100\n100 10 1\n20",
"output": "NO"
},
{
"input": "1 1 1\n0 0 0\n1",
"output": "YES"
},
{
"input": "0 0 0\n1 1 1\n1",
"output": "YES"
},
{
"input": "5 5 5\n0 0 0\n2",
"output": "NO"
},
{
"input": "0 0 0\n10 10 10\n2",
"output": "NO"
},
{
"input": "21 61 39\n63 58 69\n44",
"output": "YES"
},
{
"input": "18 95 4\n7 1 75\n46",
"output": "YES"
},
{
"input": "64 27 81\n72 35 23\n48",
"output": "YES"
},
{
"input": "6 6 6\n11 11 11\n7",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n3",
"output": "NO"
},
{
"input": "1 2 3\n2 4 6\n4",
"output": "YES"
},
{
"input": "99 99 99\n99 99 99\n89",
"output": "NO"
},
{
"input": "5 0 0\n15 0 0\n2",
"output": "NO"
},
{
"input": "10 10 10\n0 0 0\n1",
"output": "NO"
},
{
"input": "1 1 1\n1 1 1\n15",
"output": "YES"
},
{
"input": "2 3 5\n2 3 5\n2",
"output": "NO"
},
{
"input": "2 2 2\n3 3 5\n3",
"output": "NO"
},
{
"input": "1 2 2\n2 4 4\n1",
"output": "NO"
},
{
"input": "1 2 3\n1 5 5\n2",
"output": "NO"
}
] | 1,655,994,472
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 25
| 186
| 12,800,000
|
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
n=int(input())
if(math.ceil(sum(a)/5)+math.ceil(sum(b)/10)<=n):
print("YES")
else:
print("NO")
|
Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize cups and *a*3 third prize cups. Besides, he has *b*1 first prize medals, *b*2 second prize medals and *b*3 third prize medals.
Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time; - no shelf can contain more than five cups; - no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
Input Specification:
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces.
Output Specification:
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
Demo Input:
['1 1 1\n1 1 1\n4\n', '1 1 3\n2 3 4\n2\n', '1 0 0\n1 0 0\n1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none
|
```python
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
n=int(input())
if(math.ceil(sum(a)/5)+math.ceil(sum(b)/10)<=n):
print("YES")
else:
print("NO")
```
| 3
|
|
363
|
B
|
Fence
|
PROGRAMMING
| 1,100
|
[
"brute force",
"dp"
] | null | null |
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
|
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
|
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
|
[
"7 3\n1 2 6 1 1 7 1\n"
] |
[
"3\n"
] |
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
| 1,000
|
[
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"input": "2 2\n20 10",
"output": "1"
},
{
"input": "2 1\n20 1",
"output": "2"
},
{
"input": "3 1\n1 2 3",
"output": "1"
},
{
"input": "3 1\n2 1 3",
"output": "2"
},
{
"input": "3 1\n3 2 1",
"output": "3"
},
{
"input": "3 2\n1 2 3",
"output": "1"
},
{
"input": "3 2\n3 2 1",
"output": "2"
},
{
"input": "3 3\n1 2 3",
"output": "1"
},
{
"input": "4 2\n9 8 11 7",
"output": "1"
},
{
"input": "4 2\n10 1 2 3",
"output": "2"
},
{
"input": "6 3\n56 56 56 2 1 2",
"output": "4"
},
{
"input": "8 3\n1 1 1 1 2 60 90 1",
"output": "1"
},
{
"input": "4 1\n1 5 2 2",
"output": "1"
},
{
"input": "4 2\n4 6 7 4",
"output": "1"
},
{
"input": "10 4\n1 1 1 4 4 4 4 4 4 3",
"output": "1"
},
{
"input": "6 3\n1 2 1 3 1 1",
"output": "1"
},
{
"input": "5 2\n100 100 100 1 1",
"output": "4"
}
] | 1,685,903,866
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 51
| 109
| 15,769,600
|
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
from math import *
summ = 0
min_sum = inf
for right in range(k):
summ += arr[right]
min_sum = min(min_sum, summ)
idx = 0
for i in range(k, n):
summ = summ - arr[i - k] + arr[i]
if summ < min_sum:
min_sum = summ
idx = i - k + 1
print(idx + 1)
|
Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
Input Specification:
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Output Specification:
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
Demo Input:
['7 3\n1 2 6 1 1 7 1\n']
Demo Output:
['3\n']
Note:
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
|
```python
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
from math import *
summ = 0
min_sum = inf
for right in range(k):
summ += arr[right]
min_sum = min(min_sum, summ)
idx = 0
for i in range(k, n):
summ = summ - arr[i - k] + arr[i]
if summ < min_sum:
min_sum = summ
idx = i - k + 1
print(idx + 1)
```
| 3
|
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
One social network developer recently suggested a new algorithm of choosing ads for users.
There are *n* slots which advertisers can buy. It is possible to buy a segment of consecutive slots at once. The more slots you own, the bigger are the chances your ad will be shown to users.
Every time it is needed to choose ads to show, some segment of slots is picked by a secret algorithm. Then some advertisers are chosen. The only restriction is that it should be guaranteed for advertisers which own at least *p*% of slots composing this segment that their ad will be shown.
From the other side, users don't like ads. So it was decided to show no more than ads at once. You are asked to develop a system to sell segments of slots and choose ads in accordance with the rules described above.
|
The first line of the input contains three integers *n*, *m* and *p* (1<=≤<=*n*,<=*m*<=≤<=150<=000,<=20<=≤<=*p*<=≤<=100) — the number of slots, the number of queries to your system and threshold for which display of the ad is guaranteed.
Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=150<=000), where the *i*-th number means id of advertiser who currently owns the *i*-th slot.
Next *m* lines contain queries descriptions. Each description is of one of the following forms:
- 1 l r id (1<=≤<=*l*<=≤<=*r*<=≤<=*n*,<=1<=≤<=*id*<=≤<=150 000) — advertiser *id* bought all slots in a range from *l* to *r* inclusive; - 2 l r (1<=≤<=*l*<=≤<=*r*) — you need to choose advertisers for segment [*l*,<=*r*].
|
For each query of the second type answer should be printed in a separate line. First integer of the answer should be the number of advertisements that will be shown . Next *cnt* integers should be advertisers' ids.
It is allowed to print one advertiser more than once, but each advertiser that owns at least slots of the segment from *l* to *r* should be in your answer.
|
[
"5 9 33\n1 2 1 3 3\n2 1 5\n2 1 5\n2 1 3\n2 3 3\n1 2 4 5\n2 1 5\n2 3 5\n1 4 5 1\n2 1 5\n"
] |
[
"3 1 2 3\n2 1 3\n2 2 1\n3 1 1000 1000\n1 5\n2 5 3\n2 1 5"
] |
Samples demonstrate that you actually have quite a lot of freedom in choosing advertisers.
| 0
|
[] | 1,689,600,010
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1689600009.992197")# 1689600009.9922159
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One social network developer recently suggested a new algorithm of choosing ads for users.
There are *n* slots which advertisers can buy. It is possible to buy a segment of consecutive slots at once. The more slots you own, the bigger are the chances your ad will be shown to users.
Every time it is needed to choose ads to show, some segment of slots is picked by a secret algorithm. Then some advertisers are chosen. The only restriction is that it should be guaranteed for advertisers which own at least *p*% of slots composing this segment that their ad will be shown.
From the other side, users don't like ads. So it was decided to show no more than ads at once. You are asked to develop a system to sell segments of slots and choose ads in accordance with the rules described above.
Input Specification:
The first line of the input contains three integers *n*, *m* and *p* (1<=≤<=*n*,<=*m*<=≤<=150<=000,<=20<=≤<=*p*<=≤<=100) — the number of slots, the number of queries to your system and threshold for which display of the ad is guaranteed.
Next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=150<=000), where the *i*-th number means id of advertiser who currently owns the *i*-th slot.
Next *m* lines contain queries descriptions. Each description is of one of the following forms:
- 1 l r id (1<=≤<=*l*<=≤<=*r*<=≤<=*n*,<=1<=≤<=*id*<=≤<=150 000) — advertiser *id* bought all slots in a range from *l* to *r* inclusive; - 2 l r (1<=≤<=*l*<=≤<=*r*) — you need to choose advertisers for segment [*l*,<=*r*].
Output Specification:
For each query of the second type answer should be printed in a separate line. First integer of the answer should be the number of advertisements that will be shown . Next *cnt* integers should be advertisers' ids.
It is allowed to print one advertiser more than once, but each advertiser that owns at least slots of the segment from *l* to *r* should be in your answer.
Demo Input:
['5 9 33\n1 2 1 3 3\n2 1 5\n2 1 5\n2 1 3\n2 3 3\n1 2 4 5\n2 1 5\n2 3 5\n1 4 5 1\n2 1 5\n']
Demo Output:
['3 1 2 3\n2 1 3\n2 2 1\n3 1 1000 1000\n1 5\n2 5 3\n2 1 5']
Note:
Samples demonstrate that you actually have quite a lot of freedom in choosing advertisers.
|
```python
print("_RANDOM_GUESS_1689600009.992197")# 1689600009.9922159
```
| 0
|
|
707
|
A
|
Brain's Photos
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
|
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
|
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
|
[
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] |
[
"#Color",
"#Black&White",
"#Black&White"
] |
none
| 500
|
[
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,692,145,421
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 50
| 46
| 0
|
A = []
def Color (A) :
for i in A:
for j in i:
if j!='B' and j!='W' and j!='G' :
return '#Color'
return '#Black&White'
a = list(map(int,input().split()))
for i in range(a[0]):
b = list(map(str, input().split()))
A.append(b)
print(Color(A))
|
Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none
|
```python
A = []
def Color (A) :
for i in A:
for j in i:
if j!='B' and j!='W' and j!='G' :
return '#Color'
return '#Black&White'
a = list(map(int,input().split()))
for i in range(a[0]):
b = list(map(str, input().split()))
A.append(b)
print(Color(A))
```
| 3
|
|
707
|
C
|
Pythagorean Triples
|
PROGRAMMING
| 1,500
|
[
"math",
"number theory"
] | null | null |
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
|
The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle.
|
Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them.
|
[
"3\n",
"6\n",
"1\n",
"17\n",
"67\n"
] |
[
"4 5",
"8 10",
"-1",
"144 145",
"2244 2245"
] |
Illustration for the first sample.
| 1,500
|
[
{
"input": "3",
"output": "4 5"
},
{
"input": "6",
"output": "8 10"
},
{
"input": "1",
"output": "-1"
},
{
"input": "17",
"output": "144 145"
},
{
"input": "67",
"output": "2244 2245"
},
{
"input": "10",
"output": "24 26"
},
{
"input": "14",
"output": "48 50"
},
{
"input": "22",
"output": "120 122"
},
{
"input": "23",
"output": "264 265"
},
{
"input": "246",
"output": "15128 15130"
},
{
"input": "902",
"output": "203400 203402"
},
{
"input": "1000000000",
"output": "1250000000 750000000"
},
{
"input": "1998",
"output": "998000 998002"
},
{
"input": "2222222",
"output": "1234567654320 1234567654322"
},
{
"input": "2222226",
"output": "1234572098768 1234572098770"
},
{
"input": "1111110",
"output": "308641358024 308641358026"
},
{
"input": "9999998",
"output": "24999990000000 24999990000002"
},
{
"input": "1024",
"output": "1280 768"
},
{
"input": "8388608",
"output": "10485760 6291456"
},
{
"input": "4",
"output": "5 3"
},
{
"input": "8",
"output": "10 6"
},
{
"input": "16",
"output": "20 12"
},
{
"input": "492",
"output": "615 369"
},
{
"input": "493824",
"output": "617280 370368"
},
{
"input": "493804",
"output": "617255 370353"
},
{
"input": "493800",
"output": "617250 370350"
},
{
"input": "2048",
"output": "2560 1536"
},
{
"input": "8388612",
"output": "10485765 6291459"
},
{
"input": "44",
"output": "55 33"
},
{
"input": "444",
"output": "555 333"
},
{
"input": "4444",
"output": "5555 3333"
},
{
"input": "44444",
"output": "55555 33333"
},
{
"input": "444444",
"output": "555555 333333"
},
{
"input": "4444444",
"output": "5555555 3333333"
},
{
"input": "100000000",
"output": "125000000 75000000"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "4 5"
},
{
"input": "5",
"output": "12 13"
},
{
"input": "7",
"output": "24 25"
},
{
"input": "9",
"output": "40 41"
},
{
"input": "11",
"output": "60 61"
},
{
"input": "13",
"output": "84 85"
},
{
"input": "15",
"output": "112 113"
},
{
"input": "19",
"output": "180 181"
},
{
"input": "111",
"output": "6160 6161"
},
{
"input": "113",
"output": "6384 6385"
},
{
"input": "115",
"output": "6612 6613"
},
{
"input": "117",
"output": "6844 6845"
},
{
"input": "119",
"output": "7080 7081"
},
{
"input": "111111",
"output": "6172827160 6172827161"
},
{
"input": "111113",
"output": "6173049384 6173049385"
},
{
"input": "111115",
"output": "6173271612 6173271613"
},
{
"input": "111117",
"output": "6173493844 6173493845"
},
{
"input": "111119",
"output": "6173716080 6173716081"
},
{
"input": "9999993",
"output": "49999930000024 49999930000025"
},
{
"input": "9999979",
"output": "49999790000220 49999790000221"
},
{
"input": "9999990",
"output": "24999950000024 24999950000026"
},
{
"input": "9999991",
"output": "49999910000040 49999910000041"
},
{
"input": "9999992",
"output": "12499990 7499994"
},
{
"input": "9999973",
"output": "49999730000364 49999730000365"
},
{
"input": "9999994",
"output": "24999970000008 24999970000010"
},
{
"input": "9999995",
"output": "49999950000012 49999950000013"
},
{
"input": "9999996",
"output": "12499995 7499997"
},
{
"input": "9999997",
"output": "49999970000004 49999970000005"
},
{
"input": "9999978",
"output": "24999890000120 24999890000122"
},
{
"input": "99999993",
"output": "4999999300000024 4999999300000025"
},
{
"input": "99999979",
"output": "4999997900000220 4999997900000221"
},
{
"input": "99999990",
"output": "2499999500000024 2499999500000026"
},
{
"input": "99999991",
"output": "4999999100000040 4999999100000041"
},
{
"input": "99999992",
"output": "124999990 74999994"
},
{
"input": "99999973",
"output": "4999997300000364 4999997300000365"
},
{
"input": "99999994",
"output": "2499999700000008 2499999700000010"
},
{
"input": "99999995",
"output": "4999999500000012 4999999500000013"
},
{
"input": "99999996",
"output": "124999995 74999997"
},
{
"input": "99999997",
"output": "4999999700000004 4999999700000005"
},
{
"input": "99999978",
"output": "2499998900000120 2499998900000122"
},
{
"input": "987654323",
"output": "487730530870294164 487730530870294165"
},
{
"input": "2",
"output": "-1"
},
{
"input": "4",
"output": "5 3"
},
{
"input": "8",
"output": "10 6"
},
{
"input": "64",
"output": "80 48"
},
{
"input": "999999999",
"output": "499999999000000000 499999999000000001"
},
{
"input": "16",
"output": "20 12"
},
{
"input": "999999937",
"output": "499999937000001984 499999937000001985"
},
{
"input": "999999998",
"output": "249999999000000000 249999999000000002"
},
{
"input": "433494437",
"output": "93958713454973484 93958713454973485"
},
{
"input": "484916147",
"output": "117571834810662804 117571834810662805"
},
{
"input": "999999929",
"output": "499999929000002520 499999929000002521"
},
{
"input": "982451653",
"output": "482605625241216204 482605625241216205"
},
{
"input": "2048",
"output": "2560 1536"
}
] | 1,681,307,754
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 90
| 46
| 0
|
n = int(input())
if n < 3:
print(-1)
elif n % 2 == 1:
k = 1
a = (n**2//k - k)//2
b = (n**2//k + k)//2
print(a, b)
else:
k = 2
a = (n ** 2 // k - k) // 2
b = (n ** 2 // k + k) // 2
print(a, b)
|
Title: Pythagorean Triples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
Input Specification:
The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle.
Output Specification:
Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them.
Demo Input:
['3\n', '6\n', '1\n', '17\n', '67\n']
Demo Output:
['4 5', '8 10', '-1', '144 145', '2244 2245']
Note:
Illustration for the first sample.
|
```python
n = int(input())
if n < 3:
print(-1)
elif n % 2 == 1:
k = 1
a = (n**2//k - k)//2
b = (n**2//k + k)//2
print(a, b)
else:
k = 2
a = (n ** 2 // k - k) // 2
b = (n ** 2 // k + k) // 2
print(a, b)
```
| 3
|
|
14
|
A
|
Letter
|
PROGRAMMING
| 800
|
[
"implementation"
] |
A. Letter
|
1
|
64
|
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
|
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
|
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
|
[
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] |
[
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] |
none
| 0
|
[
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input": "5 1\n.\n*\n.\n.\n.",
"output": "*"
},
{
"input": "1 6\n*****.",
"output": "*****"
},
{
"input": "2 2\n..\n*.",
"output": "*"
},
{
"input": "8 2\n..\n..\n..\n..\n..\n*.\n..\n..",
"output": "*"
},
{
"input": "50 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n*"
},
{
"input": "2 1\n*\n.",
"output": "*"
},
{
"input": "5 1\n*\n*\n*\n*\n*",
"output": "*\n*\n*\n*\n*"
},
{
"input": "2 2\n*.\n..",
"output": "*"
},
{
"input": "3 4\n...*\n*...\n..*.",
"output": "...*\n*...\n..*."
},
{
"input": "8 2\n**\n**\n**\n**\n**\n**\n**\n**",
"output": "**\n**\n**\n**\n**\n**\n**\n**"
},
{
"input": "50 1\n.\n*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*\n.\n.\n.\n.\n.\n.",
"output": "*\n*\n*\n.\n.\n*\n.\n*\n*\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n.\n.\n*\n*\n.\n*\n*\n.\n.\n.\n.\n*\n*"
}
] | 1,657,381,659
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 62
| 0
|
n, m = input().split(" ")
matrix = []
imin, imax = int(n), -1
jmin, jmax = int(m), -1
for i in range(int(n)):
row = input()
matrix.append(row)
for j in range(len(row)):
if row[j] == '*':
if i < imin:
imin = i
if i > imax:
imax = i
if j < jmin:
jmin = j
if j > jmax:
jmax = j
for i in range(imin, imax+1, 1):
for j in range(jmin, jmax+1, 1):
print(matrix[i][j], end=" ")
print()
|
Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.
Input Specification:
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.
Output Specification:
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
Demo Input:
['6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n', '3 3\n***\n*.*\n***\n']
Demo Output:
['***\n*..\n***\n*..\n***\n', '***\n*.*\n***\n']
Note:
none
|
```python
n, m = input().split(" ")
matrix = []
imin, imax = int(n), -1
jmin, jmax = int(m), -1
for i in range(int(n)):
row = input()
matrix.append(row)
for j in range(len(row)):
if row[j] == '*':
if i < imin:
imin = i
if i > imax:
imax = i
if j < jmin:
jmin = j
if j > jmax:
jmax = j
for i in range(imin, imax+1, 1):
for j in range(jmin, jmax+1, 1):
print(matrix[i][j], end=" ")
print()
```
| 0
|
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,562,019,448
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 4
| 93
| 0
|
n, k = map(int, input().split())
A = [int(x) for x in input().split()]
a, b, c = 0, 0, 0
fa, fl = 0, 0
while b < len(A):
while b < len(A) and c <= k:
if A[b] == 0:
c += 1
b += 1
while c > k and a <= b:
if A[a] == 0:
c -= 1
a += 1
c = max([0, c])
if b - a > fl:
fl = b - a
fa = a
print(fl)
for i in range(len(A)):
print(1 if fa <= i and i < fa + fl else A[i], end=' ')
|
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 = [int(x) for x in input().split()]
a, b, c = 0, 0, 0
fa, fl = 0, 0
while b < len(A):
while b < len(A) and c <= k:
if A[b] == 0:
c += 1
b += 1
while c > k and a <= b:
if A[a] == 0:
c -= 1
a += 1
c = max([0, c])
if b - a > fl:
fl = b - a
fa = a
print(fl)
for i in range(len(A)):
print(1 if fa <= i and i < fa + fl else A[i], end=' ')
```
| 0
|
|
217
|
A
|
Ice Skating
|
PROGRAMMING
| 1,200
|
[
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null |
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
|
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
|
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
|
[
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] |
[
"1\n",
"0\n"
] |
none
| 500
|
[
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459",
"output": "21"
},
{
"input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815",
"output": "16"
},
{
"input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663",
"output": "10"
},
{
"input": "1\n321 88",
"output": "0"
},
{
"input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689",
"output": "7"
},
{
"input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510",
"output": "6"
},
{
"input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888",
"output": "5"
},
{
"input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802",
"output": "13"
},
{
"input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662",
"output": "11"
},
{
"input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786",
"output": "38"
},
{
"input": "3\n175 201\n907 909\n388 360",
"output": "2"
},
{
"input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86",
"output": "6"
},
{
"input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820",
"output": "16"
},
{
"input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901",
"output": "31"
},
{
"input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210",
"output": "29"
},
{
"input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894",
"output": "29"
},
{
"input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823",
"output": "13"
},
{
"input": "5\n175 158\n16 2\n397 381\n668 686\n957 945",
"output": "4"
},
{
"input": "5\n312 284\n490 509\n730 747\n504 497\n782 793",
"output": "4"
},
{
"input": "2\n802 903\n476 348",
"output": "1"
},
{
"input": "4\n325 343\n425 442\n785 798\n275 270",
"output": "3"
},
{
"input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653",
"output": "25"
},
{
"input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124",
"output": "34"
},
{
"input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255",
"output": "29"
},
{
"input": "5\n664 666\n951 941\n739 742\n844 842\n2 2",
"output": "4"
},
{
"input": "3\n939 867\n411 427\n757 708",
"output": "2"
},
{
"input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636",
"output": "34"
},
{
"input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195",
"output": "28"
},
{
"input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488",
"output": "22"
},
{
"input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235",
"output": "8"
},
{
"input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621",
"output": "22"
},
{
"input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461",
"output": "22"
},
{
"input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924",
"output": "6"
},
{
"input": "3\n1 1\n2 1\n2 2",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "5\n1 1\n1 2\n2 2\n3 1\n3 3",
"output": "0"
},
{
"input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3",
"output": "0"
},
{
"input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10",
"output": "1"
},
{
"input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11",
"output": "1"
},
{
"input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11",
"output": "3"
},
{
"input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25",
"output": "7"
},
{
"input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28",
"output": "5"
},
{
"input": "3\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n1 2",
"output": "0"
},
{
"input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4",
"output": "1"
},
{
"input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100",
"output": "6"
},
{
"input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "4\n3 1\n2 1\n2 2\n1 2",
"output": "0"
},
{
"input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "0"
},
{
"input": "4\n1 1\n2 2\n1 2\n2 1",
"output": "0"
},
{
"input": "4\n1 3\n2 1\n3 2\n3 1",
"output": "1"
},
{
"input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4",
"output": "0"
},
{
"input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700",
"output": "2"
},
{
"input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9",
"output": "1"
},
{
"input": "4\n1 1\n2 2\n3 2\n3 1",
"output": "0"
},
{
"input": "3\n1 2\n3 4\n3 2",
"output": "0"
},
{
"input": "3\n1 1\n1 2\n2 2",
"output": "0"
},
{
"input": "4\n5 5\n5 4\n6 3\n6 4",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n2 1",
"output": "0"
}
] | 1,614,400,099
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 11
| 218
| 307,200
|
from collections import defaultdict
visitedr=defaultdict(lambda:False)
visitedc=defaultdict(lambda:False)
cnt=0
for _ in range(int(input())):
a,b=map(int,input().split())
if not visitedr:
visitedr[a]=True
visitedc[b]=True
continue
if visitedr[a] or visitedc[b]:
visitedr[a]=True
visitedc[b]=True
else:
visitedr[a]=True
visitedc[b]=True
cnt+=1
print(cnt)
|
Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input Specification:
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output Specification:
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Demo Input:
['2\n2 1\n1 2\n', '2\n2 1\n4 1\n']
Demo Output:
['1\n', '0\n']
Note:
none
|
```python
from collections import defaultdict
visitedr=defaultdict(lambda:False)
visitedc=defaultdict(lambda:False)
cnt=0
for _ in range(int(input())):
a,b=map(int,input().split())
if not visitedr:
visitedr[a]=True
visitedc[b]=True
continue
if visitedr[a] or visitedc[b]:
visitedr[a]=True
visitedc[b]=True
else:
visitedr[a]=True
visitedc[b]=True
cnt+=1
print(cnt)
```
| 0
|
|
274
|
A
|
k-Multiple Free Set
|
PROGRAMMING
| 1,500
|
[
"binary search",
"greedy",
"sortings"
] | null | null |
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset.
|
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces.
|
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
|
[
"6 2\n2 3 6 5 4 10\n"
] |
[
"3\n"
] |
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
| 500
|
[
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 150 158 189 118 75 180 177 176 112 167 140 184 29 166 25 46 169 145 187 123 196 18 115 126 155 100 63 58 159 19 173 113 133 60 130 161 76 157 93 199 50 97 15 67 109 164 99 149 3 137 153 136 56 43 103 170 13 183 194 72 9 181 86 30 91 36",
"output": "79"
},
{
"input": "100 3\n13 38 137 24 46 192 33 8 170 141 118 57 198 133 112 176 40 36 91 130 166 72 123 28 82 180 134 52 64 107 97 79 199 184 158 22 181 163 98 7 88 41 73 87 167 109 15 173 153 70 50 119 139 56 17 152 84 161 11 116 31 187 143 196 27 102 132 126 149 63 146 168 67 48 53 120 20 105 155 10 128 47 23 6 94 3 113 65 44 179 189 99 75 34 111 193 60 145 171 77",
"output": "87"
},
{
"input": "12 400000000\n1 400000000 800000000 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "10 1\n1 100 300 400 500 500000 1000000 10000000 100000000 1000000000",
"output": "10"
},
{
"input": "2 1\n2 1",
"output": "2"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "1"
},
{
"input": "4 1000\n1 1000 1000000 1000000000",
"output": "2"
},
{
"input": "2 2\n1 3",
"output": "2"
},
{
"input": "2 2\n16 8",
"output": "1"
},
{
"input": "3 2\n8 4 2",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "5"
},
{
"input": "2 2\n500000000 1000000000",
"output": "1"
},
{
"input": "2 2\n4 2",
"output": "1"
},
{
"input": "10 100000000\n1 2 3 4 5 6 7 8 82000 907431936",
"output": "10"
},
{
"input": "8 65538\n65535 65536 65537 65538 65539 131072 262144 196608",
"output": "8"
},
{
"input": "5 2\n10 8 6 4 2",
"output": "4"
},
{
"input": "2 1000000000\n276447232 100000",
"output": "2"
}
] | 1,687,614,473
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 92
| 1,024,000
|
from collections import defaultdict, deque, Counter
from math import sqrt, ceil, log2, factorial, gcd
from itertools import combinations, permutations
from functools import lru_cache
from heapq import heappop, heappush, heapreplace, heapify
from bisect import bisect_left, bisect_right
from fractions import Fraction
from sys import stdin, stdout, setrecursionlimit
inf = float('inf')
setrecursionlimit(1 << 21)
write = lambda x='', end='\n': stdout.write(str(x) + end)
writes = lambda x, step=' ': stdout.write(step.join(map(str, x)) + '\n')
read = lambda x=int: x(stdin.readline().strip())
reads = lambda x=int: map(x, stdin.readline().strip().split())
n, k = reads()
s = set()
for i in sorted(reads()):
t = i // k
if t not in s:
s.add(i)
else:
s.remove(t)
s.add(i)
write(len(s))
|
Title: k-Multiple Free Set
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces.
Output Specification:
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
Demo Input:
['6 2\n2 3 6 5 4 10\n']
Demo Output:
['3\n']
Note:
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
|
```python
from collections import defaultdict, deque, Counter
from math import sqrt, ceil, log2, factorial, gcd
from itertools import combinations, permutations
from functools import lru_cache
from heapq import heappop, heappush, heapreplace, heapify
from bisect import bisect_left, bisect_right
from fractions import Fraction
from sys import stdin, stdout, setrecursionlimit
inf = float('inf')
setrecursionlimit(1 << 21)
write = lambda x='', end='\n': stdout.write(str(x) + end)
writes = lambda x, step=' ': stdout.write(step.join(map(str, x)) + '\n')
read = lambda x=int: x(stdin.readline().strip())
reads = lambda x=int: map(x, stdin.readline().strip().split())
n, k = reads()
s = set()
for i in sorted(reads()):
t = i // k
if t not in s:
s.add(i)
else:
s.remove(t)
s.add(i)
write(len(s))
```
| 0
|
|
52
|
A
|
123-sequence
|
PROGRAMMING
| 900
|
[
"implementation"
] |
A. 123-sequence
|
2
|
256
|
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
|
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
|
[
"9\n1 3 2 2 2 1 1 2 3\n"
] |
[
"5\n"
] |
In the example all the numbers equal to 1 and 3 should be replaced by 2.
| 500
|
[
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n3 2",
"output": "1"
},
{
"input": "2\n3 1",
"output": "1"
},
{
"input": "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2",
"output": "10"
},
{
"input": "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3 1 3 1",
"output": "19"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
}
] | 1,600,524,465
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 23
| 904
| 14,643,200
|
n=int(input())
count=0
one=0
two=0
three=0
x=list(map(int,input().split()))
for i in x:
if i==1:
one=one+1
elif i==2:
two=two+1
elif i==3:
three=three+1
max_=max(one,two ,three)
answer=n-max_
print(answer)
|
Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3).
Output Specification:
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Demo Input:
['9\n1 3 2 2 2 1 1 2 3\n']
Demo Output:
['5\n']
Note:
In the example all the numbers equal to 1 and 3 should be replaced by 2.
|
```python
n=int(input())
count=0
one=0
two=0
three=0
x=list(map(int,input().split()))
for i in x:
if i==1:
one=one+1
elif i==2:
two=two+1
elif i==3:
three=three+1
max_=max(one,two ,three)
answer=n-max_
print(answer)
```
| 3.746725
|
71
|
A
|
Way Too Long Words
|
PROGRAMMING
| 800
|
[
"strings"
] |
A. Way Too Long Words
|
1
|
256
|
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
|
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
|
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
|
[
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] |
[
"word\nl10n\ni18n\np43s\n"
] |
none
| 500
|
[
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,694,370,480
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 1
| 62
| 0
|
x = int(input())
arr = []
for i in range(x):
arr.append(input())
for i in range(x):
if len(arr[i])==x:
print(arr[i])
else:
s = arr[i][1:-1]
print(arr[i][0]+str(len(s))+arr[i][-1])
|
Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none
|
```python
x = int(input())
arr = []
for i in range(x):
arr.append(input())
for i in range(x):
if len(arr[i])==x:
print(arr[i])
else:
s = arr[i][1:-1]
print(arr[i][0]+str(len(s))+arr[i][-1])
```
| 0
|
343
|
C
|
Read Time
|
PROGRAMMING
| 1,900
|
[
"binary search",
"greedy",
"two pointers"
] | null | null |
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but *n* different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the *i*-th reading head is above the track number *h**i*. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered *h*1, *h*2, ..., *h**n* have been read at the beginning of the operation.
Mike needs to read the data on *m* distinct tracks with numbers *p*1, *p*2, ..., *p**m*. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.
|
The first line of the input contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains *n* distinct integers *h**i* in ascending order (1<=≤<=*h**i*<=≤<=1010, *h**i*<=<<=*h**i*<=+<=1) — the initial positions of the heads. The third line contains *m* distinct integers *p**i* in ascending order (1<=≤<=*p**i*<=≤<=1010, *p**i*<=<<=*p**i*<=+<=1) - the numbers of tracks to read.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
|
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
|
[
"3 4\n2 5 6\n1 3 6 8\n",
"3 3\n1 2 3\n1 2 3\n",
"1 2\n165\n142 200\n"
] |
[
"2\n",
"0\n",
"81\n"
] |
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:
1. during the first second move the 1-st head to the left and let it stay there; 1. move the second head to the left twice; 1. move the third head to the right twice (note that the 6-th track has already been read at the beginning).
One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
| 1,500
|
[
{
"input": "3 4\n2 5 6\n1 3 6 8",
"output": "2"
},
{
"input": "3 3\n1 2 3\n1 2 3",
"output": "0"
},
{
"input": "1 2\n165\n142 200",
"output": "81"
},
{
"input": "1 2\n5000000000\n1 10000000000",
"output": "14999999998"
},
{
"input": "2 4\n3 12\n1 7 8 14",
"output": "8"
},
{
"input": "3 3\n1 2 3\n2 3 4",
"output": "1"
},
{
"input": "2 1\n1 10\n9",
"output": "1"
},
{
"input": "3 19\n7 10 13\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19",
"output": "6"
},
{
"input": "3 3\n2 3 4\n1 3 5",
"output": "1"
},
{
"input": "10 11\n1 909090909 1818181817 2727272725 3636363633 4545454541 5454545449 6363636357 7272727265 8181818173\n454545455 1363636363 2272727271 3181818179 4090909087 4999999995 5909090903 6818181811 7727272719 8636363627 9545454535",
"output": "1363636362"
},
{
"input": "3 10\n4999999999 5000000000 5000000001\n1 1000 100000 1000000 4999999999 5000000000 5000000001 6000000000 8000000000 10000000000",
"output": "4999999999"
},
{
"input": "2 4\n4500000000 5500000000\n5 499999999 5000000001 9999999995",
"output": "5499999993"
},
{
"input": "10 10\n331462447 1369967506 1504296131 2061390288 2309640071 3006707770 4530801731 4544099460 7357049371 9704808257\n754193799 3820869903 4594383880 5685752675 6303322854 6384906441 7863448848 8542634752 9573124462 9665646063",
"output": "1840806981"
},
{
"input": "1 1\n10000000000\n1",
"output": "9999999999"
},
{
"input": "1 1\n1\n10000000000",
"output": "9999999999"
},
{
"input": "10 10\n9999999991 9999999992 9999999993 9999999994 9999999995 9999999996 9999999997 9999999998 9999999999 10000000000\n1 2 3 4 5 6 7 8 9 10",
"output": "9999999990"
},
{
"input": "3 12\n477702277 4717363935 8947981095\n477702276 477702304 477702312 477702317 4717363895 4717363896 4717363920 4717363936 8947981094 8947981111 8947981112 8947981135",
"output": "42"
},
{
"input": "10 10\n389151626 1885767612 2609703695 3054567325 4421751790 5636236054 6336088034 7961001379 8631992167 9836923433\n389144165 389158510 1885760728 1885775073 2609696234 2609710579 3054559864 3054574209 4421744329 4421758674",
"output": "21229"
},
{
"input": "1 1\n10000000000\n1",
"output": "9999999999"
}
] | 1,689,194,924
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 0
|
print("_RANDOM_GUESS_1689194924.175988")# 1689194924.1760361
|
Title: Read Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but *n* different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the *i*-th reading head is above the track number *h**i*. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered *h*1, *h*2, ..., *h**n* have been read at the beginning of the operation.
Mike needs to read the data on *m* distinct tracks with numbers *p*1, *p*2, ..., *p**m*. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.
Input Specification:
The first line of the input contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains *n* distinct integers *h**i* in ascending order (1<=≤<=*h**i*<=≤<=1010, *h**i*<=<<=*h**i*<=+<=1) — the initial positions of the heads. The third line contains *m* distinct integers *p**i* in ascending order (1<=≤<=*p**i*<=≤<=1010, *p**i*<=<<=*p**i*<=+<=1) - the numbers of tracks to read.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
Demo Input:
['3 4\n2 5 6\n1 3 6 8\n', '3 3\n1 2 3\n1 2 3\n', '1 2\n165\n142 200\n']
Demo Output:
['2\n', '0\n', '81\n']
Note:
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:
1. during the first second move the 1-st head to the left and let it stay there; 1. move the second head to the left twice; 1. move the third head to the right twice (note that the 6-th track has already been read at the beginning).
One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
|
```python
print("_RANDOM_GUESS_1689194924.175988")# 1689194924.1760361
```
| 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\nOWQ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Python 3
|
RUNTIME_ERROR
|
TESTS
| 2
| 62
| 0
|
n = int(input())
l = list()
d = dict()
for i in range(n):
team=str(input())
if team not in d:
d[team]=1
l.append(team)
else:
d[team]+=1
if n==1:
print(l[0])
elif int(d[l[0]]) > int(d[l[1]]):
print(l[0])
else:
print(l[1])
|
Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. 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())
l = list()
d = dict()
for i in range(n):
team=str(input())
if team not in d:
d[team]=1
l.append(team)
else:
d[team]+=1
if n==1:
print(l[0])
elif int(d[l[0]]) > int(d[l[1]]):
print(l[0])
else:
print(l[1])
```
| -1
|
1,009
|
C
|
Annoying Present
|
PROGRAMMING
| 1,700
|
[
"greedy",
"math"
] | null | null |
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some integer numbers $x$ and $d$, he chooses an arbitrary position $i$ ($1 \le i \le n$) and for every $j \in [1, n]$ adds $x + d \cdot dist(i, j)$ to the value of the $j$-th cell. $dist(i, j)$ is the distance between positions $i$ and $j$ (i.e. $dist(i, j) = |i - j|$, where $|x|$ is an absolute value of $x$).
For example, if Alice currently has an array $[2, 1, 2, 2]$ and Bob chooses position $3$ for $x = -1$ and $d = 2$ then the array will become $[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$ = $[5, 2, 1, 3]$. Note that Bob can't choose position $i$ outside of the array (that is, smaller than $1$ or greater than $n$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
|
[
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] |
[
"-2.500000000000000\n",
"7.000000000000000\n"
] |
none
| 0
|
[
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
"output": "0.000000000000000"
},
{
"input": "100000 1\n1000 1000",
"output": "50000500.000000000000000"
},
{
"input": "11 1\n0 -10",
"output": "-27.272727272727273"
},
{
"input": "3 1\n1 -1",
"output": "0.333333333333333"
},
{
"input": "1 2\n-1 -1\n-2 -2",
"output": "-3.000000000000000"
},
{
"input": "1 2\n0 -1\n0 1",
"output": "0.000000000000000"
},
{
"input": "1 1\n1 -2",
"output": "1.000000000000000"
},
{
"input": "3 1\n2 -1",
"output": "1.333333333333333"
},
{
"input": "3 1\n0 -1",
"output": "-0.666666666666667"
},
{
"input": "1 1\n-1000 -1000",
"output": "-1000.000000000000000"
},
{
"input": "1 1\n0 -5",
"output": "0.000000000000000"
},
{
"input": "15 3\n2 0\n2 -5\n-2 5",
"output": "18.333333333333332"
},
{
"input": "9 1\n0 -5",
"output": "-11.111111111111111"
},
{
"input": "7 1\n0 -1",
"output": "-1.714285714285714"
},
{
"input": "3 1\n-2 -2",
"output": "-3.333333333333333"
},
{
"input": "3 1\n5 -5",
"output": "1.666666666666667"
},
{
"input": "1 1\n-1 -1",
"output": "-1.000000000000000"
},
{
"input": "7 1\n-1 -5",
"output": "-9.571428571428571"
},
{
"input": "3 2\n-2 -2\n-2 -2",
"output": "-6.666666666666667"
},
{
"input": "5 1\n0 -4",
"output": "-4.800000000000000"
},
{
"input": "5 1\n-1 -5",
"output": "-7.000000000000000"
},
{
"input": "5 1\n0 -2",
"output": "-2.400000000000000"
},
{
"input": "3 5\n1 -1000\n1 -1000\n1 -1000\n1 -1000\n1 -1000",
"output": "-3328.333333333333485"
},
{
"input": "1 1\n0 -1",
"output": "0.000000000000000"
},
{
"input": "1 2\n0 -3\n0 -3",
"output": "0.000000000000000"
},
{
"input": "7 1\n2 -3",
"output": "-3.142857142857143"
},
{
"input": "3 2\n-1 -1\n-1 -1",
"output": "-3.333333333333333"
},
{
"input": "5 1\n-1 -162",
"output": "-195.400000000000006"
},
{
"input": "5 10\n-506 -243\n727 -141\n-548 -306\n740 880\n-744 -116\n-84 182\n-859 -108\n64 86\n135 446\n69 -184",
"output": "864.399999999999977"
},
{
"input": "5 1\n0 -1",
"output": "-1.200000000000000"
},
{
"input": "5 12\n634 895\n143 730\n901 245\n386 486\n395 -111\n-469 -104\n-681 -623\n-900 843\n889 -883\n476 -304\n777 986\n206 -491",
"output": "8107.800000000000182"
},
{
"input": "3 3\n4 2\n5 0\n6 -1",
"output": "16.333333333333332"
},
{
"input": "1 3\n4 2\n5 0\n6 -1",
"output": "15.000000000000000"
},
{
"input": "85 10\n-223 435\n-771 455\n72 -940\n490 -178\n400 -117\n169 -527\n836 610\n849 944\n572 -237\n-428 -428",
"output": "53047.388235294114565"
},
{
"input": "69 10\n-8 4\n-3 3\n7 5\n5 -9\n8 1\n7 -5\n-8 -8\n9 3\n1 1\n0 6",
"output": "420.579710144927560"
},
{
"input": "1 10\n1 1\n1 0\n1 0\n1 0\n-1 0\n0 1\n1 0\n0 0\n2 1\n9 2",
"output": "15.000000000000000"
},
{
"input": "5 4\n0 1\n0 2\n0 3\n0 -9",
"output": "1.200000000000000"
}
] | 1,682,173,812
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 54
| 124
| 3,891,200
|
import sys
input = sys.stdin.readline
def f(u):
return u*(u+1)//2
n, m = map(int, input().split())
x1, x2 = n//2, (n-1)//2
x, y, c, d = f(x1) + f(x2), f(n-1), 0, 0
for i in range(m):
a, b = map(int, input().split())
c += a
d += max(b*x, b*y)
print((c*n+d)/n)
|
Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some integer numbers $x$ and $d$, he chooses an arbitrary position $i$ ($1 \le i \le n$) and for every $j \in [1, n]$ adds $x + d \cdot dist(i, j)$ to the value of the $j$-th cell. $dist(i, j)$ is the distance between positions $i$ and $j$ (i.e. $dist(i, j) = |i - j|$, where $|x|$ is an absolute value of $x$).
For example, if Alice currently has an array $[2, 1, 2, 2]$ and Bob chooses position $3$ for $x = -1$ and $d = 2$ then the array will become $[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$ = $[5, 2, 1, 3]$. Note that Bob can't choose position $i$ outside of the array (that is, smaller than $1$ or greater than $n$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change.
Output Specification:
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
Demo Input:
['2 3\n-1 3\n0 0\n-1 -4\n', '3 2\n0 2\n5 0\n']
Demo Output:
['-2.500000000000000\n', '7.000000000000000\n']
Note:
none
|
```python
import sys
input = sys.stdin.readline
def f(u):
return u*(u+1)//2
n, m = map(int, input().split())
x1, x2 = n//2, (n-1)//2
x, y, c, d = f(x1) + f(x2), f(n-1), 0, 0
for i in range(m):
a, b = map(int, input().split())
c += a
d += max(b*x, b*y)
print((c*n+d)/n)
```
| 3
|
|
92
|
A
|
Chips
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] |
A. Chips
|
2
|
256
|
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
|
Print the number of chips the presenter ended up with.
|
[
"4 11\n",
"17 107\n",
"3 8\n"
] |
[
"0\n",
"2\n",
"1\n"
] |
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
| 500
|
[
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "25 9712",
"output": "11"
},
{
"input": "9 7601",
"output": "5"
},
{
"input": "1 9058",
"output": "0"
},
{
"input": "29 7772",
"output": "26"
},
{
"input": "45 9465",
"output": "14"
},
{
"input": "46 866",
"output": "5"
},
{
"input": "29 1241",
"output": "20"
},
{
"input": "17 4248",
"output": "12"
},
{
"input": "20 8082",
"output": "11"
},
{
"input": "50 9555",
"output": "0"
},
{
"input": "4 7455",
"output": "2"
},
{
"input": "36 880",
"output": "4"
},
{
"input": "24 7440",
"output": "9"
},
{
"input": "44 7888",
"output": "12"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "50 10000",
"output": "40"
},
{
"input": "1 10000",
"output": "0"
},
{
"input": "50 1",
"output": "0"
},
{
"input": "50 50",
"output": "5"
}
] | 1,507,366,718
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 25
| 124
| 0
|
n,m = map(int,input().split())
s = int(n*(n+1)/2)
m = m%s
for i in range(1,n):
if(m<i):
break
m= m-i
print(m)
|
Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Output Specification:
Print the number of chips the presenter ended up with.
Demo Input:
['4 11\n', '17 107\n', '3 8\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
|
```python
n,m = map(int,input().split())
s = int(n*(n+1)/2)
m = m%s
for i in range(1,n):
if(m<i):
break
m= m-i
print(m)
```
| 3.969
|
774
|
D
|
Lie or Truth
|
PROGRAMMING
| 1,500
|
[
"*special",
"constructive algorithms",
"implementation",
"sortings"
] | null | null |
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*.
While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to *b*1,<=*b*2,<=...,<=*b**n*.
Stepan said that he swapped only cubes which where on the positions between *l* and *r*, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions *l* and *r*, inclusive, in some way).
Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
|
The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order.
The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of integers written on cubes after Stepan rearranged their order.
It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
|
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
|
[
"5 2 4\n3 4 2 3 1\n3 2 3 4 1\n",
"3 1 2\n1 2 3\n3 1 2\n",
"4 2 4\n1 1 1 1\n1 1 1 1\n"
] |
[
"TRUTH\n",
"LIE\n",
"TRUTH\n"
] |
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).
In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.
In the third example for any values *l* and *r* there is a situation when Stepan said the truth.
| 0
|
[
{
"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1",
"output": "TRUTH"
},
{
"input": "3 1 2\n1 2 3\n3 1 2",
"output": "LIE"
},
{
"input": "4 2 4\n1 1 1 1\n1 1 1 1",
"output": "TRUTH"
},
{
"input": "5 1 3\n2 2 2 1 2\n2 2 2 1 2",
"output": "TRUTH"
},
{
"input": "7 1 4\n2 5 5 5 4 3 4\n2 5 5 5 4 3 4",
"output": "TRUTH"
},
{
"input": "10 1 10\n6 7 6 1 10 10 9 5 3 9\n7 10 9 6 1 5 9 3 10 6",
"output": "TRUTH"
},
{
"input": "1 1 1\n1\n1",
"output": "TRUTH"
},
{
"input": "4 3 4\n1 2 3 4\n2 1 3 4",
"output": "LIE"
},
{
"input": "7 2 4\n1 2 3 4 5 7 6\n1 2 3 4 5 6 7",
"output": "LIE"
},
{
"input": "5 1 2\n1 2 3 4 5\n1 2 3 5 4",
"output": "LIE"
},
{
"input": "8 3 6\n5 3 1 1 1 1 3 5\n3 3 1 1 1 1 5 5",
"output": "LIE"
},
{
"input": "4 2 2\n2 1 2 2\n1 2 2 2",
"output": "LIE"
}
] | 1,491,407,788
| 1,288
|
Python 3
|
OK
|
TESTS
| 52
| 140
| 15,155,200
|
import sys
def main():
yes = True
array = sys.stdin.readline().strip().split(' ')
array1 = sys.stdin.readline().strip().split(' ')
array2 = sys.stdin.readline().strip().split(' ')
for i in range(len(array1)):
if i < int(array[1])-1 or i >= int(array[2]):
if array1[i] != array2[i]:
yes = False
break
if yes:
print("TRUTH")
else:
print("LIE")
return
main()
|
Title: Lie or Truth
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to *a*1,<=*a*2,<=...,<=*a**n*.
While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to *b*1,<=*b*2,<=...,<=*b**n*.
Stepan said that he swapped only cubes which where on the positions between *l* and *r*, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions *l* and *r*, inclusive, in some way).
Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
Input Specification:
The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) — the number of Vasya's cubes and the positions told by Stepan.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of integers written on cubes in the Vasya's order.
The third line contains the sequence *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of integers written on cubes after Stepan rearranged their order.
It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
Output Specification:
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
Demo Input:
['5 2 4\n3 4 2 3 1\n3 2 3 4 1\n', '3 1 2\n1 2 3\n3 1 2\n', '4 2 4\n1 1 1 1\n1 1 1 1\n']
Demo Output:
['TRUTH\n', 'LIE\n', 'TRUTH\n']
Note:
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).
In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.
In the third example for any values *l* and *r* there is a situation when Stepan said the truth.
|
```python
import sys
def main():
yes = True
array = sys.stdin.readline().strip().split(' ')
array1 = sys.stdin.readline().strip().split(' ')
array2 = sys.stdin.readline().strip().split(' ')
for i in range(len(array1)):
if i < int(array[1])-1 or i >= int(array[2]):
if array1[i] != array2[i]:
yes = False
break
if yes:
print("TRUTH")
else:
print("LIE")
return
main()
```
| 3
|
|
220
|
A
|
Little Elephant and Problem
|
PROGRAMMING
| 1,300
|
[
"implementation",
"sortings"
] | null | null |
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
|
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers.
|
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
|
[
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] |
[
"YES\n",
"YES\n",
"NO\n"
] |
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
| 500
|
[
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000",
"output": "YES"
},
{
"input": "10\n1 2 9 4 5 6 7 8 3 10",
"output": "YES"
},
{
"input": "4\n2 2 2 1",
"output": "YES"
},
{
"input": "10\n1 2 4 4 4 5 5 7 7 10",
"output": "YES"
},
{
"input": "10\n4 5 11 12 13 14 16 16 16 18",
"output": "YES"
},
{
"input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321",
"output": "YES"
},
{
"input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644",
"output": "YES"
},
{
"input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5",
"output": "NO"
},
{
"input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472",
"output": "NO"
},
{
"input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503",
"output": "NO"
},
{
"input": "4\n5 12 12 6",
"output": "YES"
},
{
"input": "5\n1 3 3 3 2",
"output": "YES"
},
{
"input": "4\n2 1 1 1",
"output": "YES"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "4\n1000000000 1 1000000000 1",
"output": "YES"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 1",
"output": "YES"
},
{
"input": "6\n1 2 3 4 5 3",
"output": "NO"
},
{
"input": "9\n3 3 3 2 2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n4 1 2 3",
"output": "NO"
},
{
"input": "6\n3 4 5 6 7 2",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "4\n3 2 1 1",
"output": "NO"
},
{
"input": "4\n4 5 1 1",
"output": "NO"
},
{
"input": "6\n1 6 2 4 3 5",
"output": "NO"
},
{
"input": "5\n1 4 5 2 3",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n1 4 3 2 1",
"output": "NO"
},
{
"input": "5\n1 4 2 2 3",
"output": "NO"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "5\n5 1 2 3 4",
"output": "NO"
},
{
"input": "5\n3 3 3 2 2",
"output": "NO"
},
{
"input": "5\n100 5 6 10 7",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "NO"
},
{
"input": "5\n4 4 1 1 1",
"output": "NO"
},
{
"input": "5\n1 2 5 3 4",
"output": "NO"
},
{
"input": "4\n3 4 1 2",
"output": "NO"
},
{
"input": "4\n2 4 1 5",
"output": "NO"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 5 4 4 4",
"output": "YES"
},
{
"input": "7\n3 2 1 2 3 5 4",
"output": "NO"
},
{
"input": "5\n1 1 3 2 2",
"output": "YES"
},
{
"input": "9\n1 8 7 7 7 7 7 8 3",
"output": "YES"
},
{
"input": "5\n1 3 2 3 3",
"output": "YES"
},
{
"input": "10\n4 4 4 4 10 4 4 4 4 4",
"output": "YES"
},
{
"input": "8\n3 6 6 6 6 6 4 9",
"output": "YES"
},
{
"input": "4\n4 4 3 3",
"output": "NO"
},
{
"input": "4\n3 2 2 4",
"output": "YES"
},
{
"input": "5\n2 2 1 3 3",
"output": "YES"
},
{
"input": "5\n1 2 7 3 5",
"output": "NO"
},
{
"input": "5\n2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n1 4 3 6 2 5",
"output": "NO"
},
{
"input": "5\n3 3 1 5 4",
"output": "NO"
},
{
"input": "4\n1 2 1 2",
"output": "YES"
},
{
"input": "6\n4 5 3 4 2 6",
"output": "NO"
},
{
"input": "11\n1 2 3 4 5 1 2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n6 1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n4 1 1 1 1",
"output": "YES"
},
{
"input": "9\n1 2 3 5 4 6 7 8 9",
"output": "YES"
},
{
"input": "6\n6 1 2 3 4 2",
"output": "NO"
},
{
"input": "6\n2 2 2 2 3 2",
"output": "YES"
},
{
"input": "3\n2 1 1",
"output": "YES"
},
{
"input": "5\n1 2 1 1 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 2",
"output": "YES"
},
{
"input": "8\n5 5 5 5 5 5 1 1",
"output": "NO"
}
] | 1,462,009,338
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 46
| 4,915,200
|
'''
Created on Apr 30, 2016
Gmail : [email protected]
@author: Md. Rezwanul Haque
'''
n = int(input())
a = list(map(int,input().split()))
a.sort(key=None, reverse=False)
#for i in range(n):
#if(a[i+1])
if (len(a)%2==1 ):
print("YES")
else:
print("NO")
|
Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers.
Output Specification:
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
Demo Input:
['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
|
```python
'''
Created on Apr 30, 2016
Gmail : [email protected]
@author: Md. Rezwanul Haque
'''
n = int(input())
a = list(map(int,input().split()))
a.sort(key=None, reverse=False)
#for i in range(n):
#if(a[i+1])
if (len(a)%2==1 ):
print("YES")
else:
print("NO")
```
| 0
|
|
776
|
B
|
Sherlock and his girlfriend
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"number theory"
] | null | null |
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
|
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
|
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them.
|
[
"3\n",
"4\n"
] |
[
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] |
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
| 1,000
|
[
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 "
},
{
"input": "105",
"output": "2\n1 1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 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
},
{
"input": "99971",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 ..."
}
] | 1,521,092,554
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 53
| 623
| 6,758,400
|
n=int(input())
a=[0]*(n+2)
for i in range(2,n+2):
for j in range(i,n+2,i):
a[j]+=1
if n>2:print(2)
else:print(1)
for i in range(2,n+2):
if a[i]==1:
print(1,end=' ')
else:
print(2,end=' ')
|
Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task.
Input Specification:
The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces.
Output Specification:
The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them.
Demo Input:
['3\n', '4\n']
Demo Output:
['2\n1 1 2 ', '2\n2 1 1 2\n']
Note:
In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.
|
```python
n=int(input())
a=[0]*(n+2)
for i in range(2,n+2):
for j in range(i,n+2,i):
a[j]+=1
if n>2:print(2)
else:print(1)
for i in range(2,n+2):
if a[i]==1:
print(1,end=' ')
else:
print(2,end=' ')
```
| 3
|
|
133
|
A
|
HQ9+
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
|
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
|
Output "YES", if executing the program will produce any output, and "NO" otherwise.
|
[
"Hi!\n",
"Codeforces\n"
] |
[
"YES\n",
"NO\n"
] |
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions.
| 500
|
[
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"input": "H",
"output": "YES"
},
{
"input": "+",
"output": "NO"
},
{
"input": "~",
"output": "NO"
},
{
"input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR",
"output": "YES"
},
{
"input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC",
"output": "YES"
},
{
"input": "@F%K2=%RyL/",
"output": "NO"
},
{
"input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J",
"output": "YES"
},
{
"input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)",
"output": "YES"
},
{
"input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C",
"output": "YES"
},
{
"input": "p-UXsbd&f",
"output": "NO"
},
{
"input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_",
"output": "YES"
},
{
"input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]",
"output": "YES"
},
{
"input": "}do5RU<(w<q[\"-NR)IAH_HyiD{",
"output": "YES"
},
{
"input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8",
"output": "YES"
},
{
"input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv",
"output": "YES"
},
{
"input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`",
"output": "YES"
},
{
"input": "OKBB5z7ud81[Tn@P\"nDUd,>@",
"output": "NO"
},
{
"input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv",
"output": "YES"
},
{
"input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh",
"output": "YES"
},
{
"input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp",
"output": "NO"
},
{
"input": "!3YPv@2JQ44@)R2O_4`GO",
"output": "YES"
},
{
"input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\",
"output": "YES"
},
{
"input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L",
"output": "NO"
},
{
"input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&",
"output": "YES"
},
{
"input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}",
"output": "YES"
},
{
"input": "Uh3>ER](J",
"output": "NO"
},
{
"input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,",
"output": "YES"
},
{
"input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!",
"output": "YES"
},
{
"input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@",
"output": "YES"
},
{
"input": "'jdL(vX",
"output": "NO"
},
{
"input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5",
"output": "YES"
},
{
"input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s",
"output": "YES"
},
{
"input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]",
"output": "YES"
},
{
"input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU",
"output": "YES"
},
{
"input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->",
"output": "YES"
},
{
"input": "&ppw0._:\\p-PuWM@l}%%=",
"output": "NO"
},
{
"input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr",
"output": "YES"
},
{
"input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q",
"output": "YES"
},
{
"input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0",
"output": "YES"
},
{
"input": "VXB&r9Z)IlKOJ:??KDA",
"output": "YES"
},
{
"input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R",
"output": "YES"
},
{
"input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C",
"output": "YES"
},
{
"input": "O.&=qt(`z(",
"output": "NO"
},
{
"input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@",
"output": "YES"
},
{
"input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp",
"output": "YES"
},
{
"input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8",
"output": "YES"
},
{
"input": "!0WKT:$O",
"output": "NO"
},
{
"input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)",
"output": "YES"
},
{
"input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly",
"output": "YES"
},
{
"input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(",
"output": "NO"
},
{
"input": "Qv)X8",
"output": "YES"
},
{
"input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F",
"output": "YES"
},
{
"input": "e{}2vQ+/r@p0}cLKNe4MCk",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH",
"output": "YES"
},
{
"input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "1H1",
"output": "YES"
},
{
"input": "+Q",
"output": "YES"
},
{
"input": "1ab",
"output": "NO"
},
{
"input": "!",
"output": "NO"
},
{
"input": "0+",
"output": "NO"
},
{
"input": "+H",
"output": "YES"
},
{
"input": "cH",
"output": "YES"
},
{
"input": "+8",
"output": "NO"
},
{
"input": "8+",
"output": "NO"
},
{
"input": "++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "(+)",
"output": "NO"
},
{
"input": "H+",
"output": "YES"
},
{
"input": "a!",
"output": "NO"
},
{
"input": "++++++++++++++",
"output": "NO"
},
{
"input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "HQ9",
"output": "YES"
},
{
"input": "+++H",
"output": "YES"
},
{
"input": "++++++++++",
"output": "NO"
},
{
"input": "HHHHHHH",
"output": "YES"
},
{
"input": "abacabaH",
"output": "YES"
},
{
"input": "+G",
"output": "NO"
}
] | 1,689,393,338
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 85
| 92
| 0
|
print(["NO", "YES"][bool(set("HQ9") & set(input()))])
|
Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input Specification:
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output Specification:
Output "YES", if executing the program will produce any output, and "NO" otherwise.
Demo Input:
['Hi!\n', 'Codeforces\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions.
|
```python
print(["NO", "YES"][bool(set("HQ9") & set(input()))])
```
| 3
|
|
678
|
A
|
Johny Likes Numbers
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
|
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
|
Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*.
|
[
"5 3\n",
"25 13\n",
"26 13\n"
] |
[
"6\n",
"26\n",
"39\n"
] |
none
| 0
|
[
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894",
"output": "894"
},
{
"input": "6058 8581",
"output": "8581"
},
{
"input": "97259 41764",
"output": "125292"
},
{
"input": "453145 333625",
"output": "667250"
},
{
"input": "2233224 4394826",
"output": "4394826"
},
{
"input": "76770926 13350712",
"output": "80104272"
},
{
"input": "687355301 142098087",
"output": "710490435"
},
{
"input": "1000000000 999999999",
"output": "1999999998"
},
{
"input": "1000000000 1000000000",
"output": "2000000000"
},
{
"input": "999999999 1000000000",
"output": "1000000000"
},
{
"input": "1000000000 1",
"output": "1000000001"
},
{
"input": "1000000000 2",
"output": "1000000002"
},
{
"input": "999999999 1",
"output": "1000000000"
},
{
"input": "100000000 1",
"output": "100000001"
},
{
"input": "999999999 500000000",
"output": "1000000000"
},
{
"input": "999999990 10",
"output": "1000000000"
},
{
"input": "1000000000 999999997",
"output": "1999999994"
},
{
"input": "999999999 2",
"output": "1000000000"
},
{
"input": "999999984 1",
"output": "999999985"
},
{
"input": "999999983 1",
"output": "999999984"
},
{
"input": "666666666 1",
"output": "666666667"
},
{
"input": "1000000000 990000000",
"output": "1980000000"
},
{
"input": "41 48",
"output": "48"
},
{
"input": "123456 2",
"output": "123458"
},
{
"input": "111 111",
"output": "222"
},
{
"input": "878787 1",
"output": "878788"
},
{
"input": "121 1",
"output": "122"
},
{
"input": "114514 114514",
"output": "229028"
},
{
"input": "500000001 1000000000",
"output": "1000000000"
},
{
"input": "999999997 1",
"output": "999999998"
},
{
"input": "100000000 10",
"output": "100000010"
}
] | 1,663,689,304
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 37
| 46
| 0
|
n, k = input().split()
n = int(n)
k = int(k)
print(n-(n%k)+k)
|
Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Output Specification:
Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*.
Demo Input:
['5 3\n', '25 13\n', '26 13\n']
Demo Output:
['6\n', '26\n', '39\n']
Note:
none
|
```python
n, k = input().split()
n = int(n)
k = int(k)
print(n-(n%k)+k)
```
| 3
|
|
22
|
A
|
Second Order Statistics
|
PROGRAMMING
| 800
|
[
"brute force"
] |
A. Second Order Statistics
|
2
|
256
|
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
|
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
|
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
|
[
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] |
[
"1\n",
"2\n"
] |
none
| 0
|
[
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 91",
"output": "-48"
},
{
"input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49",
"output": "-86"
},
{
"input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94",
"output": "-98"
},
{
"input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46",
"output": "-91"
},
{
"input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89",
"output": "-98"
},
{
"input": "2\n-1 -1",
"output": "NO"
},
{
"input": "3\n-2 -2 -2",
"output": "NO"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47",
"output": "40"
},
{
"input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90",
"output": "-64"
},
{
"input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93",
"output": "-93"
},
{
"input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83",
"output": "-86"
},
{
"input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43",
"output": "-95"
},
{
"input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92",
"output": "-92"
},
{
"input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12",
"output": "-98"
},
{
"input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100",
"output": "-98"
},
{
"input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92",
"output": "-98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "9\n99 99 99 99 100 100 100 100 100",
"output": "100"
},
{
"input": "5\n-100 -100 -100 -100 -100",
"output": "NO"
}
] | 1,671,630,512
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 31
| 92
| 0
|
n1=int(input())
lis=list(map(int,input().split()))
lis=list(set(lis))
lis.sort()
if len(lis)>1:
print(lis[1])
else:
print("NO")
|
Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output Specification:
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Demo Input:
['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n']
Demo Output:
['1\n', '2\n']
Note:
none
|
```python
n1=int(input())
lis=list(map(int,input().split()))
lis=list(set(lis))
lis.sort()
if len(lis)>1:
print(lis[1])
else:
print("NO")
```
| 3.977
|
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.