contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,691,852,797 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | import math
a,b,c=map(int,input().split())
mid=(int((a+b+c)/3))
print(int(math.fabs(a-mid)+math.fabs(b-mid)+math.fabs(c-mid))) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
import math
a,b,c=map(int,input().split())
mid=(int((a+b+c)/3))
print(int(math.fabs(a-mid)+math.fabs(b-mid)+math.fabs(c-mid)))
``` | 0 |
|
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans. | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 94 8 16 73 85",
"output": "YES"
},
{
"input": "4\n25 35 7 31\n70 37 43 35",
"output": "YES"
},
{
"input": "10\n15 26 15 14 14 39 40 4 25 39\n27 72 16 44 69 48 53 17 63 42",
"output": "NO"
},
{
"input": "5\n22 5 19 16 32\n26 10 43 38 37",
"output": "NO"
},
{
"input": "5\n32 4 22 40 26\n39 20 36 98 44",
"output": "YES"
},
{
"input": "6\n18 25 3 10 13 37\n38 73 19 35 24 37",
"output": "YES"
},
{
"input": "2\n2 2\n2 2",
"output": "YES"
},
{
"input": "2\n2 5\n2 5",
"output": "YES"
},
{
"input": "2\n1000 1008\n10000 2352",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5\n1 2 3 4 11",
"output": "YES"
},
{
"input": "4\n1 0 0 0\n2 0 0 0",
"output": "YES"
},
{
"input": "2\n0 0\n1 2",
"output": "YES"
},
{
"input": "3\n9 13 4\n10 14 5",
"output": "NO"
},
{
"input": "2\n0 0\n1 1",
"output": "YES"
},
{
"input": "5\n1 1 2 3 1\n1 1 2 3 4",
"output": "NO"
},
{
"input": "2\n0 0\n0 0",
"output": "YES"
},
{
"input": "3\n5 1 1\n5 5 5",
"output": "YES"
}
] | 1,683,795,248 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# Find the two cans with the largest capacities
largest = [0, 0]
for i in range(n):
if b[i] > b[largest[0]]:
largest[1] = largest[0]
largest[0] = i
elif b[i] > b[largest[1]]:
largest[1] = i
# Check if the sum of remaining volumes fits in the two largest cans
if a[largest[0]] + a[largest[1]] <= b[largest[0]] + b[largest[1]]:
print("YES")
else:
print("NO")
| Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
Input Specification:
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans.
Output Specification:
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Demo Input:
['2\n3 5\n3 6\n', '3\n6 8 9\n6 10 12\n', '5\n0 0 5 0 0\n1 1 8 10 5\n', '4\n4 1 0 3\n5 2 2 3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'YES\n']
Note:
In the first sample, there are already 2 cans, so the answer is "YES". | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# Find the two cans with the largest capacities
largest = [0, 0]
for i in range(n):
if b[i] > b[largest[0]]:
largest[1] = largest[0]
largest[0] = i
elif b[i] > b[largest[1]]:
largest[1] = i
# Check if the sum of remaining volumes fits in the two largest cans
if a[largest[0]] + a[largest[1]] <= b[largest[0]] + b[largest[1]]:
print("YES")
else:
print("NO")
``` | 0 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,651,943,096 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | a=int(input())
b=[]
for i in range(a):
n=int(input())
b.append(n)
print(len(set(b)))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
a=int(input())
b=[]
for i in range(a):
n=int(input())
b.append(n)
print(len(set(b)))
``` | -1 |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"input": "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43",
"output": "NO"
},
{
"input": "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "5\n2 1 4 5 3",
"output": "YES"
},
{
"input": "5\n5 4 5 5 2",
"output": "YES"
}
] | 1,666,795,255 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 77 | 1,740,800 | import sys
#sys.stdin = open("input.txt", "r")
n = int(input())
li = list(map(int, input().split()))
li.insert(0,0)
# print(li)
res = 0
for i in range(1,n):
if i == li[li[li[i]]]:
res = 1
break
if res == 1:
print("YES")
else:
print("NO") | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Specification:
Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case.
Demo Input:
['5\n2 4 5 1 3\n', '5\n5 5 5 5 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | ```python
import sys
#sys.stdin = open("input.txt", "r")
n = int(input())
li = list(map(int, input().split()))
li.insert(0,0)
# print(li)
res = 0
for i in range(1,n):
if i == li[li[li[i]]]:
res = 1
break
if res == 1:
print("YES")
else:
print("NO")
``` | 3 |
|
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1",
"output": "1891"
},
{
"input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2",
"output": "1688"
},
{
"input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12",
"output": "1391"
},
{
"input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32",
"output": "368"
},
{
"input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1",
"output": "435"
},
{
"input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100",
"output": "326"
},
{
"input": "45 894\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 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1",
"output": "139"
},
{
"input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86",
"output": "514"
},
{
"input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1",
"output": "586"
},
{
"input": "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1",
"output": "384"
},
{
"input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1",
"output": "174"
},
{
"input": "81 4131\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 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "807"
},
{
"input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96",
"output": "490"
},
{
"input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1",
"output": "284"
},
{
"input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1",
"output": "1589"
},
{
"input": "10 100\n1 1 1 1 1 1 1 1 1 1",
"output": "18"
},
{
"input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99",
"output": "1017"
},
{
"input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 6\n1",
"output": "1"
},
{
"input": "1 5\n1",
"output": "0"
},
{
"input": "1 3\n4",
"output": "-1"
},
{
"input": "3 24\n2 1 2",
"output": "-1"
}
] | 1,622,719,705 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 109 | 0 | n, d = map(int, input().split())
l = list(map(int, input().split(' ')[:n]))
sum = 0
for i in range(len(l)):
sum += l[i]
if (d-sum)//5 < 5:
print(-1)
else:
print((d-sum)//5) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input Specification:
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
Output Specification:
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Demo Input:
['3 30\n2 2 1\n', '3 20\n2 1 1\n']
Demo Output:
['5\n', '-1\n']
Note:
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | ```python
n, d = map(int, input().split())
l = list(map(int, input().split(' ')[:n]))
sum = 0
for i in range(len(l)):
sum += l[i]
if (d-sum)//5 < 5:
print(-1)
else:
print((d-sum)//5)
``` | 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,658,005,291 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 184 | 0 | n = int(input())
arr = list(map(int, input().split()))
brr = [0] * 3
for i in range(n):
brr[i%3] += arr[i]
print(('chest', 'biceps', 'back')[brr.index(max(brr))]) | 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())
arr = list(map(int, input().split()))
brr = [0] * 3
for i in range(n):
brr[i%3] += arr[i]
print(('chest', 'biceps', 'back')[brr.index(max(brr))])
``` | 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,918,987 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | input_string = input()
distinct_l = set()
for char in input_string[1:-1]:
if char.isalpha():
distinct_l.add(char)
print(len(distinct_l)) | 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
input_string = input()
distinct_l = set()
for char in input_string[1:-1]:
if char.isalpha():
distinct_l.add(char)
print(len(distinct_l))
``` | 3 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,658,203,703 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 1,528 | 1,536,000 | b,power,mod = 0,3,10**9+7
for i in range(int(input())-1): b=(power-b)%mod; power=(power*3)%mod
print(b) | Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
b,power,mod = 0,3,10**9+7
for i in range(int(input())-1): b=(power-b)%mod; power=(power*3)%mod
print(b)
``` | 3 |
|
814 | B | An express train to reveries | PROGRAMMING | 1,300 | [
"constructive algorithms"
] | null | null | Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of integers from 1 to *n* inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with *n* meteorids, colours of which being integer sequences *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* respectively. Meteoroids' colours were also between 1 and *n* inclusive, and the two sequences were not identical, that is, at least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds.
Well, she almost had it all — each of the sequences *a* and *b* matched exactly *n*<=-<=1 elements in Sengoku's permutation. In other words, there is exactly one *i* (1<=≤<=*i*<=≤<=*n*) such that *a**i*<=≠<=*p**i*, and exactly one *j* (1<=≤<=*j*<=≤<=*n*) such that *b**j*<=≠<=*p**j*.
For now, Sengoku is able to recover the actual colour sequences *a* and *b* through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night. | The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the first meteor outburst.
The third line contains *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of colours in the second meteor outburst. At least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds. | Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists. | [
"5\n1 2 3 4 3\n1 2 5 4 5\n",
"5\n4 4 2 3 1\n5 4 5 3 1\n",
"4\n1 1 3 4\n1 4 3 4\n"
] | [
"1 2 5 4 3\n",
"5 4 2 3 1\n",
"1 2 3 4\n"
] | In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | 1,000 | [
{
"input": "5\n1 2 3 4 3\n1 2 5 4 5",
"output": "1 2 5 4 3"
},
{
"input": "5\n4 4 2 3 1\n5 4 5 3 1",
"output": "5 4 2 3 1"
},
{
"input": "4\n1 1 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10\n1 2 3 4 5 6 7 8 7 10\n1 2 3 4 5 6 7 8 9 9",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10\n1 2 3 4 5 6 7 8 4 10\n1 2 3 4 5 6 7 6 9 10",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "10\n8 6 1 7 9 3 5 2 10 9\n8 6 1 7 4 3 5 2 10 4",
"output": "8 6 1 7 4 3 5 2 10 9"
},
{
"input": "10\n2 9 7 7 8 5 4 10 6 1\n2 8 7 3 8 5 4 10 6 1",
"output": "2 9 7 3 8 5 4 10 6 1"
},
{
"input": "2\n2 2\n1 1",
"output": "1 2"
},
{
"input": "3\n1 2 2\n1 3 3",
"output": "1 3 2"
},
{
"input": "3\n2 2 3\n1 2 1",
"output": "1 2 3"
},
{
"input": "3\n1 3 3\n1 1 3",
"output": "1 2 3"
},
{
"input": "3\n2 1 1\n2 3 3",
"output": "2 3 1"
},
{
"input": "3\n3 3 2\n1 1 2",
"output": "1 3 2"
},
{
"input": "3\n1 3 3\n3 3 2",
"output": "1 3 2"
},
{
"input": "4\n3 2 3 4\n1 2 1 4",
"output": "1 2 3 4"
},
{
"input": "4\n2 2 3 4\n1 2 3 2",
"output": "1 2 3 4"
},
{
"input": "4\n1 2 4 4\n2 2 3 4",
"output": "1 2 3 4"
},
{
"input": "4\n4 1 3 4\n2 1 3 2",
"output": "2 1 3 4"
},
{
"input": "4\n3 2 1 3\n4 2 1 2",
"output": "4 2 1 3"
},
{
"input": "4\n1 4 1 3\n2 4 1 4",
"output": "2 4 1 3"
},
{
"input": "4\n1 3 4 4\n3 3 2 4",
"output": "1 3 2 4"
},
{
"input": "5\n5 4 5 3 1\n4 4 2 3 1",
"output": "5 4 2 3 1"
},
{
"input": "5\n4 1 2 4 5\n3 1 2 5 5",
"output": "3 1 2 4 5"
},
{
"input": "3\n2 2 3\n1 3 3",
"output": "1 2 3"
},
{
"input": "3\n1 1 3\n2 3 3",
"output": "2 1 3"
},
{
"input": "5\n5 4 5 3 1\n2 4 4 3 1",
"output": "2 4 5 3 1"
},
{
"input": "3\n3 3 1\n2 1 1",
"output": "2 3 1"
},
{
"input": "5\n5 4 3 5 2\n5 4 1 1 2",
"output": "5 4 3 1 2"
},
{
"input": "6\n1 2 3 4 2 5\n1 6 3 4 4 5",
"output": "1 6 3 4 2 5"
},
{
"input": "4\n1 3 2 1\n2 3 2 1",
"output": "4 3 2 1"
},
{
"input": "4\n1 3 3 4\n1 4 3 4",
"output": "1 2 3 4"
},
{
"input": "11\n1 2 3 4 5 6 7 8 9 10 10\n1 2 3 4 5 6 7 8 9 10 3",
"output": "1 2 3 4 5 6 7 8 9 10 11"
},
{
"input": "5\n1 2 3 2 5\n1 4 3 3 5",
"output": "1 4 3 2 5"
},
{
"input": "5\n1 2 3 4 3\n1 2 5 4 2",
"output": "1 2 5 4 3"
},
{
"input": "5\n1 2 3 4 4\n1 2 3 4 3",
"output": "1 2 3 4 5"
},
{
"input": "4\n1 3 1 4\n1 3 4 4",
"output": "1 3 2 4"
},
{
"input": "5\n2 5 3 2 1\n4 5 3 3 1",
"output": "4 5 3 2 1"
},
{
"input": "5\n1 2 3 2 5\n1 3 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "5\n5 2 3 4 5\n2 2 3 4 5",
"output": "1 2 3 4 5"
},
{
"input": "5\n5 4 1 1 2\n5 4 3 5 2",
"output": "5 4 3 1 2"
},
{
"input": "4\n1 4 3 4\n1 3 3 4",
"output": "1 2 3 4"
},
{
"input": "4\n1 2 3 1\n1 2 3 2",
"output": "1 2 3 4"
},
{
"input": "5\n4 5 3 3 1\n2 5 3 2 1",
"output": "4 5 3 2 1"
},
{
"input": "5\n1 2 3 5 5\n1 2 3 4 3",
"output": "1 2 3 4 5"
},
{
"input": "4\n2 3 3 4\n2 4 3 4",
"output": "2 1 3 4"
}
] | 1,496,906,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ad = []
bd = []
for i in range(0, n):
if (a[i] != b[i]):
ad.append(a[i])
bd.append(b[i])
ad[0] = bd[0]
if (len(ad) == 1):
ad[0] = -1
for i in range(0, n):
if (a[i] != b[i]):
a[i] = ad.pop(0)
for i in a:
cand = i
if cand == -1:
for j in range(1, n + 1):
if j not in a:
cand = j
break
print(cand, end=' ')
print()
| Title: An express train to reveries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.
On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of integers from 1 to *n* inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with *n* meteorids, colours of which being integer sequences *a*1,<=*a*2,<=...,<=*a**n* and *b*1,<=*b*2,<=...,<=*b**n* respectively. Meteoroids' colours were also between 1 and *n* inclusive, and the two sequences were not identical, that is, at least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds.
Well, she almost had it all — each of the sequences *a* and *b* matched exactly *n*<=-<=1 elements in Sengoku's permutation. In other words, there is exactly one *i* (1<=≤<=*i*<=≤<=*n*) such that *a**i*<=≠<=*p**i*, and exactly one *j* (1<=≤<=*j*<=≤<=*n*) such that *b**j*<=≠<=*p**j*.
For now, Sengoku is able to recover the actual colour sequences *a* and *b* through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.
Input Specification:
The first line of input contains a positive integer *n* (2<=≤<=*n*<=≤<=1<=000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the sequence of colours in the first meteor outburst.
The third line contains *n* space-separated integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*) — the sequence of colours in the second meteor outburst. At least one *i* (1<=≤<=*i*<=≤<=*n*) exists, such that *a**i*<=≠<=*b**i* holds.
Output Specification:
Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.
Input guarantees that such permutation exists.
Demo Input:
['5\n1 2 3 4 3\n1 2 5 4 5\n', '5\n4 4 2 3 1\n5 4 5 3 1\n', '4\n1 1 3 4\n1 4 3 4\n']
Demo Output:
['1 2 5 4 3\n', '5 4 2 3 1\n', '1 2 3 4\n']
Note:
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.
In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints. | ```python
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ad = []
bd = []
for i in range(0, n):
if (a[i] != b[i]):
ad.append(a[i])
bd.append(b[i])
ad[0] = bd[0]
if (len(ad) == 1):
ad[0] = -1
for i in range(0, n):
if (a[i] != b[i]):
a[i] = ad.pop(0)
for i in a:
cand = i
if cand == -1:
for j in range(1, n + 1):
if j not in a:
cand = j
break
print(cand, end=' ')
print()
``` | 0 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,688,812,390 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 108 | 15,974,400 | n = int(input())
a = input()
x = []
for i in a:
if len(x) == 0 or x[-1] == i:
x.append(i)
else:
x.pop()
print(len(x)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n = int(input())
a = input()
x = []
for i in a:
if len(x) == 0 or x[-1] == i:
x.append(i)
else:
x.pop()
print(len(x))
``` | 3 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,663,246,720 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
m = int(input())
a = int(input())
if n>1 and m>1 and a <= 10**9:
if n % a > 0:
c = n // a + 1
else:
c = n / a
if n > 1 and m>1 and a <= 10 ** 9:
if n % a > 0:
d = m // a + 1
else:
d = m / a
e = (c - 1) * (d - 1) + c + d - 1
print(e) | 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
n = int(input())
m = int(input())
a = int(input())
if n>1 and m>1 and a <= 10**9:
if n % a > 0:
c = n // a + 1
else:
c = n / a
if n > 1 and m>1 and a <= 10 ** 9:
if n % a > 0:
d = m // a + 1
else:
d = m / a
e = (c - 1) * (d - 1) + c + d - 1
print(e)
``` | -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,586,755,482 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | for i in range( int(input()),0,-1):
print(i,'',end = "") | 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
for i in range( int(input()),0,-1):
print(i,'',end = "")
``` | 0 |
|
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range? | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
}
] | 1,633,968,045 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,500 | 149,401,600 | # your code goes here
if __name__ == "__main__":
n, k, q = map(int, input().strip().split())
r = []
for _ in range(n):
a, b = map(int, input().strip().split())
r += list(range(a, b + 1))
for _ in range(q):
a, b = map(int, input().strip().split())
l = len(list(i for i in range(a, b + 1) if r.count(i) >= k))
print(l)
| Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range?
Input Specification:
The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
Output Specification:
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
Demo Input:
['3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n', '2 1 1\n1 1\n200000 200000\n90 100\n']
Demo Output:
['3\n3\n0\n4\n', '0\n']
Note:
In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | ```python
# your code goes here
if __name__ == "__main__":
n, k, q = map(int, input().strip().split())
r = []
for _ in range(n):
a, b = map(int, input().strip().split())
r += list(range(a, b + 1))
for _ in range(q):
a, b = map(int, input().strip().split())
l = len(list(i for i in range(a, b + 1) if r.count(i) >= k))
print(l)
``` | 0 |
|
476 | B | Dreamoon and WiFi | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"math",
"probabilities"
] | null | null | Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? | The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10. | Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. | [
"++-+-\n+-+-+\n",
"+-+-\n+-??\n",
"+++\n??-\n"
] | [
"1.000000000000\n",
"0.500000000000\n",
"0.000000000000\n"
] | For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | 1,500 | [
{
"input": "++-+-\n+-+-+",
"output": "1.000000000000"
},
{
"input": "+-+-\n+-??",
"output": "0.500000000000"
},
{
"input": "+++\n??-",
"output": "0.000000000000"
},
{
"input": "++++++++++\n+++??++?++",
"output": "0.125000000000"
},
{
"input": "--+++---+-\n??????????",
"output": "0.205078125000"
},
{
"input": "+--+++--+-\n??????????",
"output": "0.246093750000"
},
{
"input": "+\n+",
"output": "1.000000000000"
},
{
"input": "-\n?",
"output": "0.500000000000"
},
{
"input": "+\n-",
"output": "0.000000000000"
},
{
"input": "-\n-",
"output": "1.000000000000"
},
{
"input": "-\n+",
"output": "0.000000000000"
},
{
"input": "+\n?",
"output": "0.500000000000"
},
{
"input": "++++++++++\n++++++++++",
"output": "1.000000000000"
},
{
"input": "++++++++++\n++++-+++++",
"output": "0.000000000000"
},
{
"input": "----------\n++++++++++",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++??++++",
"output": "0.250000000000"
},
{
"input": "----------\n+++?++++-+",
"output": "0.000000000000"
},
{
"input": "++++++++++\n++++++++?+",
"output": "0.500000000000"
},
{
"input": "--++++--+\n?-+?-??+-",
"output": "0.250000000000"
},
{
"input": "----------\n??????????",
"output": "0.000976562500"
},
{
"input": "+--++\n+--+-",
"output": "0.000000000000"
},
{
"input": "-----++---\n????????+?",
"output": "0.017578125000"
},
{
"input": "------+--+\n??????????",
"output": "0.043945312500"
},
{
"input": "---++--\n???????",
"output": "0.164062500000"
},
{
"input": "-----++\n???????",
"output": "0.164062500000"
},
{
"input": "+---+--\n???????",
"output": "0.164062500000"
},
{
"input": "---+-+\n??????",
"output": "0.234375000000"
},
{
"input": "+++-+\n---++",
"output": "0.000000000000"
},
{
"input": "++-+--+\n?-?+??+",
"output": "0.375000000000"
},
{
"input": "----+++--\n-+?+++?--",
"output": "0.000000000000"
},
{
"input": "+-----\n+?----",
"output": "0.500000000000"
}
] | 1,697,877,033 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | s1 = input()
s2 = input()
p1 = s1.count("+")
l1 = s1.count("-")
p2 = s2.count("+")
l2 = s2.count("-")
v = s2.count("?")
if p1==p2 and l1==l2:
print('1.000000000000')
elif abs(p1-p2) + abs(l1-l2) == v:
print('0.500000000000')
else:
print('0.000000000000')
| Title: Dreamoon and WiFi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.
Each command is one of the following two types:
1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-'
But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5).
You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?
Input Specification:
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.
The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command.
Lengths of two strings are equal and do not exceed 10.
Output Specification:
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
Demo Input:
['++-+-\n+-+-+\n', '+-+-\n+-??\n', '+++\n??-\n']
Demo Output:
['1.000000000000\n', '0.500000000000\n', '0.000000000000\n']
Note:
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position + 1.
For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="lower-index">2</sub>: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5.
For the third sample, *s*<sub class="lower-index">2</sub> could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. | ```python
s1 = input()
s2 = input()
p1 = s1.count("+")
l1 = s1.count("-")
p2 = s2.count("+")
l2 = s2.count("-")
v = s2.count("?")
if p1==p2 and l1==l2:
print('1.000000000000')
elif abs(p1-p2) + abs(l1-l2) == v:
print('0.500000000000')
else:
print('0.000000000000')
``` | 0 |
|
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries. | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "0\n0\n0\n0"
},
{
"input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4",
"output": "0\n0\n0\n0\n0"
},
{
"input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4",
"output": "0\n1\n0\n0\n0\n1"
},
{
"input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7",
"output": "0\n0\n0\n0\n0\n0\n1"
},
{
"input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0\n0"
},
{
"input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5",
"output": "0\n1\n0\n0\n0\n0\n0\n1\n0"
},
{
"input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1",
"output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0"
},
{
"input": "1 1\n-1\n1 1",
"output": "0"
},
{
"input": "1 1\n1\n1 1",
"output": "0"
}
] | 1,629,261,278 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 10,547,200 | def is_even(number):
return (int(number / 2) * 2 == number)
def find_answers():
element_count, query_count = map(int, input().split())
elements = input().split()
minus_one_count = elements.count("-1")
ones_count = element_count-minus_one_count
for _ in range(query_count):
l, r = map(int, input().split())
query_range = r-l+1
if not is_even(query_range):
print(0)
else:
expected_ones = query_range//2
if expected_ones <= ones_count and expected_ones <= minus_one_count:
print(1)
else:
print(0)
find_answers() | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries.
Input Specification:
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
Demo Input:
['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n']
Demo Output:
['0\n1\n0\n', '0\n1\n0\n1\n0\n']
Note:
none | ```python
def is_even(number):
return (int(number / 2) * 2 == number)
def find_answers():
element_count, query_count = map(int, input().split())
elements = input().split()
minus_one_count = elements.count("-1")
ones_count = element_count-minus_one_count
for _ in range(query_count):
l, r = map(int, input().split())
query_range = r-l+1
if not is_even(query_range):
print(0)
else:
expected_ones = query_range//2
if expected_ones <= ones_count and expected_ones <= minus_one_count:
print(1)
else:
print(0)
find_answers()
``` | 0 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,697,541,387 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
l = [
]
c = 0
for i in range(n):
j = list(map(int, input("Ente: ").split(" ")))
l.append(j)
for i in l:
j = i[0]
for k in l:
if j == k[1]:
c += 1
print(c)
| Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
n = int(input())
l = [
]
c = 0
for i in range(n):
j = list(map(int, input("Ente: ").split(" ")))
l.append(j)
for i in l:
j = i[0]
for k in l:
if j == k[1]:
c += 1
print(c)
``` | 0 |
|
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
"output": "2\n99 100 "
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 "
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421",
"output": "8\n117 151 183 227 954 222 909 421 "
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2",
"output": "4\n62 726 903 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2",
"output": "6\n5 33 375 37 3 2 "
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6",
"output": "6\n4 3 2 5 1 6 "
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "2\n233 1 "
},
{
"input": "47\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",
"output": "1\n1 "
},
{
"input": "2\n964 964",
"output": "1\n964 "
},
{
"input": "2\n1000 1000",
"output": "1\n1000 "
},
{
"input": "1\n1000",
"output": "1\n1000 "
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993",
"output": "10\n996 1000 999 992 997 991 995 998 994 993 "
},
{
"input": "6\n994 993 1000 998 991 994",
"output": "5\n993 1000 998 991 994 "
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999",
"output": "10\n993 996 995 991 994 997 998 992 1000 999 "
},
{
"input": "3\n6 6 3",
"output": "2\n6 3 "
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997",
"output": "9\n1000 995 994 993 999 996 998 991 997 "
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996",
"output": "10\n998 995 999 992 1000 993 994 997 991 996 "
},
{
"input": "2\n1000 999",
"output": "2\n1000 999 "
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000",
"output": "10\n996 999 993 994 997 995 991 992 998 1000 "
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992",
"output": "8\n993 997 998 994 1000 991 995 992 "
},
{
"input": "6\n1000 1 1000 2 1000 1",
"output": "3\n2 1000 1 "
},
{
"input": "6\n1000 1 1000 2 1 1000",
"output": "3\n2 1 1000 "
},
{
"input": "7\n1 1000 1 999 1000 1 2",
"output": "4\n999 1000 1 2 "
}
] | 1,700,129,966 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | input()
num = list(map(int, input().split()))
unique = []
for i in reversed(num):
if i not in unique:
unique.insert(0, i)
print(len(unique))
print(" ".join(map(str, unique))) | Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
Output Specification:
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
Demo Input:
['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n']
Demo Output:
['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n']
Note:
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | ```python
input()
num = list(map(int, input().split()))
unique = []
for i in reversed(num):
if i not in unique:
unique.insert(0, i)
print(len(unique))
print(" ".join(map(str, unique)))
``` | 3 |
|
864 | B | Polycarp and Letters | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowercase; - there are no uppercase letters in the string which are situated between positions from *A* (i.e. there is no such *j* that *s*[*j*] is an uppercase letter, and *a*1<=<<=*j*<=<<=*a*2 for some *a*1 and *a*2 from *A*).
Write a program that will determine the maximum number of elements in a pretty set of positions. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters. | Print maximum number of elements in pretty set of positions for string *s*. | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n"
] | [
"2\n",
"3\n",
"0\n"
] | In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string *s* does not contain any lowercase letters, so the answer is 0. | 1,000 | [
{
"input": "11\naaaaBaabAbA",
"output": "2"
},
{
"input": "12\nzACaAbbaazzC",
"output": "3"
},
{
"input": "3\nABC",
"output": "0"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\naz",
"output": "2"
},
{
"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh",
"output": "8"
},
{
"input": "2\nAZ",
"output": "0"
},
{
"input": "28\nAabcBabcCBNMaaaaabbbbbcccccc",
"output": "3"
},
{
"input": "200\nrsgraosldglhdoorwhkrsehjpuxrjuwgeanjgezhekprzarelduuaxdnspzjuooguuwnzkowkuhzduakdrzpnslauejhrrkalwpurpuuswdgeadlhjwzjgegwpknepazwwleulppwrlgrgedlwdzuodzropsrrkxusjnuzshdkjrxxpgzanzdrpnggdwxarpwohxdepJ",
"output": "17"
},
{
"input": "1\nk",
"output": "1"
},
{
"input": "1\nH",
"output": "0"
},
{
"input": "2\nzG",
"output": "1"
},
{
"input": "2\ngg",
"output": "1"
},
{
"input": "2\nai",
"output": "2"
},
{
"input": "20\npEjVrKWLIFCZjIHgggVU",
"output": "1"
},
{
"input": "20\niFSiiigiYFSKmDnMGcgM",
"output": "2"
},
{
"input": "20\nedxedxxxCQiIVmYEUtLi",
"output": "3"
},
{
"input": "20\nprnchweyabjvzkoqiltm",
"output": "20"
},
{
"input": "35\nQLDZNKFXKVSVLUVHRTDPQYMSTDXBELXBOTS",
"output": "0"
},
{
"input": "35\nbvZWiitgxodztelnYUyljYGnCoWluXTvBLp",
"output": "10"
},
{
"input": "35\nBTexnaeplecllxwlanarpcollawHLVMHIIF",
"output": "10"
},
{
"input": "35\nhhwxqysolegsthsvfcqiryenbujbrrScobu",
"output": "20"
},
{
"input": "26\npbgfqosklxjuzmdheyvawrictn",
"output": "26"
},
{
"input": "100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl",
"output": "20"
},
{
"input": "100\nhXYLXKUMBrGkjqQJTGbGWAfmztqqapdbjbhcualhypgnaieKXmhzGMnqXVlcPesskfaEVgvWQTTShRRnEtFahWDyuBzySMpugxCM",
"output": "19"
},
{
"input": "100\nucOgELrgjMrFOgtHzqgvUgtHngKJxdMFKBjfcCppciqmGZXXoiSZibgpadshyljqrwxbomzeutvnhTLGVckZUmyiFPLlwuLBFito",
"output": "23"
},
{
"input": "200\nWTCKAKLVGXSYFVMVJDUYERXNMVNTGWXUGRFCGMYXJQGLODYZTUIDENHYEGFKXFIEUILAMESAXAWZXVCZPJPEYUXBITHMTZOTMKWITGRSFHODKVJHPAHVVWTCTHIVAWAREQXWMPUWQSTPPJFHKGKELBTPUYDAVIUMGASPUEDIODRYXIWCORHOSLIBLOZUNJPHHMXEXOAY",
"output": "0"
},
{
"input": "200\neLCCuYMPPwQoNlCpPOtKWJaQJmWfHeZCKiMSpILHSKjFOYGpRMzMCfMXdDuQdBGNsCNrHIVJzEFfBZcNMwNcFjOFVJvEtUQmLbFNKVHgNDyFkFVQhUTUQDgXhMjJZgFSSiHhMKuTgZQYJqAqKBpHoHddddddddddddddddXSSYNKNnRrKuOjAVKZlRLzCjExPdHaDHBT",
"output": "1"
},
{
"input": "200\nitSYxgOLlwOoAkkkkkzzzzzzzzkzkzkzkkkkkzkzzkzUDJSKybRPBvaIDsNuWImPJvrHkKiMeYukWmtHtgZSyQsgYanZvXNbKXBlFLSUcqRnGWSriAvKxsTkDJfROqaKdzXhvJsPEDATueCraWOGEvRDWjPwXuiNpWsEnCuhDcKWOQxjBkdBqmFatWFkgKsbZuLtRGtY",
"output": "2"
},
{
"input": "200\noggqoqqogoqoggggoggqgooqggogogooogqqgggoqgggqoqogogggogggqgooqgqggqqqoqgqgoooqgqogqoggoqqgqoqgoooqoogooqoogqoqoqqgoqgoqgggogqqqoqoggoqoqqoqggqoggooqqqoqggoggqqqqqqqqqgogqgggggooogogqgggqogqgoqoqogoooq",
"output": "3"
},
{
"input": "200\nCtclUtUnmqFniaLqGRmMoUMeLyFfAgWxIZxdrBarcRQprSOGcdUYsmDbooSuOvBLgrYlgaIjJtFgcxJKHGkCXpYfVKmUbouuIqGstFrrwJzYQqjjqqppqqqqqpqqqjpjjpjqjXRYkfPhGAatOigFuItkKxkjCBLdiNMVGjmdWNMgOOvmaJEdGsWNoaERrINNKqKeQajv",
"output": "3"
},
{
"input": "200\nmeZNrhqtSTSmktGQnnNOTcnyAMTKSixxKQKiagrMqRYBqgbRlsbJhvtNeHVUuMCyZLCnsIixRYrYEAkfQOxSVqXkrPqeCZQksInzRsRKBgvIqlGVPxPQnypknSXjgMjsjElcqGsaJRbegJVAKtWcHoOnzHqzhoKReqBBsOhZYLaYJhmqOMQsizdCsQfjUDHcTtHoeYwu",
"output": "4"
},
{
"input": "200\nvFAYTHJLZaivWzSYmiuDBDUFACDSVbkImnVaXBpCgrbgmTfXKJfoglIkZxWPSeVSFPnHZDNUAqLyhjLXSuAqGLskBlDxjxGPJyGdwzlPfIekwsblIrkxzfhJeNoHywdfAGlJzqXOfQaKceSqViVFTRJEGfACnsFeSFpOYisIHJciqTMNAmgeXeublTvfWoPnddtvKIyF",
"output": "6"
},
{
"input": "200\ngnDdkqJjYvduVYDSsswZDvoCouyaYZTfhmpSakERWLhufZtthWsfbQdTGwhKYjEcrqWBOyxBbiFhdLlIjChLOPiOpYmcrJgDtXsJfmHtLrabyGKOfHQRukEtTzwoqBHfmyVXPebfcpGQacLkGWFwerszjdHpTBXGssYXmGHlcCBgBXyGJqxbVhvDffLyCrZnxonABEXV",
"output": "7"
},
{
"input": "200\nBmggKNRZBXPtJqlJaXLdKKQLDJvXpDuQGupiRQfDwCJCJvAlDDGpPZNOvXkrdKOFOEFBVfrsZjWyHPoKGzXmTAyPJGEmxCyCXpeAdTwbrMtWLmlmGNqxvuxmqpmtpuhrmxxtrquSLFYVlnSYgRJDYHWgHBbziBLZRwCIJNvbtsEdLLxmTbnjkoqSPAuzEeTYLlmejOUH",
"output": "9"
},
{
"input": "200\nMkuxcDWdcnqsrlTsejehQKrTwoOBRCUAywqSnZkDLRmVBDVoOqdZHbrInQQyeRFAjiYYmHGrBbWgWstCPfLPRdNVDXBdqFJsGQfSXbufsiogybEhKDlWfPazIuhpONwGzZWaQNwVnmhTqWdewaklgjwaumXYDGwjSeEcYXjkVtLiYSWULEnTFukIlWQGWsXwWRMJGTcI",
"output": "10"
},
{
"input": "200\nOgMBgYeuMJdjPtLybvwmGDrQEOhliaabEtwulzNEjsfnaznXUMoBbbxkLEwSQzcLrlJdjJCLGVNBxorghPxTYCoqniySJMcilpsqpBAbqdzqRUDVaYOgqGhGrxlIJkyYgkOdTUgRZwpgIkeZFXojLXpDilzirHVVadiHaMrxhzodzpdvhvrzdzxbhmhdpxqqpoDegfFQ",
"output": "11"
},
{
"input": "200\nOLaJOtwultZLiZPSYAVGIbYvbIuZkqFZXwfsqpsavCDmBMStAuUFLBVknWDXNzmiuUYIsUMGxtoadWlPYPqvqSvpYdOiJRxFzGGnnmstniltvitnrmyrblnqyruylummmlsqtqitlbulvtuitiqimuintbimqyurviuntqnnvslynlNYMpYVKYwKVTbIUVdlNGrcFZON",
"output": "12"
},
{
"input": "200\nGAcmlaqfjSAQLvXlkhxujXgSbxdFAwnoxDuldDvYmpUhTWJdcEQSdARLrozJzIgFVCkzPUztWIpaGfiKeqzoXinEjVuoKqyBHmtFjBWcRdBmyjviNlGAIkpikjAimmBgayfphrstfbjexjbttzfzfzaysxfyrjazfhtpghnbbeffjhxrjxpttesgzrnrfbgzzsRsCgmz",
"output": "15"
},
{
"input": "200\nYRvIopNqSTYDhViTqCLMwEbTTIdHkoeuBmAJWhgtOgVxlcHSsavDNzMfpwTghkBvYEtCYQxicLUxdgAcaCzOOgbQYsfnaTXFlFxbeEiGwdNvxwHzkTdKtWlqzalwniDDBDipkxfflpaqkfkgfezbkxdvzemlfohwtgytzzywmwhvzUgPlPdeAVqTPAUZbogQheRXetvT",
"output": "20"
},
{
"input": "200\nNcYVomemswLCUqVRSDKHCknlBmqeSWhVyRzQrnZaOANnTGqsRFMjpczllcEVebqpxdavzppvztxsnfmtcharzqlginndyjkawzurqkxJLXiXKNZTIIxhSQghDpjwzatEqnLMTLxwoEKpHytvWkKFDUcZjLShCiVdocxRvvJtbXHCDGpJvMwRKWLhcTFtswdLUHkbhfau",
"output": "25"
},
{
"input": "200\nDxNZuvkTkQEqdWIkLzcKAwfqvZQiptnTazydSCTIfGjDhLMrlPZiKEsqIdDhgKPAlEvXyzNwWtYorotgkcwydpabjqnzubaksdchucxtkmjzfretdmvlxgklyvicrtftvztsbiUaQorfNIYUOdwQDRsKpxLUiLknbLbinilpPXPTTwLAnXVpMHBaAcKWgDBeOFabPtXU",
"output": "26"
},
{
"input": "4\nabbc",
"output": "3"
},
{
"input": "3\naaa",
"output": "1"
},
{
"input": "3\naba",
"output": "2"
},
{
"input": "3\nabb",
"output": "2"
},
{
"input": "3\nbba",
"output": "2"
},
{
"input": "3\nAaa",
"output": "1"
},
{
"input": "3\nAba",
"output": "2"
},
{
"input": "3\naBa",
"output": "1"
},
{
"input": "3\naAa",
"output": "1"
},
{
"input": "3\naAb",
"output": "1"
},
{
"input": "3\nAaA",
"output": "1"
},
{
"input": "5\naBacd",
"output": "3"
},
{
"input": "5\naAabc",
"output": "3"
}
] | 1,670,355,565 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 3 | 62 | 2,867,200 | # Author : Mohamed Yousef
# Date : 2022-12-06
import sys,math,bisect,collections,itertools,heapq
from collections import defaultdict,deque
n=int(sys.stdin.readline())
s=sys.stdin.readline().strip()
newsring=""
for i in range(1,n):
if s[i-1]!=s[i]:
newsring+=s[i-1]
if s[-1]!=s[-2]:
newsring+=s[-1]
s=newsring
# print(s)
out=0
ans=0
for i in s:
if i.lower() == i :
out+=1
else:out=0
ans=max(ans,out)
print(ans) | Title: Polycarp and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string *s* consisting only of lowercase and uppercase Latin letters.
Let *A* be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from *A* in the string are all distinct and lowercase; - there are no uppercase letters in the string which are situated between positions from *A* (i.e. there is no such *j* that *s*[*j*] is an uppercase letter, and *a*1<=<<=*j*<=<<=*a*2 for some *a*1 and *a*2 from *A*).
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — length of string *s*.
The second line contains a string *s* consisting of lowercase and uppercase Latin letters.
Output Specification:
Print maximum number of elements in pretty set of positions for string *s*.
Demo Input:
['11\naaaaBaabAbA\n', '12\nzACaAbbaazzC\n', '3\nABC\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string *s* does not contain any lowercase letters, so the answer is 0. | ```python
# Author : Mohamed Yousef
# Date : 2022-12-06
import sys,math,bisect,collections,itertools,heapq
from collections import defaultdict,deque
n=int(sys.stdin.readline())
s=sys.stdin.readline().strip()
newsring=""
for i in range(1,n):
if s[i-1]!=s[i]:
newsring+=s[i-1]
if s[-1]!=s[-2]:
newsring+=s[-1]
s=newsring
# print(s)
out=0
ans=0
for i in s:
if i.lower() == i :
out+=1
else:out=0
ans=max(ans,out)
print(ans)
``` | -1 |
|
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,696,251,051 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | w = input()
h=w.find('h')
e=w.find('e',h+1)
l=w.find('l',e+1)
l2=w.find('l',l+1)
o=w.find('o',l2+1)
if (h<e<l<l2<o) == True:
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
w = input()
h=w.find('h')
e=w.find('e',h+1)
l=w.find('l',e+1)
l2=w.find('l',l+1)
o=w.find('o',l2+1)
if (h<e<l<l2<o) == True:
print("YES")
else:
print("NO")
``` | 3.977 |
357 | A | Group of Students | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got 1 point, *c*2 children got 2 points, ..., *c**m* children got *m* points. Now you need to set the passing rate *k* (integer from 1 to *m*): all schoolchildren who got less than *k* points go to the beginner group and those who get at strictly least *k* points go to the intermediate group. We know that if the size of a group is more than *y*, then the university won't find a room for them. We also know that if a group has less than *x* schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from *x* to *y*, inclusive.
Help the university pick the passing rate in a way that meets these requirements. | The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0. | If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. | [
"5\n3 4 3 2 1\n6 8\n",
"5\n0 3 3 4 2\n3 10\n",
"2\n2 5\n3 6\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | 500 | [
{
"input": "5\n3 4 3 2 1\n6 8",
"output": "3"
},
{
"input": "5\n0 3 3 4 2\n3 10",
"output": "4"
},
{
"input": "2\n2 5\n3 6",
"output": "0"
},
{
"input": "3\n0 1 0\n2 10",
"output": "0"
},
{
"input": "5\n2 2 2 2 2\n5 5",
"output": "0"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n1 10",
"output": "10"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n5 5",
"output": "6"
},
{
"input": "6\n0 0 1 1 0 0\n1 6",
"output": "4"
},
{
"input": "7\n3 2 3 3 2 1 1\n5 10",
"output": "4"
},
{
"input": "4\n1 0 0 100\n1 100",
"output": "4"
},
{
"input": "100\n46 6 71 27 94 59 99 82 5 41 18 89 86 2 31 35 52 18 1 14 54 11 28 83 42 15 13 77 22 70 87 65 79 35 44 71 79 9 95 57 5 59 42 62 66 26 33 66 67 45 39 17 97 28 36 100 52 23 68 29 83 6 61 85 71 2 85 98 85 65 95 53 35 96 29 28 82 80 52 60 61 46 46 80 11 3 35 6 12 10 64 7 7 7 65 93 58 85 20 12\n2422 2429",
"output": "52"
},
{
"input": "10\n3 6 1 5 3 7 0 1 0 8\n16 18",
"output": "6"
},
{
"input": "10\n3 3 0 4 0 5 2 10 7 0\n10 24",
"output": "8"
},
{
"input": "10\n9 4 7 7 1 3 7 3 8 5\n23 31",
"output": "7"
},
{
"input": "10\n9 6 9 5 5 4 3 3 9 10\n9 54",
"output": "10"
},
{
"input": "10\n2 4 8 5 2 2 2 5 6 2\n14 24",
"output": "7"
},
{
"input": "10\n10 58 86 17 61 12 75 93 37 30\n10 469",
"output": "10"
},
{
"input": "10\n56 36 0 28 68 54 34 48 28 92\n92 352",
"output": "10"
},
{
"input": "10\n2 81 94 40 74 62 39 70 87 86\n217 418",
"output": "8"
},
{
"input": "10\n48 93 9 96 70 14 100 93 44 79\n150 496",
"output": "8"
},
{
"input": "10\n94 85 4 9 30 45 90 76 0 65\n183 315",
"output": "7"
},
{
"input": "100\n1 0 7 9 0 4 3 10 9 4 9 7 4 4 7 7 6 1 3 3 8 1 4 3 5 8 0 0 6 2 3 5 0 1 5 8 6 3 2 4 9 5 8 6 0 2 5 1 9 5 9 0 6 0 4 5 9 7 1 4 7 5 4 5 6 8 2 3 3 2 8 2 9 5 9 2 4 7 7 8 10 1 3 0 8 0 9 1 1 7 7 8 9 3 5 9 9 8 0 8\n200 279",
"output": "63"
},
{
"input": "100\n5 4 9 7 8 10 7 8 10 0 10 9 7 1 0 7 8 5 5 8 7 7 7 2 5 8 0 7 5 7 1 7 6 5 4 10 6 1 4 4 8 7 0 3 2 10 8 6 1 3 2 6 8 1 9 3 9 5 2 0 3 6 7 5 10 0 2 8 3 10 1 3 8 8 0 2 10 3 4 4 0 7 4 0 9 7 10 2 7 10 9 9 6 6 8 1 10 1 2 0\n52 477",
"output": "91"
},
{
"input": "100\n5 1 6 6 5 4 5 8 0 2 10 1 10 0 6 6 0 1 5 7 10 5 8 4 4 5 10 4 10 3 0 10 10 1 2 6 2 6 3 9 4 4 5 5 7 7 7 4 3 2 1 4 5 0 2 1 8 5 4 5 10 7 0 3 5 4 10 4 10 7 10 1 8 3 9 8 6 9 5 7 3 4 7 8 4 0 3 4 4 1 6 6 2 0 1 5 3 3 9 10\n22 470",
"output": "98"
},
{
"input": "100\n73 75 17 93 35 7 71 88 11 58 78 33 7 38 14 83 30 25 75 23 60 10 100 7 90 51 82 0 78 54 61 32 20 90 54 45 100 62 40 99 43 86 87 64 10 41 29 51 38 22 5 63 10 64 90 20 100 33 95 72 40 82 92 30 38 3 71 85 99 66 4 26 33 41 85 14 26 61 21 96 29 40 25 14 48 4 30 44 6 41 71 71 4 66 13 50 30 78 64 36\n2069 2800",
"output": "57"
},
{
"input": "100\n86 19 100 37 9 49 97 9 70 51 14 31 47 53 76 65 10 40 4 92 2 79 22 70 85 58 73 96 89 91 41 88 70 31 53 33 22 51 10 56 90 39 70 38 86 15 94 63 82 19 7 65 22 83 83 71 53 6 95 89 53 41 95 11 32 0 7 84 39 11 37 73 20 46 18 28 72 23 17 78 37 49 43 62 60 45 30 69 38 41 71 43 47 80 64 40 77 99 36 63\n1348 3780",
"output": "74"
},
{
"input": "100\n65 64 26 48 16 90 68 32 95 11 27 29 87 46 61 35 24 99 34 17 79 79 11 66 14 75 31 47 43 61 100 32 75 5 76 11 46 74 81 81 1 25 87 45 16 57 24 76 58 37 42 0 46 23 75 66 75 11 50 5 10 11 43 26 38 42 88 15 70 57 2 74 7 72 52 8 72 19 37 38 66 24 51 42 40 98 19 25 37 7 4 92 47 72 26 76 66 88 53 79\n1687 2986",
"output": "65"
},
{
"input": "100\n78 43 41 93 12 76 62 54 85 5 42 61 93 37 22 6 50 80 63 53 66 47 0 60 43 93 90 8 97 64 80 22 23 47 30 100 80 75 84 95 35 69 36 20 58 99 78 88 1 100 10 69 57 77 68 61 62 85 4 45 24 4 24 74 65 73 91 47 100 35 25 53 27 66 62 55 38 83 56 20 62 10 71 90 41 5 75 83 36 75 15 97 79 52 88 32 55 42 59 39\n873 4637",
"output": "85"
},
{
"input": "100\n12 25 47 84 72 40 85 37 8 92 85 90 12 7 45 14 98 62 31 62 10 89 37 65 77 29 5 3 21 21 10 98 44 37 37 37 50 15 69 27 19 99 98 91 63 42 32 68 77 88 78 35 13 44 4 82 42 76 28 50 65 64 88 46 94 37 40 7 10 58 21 31 17 91 75 86 3 9 9 14 72 20 40 57 11 75 91 48 79 66 53 24 93 16 58 4 10 89 75 51\n666 4149",
"output": "88"
},
{
"input": "10\n8 0 2 2 5 1 3 5 2 2\n13 17",
"output": "6"
},
{
"input": "10\n10 4 4 6 2 2 0 5 3 7\n19 24",
"output": "5"
},
{
"input": "10\n96 19 75 32 94 16 81 2 93 58\n250 316",
"output": "6"
},
{
"input": "10\n75 65 68 43 89 57 7 58 51 85\n258 340",
"output": "6"
},
{
"input": "100\n59 51 86 38 90 10 36 3 97 35 32 20 25 96 49 39 66 44 64 50 97 68 50 79 3 33 72 96 32 74 67 9 17 77 67 15 1 100 99 81 18 1 15 36 7 34 30 78 10 97 7 19 87 47 62 61 40 29 1 34 6 77 76 21 66 11 65 96 82 54 49 65 56 90 29 75 48 77 48 53 91 21 98 26 80 44 57 97 11 78 98 45 40 88 27 27 47 5 26 6\n2479 2517",
"output": "53"
},
{
"input": "100\n5 11 92 53 49 42 15 86 31 10 30 49 21 66 14 13 80 25 21 25 86 20 86 83 36 81 21 23 0 30 64 85 15 33 74 96 83 51 84 4 35 65 10 7 11 11 41 80 51 51 74 52 43 83 88 38 77 20 14 40 37 25 27 93 27 77 48 56 93 65 79 33 91 14 9 95 13 36 24 2 66 31 56 28 49 58 74 17 88 36 46 73 54 18 63 22 2 41 8 50\n2229 2279",
"output": "52"
},
{
"input": "2\n0 1\n1 1",
"output": "0"
},
{
"input": "4\n1 0 0 4\n1 3",
"output": "0"
},
{
"input": "4\n1 0 0 0\n1 10",
"output": "0"
},
{
"input": "3\n2 1 4\n3 3",
"output": "0"
},
{
"input": "5\n2 0 2 0 0\n2 2",
"output": "3"
},
{
"input": "4\n1 2 3 4\n1 7",
"output": "4"
},
{
"input": "2\n7 1\n1 6",
"output": "0"
},
{
"input": "5\n1 3 7 8 9\n4 6",
"output": "0"
},
{
"input": "2\n5 2\n5 6",
"output": "0"
},
{
"input": "2\n1 0\n1 2",
"output": "0"
},
{
"input": "4\n2 3 9 10\n5 14",
"output": "4"
},
{
"input": "3\n1 2 1\n1 1",
"output": "0"
},
{
"input": "4\n2 3 9 50\n5 30",
"output": "0"
},
{
"input": "3\n7 1 1\n6 8",
"output": "0"
},
{
"input": "6\n1 1 2 3 4 5\n3 9",
"output": "5"
},
{
"input": "3\n4 5 5\n4 9",
"output": "3"
},
{
"input": "6\n1 2 3 4 5 6\n1 3",
"output": "0"
},
{
"input": "5\n3 4 3 2 10\n6 8",
"output": "0"
},
{
"input": "5\n1 1 3 4 6\n2 2",
"output": "0"
},
{
"input": "5\n5 3 5 8 10\n2 20",
"output": "4"
},
{
"input": "4\n0 0 5 0\n3 6",
"output": "0"
},
{
"input": "8\n1 1 1 1 2 2 2 1\n3 7",
"output": "6"
},
{
"input": "3\n1 100 100\n101 200",
"output": "0"
}
] | 1,586,624,871 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 307,200 | estudiantes = int(input())
calificaciones = list(str(input()).split())
xy = list(str(input()).split())
contador1 = 0
contador2 = 0
partitura = 0
entro = False
for i in range(len(calificaciones)):
calificaciones[i] = int(calificaciones[i])
xy[0] = int(xy[0])
xy[1] = int(xy[1])
for j in range(len(calificaciones)):
contador1 = 0
contador2 = 0
for i in range(0,j):
contador1 += calificaciones[i]
for k in range(j,len(calificaciones)):
contador2 += calificaciones[k]
if (contador1 >= xy[0] and contador1<=xy[1])and(contador2 >= xy[0] and contador2<=xy[1]):
entro = True
partitura = j
break
if entro == True:
partitura+=1
print(partitura)
| Title: Group of Students
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got 1 point, *c*2 children got 2 points, ..., *c**m* children got *m* points. Now you need to set the passing rate *k* (integer from 1 to *m*): all schoolchildren who got less than *k* points go to the beginner group and those who get at strictly least *k* points go to the intermediate group. We know that if the size of a group is more than *y*, then the university won't find a room for them. We also know that if a group has less than *x* schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from *x* to *y*, inclusive.
Help the university pick the passing rate in a way that meets these requirements.
Input Specification:
The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0.
Output Specification:
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
Demo Input:
['5\n3 4 3 2 1\n6 8\n', '5\n0 3 3 4 2\n3 10\n', '2\n2 5\n3 6\n']
Demo Output:
['3\n', '4\n', '0\n']
Note:
In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | ```python
estudiantes = int(input())
calificaciones = list(str(input()).split())
xy = list(str(input()).split())
contador1 = 0
contador2 = 0
partitura = 0
entro = False
for i in range(len(calificaciones)):
calificaciones[i] = int(calificaciones[i])
xy[0] = int(xy[0])
xy[1] = int(xy[1])
for j in range(len(calificaciones)):
contador1 = 0
contador2 = 0
for i in range(0,j):
contador1 += calificaciones[i]
for k in range(j,len(calificaciones)):
contador2 += calificaciones[k]
if (contador1 >= xy[0] and contador1<=xy[1])and(contador2 >= xy[0] and contador2<=xy[1]):
entro = True
partitura = j
break
if entro == True:
partitura+=1
print(partitura)
``` | 3 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,693,665,818 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 36 | 92 | 0 | s=str(int(input()))
s1=s
s=s.split('1')
l=[len(i) for i in s]
max1 = max(l)
s1=s1.split('0')
l=[len(i) for i in s1]
max2 = max(l)
if(max2 >=7 or max1>=7):
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
s=str(int(input()))
s1=s
s=s.split('1')
l=[len(i) for i in s]
max1 = max(l)
s1=s1.split('0')
l=[len(i) for i in s1]
max2 = max(l)
if(max2 >=7 or max1>=7):
print("YES")
else:
print("NO")
``` | 0 |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*.
It is guaranteed that Andryusha took exactly two socks of each pair. | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe. | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32",
"output": "25"
},
{
"input": "50\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50",
"output": "1"
},
{
"input": "50\n50 50 49 49 48 48 47 47 46 46 45 45 44 44 43 43 42 42 41 41 40 40 39 39 38 38 37 37 36 36 35 35 34 34 33 33 32 32 31 31 30 30 29 29 28 28 27 27 26 26 25 25 24 24 23 23 22 22 21 21 20 20 19 19 18 18 17 17 16 16 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1",
"output": "1"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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",
"output": "50"
},
{
"input": "50\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "50"
},
{
"input": "10\n2 9 4 1 6 7 10 3 1 5 8 6 2 3 10 7 4 8 5 9",
"output": "9"
}
] | 1,563,048,210 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 280 | 11,264,000 | n = int(input())
a = [0]*n
k = 0
km = 0
for i in input().split():
i = int(i) - 1
if a[i] == 0:
a[i] = 1
k += 1
if k > km: km = k
else:
a[i] = 0
k -= 1
print(km)
| Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*.
It is guaranteed that Andryusha took exactly two socks of each pair.
Output Specification:
Print single integer — the maximum number of socks that were on the table at the same time.
Demo Input:
['1\n1 1\n', '3\n2 1 1 3 2 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe. | ```python
n = int(input())
a = [0]*n
k = 0
km = 0
for i in input().split():
i = int(i) - 1
if a[i] == 0:
a[i] = 1
k += 1
if k > km: km = k
else:
a[i] = 0
k -= 1
print(km)
``` | 3 |
|
851 | A | Arpa and a research in Mexican wave | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits.
Arpa wants to know how many spectators are standing at time *t*. | The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*). | Print single integer: how many spectators are standing at time *t*. | [
"10 5 3\n",
"10 5 7\n",
"10 5 12\n"
] | [
"3\n",
"5\n",
"3\n"
] | In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1 ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2 ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3 ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4 ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5 ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6 -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7 --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8 ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9 ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. | 500 | [
{
"input": "10 5 3",
"output": "3"
},
{
"input": "10 5 7",
"output": "5"
},
{
"input": "10 5 12",
"output": "3"
},
{
"input": "840585600 770678331 788528791",
"output": "770678331"
},
{
"input": "25462281 23343504 8024619",
"output": "8024619"
},
{
"input": "723717988 205757169 291917494",
"output": "205757169"
},
{
"input": "27462087 20831796 15492397",
"output": "15492397"
},
{
"input": "966696824 346707476 1196846860",
"output": "116557440"
},
{
"input": "290274403 41153108 327683325",
"output": "3744186"
},
{
"input": "170963478 151220598 222269210",
"output": "99914866"
},
{
"input": "14264008 309456 11132789",
"output": "309456"
},
{
"input": "886869816 281212106 52891064",
"output": "52891064"
},
{
"input": "330543750 243917820 205522400",
"output": "205522400"
},
{
"input": "457658451 18625039 157624558",
"output": "18625039"
},
{
"input": "385908940 143313325 509731380",
"output": "19490885"
},
{
"input": "241227633 220621961 10025257",
"output": "10025257"
},
{
"input": "474139818 268918981 388282504",
"output": "268918981"
},
{
"input": "25963410 3071034 820199",
"output": "820199"
},
{
"input": "656346757 647995766 75748423",
"output": "75748423"
},
{
"input": "588568132 411878522 521753621",
"output": "411878522"
},
{
"input": "735788762 355228487 139602545",
"output": "139602545"
},
{
"input": "860798593 463398487 506871376",
"output": "463398487"
},
{
"input": "362624055 110824996 194551217",
"output": "110824996"
},
{
"input": "211691721 195866131 313244576",
"output": "94313276"
},
{
"input": "45661815 26072719 9643822",
"output": "9643822"
},
{
"input": "757183104 590795077 709609355",
"output": "590795077"
},
{
"input": "418386749 1915035 197248338",
"output": "1915035"
},
{
"input": "763782282 297277890 246562421",
"output": "246562421"
},
{
"input": "893323188 617630677 607049638",
"output": "607049638"
},
{
"input": "506708261 356545583 296093684",
"output": "296093684"
},
{
"input": "984295813 427551190 84113823",
"output": "84113823"
},
{
"input": "774984967 61373612 96603505",
"output": "61373612"
},
{
"input": "774578969 342441237 91492393",
"output": "91492393"
},
{
"input": "76495801 8780305 56447339",
"output": "8780305"
},
{
"input": "48538385 582843 16805978",
"output": "582843"
},
{
"input": "325794610 238970909 553089099",
"output": "11676420"
},
{
"input": "834925315 316928679 711068031",
"output": "316928679"
},
{
"input": "932182199 454838315 267066713",
"output": "267066713"
},
{
"input": "627793782 552043394 67061810",
"output": "67061810"
},
{
"input": "24317170 17881607 218412",
"output": "218412"
},
{
"input": "1000000000 1000 1",
"output": "1"
},
{
"input": "1000000000 1000 2",
"output": "2"
},
{
"input": "1000000000 1 1000",
"output": "1"
},
{
"input": "100 100 100",
"output": "100"
},
{
"input": "100 100 99",
"output": "99"
},
{
"input": "100 100 101",
"output": "99"
},
{
"input": "100 100 199",
"output": "1"
},
{
"input": "1000000000 1000000000 1999999999",
"output": "1"
},
{
"input": "10 5 5",
"output": "5"
},
{
"input": "5 3 5",
"output": "3"
},
{
"input": "10 3 3",
"output": "3"
},
{
"input": "10 5 6",
"output": "5"
},
{
"input": "3 2 4",
"output": "1"
},
{
"input": "10 5 14",
"output": "1"
},
{
"input": "6 1 4",
"output": "1"
},
{
"input": "10 10 19",
"output": "1"
},
{
"input": "10 4 11",
"output": "3"
},
{
"input": "2 2 3",
"output": "1"
},
{
"input": "10 5 11",
"output": "4"
},
{
"input": "600 200 700",
"output": "100"
},
{
"input": "2000 1000 2001",
"output": "999"
},
{
"input": "1000 1000 1001",
"output": "999"
},
{
"input": "5 4 6",
"output": "3"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "10 3 10",
"output": "3"
},
{
"input": "15 10 10",
"output": "10"
},
{
"input": "10 5 13",
"output": "2"
},
{
"input": "2 2 2",
"output": "2"
},
{
"input": "5 5 6",
"output": "4"
},
{
"input": "10 6 12",
"output": "4"
},
{
"input": "7 5 8",
"output": "4"
},
{
"input": "10 4 9",
"output": "4"
},
{
"input": "9 2 6",
"output": "2"
},
{
"input": "5 2 6",
"output": "1"
},
{
"input": "6 2 6",
"output": "2"
},
{
"input": "5 5 8",
"output": "2"
},
{
"input": "3 3 5",
"output": "1"
},
{
"input": "10 2 5",
"output": "2"
},
{
"input": "5 3 7",
"output": "1"
},
{
"input": "5 4 8",
"output": "1"
},
{
"input": "10 6 11",
"output": "5"
},
{
"input": "5 3 6",
"output": "2"
},
{
"input": "10 6 14",
"output": "2"
},
{
"input": "10 10 10",
"output": "10"
},
{
"input": "1000000000 1 1000000000",
"output": "1"
},
{
"input": "20 4 22",
"output": "2"
},
{
"input": "5 4 4",
"output": "4"
},
{
"input": "4 3 6",
"output": "1"
},
{
"input": "12 8 18",
"output": "2"
},
{
"input": "10 5 10",
"output": "5"
},
{
"input": "100 50 149",
"output": "1"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "7 6 9",
"output": "4"
},
{
"input": "16 10 21",
"output": "5"
},
{
"input": "10 2 11",
"output": "1"
},
{
"input": "600 200 500",
"output": "200"
},
{
"input": "100 30 102",
"output": "28"
},
{
"input": "10 10 18",
"output": "2"
},
{
"input": "15 3 10",
"output": "3"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "5 5 5",
"output": "5"
},
{
"input": "10 3 12",
"output": "1"
},
{
"input": "747 457 789",
"output": "415"
},
{
"input": "5 4 7",
"output": "2"
},
{
"input": "15 5 11",
"output": "5"
},
{
"input": "3 2 2",
"output": "2"
},
{
"input": "7 6 8",
"output": "5"
},
{
"input": "7 4 8",
"output": "3"
},
{
"input": "10 4 13",
"output": "1"
},
{
"input": "10 3 9",
"output": "3"
},
{
"input": "20 2 21",
"output": "1"
},
{
"input": "6 5 9",
"output": "2"
},
{
"input": "10 9 18",
"output": "1"
},
{
"input": "12 4 9",
"output": "4"
},
{
"input": "10 7 15",
"output": "2"
},
{
"input": "999999999 999999998 1500000000",
"output": "499999997"
},
{
"input": "20 5 20",
"output": "5"
},
{
"input": "4745 4574 4757",
"output": "4562"
},
{
"input": "10 7 12",
"output": "5"
},
{
"input": "17 15 18",
"output": "14"
},
{
"input": "3 1 3",
"output": "1"
},
{
"input": "100 3 7",
"output": "3"
},
{
"input": "6 2 7",
"output": "1"
},
{
"input": "8 5 10",
"output": "3"
},
{
"input": "3 3 3",
"output": "3"
},
{
"input": "9 5 10",
"output": "4"
},
{
"input": "10 6 13",
"output": "3"
},
{
"input": "13 10 14",
"output": "9"
},
{
"input": "13 12 15",
"output": "10"
},
{
"input": "10 4 12",
"output": "2"
},
{
"input": "41 3 3",
"output": "3"
},
{
"input": "1000000000 1000000000 1400000000",
"output": "600000000"
},
{
"input": "10 3 11",
"output": "2"
},
{
"input": "12 7 18",
"output": "1"
},
{
"input": "15 3 17",
"output": "1"
},
{
"input": "10 2 8",
"output": "2"
},
{
"input": "1000000000 1000 1000000999",
"output": "1"
},
{
"input": "5 5 9",
"output": "1"
},
{
"input": "100 3 6",
"output": "3"
},
{
"input": "100 5 50",
"output": "5"
},
{
"input": "10000 10 10000",
"output": "10"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "4"
},
{
"input": "9979797 555554 10101010",
"output": "434341"
},
{
"input": "13 5 12",
"output": "5"
},
{
"input": "9 4 10",
"output": "3"
},
{
"input": "7 5 10",
"output": "2"
},
{
"input": "100000000 10000000 100005000",
"output": "9995000"
},
{
"input": "100000 50000 100001",
"output": "49999"
},
{
"input": "15 10 20",
"output": "5"
},
{
"input": "4 4 5",
"output": "3"
},
{
"input": "5 3 3",
"output": "3"
},
{
"input": "30 5 30",
"output": "5"
},
{
"input": "200000 10 200005",
"output": "5"
},
{
"input": "10 9 12",
"output": "7"
},
{
"input": "10 6 15",
"output": "1"
},
{
"input": "1000000000 10 1000000000",
"output": "10"
},
{
"input": "7 5 11",
"output": "1"
},
{
"input": "9 4 4",
"output": "4"
},
{
"input": "14 3 15",
"output": "2"
},
{
"input": "1000000000 100000000 1000000000",
"output": "100000000"
},
{
"input": "40 10 22",
"output": "10"
},
{
"input": "50 10 51",
"output": "9"
},
{
"input": "999999997 999999995 1999999991",
"output": "1"
},
{
"input": "92 79 144",
"output": "27"
},
{
"input": "8 4 4",
"output": "4"
}
] | 1,504,537,424 | 1,724 | PyPy 3 | OK | TESTS | 166 | 124 | 307,200 | mass = input().split()
n = int(mass[0])
k = int(mass[1])
t = int(mass[2])
'''for i in range(1, t + 1):
if i <= k:
result = result + 1
elif i <= n:
result = result
else:
result = result - 1
'''
if t <= k:
print(t)
elif t <= n:
print(k)
else:
print(k - (t % n))
| Title: Arpa and a research in Mexican wave
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits.
Arpa wants to know how many spectators are standing at time *t*.
Input Specification:
The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*).
Output Specification:
Print single integer: how many spectators are standing at time *t*.
Demo Input:
['10 5 3\n', '10 5 7\n', '10 5 12\n']
Demo Output:
['3\n', '5\n', '3\n']
Note:
In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. - At *t* = 1 ^--------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 2 ^^-------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 3 ^^^------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 4 ^^^^------ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 5 ^^^^^----- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 6 -^^^^^---- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 7 --^^^^^--- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 8 ---^^^^^-- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 9 ----^^^^^- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 10 -----^^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 5. - At *t* = 11 ------^^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 4. - At *t* = 12 -------^^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 3. - At *t* = 13 --------^^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 2. - At *t* = 14 ---------^ <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 1. - At *t* = 15 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spectators = 0. | ```python
mass = input().split()
n = int(mass[0])
k = int(mass[1])
t = int(mass[2])
'''for i in range(1, t + 1):
if i <= k:
result = result + 1
elif i <= n:
result = result
else:
result = result - 1
'''
if t <= k:
print(t)
elif t <= n:
print(k)
else:
print(k - (t % n))
``` | 3 |
|
453 | A | Little Pony and Expected Maximum | PROGRAMMING | 1,600 | [
"probabilities"
] | null | null | Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times. | A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). | Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. | [
"6 1\n",
"6 3\n",
"2 2\n"
] | [
"3.500000000000\n",
"4.958333333333\n",
"1.750000000000\n"
] | Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value | 500 | [
{
"input": "6 1",
"output": "3.500000000000"
},
{
"input": "6 3",
"output": "4.958333333333"
},
{
"input": "2 2",
"output": "1.750000000000"
},
{
"input": "5 4",
"output": "4.433600000000"
},
{
"input": "5 8",
"output": "4.814773760000"
},
{
"input": "3 10",
"output": "2.982641534996"
},
{
"input": "3 6",
"output": "2.910836762689"
},
{
"input": "1 8",
"output": "1.000000000000"
},
{
"input": "24438 9",
"output": "21994.699969310015"
},
{
"input": "94444 9",
"output": "85000.099992058866"
},
{
"input": "8 66716",
"output": "8.000000000000"
},
{
"input": "4 25132",
"output": "4.000000000000"
},
{
"input": "51520 73331",
"output": "51519.682650242677"
},
{
"input": "54230 31747",
"output": "54228.743352775018"
},
{
"input": "24236 90163",
"output": "24235.975171545670"
},
{
"input": "26946 99523",
"output": "26945.974480086279"
},
{
"input": "50323 7",
"output": "44033.124988408454"
},
{
"input": "53033 3",
"output": "39775.249995286234"
},
{
"input": "55743 5",
"output": "46452.999992525307"
},
{
"input": "59964 79",
"output": "59214.949890211828"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "1 1",
"output": "1.000000000000"
},
{
"input": "3 1",
"output": "2.000000000000"
},
{
"input": "1 2",
"output": "1.000000000000"
},
{
"input": "53513 34040",
"output": "53511.875329020870"
},
{
"input": "100000 100000",
"output": "99999.418033254507"
},
{
"input": "1 100000",
"output": "1.000000000000"
},
{
"input": "100000 1",
"output": "50000.499999999935"
},
{
"input": "2 100000",
"output": "2.000000000000"
},
{
"input": "100000 2",
"output": "66667.166665000332"
},
{
"input": "50000 100000",
"output": "49999.843487110789"
},
{
"input": "99999 1111",
"output": "99909.571915885972"
},
{
"input": "99999 99999",
"output": "99998.418033254609"
},
{
"input": "1000 1000",
"output": "999.419018443269"
},
{
"input": "50000 50000",
"output": "49999.418043215679"
},
{
"input": "88888 88888",
"output": "88887.418034499773"
},
{
"input": "99999 100000",
"output": "99998.418042461126"
},
{
"input": "100000 555",
"output": "99820.643422392372"
},
{
"input": "10000 10000",
"output": "9999.418122897887"
},
{
"input": "100000 5001",
"output": "99980.503829474910"
},
{
"input": "100000 1000",
"output": "99900.599066768002"
}
] | 1,602,940,343 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 187 | 0 | def prob(m, n):
ans = 0.0
i = m
while (i):
ans += (pow(i / m, n) - pow((i - 1) / m, n)) * i
i = i - 1
return ans
m, n = map(int, input().split())
print(prob(m, n))
| Title: Little Pony and Expected Maximum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.
The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times.
Input Specification:
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output Specification:
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
Demo Input:
['6 1\n', '6 3\n', '2 2\n']
Demo Output:
['3.500000000000\n', '4.958333333333\n', '1.750000000000\n']
Note:
Consider the third test example. If you've made two tosses:
1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.
The probability of each outcome is 0.25, that is expectation equals to:
You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value | ```python
def prob(m, n):
ans = 0.0
i = m
while (i):
ans += (pow(i / m, n) - pow((i - 1) / m, n)) * i
i = i - 1
return ans
m, n = map(int, input().split())
print(prob(m, n))
``` | 3 |
|
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 1,657,178,590 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 108 | 9,113,600 | x = int(input())
s = list(map(int,input().split()))
c = 0
max = max(s)
min = min(s)
for i in range(0,x):
if s[i] != max and s[i]!=min:
c = c + 1
print(c) | Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | ```python
x = int(input())
s = list(map(int,input().split()))
c = 0
max = max(s)
min = min(s)
for i in range(0,x):
if s[i] != max and s[i]!=min:
c = c + 1
print(c)
``` | 3 |
|
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
},
{
"input": "12\n4773\n325\n377\n192\n780\n881\n816\n839\n223\n215\n125\n952\n8",
"output": "7"
},
{
"input": "15\n7758\n182\n272\n763\n910\n24\n359\n583\n890\n735\n819\n66\n992\n440\n496\n227",
"output": "15"
},
{
"input": "30\n70\n6\n2\n10\n4\n7\n10\n5\n1\n8\n10\n4\n3\n5\n9\n3\n6\n6\n4\n2\n6\n5\n10\n1\n9\n7\n2\n1\n10\n7\n5",
"output": "8"
},
{
"input": "40\n15705\n702\n722\n105\n873\n417\n477\n794\n300\n869\n496\n572\n232\n456\n298\n473\n584\n486\n713\n934\n121\n303\n956\n934\n840\n358\n201\n861\n497\n131\n312\n957\n96\n914\n509\n60\n300\n722\n658\n820\n103",
"output": "21"
},
{
"input": "50\n18239\n300\n151\n770\n9\n200\n52\n247\n753\n523\n263\n744\n463\n540\n244\n608\n569\n771\n32\n425\n777\n624\n761\n628\n124\n405\n396\n726\n626\n679\n237\n229\n49\n512\n18\n671\n290\n768\n632\n739\n18\n136\n413\n117\n83\n413\n452\n767\n664\n203\n404",
"output": "31"
},
{
"input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\n9\n9\n9\n3\n4\n2\n2\n5\n8\n9\n1\n10\n3\n4\n3\n1\n9\n3\n5\n1\n3\n7\n6\n9\n8\n9\n1\n7\n4\n4\n2\n3\n5\n7",
"output": "17"
},
{
"input": "70\n2731\n26\n75\n86\n94\n37\n25\n32\n35\n92\n1\n51\n73\n53\n66\n16\n80\n15\n81\n100\n87\n55\n48\n30\n71\n39\n87\n77\n25\n70\n22\n75\n23\n97\n16\n75\n95\n61\n61\n28\n10\n78\n54\n80\n51\n25\n24\n90\n58\n4\n77\n40\n54\n53\n47\n62\n30\n38\n71\n97\n71\n60\n58\n1\n21\n15\n55\n99\n34\n88\n99",
"output": "35"
},
{
"input": "70\n28625\n34\n132\n181\n232\n593\n413\n862\n887\n808\n18\n35\n89\n356\n640\n339\n280\n975\n82\n345\n398\n948\n372\n91\n755\n75\n153\n948\n603\n35\n694\n722\n293\n363\n884\n264\n813\n175\n169\n646\n138\n449\n488\n828\n417\n134\n84\n763\n288\n845\n801\n556\n972\n332\n564\n934\n699\n842\n942\n644\n203\n406\n140\n37\n9\n423\n546\n675\n491\n113\n587",
"output": "45"
},
{
"input": "80\n248\n3\n9\n4\n5\n10\n7\n2\n6\n2\n2\n8\n2\n1\n3\n7\n9\n2\n8\n4\n4\n8\n5\n4\n4\n10\n2\n1\n4\n8\n4\n10\n1\n2\n10\n2\n3\n3\n1\n1\n8\n9\n5\n10\n2\n8\n10\n5\n3\n6\n1\n7\n8\n9\n10\n5\n10\n10\n2\n10\n1\n2\n4\n1\n9\n4\n7\n10\n8\n5\n8\n1\n4\n2\n2\n3\n9\n9\n9\n10\n6",
"output": "27"
},
{
"input": "80\n2993\n18\n14\n73\n38\n14\n73\n77\n18\n81\n6\n96\n65\n77\n86\n76\n8\n16\n81\n83\n83\n34\n69\n58\n15\n19\n1\n16\n57\n95\n35\n5\n49\n8\n15\n47\n84\n99\n94\n93\n55\n43\n47\n51\n61\n57\n13\n7\n92\n14\n4\n83\n100\n60\n75\n41\n95\n74\n40\n1\n4\n95\n68\n59\n65\n15\n15\n75\n85\n46\n77\n26\n30\n51\n64\n75\n40\n22\n88\n68\n24",
"output": "38"
},
{
"input": "80\n37947\n117\n569\n702\n272\n573\n629\n90\n337\n673\n589\n576\n205\n11\n284\n645\n719\n777\n271\n567\n466\n251\n402\n3\n97\n288\n699\n208\n173\n530\n782\n266\n395\n957\n159\n463\n43\n316\n603\n197\n386\n132\n799\n778\n905\n784\n71\n851\n963\n883\n705\n454\n275\n425\n727\n223\n4\n870\n833\n431\n463\n85\n505\n800\n41\n954\n981\n242\n578\n336\n48\n858\n702\n349\n929\n646\n528\n993\n506\n274\n227",
"output": "70"
},
{
"input": "90\n413\n5\n8\n10\n7\n5\n7\n5\n7\n1\n7\n8\n4\n3\n9\n4\n1\n10\n3\n1\n10\n9\n3\n1\n8\n4\n7\n5\n2\n9\n3\n10\n10\n3\n6\n3\n3\n10\n7\n5\n1\n1\n2\n4\n8\n2\n5\n5\n3\n9\n5\n5\n3\n10\n2\n3\n8\n5\n9\n1\n3\n6\n5\n9\n2\n3\n7\n10\n3\n4\n4\n1\n5\n9\n2\n6\n9\n1\n1\n9\n9\n7\n7\n7\n8\n4\n5\n3\n4\n6\n9",
"output": "59"
},
{
"input": "90\n4226\n33\n43\n83\n46\n75\n14\n88\n36\n8\n25\n47\n4\n96\n19\n33\n49\n65\n17\n59\n72\n1\n55\n94\n92\n27\n33\n39\n14\n62\n79\n12\n89\n22\n86\n13\n19\n77\n53\n96\n74\n24\n25\n17\n64\n71\n81\n87\n52\n72\n55\n49\n74\n36\n65\n86\n91\n33\n61\n97\n38\n87\n61\n14\n73\n95\n43\n67\n42\n67\n22\n12\n62\n32\n96\n24\n49\n82\n46\n89\n36\n75\n91\n11\n10\n9\n33\n86\n28\n75\n39",
"output": "64"
},
{
"input": "90\n40579\n448\n977\n607\n745\n268\n826\n479\n59\n330\n609\n43\n301\n970\n726\n172\n632\n600\n181\n712\n195\n491\n312\n849\n722\n679\n682\n780\n131\n404\n293\n387\n567\n660\n54\n339\n111\n833\n612\n911\n869\n356\n884\n635\n126\n639\n712\n473\n663\n773\n435\n32\n973\n484\n662\n464\n699\n274\n919\n95\n904\n253\n589\n543\n454\n250\n349\n237\n829\n511\n536\n36\n45\n152\n626\n384\n199\n877\n941\n84\n781\n115\n20\n52\n726\n751\n920\n291\n571\n6\n199",
"output": "64"
},
{
"input": "100\n66\n7\n9\n10\n5\n2\n8\n6\n5\n4\n10\n10\n6\n5\n2\n2\n1\n1\n5\n8\n7\n8\n10\n5\n6\n6\n5\n9\n9\n6\n3\n8\n7\n10\n5\n9\n6\n7\n3\n5\n8\n6\n8\n9\n1\n1\n1\n2\n4\n5\n5\n1\n1\n2\n6\n7\n1\n5\n8\n7\n2\n1\n7\n10\n9\n10\n2\n4\n10\n4\n10\n10\n5\n3\n9\n1\n2\n1\n10\n5\n1\n7\n4\n4\n5\n7\n6\n10\n4\n7\n3\n4\n3\n6\n2\n5\n2\n4\n9\n5\n3",
"output": "7"
},
{
"input": "100\n4862\n20\n47\n85\n47\n76\n38\n48\n93\n91\n81\n31\n51\n23\n60\n59\n3\n73\n72\n57\n67\n54\n9\n42\n5\n32\n46\n72\n79\n95\n61\n79\n88\n33\n52\n97\n10\n3\n20\n79\n82\n93\n90\n38\n80\n18\n21\n43\n60\n73\n34\n75\n65\n10\n84\n100\n29\n94\n56\n22\n59\n95\n46\n22\n57\n69\n67\n90\n11\n10\n61\n27\n2\n48\n69\n86\n91\n69\n76\n36\n71\n18\n54\n90\n74\n69\n50\n46\n8\n5\n41\n96\n5\n14\n55\n85\n39\n6\n79\n75\n87",
"output": "70"
},
{
"input": "100\n45570\n14\n881\n678\n687\n993\n413\n760\n451\n426\n787\n503\n343\n234\n530\n294\n725\n941\n524\n574\n441\n798\n399\n360\n609\n376\n525\n229\n995\n478\n347\n47\n23\n468\n525\n749\n601\n235\n89\n995\n489\n1\n239\n415\n122\n671\n128\n357\n886\n401\n964\n212\n968\n210\n130\n871\n360\n661\n844\n414\n187\n21\n824\n266\n713\n126\n496\n916\n37\n193\n755\n894\n641\n300\n170\n176\n383\n488\n627\n61\n897\n33\n242\n419\n881\n698\n107\n391\n418\n774\n905\n87\n5\n896\n835\n318\n373\n916\n393\n91\n460",
"output": "78"
},
{
"input": "100\n522\n1\n5\n2\n4\n2\n6\n3\n4\n2\n10\n10\n6\n7\n9\n7\n1\n7\n2\n5\n3\n1\n5\n2\n3\n5\n1\n7\n10\n10\n4\n4\n10\n9\n10\n6\n2\n8\n2\n6\n10\n9\n2\n7\n5\n9\n4\n6\n10\n7\n3\n1\n1\n9\n5\n10\n9\n2\n8\n3\n7\n5\n4\n7\n5\n9\n10\n6\n2\n9\n2\n5\n10\n1\n7\n7\n10\n5\n6\n2\n9\n4\n7\n10\n10\n8\n3\n4\n9\n3\n6\n9\n10\n2\n9\n9\n3\n4\n1\n10\n2",
"output": "74"
},
{
"input": "100\n32294\n414\n116\n131\n649\n130\n476\n630\n605\n213\n117\n757\n42\n109\n85\n127\n635\n629\n994\n410\n764\n204\n161\n231\n577\n116\n936\n537\n565\n571\n317\n722\n819\n229\n284\n487\n649\n304\n628\n727\n816\n854\n91\n111\n549\n87\n374\n417\n3\n868\n882\n168\n743\n77\n534\n781\n75\n956\n910\n734\n507\n568\n802\n946\n891\n659\n116\n678\n375\n380\n430\n627\n873\n350\n930\n285\n6\n183\n96\n517\n81\n794\n235\n360\n551\n6\n28\n799\n226\n996\n894\n981\n551\n60\n40\n460\n479\n161\n318\n952\n433",
"output": "42"
},
{
"input": "100\n178\n71\n23\n84\n98\n8\n14\n4\n42\n56\n83\n87\n28\n22\n32\n50\n5\n96\n90\n1\n59\n74\n56\n96\n77\n88\n71\n38\n62\n36\n85\n1\n97\n98\n98\n32\n99\n42\n6\n81\n20\n49\n57\n71\n66\n9\n45\n41\n29\n28\n32\n68\n38\n29\n35\n29\n19\n27\n76\n85\n68\n68\n41\n32\n78\n72\n38\n19\n55\n83\n83\n25\n46\n62\n48\n26\n53\n14\n39\n31\n94\n84\n22\n39\n34\n96\n63\n37\n42\n6\n78\n76\n64\n16\n26\n6\n79\n53\n24\n29\n63",
"output": "2"
},
{
"input": "100\n885\n226\n266\n321\n72\n719\n29\n121\n533\n85\n672\n225\n830\n783\n822\n30\n791\n618\n166\n487\n922\n434\n814\n473\n5\n741\n947\n910\n305\n998\n49\n945\n588\n868\n809\n803\n168\n280\n614\n434\n634\n538\n591\n437\n540\n445\n313\n177\n171\n799\n778\n55\n617\n554\n583\n611\n12\n94\n599\n182\n765\n556\n965\n542\n35\n460\n177\n313\n485\n744\n384\n21\n52\n879\n792\n411\n614\n811\n565\n695\n428\n587\n631\n794\n461\n258\n193\n696\n936\n646\n756\n267\n55\n690\n730\n742\n734\n988\n235\n762\n440",
"output": "1"
},
{
"input": "100\n29\n9\n2\n10\n8\n6\n7\n7\n3\n3\n10\n4\n5\n2\n5\n1\n6\n3\n2\n5\n10\n10\n9\n1\n4\n5\n2\n2\n3\n1\n2\n2\n9\n6\n9\n7\n8\n8\n1\n5\n5\n3\n1\n5\n6\n1\n9\n2\n3\n8\n10\n8\n3\n2\n7\n1\n2\n1\n2\n8\n10\n5\n2\n3\n1\n10\n7\n1\n7\n4\n9\n6\n6\n4\n7\n1\n2\n7\n7\n9\n9\n7\n10\n4\n10\n8\n2\n1\n5\n5\n10\n5\n8\n1\n5\n6\n5\n1\n5\n6\n8",
"output": "3"
},
{
"input": "100\n644\n94\n69\n43\n36\n54\n93\n30\n74\n56\n95\n70\n49\n11\n36\n57\n30\n59\n3\n52\n59\n90\n82\n39\n67\n32\n8\n80\n64\n8\n65\n51\n48\n89\n90\n35\n4\n54\n66\n96\n68\n90\n30\n4\n13\n97\n41\n90\n85\n17\n45\n94\n31\n58\n4\n39\n76\n95\n92\n59\n67\n46\n96\n55\n82\n64\n20\n20\n83\n46\n37\n15\n60\n37\n79\n45\n47\n63\n73\n76\n31\n52\n36\n32\n49\n26\n61\n91\n31\n25\n62\n90\n65\n65\n5\n94\n7\n15\n97\n88\n68",
"output": "7"
},
{
"input": "100\n1756\n98\n229\n158\n281\n16\n169\n149\n239\n235\n182\n147\n215\n49\n270\n194\n242\n295\n289\n249\n19\n12\n144\n157\n92\n270\n122\n212\n97\n152\n14\n42\n12\n198\n98\n295\n154\n229\n191\n294\n5\n156\n43\n185\n184\n20\n125\n23\n10\n257\n244\n264\n79\n46\n277\n13\n22\n97\n212\n77\n293\n20\n51\n17\n109\n37\n68\n117\n51\n248\n10\n149\n179\n192\n239\n161\n13\n173\n297\n73\n43\n109\n288\n198\n81\n70\n254\n187\n277\n1\n295\n113\n95\n291\n293\n119\n205\n191\n37\n34\n116",
"output": "6"
},
{
"input": "100\n20562\n721\n452\n11\n703\n376\n183\n197\n203\n406\n642\n346\n446\n256\n760\n201\n360\n702\n707\n388\n779\n653\n610\n497\n768\n670\n134\n780\n306\n661\n180\n259\n256\n362\n6\n121\n415\n747\n170\n67\n439\n728\n193\n622\n481\n38\n225\n343\n303\n253\n436\n305\n68\n794\n247\n291\n600\n750\n188\n199\n757\n28\n776\n749\n253\n351\n53\n629\n129\n578\n209\n89\n651\n262\n638\n353\n469\n31\n144\n460\n176\n535\n562\n366\n639\n234\n577\n364\n761\n617\n303\n450\n778\n311\n289\n221\n274\n239\n626\n194\n36",
"output": "30"
},
{
"input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n86\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n97\n447\n119\n91\n372\n194\n394\n667\n384\n635\n611\n746\n758\n613\n54\n508\n405\n188\n570\n254\n28\n599\n767\n115\n737\n194\n148\n686\n705\n236\n762\n613\n770\n633\n401\n773\n448\n274\n141\n718",
"output": "52"
},
{
"input": "1\n1\n1",
"output": "1"
}
] | 1,688,846,066 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | #Code:
test=[]
for i in range(int(input())+1):
test.append(int(input()))
size= test[0]
test.remove(test[0])
test.sort(reverse=True)
c=0
n=0
while c<size:
a= test[0]
c=c+a
n=n+1
test.remove(test[0])
print(n) | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
Input Specification:
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*.
Output Specification:
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
Demo Input:
['3\n5\n2\n1\n3\n', '3\n6\n2\n3\n2\n', '2\n5\n5\n10\n']
Demo Output:
['2\n', '3\n', '1\n']
Note:
In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | ```python
#Code:
test=[]
for i in range(int(input())+1):
test.append(int(input()))
size= test[0]
test.remove(test[0])
test.sort(reverse=True)
c=0
n=0
while c<size:
a= test[0]
c=c+a
n=n+1
test.remove(test[0])
print(n)
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,592,494,845 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 139 | 0 | s1 = input();s2 = input();string = ""
for i in range(len(s1)):
if s1[i] == s2[i]:string += '0'
else:string += '1'
print(string) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
s1 = input();s2 = input();string = ""
for i in range(len(s1)):
if s1[i] == s2[i]:string += '0'
else:string += '1'
print(string)
``` | 3.96525 |
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.
More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.
Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"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": "100"
},
{
"input": "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "80"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1",
"output": "53"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "100"
},
{
"input": "3\n1 0 0",
"output": "2"
},
{
"input": "10\n1 1 0 0 0 1 1 0 0 0",
"output": "6"
},
{
"input": "90\n1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0",
"output": "52"
},
{
"input": "78\n0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0",
"output": "42"
},
{
"input": "4\n1 0 0 1",
"output": "3"
},
{
"input": "2\n0 1",
"output": "2"
},
{
"input": "5\n0 1 0 0 1",
"output": "4"
},
{
"input": "3\n1 0 1",
"output": "2"
},
{
"input": "3\n1 1 0",
"output": "2"
},
{
"input": "16\n1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 1",
"output": "9"
}
] | 1,508,058,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n = int(input())
games = str(input())
new_games = ""
for el in games:
if el != " ":
new_games += el
need = new_games
need_2 = new_games
checker_1 = 0
checker_2 = 0
a = new_games.rfind("0")
b = new_games.find("1")
for i,el in enumerate(new_games):
if i < a and el == "1":
need = need.replace("1","")
checker_1 = len(need)
for i,el in enumerate(new_games):
if i > b and el == "0":
need_2 = need_2.replace("0","")
checker_2 = len(need_2)
if checker_1 > checker_2:
print(checker_1)
else:
print(checker_2) | Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV.
More formally, you are given an array *s*1,<=*s*2,<=...,<=*s**n* of zeros and ones. Zero corresponds to an unsuccessful game, one — to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one.
Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV.
Input Specification:
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one.
Output Specification:
Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one.
Demo Input:
['4\n1 1 0 1\n', '6\n0 1 0 0 1 0\n', '1\n0\n']
Demo Output:
['3\n', '4\n', '1\n']
Note:
none | ```python
n = int(input())
games = str(input())
new_games = ""
for el in games:
if el != " ":
new_games += el
need = new_games
need_2 = new_games
checker_1 = 0
checker_2 = 0
a = new_games.rfind("0")
b = new_games.find("1")
for i,el in enumerate(new_games):
if i < a and el == "1":
need = need.replace("1","")
checker_1 = len(need)
for i,el in enumerate(new_games):
if i > b and el == "0":
need_2 = need_2.replace("0","")
checker_2 = len(need_2)
if checker_1 > checker_2:
print(checker_1)
else:
print(checker_2)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | 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}. | 0 | [
{
"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,671,096,220 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n, k = map(int,input().split())
st = set(map(int,input().split()))
cnt=0
tmpst=set()
for i in st:
if i*k in st:
if i not in tmpst:
tmpst.add(i)
print(len(st)-len(tmpst))
| Title: none
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
n, k = map(int,input().split())
st = set(map(int,input().split()))
cnt=0
tmpst=set()
for i in st:
if i*k in st:
if i not in tmpst:
tmpst.add(i)
print(len(st)-len(tmpst))
``` | 0 |
|
913 | A | Modular Exponentiation | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108). | Output a single integer — the value of . | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n"
] | [
"10\n",
"0\n",
"23456789\n"
] | In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | 500 | [
{
"input": "4\n42",
"output": "10"
},
{
"input": "1\n58",
"output": "0"
},
{
"input": "98765432\n23456789",
"output": "23456789"
},
{
"input": "8\n88127381",
"output": "149"
},
{
"input": "32\n92831989",
"output": "92831989"
},
{
"input": "92831989\n25",
"output": "25"
},
{
"input": "100000000\n100000000",
"output": "100000000"
},
{
"input": "7\n1234",
"output": "82"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n100000000",
"output": "0"
},
{
"input": "100000000\n1",
"output": "1"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n1",
"output": "1"
},
{
"input": "2\n2",
"output": "2"
},
{
"input": "2\n3",
"output": "3"
},
{
"input": "2\n4",
"output": "0"
},
{
"input": "2\n5",
"output": "1"
},
{
"input": "25\n33554432",
"output": "0"
},
{
"input": "26\n33554432",
"output": "33554432"
},
{
"input": "25\n67108864",
"output": "0"
},
{
"input": "26\n67108864",
"output": "0"
},
{
"input": "25\n92831989",
"output": "25723125"
},
{
"input": "26\n92831989",
"output": "25723125"
},
{
"input": "27\n92831989",
"output": "92831989"
},
{
"input": "29\n92831989",
"output": "92831989"
},
{
"input": "30\n92831989",
"output": "92831989"
},
{
"input": "31\n92831989",
"output": "92831989"
},
{
"input": "99812399\n93172892",
"output": "93172892"
},
{
"input": "67108864\n12345678",
"output": "12345678"
},
{
"input": "3\n98391849",
"output": "1"
},
{
"input": "13\n1231232",
"output": "2432"
},
{
"input": "18\n9842194",
"output": "142866"
},
{
"input": "24\n71237177",
"output": "4128313"
},
{
"input": "11\n65535",
"output": "2047"
},
{
"input": "11\n65536",
"output": "0"
},
{
"input": "12\n123",
"output": "123"
},
{
"input": "123456\n12",
"output": "12"
},
{
"input": "88\n888",
"output": "888"
},
{
"input": "888\n88",
"output": "88"
},
{
"input": "8888\n8888",
"output": "8888"
},
{
"input": "64\n128",
"output": "128"
},
{
"input": "128\n64",
"output": "64"
},
{
"input": "60\n9999999",
"output": "9999999"
},
{
"input": "200\n100000",
"output": "100000"
},
{
"input": "3\n8",
"output": "0"
},
{
"input": "10000000\n25024886",
"output": "25024886"
},
{
"input": "100\n100000",
"output": "100000"
},
{
"input": "99999999\n100000000",
"output": "100000000"
},
{
"input": "70\n12345678",
"output": "12345678"
}
] | 1,597,673,450 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 46,387,200 | x = int(input())
y = int(input())
result = y % 2 ** x
print(result) | Title: Modular Exponentiation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The following problem is well-known: given integers *n* and *m*, calculate
where 2*n*<==<=2·2·...·2 (*n* factors), and denotes the remainder of division of *x* by *y*.
You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=108).
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=108).
Output Specification:
Output a single integer — the value of .
Demo Input:
['4\n42\n', '1\n58\n', '98765432\n23456789\n']
Demo Output:
['10\n', '0\n', '23456789\n']
Note:
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10.
In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0. | ```python
x = int(input())
y = int(input())
result = y % 2 ** x
print(result)
``` | 0 |
|
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",
"output": "3"
},
{
"input": "1\n01",
"output": "1"
},
{
"input": "2\n01\n01",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "2"
},
{
"input": "3\n01\n01\n01",
"output": "1"
},
{
"input": "3\n10\n10\n01",
"output": "2"
},
{
"input": "3\n01\n10\n10",
"output": "2"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10",
"output": "55"
}
] | 1,699,016,498 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 278 | 8,704,000 | n=int(input())
m_o=[input() for _ in range(n)]
grp=1
for i in range(1,n):
if m_o[i]!=m_o[i-1]:
grp+=1
print(grp)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output Specification:
On the single line of the output print the number of groups of magnets.
Demo Input:
['6\n10\n10\n10\n01\n10\n10\n', '4\n01\n01\n10\n10\n']
Demo Output:
['3\n', '2\n']
Note:
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | ```python
n=int(input())
m_o=[input() for _ in range(n)]
grp=1
for i in range(1,n):
if m_o[i]!=m_o[i-1]:
grp+=1
print(grp)
``` | 3 |
|
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron",
"output": "256"
},
{
"input": "1\nTetrahedron",
"output": "4"
},
{
"input": "1\nCube",
"output": "6"
},
{
"input": "1\nOctahedron",
"output": "8"
},
{
"input": "1\nDodecahedron",
"output": "12"
},
{
"input": "1\nIcosahedron",
"output": "20"
},
{
"input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron",
"output": "340"
}
] | 1,690,249,748 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 1,512 | 9,523,200 | # LUOGU_RID: 117305460
n = int(input().strip())
ans = 0
while n:
n -= 1
q = input().strip()
if q == "Tetrahedron":
ans += 4
elif q == "Cube":
ans += 6
elif q == "Octahedron":
ans += 8
elif q == "Dodecahedron":
ans += 12
else:
ans += 20
print(ans) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output Specification:
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
Demo Input:
['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n']
Demo Output:
['42\n', '28\n']
Note:
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | ```python
# LUOGU_RID: 117305460
n = int(input().strip())
ans = 0
while n:
n -= 1
q = input().strip()
if q == "Tetrahedron":
ans += 4
elif q == "Cube":
ans += 6
elif q == "Octahedron":
ans += 8
elif q == "Dodecahedron":
ans += 12
else:
ans += 20
print(ans)
``` | 3 |
|
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2",
"output": "5\n7\n5\n5\n2\n7\n7\n13\n4"
},
{
"input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7",
"output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326"
},
{
"input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29",
"output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772"
},
{
"input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12",
"output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195"
},
{
"input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1",
"output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2"
},
{
"input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2",
"output": "6\n1\n6\n1\n5\n6\n1\n5"
},
{
"input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4",
"output": "22\n10\n10\n6\n12\n36\n6\n14\n16"
},
{
"input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4",
"output": "11\n11\n2\n10\n1\n3\n10\n12\n12"
},
{
"input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5",
"output": "8\n27\n1\n8\n26"
},
{
"input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8",
"output": "10\n2\n13\n10"
},
{
"input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5",
"output": "9\n24\n28"
},
{
"input": "1\n1\n2\n1 1 1\n2 1 1",
"output": "1\n1"
}
] | 1,635,543,623 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 6,656,000 | n = int(input())
costs = list(map(int, input().split(' ')))
crescent = costs.copy()
crescent.sort()
m = int(input())
for idx in range(m):
sum = 0
tlr = list(map(int, input().split(' ')))
if tlr[0] == 1:
for idx1 in range(tlr[1]-1,tlr[2]):
sum += costs[idx1]
else:
for idx1 in range(tlr[1]-1,tlr[2]):
sum += crescent[idx1]
print(sum)
| Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Output Specification:
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
Demo Input:
['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n']
Demo Output:
['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n']
Note:
Please note that the answers to the questions may overflow 32-bit integer type. | ```python
n = int(input())
costs = list(map(int, input().split(' ')))
crescent = costs.copy()
crescent.sort()
m = int(input())
for idx in range(m):
sum = 0
tlr = list(map(int, input().split(' ')))
if tlr[0] == 1:
for idx1 in range(tlr[1]-1,tlr[2]):
sum += costs[idx1]
else:
for idx1 in range(tlr[1]-1,tlr[2]):
sum += crescent[idx1]
print(sum)
``` | 0 |
|
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 1,496,514,580 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 16 | 124 | 0 | c=0
d=10
k=0
j=False
n,m = map(int,input().split())
for i in range(0,n):
a=[]
s = input()
a=list(map(int, s))
if a[0]==d:
c=0
print('NO')
break
else:
d=a[0]
for k in range(0, m-1):
if a[k]==a[k+1]:
c=c+1
else:
c=0
print('NO')
j=True
break
if(j):
break
if c!=0:
print('YES')
| Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input Specification:
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output Specification:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Demo Input:
['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
c=0
d=10
k=0
j=False
n,m = map(int,input().split())
for i in range(0,n):
a=[]
s = input()
a=list(map(int, s))
if a[0]==d:
c=0
print('NO')
break
else:
d=a[0]
for k in range(0, m-1):
if a[k]==a[k+1]:
c=c+1
else:
c=0
print('NO')
j=True
break
if(j):
break
if c!=0:
print('YES')
``` | 0 |
293 | C | Cube Problem | PROGRAMMING | 2,400 | [
"brute force",
"math",
"number theory"
] | null | null | Yaroslav, Andrey and Roman love playing cubes. Sometimes they get together and play cubes for hours and hours!
Today they got together again and they are playing cubes. Yaroslav took unit cubes and composed them into an *a*<=×<=*a*<=×<=*a* cube, Andrey made a *b*<=×<=*b*<=×<=*b* cube and Roman made a *c*<=×<=*c*<=×<=*c* cube. After that the game was finished and the guys left. But later, Vitaly entered the room. He saw the cubes and wanted to make a cube as well. But what size should the cube be? Of course it should be a large cube with the side of length *a*<=+<=*b*<=+<=*c*. Besides, Vitaly decided to decompose the cubes built by Yaroslav, Andrey and Roman and compose his own large cube out of them. However, it turned out that the unit cubes he got from destroying the three cubes just weren't enough to make a large cube. We know that Vitaly was short of exactly *n* cubes. Vitaly got upset, demolished everything and left. As he was leaving, he met Petya and told him that there had been three cubes in the room and that he needed another *n* unit cubes to make his own large cube.
Petya entered the room and saw the messily scattered cubes. He wanted to make it neat and orderly again. But he only knows that there had been three cubes, made of small unit cubes and that Vitaly needed *n* more unit cubes to make a large one! Help Petya understand, how many ways of sizes *a*, *b*, *c* are there to restore Yaroslav's, Andrey's and Roman's cubes. | The single line of the input contains integer *n* (1<=≤<=*n*<=≤<=1014). We know that all numbers *a*, *b*, *c* are positive integers.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | In the single line print the required number of ways. If it turns out that there isn't a single way of suitable sizes of *a*, *b*, *c*, print 0. | [
"24\n",
"648\n",
"5\n",
"93163582512000\n"
] | [
"1\n",
"7\n",
"0\n",
"39090\n"
] | none | 1,500 | [
{
"input": "24",
"output": "1"
},
{
"input": "648",
"output": "7"
},
{
"input": "5",
"output": "0"
},
{
"input": "93163582512000",
"output": "39090"
},
{
"input": "1260",
"output": "0"
},
{
"input": "1680",
"output": "0"
},
{
"input": "2520",
"output": "6"
},
{
"input": "1081080",
"output": "108"
},
{
"input": "110270160",
"output": "444"
},
{
"input": "1102701600",
"output": "1290"
},
{
"input": "97821761637600",
"output": "38298"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "12",
"output": "0"
},
{
"input": "24",
"output": "1"
},
{
"input": "36",
"output": "0"
},
{
"input": "48",
"output": "0"
},
{
"input": "60",
"output": "0"
},
{
"input": "120",
"output": "0"
},
{
"input": "180",
"output": "6"
},
{
"input": "128501493120",
"output": "5160"
},
{
"input": "146659312800",
"output": "5796"
},
{
"input": "160626866400",
"output": "5070"
},
{
"input": "240940299600",
"output": "5526"
},
{
"input": "293318625600",
"output": "8124"
},
{
"input": "321253732800",
"output": "7158"
},
{
"input": "481880599200",
"output": "8352"
},
{
"input": "642507465600",
"output": "9996"
},
{
"input": "963761198400",
"output": "11700"
},
{
"input": "1124388064800",
"output": "9222"
},
{
"input": "1606268664000",
"output": "11022"
},
{
"input": "1686582097200",
"output": "9918"
},
{
"input": "1927522396800",
"output": "15726"
},
{
"input": "2248776129600",
"output": "13146"
},
{
"input": "3212537328000",
"output": "15018"
},
{
"input": "3373164194400",
"output": "14892"
},
{
"input": "4497552259200",
"output": "17844"
},
{
"input": "6746328388800",
"output": "21318"
},
{
"input": "8995104518400",
"output": "23544"
},
{
"input": "9316358251200",
"output": "18222"
},
{
"input": "13492656777600",
"output": "29070"
},
{
"input": "18632716502400",
"output": "24822"
},
{
"input": "26985313555200",
"output": "37926"
},
{
"input": "27949074753600",
"output": "29556"
},
{
"input": "32607253879200",
"output": "23586"
},
{
"input": "46581791256000",
"output": "28422"
},
{
"input": "48910880818800",
"output": "25422"
},
{
"input": "55898149507200",
"output": "40080"
},
{
"input": "65214507758400",
"output": "34044"
},
{
"input": "100000000000000",
"output": "0"
},
{
"input": "30000000000000",
"output": "72"
},
{
"input": "90000000000000",
"output": "129"
},
{
"input": "128397219837",
"output": "0"
},
{
"input": "100000000000000",
"output": "0"
},
{
"input": "99999999999999",
"output": "0"
},
{
"input": "99999999999998",
"output": "0"
},
{
"input": "99999999999997",
"output": "0"
},
{
"input": "99999999999996",
"output": "0"
},
{
"input": "12121382",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "1000000009",
"output": "0"
},
{
"input": "1018081",
"output": "0"
}
] | 1,691,054,185 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <cmath>
#include <set>
#define get_an_ac ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int unsigned long long
using namespace std;
vector<int> getabc(int x, int y, int z) {
if ((x + y + z) % 2 != 0) return {-1, -1, -1};
int tong = (x + y + z) / 2;
return {tong - y, tong - z, tong - x};
}
signed main() {
get_an_ac
int n;
cin >> n;
if (n % 3 != 0) {
cout << 0 << endl;
return 0;
}
n /= 3;
int x = 2, ans = 0;
while (pow(x, 3) <= n) {
if (n % x == 0) {
for (int y = x; y <= sqrt(n / x); ++y) {
if ((n / x) % y == 0) {
int z = (n / x) / y;
vector<int> abc = getabc(x, y, z);
if (abc[0] > 0 && abc[1] > 0 && abc[2] > 0) {
int ln = set<int>(abc.begin(), abc.end()).size();
ans += ln * (ln + 1) / 2;
}
}
}
}
x += 1;
}
cout << ans << "\n";
return 0;
}
| Title: Cube Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav, Andrey and Roman love playing cubes. Sometimes they get together and play cubes for hours and hours!
Today they got together again and they are playing cubes. Yaroslav took unit cubes and composed them into an *a*<=×<=*a*<=×<=*a* cube, Andrey made a *b*<=×<=*b*<=×<=*b* cube and Roman made a *c*<=×<=*c*<=×<=*c* cube. After that the game was finished and the guys left. But later, Vitaly entered the room. He saw the cubes and wanted to make a cube as well. But what size should the cube be? Of course it should be a large cube with the side of length *a*<=+<=*b*<=+<=*c*. Besides, Vitaly decided to decompose the cubes built by Yaroslav, Andrey and Roman and compose his own large cube out of them. However, it turned out that the unit cubes he got from destroying the three cubes just weren't enough to make a large cube. We know that Vitaly was short of exactly *n* cubes. Vitaly got upset, demolished everything and left. As he was leaving, he met Petya and told him that there had been three cubes in the room and that he needed another *n* unit cubes to make his own large cube.
Petya entered the room and saw the messily scattered cubes. He wanted to make it neat and orderly again. But he only knows that there had been three cubes, made of small unit cubes and that Vitaly needed *n* more unit cubes to make a large one! Help Petya understand, how many ways of sizes *a*, *b*, *c* are there to restore Yaroslav's, Andrey's and Roman's cubes.
Input Specification:
The single line of the input contains integer *n* (1<=≤<=*n*<=≤<=1014). We know that all numbers *a*, *b*, *c* are positive integers.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
In the single line print the required number of ways. If it turns out that there isn't a single way of suitable sizes of *a*, *b*, *c*, print 0.
Demo Input:
['24\n', '648\n', '5\n', '93163582512000\n']
Demo Output:
['1\n', '7\n', '0\n', '39090\n']
Note:
none | ```python
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#define get_an_ac ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int unsigned long long
using namespace std;
vector<int> getabc(int x, int y, int z) {
if ((x + y + z) % 2 != 0) return {-1, -1, -1};
int tong = (x + y + z) / 2;
return {tong - y, tong - z, tong - x};
}
signed main() {
get_an_ac
int n;
cin >> n;
if (n % 3 != 0) {
cout << 0 << endl;
return 0;
}
n /= 3;
int x = 2, ans = 0;
while (pow(x, 3) <= n) {
if (n % x == 0) {
for (int y = x; y <= sqrt(n / x); ++y) {
if ((n / x) % y == 0) {
int z = (n / x) / y;
vector<int> abc = getabc(x, y, z);
if (abc[0] > 0 && abc[1] > 0 && abc[2] > 0) {
int ln = set<int>(abc.begin(), abc.end()).size();
ans += ln * (ln + 1) / 2;
}
}
}
}
x += 1;
}
cout << ans << "\n";
return 0;
}
``` | -1 |
|
388 | B | Fox and Minimal path | PROGRAMMING | 1,900 | [
"bitmasks",
"constructive algorithms",
"graphs",
"implementation",
"math"
] | null | null | Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with *n* vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."
Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to *k*? | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=109). | You should output a graph *G* with *n* vertexes (2<=≤<=*n*<=≤<=1000). There must be exactly *k* shortest paths between vertex 1 and vertex 2 of the graph.
The first line must contain an integer *n*. Then adjacency matrix *G* with *n* rows and *n* columns must follow. Each element of the matrix must be 'N' or 'Y'. If *G**ij* is 'Y', then graph *G* has a edge connecting vertex *i* and vertex *j*. Consider the graph vertexes are numbered from 1 to *n*.
The graph must be undirected and simple: *G**ii* = 'N' and *G**ij*<==<=*G**ji* must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them. | [
"2",
"9",
"1"
] | [
"4\nNNYY\nNNYY\nYYNN\nYYNN",
"8\nNNYYYNNN\nNNNNNYYY\nYNNNNYYY\nYNNNNYYY\nYNNNNYYY\nNYYYYNNN\nNYYYYNNN\nNYYYYNNN",
"2\nNY\nYN"
] | In first example, there are 2 shortest paths: 1-3-2 and 1-4-2.
In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2. | 1,000 | [
{
"input": "2",
"output": "498\nNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN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NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\nNNNNNN..."
}
] | 1,692,346,277 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | print("_RANDOM_GUESS_1692346277.3780437")# 1692346277.3780599 | Title: Fox and Minimal path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with *n* vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."
Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to *k*?
Input Specification:
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=109).
Output Specification:
You should output a graph *G* with *n* vertexes (2<=≤<=*n*<=≤<=1000). There must be exactly *k* shortest paths between vertex 1 and vertex 2 of the graph.
The first line must contain an integer *n*. Then adjacency matrix *G* with *n* rows and *n* columns must follow. Each element of the matrix must be 'N' or 'Y'. If *G**ij* is 'Y', then graph *G* has a edge connecting vertex *i* and vertex *j*. Consider the graph vertexes are numbered from 1 to *n*.
The graph must be undirected and simple: *G**ii* = 'N' and *G**ij*<==<=*G**ji* must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them.
Demo Input:
['2', '9', '1']
Demo Output:
['4\nNNYY\nNNYY\nYYNN\nYYNN', '8\nNNYYYNNN\nNNNNNYYY\nYNNNNYYY\nYNNNNYYY\nYNNNNYYY\nNYYYYNNN\nNYYYYNNN\nNYYYYNNN', '2\nNY\nYN']
Note:
In first example, there are 2 shortest paths: 1-3-2 and 1-4-2.
In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2. | ```python
print("_RANDOM_GUESS_1692346277.3780437")# 1692346277.3780599
``` | 0 |
|
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX",
"output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzF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WxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ"
},
{
"input": "P",
"output": "P"
},
{
"input": "Xyzzy",
"output": "Xyzzy"
},
{
"input": "Zzz",
"output": "Zzz"
},
{
"input": "Zp",
"output": "Zp"
}
] | 1,698,848,018 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n = input()
s = n.title()
print(s)
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input Specification:
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output Specification:
Output the given word after capitalization.
Demo Input:
['ApPLe\n', 'konjac\n']
Demo Output:
['ApPLe\n', 'Konjac\n']
Note:
none | ```python
n = input()
s = n.title()
print(s)
``` | 0 |
|
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1000000000 -1000000000\n1000000000 1000000000",
"output": "Yes"
},
{
"input": "23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-9 14\n-5 -3\n-6 -2\n-7 -11\n-4 -4\n-8 -5",
"output": "Yes"
},
{
"input": "4\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n1000000000 -1000000000",
"output": "No"
},
{
"input": "2\n-1000000000 1000000000\n-1000000000 -1000000000",
"output": "Yes"
},
{
"input": "5\n-1 -1\n-2 2\n2 2\n2 -2\n3 2",
"output": "No"
},
{
"input": "2\n1 0\n-1 0",
"output": "Yes"
},
{
"input": "4\n-1 1\n-1 2\n-1 3\n-1 4",
"output": "Yes"
},
{
"input": "2\n-1 0\n1 0",
"output": "Yes"
},
{
"input": "2\n1 2\n-1 2",
"output": "Yes"
},
{
"input": "2\n8 0\n7 0",
"output": "Yes"
},
{
"input": "6\n-1 0\n-2 0\n-1 -1\n-1 5\n1 0\n1 1",
"output": "No"
},
{
"input": "4\n1 0\n2 0\n-1 0\n-2 0",
"output": "No"
},
{
"input": "4\n-2 0\n-1 0\n1 0\n2 0",
"output": "No"
},
{
"input": "2\n1 1\n-1 1",
"output": "Yes"
},
{
"input": "4\n-1 0\n-2 0\n1 0\n2 0",
"output": "No"
},
{
"input": "2\n4 3\n-4 -2",
"output": "Yes"
},
{
"input": "4\n1 0\n2 0\n-1 1\n-1 2",
"output": "No"
},
{
"input": "5\n1 1\n2 1\n3 1\n-1 1\n-2 1",
"output": "No"
},
{
"input": "2\n1 1\n-1 -1",
"output": "Yes"
},
{
"input": "4\n1 2\n1 0\n1 -2\n-1 2",
"output": "Yes"
},
{
"input": "5\n-2 3\n-3 3\n4 2\n3 2\n1 2",
"output": "No"
},
{
"input": "3\n2 0\n3 0\n4 0",
"output": "Yes"
},
{
"input": "5\n-3 1\n-2 1\n-1 1\n1 1\n2 1",
"output": "No"
},
{
"input": "4\n-3 0\n1 0\n2 0\n3 0",
"output": "Yes"
},
{
"input": "2\n1 0\n-1 1",
"output": "Yes"
},
{
"input": "3\n-1 0\n1 0\n2 0",
"output": "Yes"
},
{
"input": "5\n1 0\n3 0\n-1 0\n-6 0\n-4 1",
"output": "No"
},
{
"input": "5\n-1 2\n-2 2\n-3 1\n1 2\n2 3",
"output": "No"
},
{
"input": "3\n1 0\n-1 0\n-2 0",
"output": "Yes"
},
{
"input": "4\n1 0\n2 0\n3 1\n4 1",
"output": "Yes"
},
{
"input": "4\n1 0\n1 2\n1 3\n-1 5",
"output": "Yes"
},
{
"input": "4\n2 2\n2 5\n-2 3\n-2 0",
"output": "No"
},
{
"input": "4\n1 1\n-1 1\n-1 0\n-1 -1",
"output": "Yes"
},
{
"input": "4\n2 0\n3 0\n-3 -3\n-3 -4",
"output": "No"
},
{
"input": "4\n-1 0\n-2 0\n-3 0\n-4 0",
"output": "Yes"
},
{
"input": "2\n-1 1\n1 1",
"output": "Yes"
},
{
"input": "5\n1 1\n2 2\n3 3\n-4 -4\n-5 -5",
"output": "No"
},
{
"input": "5\n2 0\n3 0\n4 0\n5 0\n6 0",
"output": "Yes"
},
{
"input": "2\n-1 2\n1 2",
"output": "Yes"
},
{
"input": "4\n1 1\n2 1\n-3 0\n-4 0",
"output": "No"
},
{
"input": "4\n-1 0\n-2 0\n3 0\n4 0",
"output": "No"
},
{
"input": "3\n3 0\n2 0\n1 0",
"output": "Yes"
},
{
"input": "4\n-2 0\n-3 0\n1 -1\n3 1",
"output": "No"
},
{
"input": "3\n-1 -1\n1 1\n2 2",
"output": "Yes"
},
{
"input": "4\n-2 0\n-1 0\n2 0\n1 0",
"output": "No"
},
{
"input": "2\n-3 5\n3 5",
"output": "Yes"
},
{
"input": "2\n-1 5\n1 5",
"output": "Yes"
},
{
"input": "4\n2 0\n3 0\n-2 0\n-3 0",
"output": "No"
},
{
"input": "3\n-1 1\n1 1\n1 -1",
"output": "Yes"
},
{
"input": "2\n1 0\n2 0",
"output": "Yes"
},
{
"input": "4\n-1 1\n-2 1\n2 -1\n3 -1",
"output": "No"
},
{
"input": "5\n1 0\n2 0\n3 0\n-1 0\n-2 0",
"output": "No"
},
{
"input": "4\n-3 0\n-4 0\n-5 0\n-6 0",
"output": "Yes"
},
{
"input": "6\n-3 0\n-2 0\n-1 0\n1 0\n2 0\n3 0",
"output": "No"
},
{
"input": "4\n5 0\n5 1\n6 0\n6 1",
"output": "Yes"
}
] | 1,655,543,292 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n = int(input())
xplus = 0
xminus = 0
for _ in range(n):
x, y = map(int, input().split())
if x > 0:
xplus += 1
else:
xminus += 1
if abs(xplus - xminus) == 1 or xplus == 0 or xminus == 0:
print('Yes')
else:
print('No')
| Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Output Specification:
Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower).
Demo Input:
['3\n1 1\n-1 -1\n2 -1\n', '4\n1 1\n2 2\n-1 1\n-2 2\n', '3\n1 2\n2 1\n4 60\n']
Demo Output:
['Yes', 'No', 'Yes']
Note:
In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | ```python
n = int(input())
xplus = 0
xminus = 0
for _ in range(n):
x, y = map(int, input().split())
if x > 0:
xplus += 1
else:
xminus += 1
if abs(xplus - xminus) == 1 or xplus == 0 or xminus == 0:
print('Yes')
else:
print('No')
``` | 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,695,800,172 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 5,632,000 | berry = int(input("What is the weight of the watermelon: "))
if ((berry / 2) % 2 == 0) and (berry > 2):
print("YES")
else:
print("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
berry = int(input("What is the weight of the watermelon: "))
if ((berry / 2) % 2 == 0) and (berry > 2):
print("YES")
else:
print("NO")
``` | 0 |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424",
"output": "64"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981",
"output": "15"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n-1 -1 0 1",
"output": "-1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1000000000",
"output": "0"
},
{
"input": "2\n1 -1",
"output": "-1"
},
{
"input": "2\n100 50",
"output": "50"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n606194955 -856471310 117647402",
"output": "117647402"
},
{
"input": "2\n615002717 -843553590",
"output": "-843553590"
},
{
"input": "2\n-1 2",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "5\n-638512131 348325781 -550537933 -618161835 -567935532",
"output": "-567935532"
},
{
"input": "1\n120",
"output": "120"
},
{
"input": "2\n-1000000000 1000000000",
"output": "-1000000000"
},
{
"input": "1\n618309368",
"output": "618309368"
}
] | 1,473,153,236 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 342 | 22,937,600 | n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if n % 2 == 0:
x = n // 2
else:
x = (n + 1) // 2
print(a[x-1])
| Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Output Specification:
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Demo Input:
['4\n1 2 3 4\n']
Demo Output:
['2\n']
Note:
none | ```python
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if n % 2 == 0:
x = n // 2
else:
x = (n + 1) // 2
print(a[x-1])
``` | 3 |
|
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally. | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"output": "Second"
},
{
"input": "1 1 1 1",
"output": "Second"
},
{
"input": "50 50 50 50",
"output": "Second"
},
{
"input": "50 49 1 2",
"output": "First"
},
{
"input": "50 48 3 1",
"output": "First"
},
{
"input": "48 50 12 11",
"output": "Second"
},
{
"input": "49 50 11 12",
"output": "Second"
},
{
"input": "49 49 4 1",
"output": "Second"
},
{
"input": "49 49 3 3",
"output": "Second"
},
{
"input": "1 50 1 50",
"output": "Second"
},
{
"input": "1 50 50 50",
"output": "Second"
},
{
"input": "50 1 1 1",
"output": "First"
},
{
"input": "50 1 1 50",
"output": "First"
},
{
"input": "32 31 10 9",
"output": "First"
},
{
"input": "32 4 17 3",
"output": "First"
}
] | 1,560,373,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | n1,n2,k1,k2=[int(x) for x in input("").split()]
if n2>=n1:
print("Second")
else:
print ("first") | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.
Input Specification:
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output Specification:
Output "First" if the first player wins and "Second" otherwise.
Demo Input:
['2 2 1 2\n', '2 1 1 1\n']
Demo Output:
['Second\n', 'First\n']
Note:
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | ```python
n1,n2,k1,k2=[int(x) for x in input("").split()]
if n2>=n1:
print("Second")
else:
print ("first")
``` | 0 |
|
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrbbrbbrbbbbrbbrrbbbrrbbbbrbrbbbbbbbbbbbbbbbbrrrrbbbbrrrbbbbbbbrbrrbrbbbbrrrbbbbrbbrbbbrb",
"output": "34"
},
{
"input": "166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb",
"output": "70"
},
{
"input": "1\nr",
"output": "0"
},
{
"input": "1\nb",
"output": "0"
},
{
"input": "2\nrb",
"output": "0"
},
{
"input": "2\nbr",
"output": "0"
},
{
"input": "2\nrr",
"output": "1"
},
{
"input": "2\nbb",
"output": "1"
},
{
"input": "8\nrbbrbrbr",
"output": "1"
},
{
"input": "7\nrrbrbrb",
"output": "1"
}
] | 1,474,652,923 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 249 | 716,800 | n = int(input())
s = list(input())
order = "rb"
data0 = sum(map(lambda x, y: order.index(x) == 0 and y % 2 == 0 , s, range(n)))
data1 = sum(map(lambda x, y: order.index(x) == 1 and y % 2 == 1 , s, range(n)))
count1 = max(data0, data1)
order = "br"
data0 = sum(map(lambda x, y: order.index(x) == 0 and y % 2 == 0 , s, range(n)))
data1 = sum(map(lambda x, y: order.index(x) == 1 and y % 2 == 1 , s, range(n)))
count2 = max(data0, data1)
print(min(count1, count2)) | Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output Specification:
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Demo Input:
['5\nrbbrr\n', '5\nbbbbb\n', '3\nrbr\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0. | ```python
n = int(input())
s = list(input())
order = "rb"
data0 = sum(map(lambda x, y: order.index(x) == 0 and y % 2 == 0 , s, range(n)))
data1 = sum(map(lambda x, y: order.index(x) == 1 and y % 2 == 1 , s, range(n)))
count1 = max(data0, data1)
order = "br"
data0 = sum(map(lambda x, y: order.index(x) == 0 and y % 2 == 0 , s, range(n)))
data1 = sum(map(lambda x, y: order.index(x) == 1 and y % 2 == 1 , s, range(n)))
count2 = max(data0, data1)
print(min(count1, count2))
``` | 3 |
|
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. | The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "499999999"
},
{
"input": "1924704072",
"output": "481176017"
},
{
"input": "73740586",
"output": "18435146"
},
{
"input": "1925088820",
"output": "481272204"
},
{
"input": "593070992",
"output": "148267747"
},
{
"input": "1925473570",
"output": "481368392"
},
{
"input": "629490186",
"output": "157372546"
},
{
"input": "1980649112",
"output": "495162277"
},
{
"input": "36661322",
"output": "9165330"
},
{
"input": "1943590793",
"output": "0"
},
{
"input": "71207034",
"output": "17801758"
},
{
"input": "1757577394",
"output": "439394348"
},
{
"input": "168305294",
"output": "42076323"
},
{
"input": "1934896224",
"output": "483724055"
},
{
"input": "297149088",
"output": "74287271"
},
{
"input": "1898001634",
"output": "474500408"
},
{
"input": "176409698",
"output": "44102424"
},
{
"input": "1873025522",
"output": "468256380"
},
{
"input": "5714762",
"output": "1428690"
},
{
"input": "1829551192",
"output": "457387797"
},
{
"input": "16269438",
"output": "4067359"
},
{
"input": "1663283390",
"output": "415820847"
},
{
"input": "42549941",
"output": "0"
},
{
"input": "1967345604",
"output": "491836400"
},
{
"input": "854000",
"output": "213499"
},
{
"input": "1995886626",
"output": "498971656"
},
{
"input": "10330019",
"output": "0"
},
{
"input": "1996193634",
"output": "499048408"
},
{
"input": "9605180",
"output": "2401294"
},
{
"input": "1996459740",
"output": "499114934"
},
{
"input": "32691948",
"output": "8172986"
},
{
"input": "1975903308",
"output": "493975826"
},
{
"input": "1976637136",
"output": "494159283"
},
{
"input": "29803038",
"output": "7450759"
},
{
"input": "1977979692",
"output": "494494922"
},
{
"input": "1978595336",
"output": "494648833"
},
{
"input": "27379344",
"output": "6844835"
},
{
"input": "1979729912",
"output": "494932477"
},
{
"input": "1980253780",
"output": "495063444"
},
{
"input": "1980751584",
"output": "495187895"
},
{
"input": "53224878",
"output": "13306219"
},
{
"input": "5",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "0"
},
{
"input": "10",
"output": "2"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "2"
},
{
"input": "13",
"output": "0"
},
{
"input": "14",
"output": "3"
},
{
"input": "15",
"output": "0"
},
{
"input": "16",
"output": "3"
},
{
"input": "17",
"output": "0"
},
{
"input": "18",
"output": "4"
},
{
"input": "19",
"output": "0"
},
{
"input": "21",
"output": "0"
},
{
"input": "22",
"output": "5"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "5"
},
{
"input": "25",
"output": "0"
},
{
"input": "26",
"output": "6"
},
{
"input": "27",
"output": "0"
},
{
"input": "28",
"output": "6"
},
{
"input": "29",
"output": "0"
},
{
"input": "30",
"output": "7"
},
{
"input": "111",
"output": "0"
},
{
"input": "55",
"output": "0"
},
{
"input": "105",
"output": "0"
},
{
"input": "199",
"output": "0"
},
{
"input": "151",
"output": "0"
}
] | 1,531,075,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | x=int(input())
if x==1:
print("0")
else:
print(round(x/4)-1) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
Output Specification:
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Demo Input:
['6\n', '20\n']
Demo Output:
['1\n', '4\n']
Note:
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | ```python
x=int(input())
if x==1:
print("0")
else:
print(round(x/4)-1)
``` | 0 |
|
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"output": "8"
},
{
"input": "31",
"output": "3"
},
{
"input": "59",
"output": "8"
},
{
"input": "79",
"output": "9"
},
{
"input": "7",
"output": "3"
},
{
"input": "55",
"output": "4"
},
{
"input": "40",
"output": "2"
},
{
"input": "719",
"output": "13"
},
{
"input": "847",
"output": "13"
},
{
"input": "225",
"output": "4"
},
{
"input": "4704",
"output": "51"
},
{
"input": "1132",
"output": "15"
},
{
"input": "7811",
"output": "80"
},
{
"input": "7981",
"output": "84"
},
{
"input": "82655",
"output": "830"
},
{
"input": "6364",
"output": "70"
},
{
"input": "74611",
"output": "748"
},
{
"input": "45391",
"output": "459"
},
{
"input": "620448",
"output": "6210"
},
{
"input": "265145",
"output": "2654"
},
{
"input": "671704",
"output": "6721"
},
{
"input": "365173",
"output": "3658"
},
{
"input": "7130872",
"output": "71314"
},
{
"input": "9628747",
"output": "96292"
},
{
"input": "8898399",
"output": "88993"
},
{
"input": "9497953",
"output": "94985"
},
{
"input": "19070947",
"output": "190714"
},
{
"input": "20185520",
"output": "201856"
},
{
"input": "91402248",
"output": "914028"
},
{
"input": "27035533",
"output": "270360"
},
{
"input": "22717528",
"output": "227180"
},
{
"input": "24403439",
"output": "244041"
},
{
"input": "163565555",
"output": "1635659"
},
{
"input": "152541908",
"output": "1525423"
},
{
"input": "668439837",
"output": "6684403"
},
{
"input": "20",
"output": "1"
},
{
"input": "999999999",
"output": "10000009"
},
{
"input": "10",
"output": "1"
},
{
"input": "7",
"output": "3"
},
{
"input": "6",
"output": "2"
},
{
"input": "99999999",
"output": "1000009"
},
{
"input": "1000001",
"output": "10001"
},
{
"input": "2521",
"output": "27"
}
] | 1,698,956,814 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | # https://codeforces.com/problemset/problem/996/A
n = int(input())
bills = [100, 20, 10, 5, 1]
i = 0
c = 0
while i < len(bills) and n > 0:
bill = bills[i]
while n >= bill:
n -= bill
c += 1
i += 1
print(c)
| Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
Input Specification:
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output Specification:
Output the minimum number of bills that Allen could receive.
Demo Input:
['125\n', '43\n', '1000000000\n']
Demo Output:
['3\n', '5\n', '10000000\n']
Note:
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen can withdraw $100000000$ (ten million!) $100$ dollar bills. | ```python
# https://codeforces.com/problemset/problem/996/A
n = int(input())
bills = [100, 20, 10, 5, 1]
i = 0
c = 0
while i < len(bills) and n > 0:
bill = bills[i]
while n >= bill:
n -= bill
c += 1
i += 1
print(c)
``` | 0 |
|
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,667,568,059 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 218 | 16,179,200 |
num = int(input())
directions = input()
positions = list(map(int, input().split(' ')))
count = positions[-1]
stop = True
for ind in range(num-1):
if(directions[ind]!=directions[ind+1]):
x = (positions[ind]-positions[ind+1])
if ( directions[ind]=='R'):
x *=-1
if(x>0 and x<=count):
stop = False
count =x
if(stop):
print(-1)
else:
print(count//2) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
num = int(input())
directions = input()
positions = list(map(int, input().split(' ')))
count = positions[-1]
stop = True
for ind in range(num-1):
if(directions[ind]!=directions[ind+1]):
x = (positions[ind]-positions[ind+1])
if ( directions[ind]=='R'):
x *=-1
if(x>0 and x<=count):
stop = False
count =x
if(stop):
print(-1)
else:
print(count//2)
``` | 3 |
|
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo. | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
{
"input": "8\n5 4 2 5 5 2 5 5",
"output": "1"
},
{
"input": "5\n5 5 2 5 5",
"output": "1"
},
{
"input": "6\n5 5 5 5 5 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "5"
},
{
"input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4",
"output": "40"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "4\n3 2 5 5",
"output": "1"
},
{
"input": "6\n4 3 3 3 3 4",
"output": "4"
},
{
"input": "8\n3 3 5 3 3 3 5 5",
"output": "3"
},
{
"input": "10\n2 4 5 5 5 5 2 3 3 2",
"output": "3"
},
{
"input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2",
"output": "10"
},
{
"input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4",
"output": "13"
},
{
"input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2",
"output": "15"
},
{
"input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5",
"output": "14"
},
{
"input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2",
"output": "33"
},
{
"input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4",
"output": "34"
},
{
"input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5",
"output": "16"
},
{
"input": "99\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",
"output": "83"
},
{
"input": "100\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 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2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2",
"output": "61"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "1"
},
{
"input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5",
"output": "35"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5",
"output": "1"
}
] | 1,609,999,996 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 155 | 0 | n = int(input())
a = list(map(int, input().strip().split()))
a.sort()
s = sum(a)
ans = 0
for i in range(n):
if 2 * s >= n * 9:
print(ans)
exit(0)
delta = 5 - a[i]
s += delta
ans += 1
print(ans)
| Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
Input Specification:
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output Specification:
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
Demo Input:
['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | ```python
n = int(input())
a = list(map(int, input().strip().split()))
a.sort()
s = sum(a)
ans = 0
for i in range(n):
if 2 * s >= n * 9:
print(ans)
exit(0)
delta = 5 - a[i]
s += delta
ans += 1
print(ans)
``` | 3 |
|
716 | B | Complete the Word | PROGRAMMING | 1,300 | [
"greedy",
"two pointers"
] | null | null | ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.
Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? | The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. | If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.
If there are multiple solutions, you may print any of them. | [
"ABC??FGHIJK???OPQR?TUVWXY?\n",
"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n",
"??????????????????????????\n",
"AABCDEFGHIJKLMNOPQRSTUVW??M\n"
] | [
"ABCDEFGHIJKLMNOPQRZTUVWXYS",
"-1",
"MNBVCXZLKJHGFDSAQPWOEIRUYT",
"-1"
] | In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.
In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1.
In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer. | 1,000 | [
{
"input": "ABC??FGHIJK???OPQR?TUVWXY?",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO",
"output": "-1"
},
{
"input": "??????????????????????????",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AABCDEFGHIJKLMNOPQRSTUVW??M",
"output": "-1"
},
{
"input": "QWERTYUIOPASDFGHJKL???????",
"output": "QWERTYUIOPASDFGHJKLBCMNVXZ"
},
{
"input": "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z",
"output": "ABABABBABAAAAAAAAAAAAABABABABAAAAAAAAAAAAABABABABADEFGHIMNOKLCSJBPQRTUVWXYZ"
},
{
"input": "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N",
"output": "QAEATAUAOAAADAGAJALAXAVAMMQBECTFUHOIAKDPGRJSLWXYVZN"
},
{
"input": "???????????????????????????",
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output": "-1"
},
{
"input": "BRTYNUVBBWMFDSRXAMLNSBIN???WDDQVPCSWGJTHLRAKTPFKGVLHAKNRIEYIDDRDZLLTBRKXRVRSPBSLXIZRRBEVMHJSAFPLZAIHFVTTEKDO?DYWKILEYRM?VHSEQCBYZZRZMICVZRYA?ONCSZOPGZUMIHJQJPIFX?YJMIERCMKTSFTDZIKEZPLDEOOCJLQIZ?RPHUEQHPNNSBRQRTDGLWNSCZ?WQVIZPTOETEXYI?DRQUOMREPUTOAJKFNBGYNWMGCAOELXEPLLZEYHTVLT?ETJJXLHJMAUDQESNQ?ZCGNDGI?JSGUXQV?QAWQIYKXBKCCSWNRTGHPZF?CSWDQSAZIWQNHOWHYAEZNXRMPAZEQQPPIBQQJEDHJEDHVXNEDETEN?ZHEPJJ?VVDYGPJUWGCBMB?ANFJHJXQVAJWCAZEZXZX?BACPPXORNENMCRMQPIYKNPHX?NSKGEABWWVLHQ?ESWLJUPQJSFIUEGMGHEYVLYEDWJG?L",
"output": "-1"
},
{
"input": "TESTEIGHTYFOUR",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "-1"
},
{
"input": "?????????????????????????",
"output": "-1"
},
{
"input": "Q?RYJPGLNQ",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRZTUVWXYS",
"output": "ABCDEFGHIJKLMNOPQRZTUVWXYS"
},
{
"input": "AACDEFGHIJKLMNOPQRZTUVWXYS",
"output": "-1"
},
{
"input": "ZA?ABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "ZAZABCDEFGHIJKLMNOPQRSTUVWXY"
},
{
"input": "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXYYYZABC",
"output": "-1"
},
{
"input": "????",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRZTUVWXYS??",
"output": "ABCDEFGHIJKLMNOPQRZTUVWXYSAA"
},
{
"input": "A",
"output": "-1"
},
{
"input": "NKBDABACEFGGGIJLLLLMMMOMPQWZSSRHHTTUWUWVXYY",
"output": "-1"
},
{
"input": "AA",
"output": "-1"
},
{
"input": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXA?CDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "???DEFGHIJKL??L?PQRSTUVW???",
"output": "-1"
},
{
"input": "?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A",
"output": "-1"
},
{
"input": "A?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA???????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????",
"output": "-1"
},
{
"input": "ZXXCVBNMLKJHGFDSAQWWERTYUIOP",
"output": "-1"
},
{
"input": "ABCA???????????????????????",
"output": "ABCADEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "AB",
"output": "-1"
},
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "BCDEFGHIAJKLMNOPQARSTUVWXYZ",
"output": "-1"
},
{
"input": "AABBCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "-1"
},
{
"input": "???AA????????????????????BB???",
"output": "-1"
},
{
"input": "ABC??FGAHIJ??MNOPQRST??WXYZ",
"output": "ABCDEFGAHIJKLMNOPQRSTUVWXYZ"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBN",
"output": "-1"
},
{
"input": "??????AAAAAAAAAAAAAAAAAAAABBBBB??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSFFFFFFF?????????DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??????WWWWWWWWWWEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRRRRRRHHHHHHHHHH?????",
"output": "-1"
}
] | 1,589,829,499 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 5 | 202 | 2,150,400 | if __name__ == "__main__":
word = str(input())
word = list(word)
dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i, c in enumerate(word):
if c == '?':
for s in dictionary:
if s not in word:
word[i] = s
break
freq = {chr(i): 1 for i in range(65, 65 + 26)}
if len(word) == 26:
if len(set(word)) == len(word):
word = ''.join(word)
print(word)
exit()
for i in range(0, len(word) - 26):
for j in range(i, i + 26):
if freq[word[j]] != 1:
break
else:
freq[word[j]] -= 1
if j == i + 26:
print(word)
exit()
print(-1)
| Title: Complete the Word
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.
Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
Input Specification:
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
Output Specification:
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.
If there are multiple solutions, you may print any of them.
Demo Input:
['ABC??FGHIJK???OPQR?TUVWXY?\n', 'WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n', '??????????????????????????\n', 'AABCDEFGHIJKLMNOPQRSTUVW??M\n']
Demo Output:
['ABCDEFGHIJKLMNOPQRZTUVWXYS', '-1', 'MNBVCXZLKJHGFDSAQPWOEIRUYT', '-1']
Note:
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.
In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1.
In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer. | ```python
if __name__ == "__main__":
word = str(input())
word = list(word)
dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i, c in enumerate(word):
if c == '?':
for s in dictionary:
if s not in word:
word[i] = s
break
freq = {chr(i): 1 for i in range(65, 65 + 26)}
if len(word) == 26:
if len(set(word)) == len(word):
word = ''.join(word)
print(word)
exit()
for i in range(0, len(word) - 26):
for j in range(i, i + 26):
if freq[word[j]] != 1:
break
else:
freq[word[j]] -= 1
if j == i + 26:
print(word)
exit()
print(-1)
``` | -1 |
|
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,660,057,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
data = list(map(int, input().split()))
intial_diff = abs(data[0] - data[1])
solders = [0, 1]
for i in range(len(data)):
for j in range(len(data)):
if i != j and abs(data[i] - data[j]) < intial_diff:
# print(data[i], data[j], i, j)
initial_diff = abs(data[i] - data[j])
solders = [i+1, j+1]
print(solders) | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n = int(input())
data = list(map(int, input().split()))
intial_diff = abs(data[0] - data[1])
solders = [0, 1]
for i in range(len(data)):
for j in range(len(data)):
if i != j and abs(data[i] - data[j]) < intial_diff:
# print(data[i], data[j], i, j)
initial_diff = abs(data[i] - data[j])
solders = [i+1, j+1]
print(solders)
``` | 0 |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order. | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 1,604,631,699 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | arr=[]
f,s='',''
for _ in range(int(input())):
temp=input()
arr.append(temp)
if temp[0]=='-':
s+=temp[1:]
else:
f+=temp
if s>f:
print('second')
elif f>s:
print('first')
else:
if arr[-1][0]=='-':
print('second')
else:
print('first') | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input Specification:
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
Output Specification:
If the first wrestler wins, print string "first", otherwise print "second"
Demo Input:
['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n']
Demo Output:
['second\n', 'first\n', 'second\n']
Note:
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | ```python
arr=[]
f,s='',''
for _ in range(int(input())):
temp=input()
arr.append(temp)
if temp[0]=='-':
s+=temp[1:]
else:
f+=temp
if s>f:
print('second')
elif f>s:
print('first')
else:
if arr[-1][0]=='-':
print('second')
else:
print('first')
``` | 0 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,697,814,283 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 |
s = input().strip()
count_1 = s.count('1')
count_2 = s.count('2')
count_3 = s.count('3')
new_sum = "+".join(['1' * count_1, '2' * count_2, '3' * count_3])
# Print the new sum
print(new_sum)
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
s = input().strip()
count_1 = s.count('1')
count_2 = s.count('2')
count_3 = s.count('3')
new_sum = "+".join(['1' * count_1, '2' * count_2, '3' * count_3])
# Print the new sum
print(new_sum)
``` | 0 |
|
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"output": "YES"
},
{
"input": "1\n999993399999",
"output": "NO"
},
{
"input": "9\n111 121 131 111 121 131 111 121 131",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n976197352729",
"output": "NO"
},
{
"input": "1\n1000000000000",
"output": "NO"
},
{
"input": "1\n9",
"output": "YES"
},
{
"input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n223092870 6469693230 200560490130",
"output": "NO\nNO\nNO"
},
{
"input": "2\n81 25",
"output": "NO\nYES"
},
{
"input": "1\n16",
"output": "NO"
},
{
"input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "1\n225",
"output": "NO"
},
{
"input": "1\n1521",
"output": "NO"
},
{
"input": "1\n81",
"output": "NO"
}
] | 1,697,876,325 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | n= int(input())
nums = list(input().split(' '))
for i in nums[0:n]:
total = 0
i = int(i)
for j in range(1,i+1):
if int(i)%j ==0:
total +=1
if total == 3:
print("YES")
else:
print("NO") | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
Input Specification:
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
Demo Input:
['3\n4 5 6\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | ```python
n= int(input())
nums = list(input().split(' '))
for i in nums[0:n]:
total = 0
i = int(i)
for j in range(1,i+1):
if int(i)%j ==0:
total +=1
if total == 3:
print("YES")
else:
print("NO")
``` | 0 |
|
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,679,567,188 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | word = input()
word_lenght = len(word)
for letter in word.split():
if word_lenght > 10:
first_letter = word[0]
last_letter = word[-1]
print(f'{first_letter}{word_lenght-2}{last_letter}')
else:
print(word)
| 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
word = input()
word_lenght = len(word)
for letter in word.split():
if word_lenght > 10:
first_letter = word[0]
last_letter = word[-1]
print(f'{first_letter}{word_lenght-2}{last_letter}')
else:
print(word)
``` | 0 |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,630,462,828 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 109 | 20,172,800 | from sys import stdin, stdout
def read():
return stdin.readline().rstrip()
def read_int():
return int(read())
def read_ints():
return list(map(int, read().split()))
def solve():
a=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
v=read_ints()
for j in range(3):
if v[j]%2==1:
for (nx, ny) in [(i,j),(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
if nx>=0 and ny>=0 and nx<3 and ny<3:
a[nx][ny]=1-a[nx][ny]
print("\n".join("".join(str(x) for x in v) for v in a))
solve()
| Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
from sys import stdin, stdout
def read():
return stdin.readline().rstrip()
def read_int():
return int(read())
def read_ints():
return list(map(int, read().split()))
def solve():
a=[[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
v=read_ints()
for j in range(3):
if v[j]%2==1:
for (nx, ny) in [(i,j),(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
if nx>=0 and ny>=0 and nx<3 and ny<3:
a[nx][ny]=1-a[nx][ny]
print("\n".join("".join(str(x) for x in v) for v in a))
solve()
``` | 3 |
|
767 | B | The Queue | PROGRAMMING | 2,100 | [
"brute force",
"greedy"
] | null | null | Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He knows that the receptionist starts working after *t**s* minutes have passed after midnight and closes after *t**f* minutes have passed after midnight (so that (*t**f*<=-<=1) is the last minute when the receptionist is still working). The receptionist spends exactly *t* minutes on each person in the queue. If the receptionist would stop working within *t* minutes, he stops serving visitors (other than the one he already serves).
Vasya also knows that exactly *n* visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.
For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.
Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him! | The first line contains three integers: the point of time when the receptionist begins to work *t**s*, the point of time when the receptionist stops working *t**f* and the time the receptionist spends on each visitor *t*. The second line contains one integer *n* — the amount of visitors (0<=≤<=*n*<=≤<=100<=000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.
All times are set in minutes and do not exceed 1012; it is guaranteed that *t**s*<=<<=*t**f*. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist. | Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them. | [
"10 15 2\n2\n10 13\n",
"8 17 3\n4\n3 4 5 8\n"
] | [
"12",
"2"
] | In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.
In the second example, Vasya has to come before anyone else to be served. | 1,250 | [
{
"input": "10 15 2\n2\n10 13",
"output": "12"
},
{
"input": "8 17 3\n4\n3 4 5 8",
"output": "2"
},
{
"input": "7 14 3\n2\n1 2",
"output": "0"
},
{
"input": "30 70 10\n3\n30 32 35",
"output": "60"
},
{
"input": "21 56 7\n5\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 1000000000 25\n20\n1 1 5 7 8 10 12 22 44 47 73 77 82 83 89 141 142 168 195 199",
"output": "510"
},
{
"input": "30 60 3\n10\n1 5 6 10 12 13 18 23 24 25",
"output": "4"
},
{
"input": "61 1000000000 13\n55\n29 72 85 94 103 123 125 144 147 153 154 184 189 192 212 234 247 265 292 296 299 304 309 365 378 379 393 401 414 417 421 427 439 441 480 500 509 515 522 539 571 582 623 630 634 635 643 649 654 679 680 686 747 748 775",
"output": "360"
},
{
"input": "117 120 3\n0",
"output": "117"
},
{
"input": "37 3813 32\n117\n1 1 4 5 6 8 10 13 13 16 18 19 20 23 30 32 33 38 49 59 66 69 96 157 160 183 205 292 301 320 349 360 370 372 384 400 410 413 423 434 434 445 451 463 464 490 494 496 497 517 528 532 556 572 607 647 668 689 708 729 748 806 819 879 905 905 915 925 928 931 959 970 1133 1146 1150 1156 1172 1189 1193 1218 1228 1233 1247 1297 1383 1447 1468 1512 1539 1550 1634 1635 1702 1836 1845 1866 1880 2068 2082 2143 2146 2167 2234 2239 2277 2331 2351 2432 2478 2592 2684 2863 2885 3043 3141 3258 3426",
"output": "3781"
},
{
"input": "100000000000 200000000000 10000000000\n10\n1 1 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000",
"output": "109999999999"
},
{
"input": "1 2 1\n0",
"output": "1"
},
{
"input": "50 230 10\n20\n50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240",
"output": "49"
},
{
"input": "100000000000 100000000005 2\n0",
"output": "100000000000"
},
{
"input": "333 500 5\n1\n3000",
"output": "333"
}
] | 1,650,467,195 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 8 | 77 | 3,379,200 | ts, tf, t = [int(value) for value in input().split()]
n = int(input())
a = [int(value) for value in input().split()]
menor_tempo = tf
ts_atual = ts
for i in a:
tempo_atual = ts_atual + t - (i - 1)
if tempo_atual < menor_tempo:
menor_tempo = tempo_atual
primeiro = i - 1
ts_atual += t
#primeiro = a[0] - 1
while ts < tf:
if len(a):
if a[0] > ts:
primeiro = ts
break
else:
ts += t
del a[0]
elif(tf - ts) >= t:
primeiro = ts
break
else:
break
print(primeiro) | Title: The Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He knows that the receptionist starts working after *t**s* minutes have passed after midnight and closes after *t**f* minutes have passed after midnight (so that (*t**f*<=-<=1) is the last minute when the receptionist is still working). The receptionist spends exactly *t* minutes on each person in the queue. If the receptionist would stop working within *t* minutes, he stops serving visitors (other than the one he already serves).
Vasya also knows that exactly *n* visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.
For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.
Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!
Input Specification:
The first line contains three integers: the point of time when the receptionist begins to work *t**s*, the point of time when the receptionist stops working *t**f* and the time the receptionist spends on each visitor *t*. The second line contains one integer *n* — the amount of visitors (0<=≤<=*n*<=≤<=100<=000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.
All times are set in minutes and do not exceed 1012; it is guaranteed that *t**s*<=<<=*t**f*. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.
Output Specification:
Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.
Demo Input:
['10 15 2\n2\n10 13\n', '8 17 3\n4\n3 4 5 8\n']
Demo Output:
['12', '2']
Note:
In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.
In the second example, Vasya has to come before anyone else to be served. | ```python
ts, tf, t = [int(value) for value in input().split()]
n = int(input())
a = [int(value) for value in input().split()]
menor_tempo = tf
ts_atual = ts
for i in a:
tempo_atual = ts_atual + t - (i - 1)
if tempo_atual < menor_tempo:
menor_tempo = tempo_atual
primeiro = i - 1
ts_atual += t
#primeiro = a[0] - 1
while ts < tf:
if len(a):
if a[0] > ts:
primeiro = ts
break
else:
ts += t
del a[0]
elif(tf - ts) >= t:
primeiro = ts
break
else:
break
print(primeiro)
``` | -1 |
|
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,538,317,360 | 760 | Python 3 | OK | TESTS | 31 | 124 | 0 | a,b = map(int,input().split())
y = [int(i) for i in input().split()]
g = {i for i in input().split()}
s = []
for i in range(a):
if str(y[i]) in g:
s.append(y[i])
for i in range(len(s)):
print(s[i],end=' ') | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
a,b = map(int,input().split())
y = [int(i) for i in input().split()]
g = {i for i in input().split()}
s = []
for i in range(a):
if str(y[i]) in g:
s.append(y[i])
for i in range(len(s)):
print(s[i],end=' ')
``` | 3 |
|
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson? | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "1000 700",
"output": "6"
},
{
"input": "959986566087 524054155168",
"output": "90"
},
{
"input": "4 3",
"output": "4"
},
{
"input": "7 6",
"output": "7"
},
{
"input": "1000 999",
"output": "1000"
},
{
"input": "1000 998",
"output": "500"
},
{
"input": "1000 997",
"output": "336"
},
{
"input": "42 1",
"output": "42"
},
{
"input": "1000 1",
"output": "1000"
},
{
"input": "8 5",
"output": "5"
},
{
"input": "13 8",
"output": "6"
},
{
"input": "987 610",
"output": "15"
},
{
"input": "442 42",
"output": "22"
},
{
"input": "754 466",
"output": "13"
},
{
"input": "1000000000000 999999999999",
"output": "1000000000000"
},
{
"input": "1000000000000 999999999998",
"output": "500000000000"
},
{
"input": "941 14",
"output": "74"
},
{
"input": "998 2",
"output": "499"
},
{
"input": "1000 42",
"output": "32"
},
{
"input": "1000 17",
"output": "66"
},
{
"input": "5 1",
"output": "5"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "5 3",
"output": "4"
},
{
"input": "5 4",
"output": "5"
},
{
"input": "293 210",
"output": "17"
},
{
"input": "787878787878 424242424242",
"output": "8"
},
{
"input": "956722026041 591286729879",
"output": "58"
},
{
"input": "956722026041 365435296162",
"output": "58"
},
{
"input": "628625247282 464807889701",
"output": "102"
},
{
"input": "695928431619 424778620208",
"output": "167"
},
{
"input": "1000000000000 42",
"output": "23809523821"
},
{
"input": "987654345678 23",
"output": "42941493300"
},
{
"input": "10000000001 2",
"output": "5000000002"
},
{
"input": "1000000000000 2",
"output": "500000000000"
},
{
"input": "1000000000000 3",
"output": "333333333336"
},
{
"input": "100000000000 3",
"output": "33333333336"
},
{
"input": "100000000000 23",
"output": "4347826109"
},
{
"input": "999999999997 7",
"output": "142857142861"
},
{
"input": "8589934592 4294967296",
"output": "2"
}
] | 1,593,676,271 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 37 | 2,000 | 0 | a,b=[int(x) for x in input().split()]
k=0
while a!=b:
if a%b==0:
k+=a//b
break
elif b%a==0:
k+=b//a
break
elif a>b:
a=a-b
k+=1
else:
b=b-a
k+=1
print(k)
| Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=×<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input Specification:
The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper.
Output Specification:
Print a single integer — the number of ships that Vasya will make.
Demo Input:
['2 1\n', '10 7\n', '1000000000000 1\n']
Demo Output:
['2\n', '6\n', '1000000000000\n']
Note:
Pictures to the first and second sample test. | ```python
a,b=[int(x) for x in input().split()]
k=0
while a!=b:
if a%b==0:
k+=a//b
break
elif b%a==0:
k+=b//a
break
elif a>b:
a=a-b
k+=1
else:
b=b-a
k+=1
print(k)
``` | 0 |
|
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "14"
},
{
"input": "5 5\n3 2 1 0 0",
"output": "3"
},
{
"input": "8 6\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 7\n10 9 8 7 7 7 5 5",
"output": "8"
},
{
"input": "8 4\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 3\n10 9 8 7 7 7 5 5",
"output": "3"
},
{
"input": "8 1\n10 9 8 7 7 7 5 5",
"output": "1"
},
{
"input": "8 2\n10 9 8 7 7 7 5 5",
"output": "2"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "50 25\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "26"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "11 5\n100 99 98 97 96 95 94 93 92 91 90",
"output": "5"
},
{
"input": "10 4\n100 81 70 69 64 43 34 29 15 3",
"output": "4"
},
{
"input": "11 6\n87 71 62 52 46 46 43 35 32 25 12",
"output": "6"
},
{
"input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2",
"output": "12"
},
{
"input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2",
"output": "3"
},
{
"input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5",
"output": "12"
},
{
"input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1",
"output": "9"
},
{
"input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0",
"output": "29"
},
{
"input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4",
"output": "34"
},
{
"input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4",
"output": "44"
},
{
"input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3",
"output": "13"
},
{
"input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3",
"output": "30"
},
{
"input": "2 1\n10 10",
"output": "2"
},
{
"input": "2 2\n10 10",
"output": "2"
},
{
"input": "2 2\n10 0",
"output": "1"
},
{
"input": "2 2\n10 1",
"output": "2"
},
{
"input": "2 1\n10 0",
"output": "1"
},
{
"input": "2 1\n10 2",
"output": "1"
},
{
"input": "50 13\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "50 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "10 1\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 2\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 3\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 4\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 5\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 6\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 7\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 8\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 9\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 10\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
}
] | 1,699,033,293 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | n, k = map(int, input().split())
scores = list(map(int, input().split()))
t = 0
min_score = scores[k-1]
for s in scores:
if s >= min_score and s > 0:
t += 1
print(t)
| Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output Specification:
Output the number of participants who advance to the next round.
Demo Input:
['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n']
Demo Output:
['6\n', '0\n']
Note:
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | ```python
n, k = map(int, input().split())
scores = list(map(int, input().split()))
t = 0
min_score = scores[k-1]
for s in scores:
if s >= min_score and s > 0:
t += 1
print(t)
``` | 3 |
|
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,610,083,488 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 405 | 15,974,400 | n = int(input())
s = input()
x = [int(x) for x in input().split()]
a = [0 for x in range(n)]
a[-1]=-1
for i in range(len(a)-2,-1,-1):
if s[i+1]=='L':
a[i]=i+1
else:
a[i]=a[i+1]
mini = float('inf')
flag = False
for i in range(len(x)):
if s[i]=='R' and a[i]!=-1:
mini = min(mini, x[a[i]]-x[i])
flag = True
if not flag:
print(-1)
else:
print(mini//2) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
n = int(input())
s = input()
x = [int(x) for x in input().split()]
a = [0 for x in range(n)]
a[-1]=-1
for i in range(len(a)-2,-1,-1):
if s[i+1]=='L':
a[i]=i+1
else:
a[i]=a[i+1]
mini = float('inf')
flag = False
for i in range(len(x)):
if s[i]=='R' and a[i]!=-1:
mini = min(mini, x[a[i]]-x[i])
flag = True
if not flag:
print(-1)
else:
print(mini//2)
``` | 3 |
|
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"output": "50"
},
{
"input": "50 250",
"output": "0"
},
{
"input": "29 116",
"output": "0"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "46 127",
"output": "11"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "36 99",
"output": "9"
},
{
"input": "45 104",
"output": "31"
},
{
"input": "13 57",
"output": "0"
},
{
"input": "25 106",
"output": "0"
},
{
"input": "8 19",
"output": "5"
},
{
"input": "20 69",
"output": "0"
},
{
"input": "13 32",
"output": "7"
},
{
"input": "47 128",
"output": "13"
},
{
"input": "17 73",
"output": "0"
},
{
"input": "3 7",
"output": "2"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "38 137",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "1 5",
"output": "0"
},
{
"input": "36 155",
"output": "0"
},
{
"input": "5 15",
"output": "0"
},
{
"input": "27 75",
"output": "6"
},
{
"input": "21 73",
"output": "0"
},
{
"input": "2 5",
"output": "1"
},
{
"input": "49 177",
"output": "0"
},
{
"input": "7 20",
"output": "1"
},
{
"input": "44 173",
"output": "0"
},
{
"input": "49 219",
"output": "0"
},
{
"input": "16 70",
"output": "0"
},
{
"input": "10 28",
"output": "2"
}
] | 1,693,844,420 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 92 | 0 | n, k = map(int, input().split())
print(max(3*n-k, 0)) | Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*.
Input Specification:
The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*.
Output Specification:
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*.
Demo Input:
['4 8\n', '4 10\n', '1 3\n']
Demo Output:
['4\n', '2\n', '0\n']
Note:
In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | ```python
n, k = map(int, input().split())
print(max(3*n-k, 0))
``` | 3 |
|
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,697,618,299 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 217 | 9,011,200 | n=int(input())
x=[]
h=[]
for i in range(n):
xi,hi=map(int,input().split())
x.append(xi)
h.append(hi)
cut=2
for i in range(1,n-1):
if x[i]-h[i]>x[i-1]:
cut+=1
elif x[i]+h[i]<x[i+1]:
cut+=1
x[i]=x[i]+h[i]
print(cut) | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | ```python
n=int(input())
x=[]
h=[]
for i in range(n):
xi,hi=map(int,input().split())
x.append(xi)
h.append(hi)
cut=2
for i in range(1,n-1):
if x[i]-h[i]>x[i-1]:
cut+=1
elif x[i]+h[i]<x[i+1]:
cut+=1
x[i]=x[i]+h[i]
print(cut)
``` | 0 |
|
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 1,690,042,543 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | a=int(input())
while True:
a+=1
if len(set(str(a)))==len(str(a)):
print(a)
break | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input Specification:
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Output Specification:
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
Demo Input:
['1987\n', '2013\n']
Demo Output:
['2013\n', '2014\n']
Note:
none | ```python
a=int(input())
while True:
a+=1
if len(set(str(a)))==len(str(a)):
print(a)
break
``` | 3 |
|
29 | C | Mail Stamps | PROGRAMMING | 1,700 | [
"data structures",
"dfs and similar",
"graphs",
"implementation"
] | C. Mail Stamps | 2 | 256 | One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately.
There are *n* stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of mail stamps on the envelope. Then there follow *n* lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city. | Output *n*<=+<=1 numbers — indexes of cities in one of the two possible routes of the letter. | [
"2\n1 100\n100 2\n",
"3\n3 1\n100 2\n3 2\n"
] | [
"2 100 1 ",
"100 2 3 1 "
] | none | 1,500 | [
{
"input": "2\n1 100\n100 2",
"output": "2 100 1 "
},
{
"input": "3\n3 1\n100 2\n3 2",
"output": "100 2 3 1 "
},
{
"input": "3\n458744979 589655889\n248228386 824699605\n458744979 824699605",
"output": "589655889 458744979 824699605 248228386 "
},
{
"input": "4\n90104473 221011623\n18773664 221011623\n90104473 74427905\n74427905 186329050",
"output": "186329050 74427905 90104473 221011623 18773664 "
},
{
"input": "5\n695442143 421284135\n641835294 542627184\n852367357 120042890\n641835294 852367357\n542627184 421284135",
"output": "695442143 421284135 542627184 641835294 852367357 120042890 "
},
{
"input": "6\n264896923 2497658\n57071588 447086061\n2497658 483723090\n57071588 264896923\n158310110 483723090\n158310110 72866107",
"output": "447086061 57071588 264896923 2497658 483723090 158310110 72866107 "
},
{
"input": "1\n1 1000000000",
"output": "1000000000 1 "
},
{
"input": "1\n1000000000 999999999",
"output": "1000000000 999999999 "
},
{
"input": "10\n661239801 721746596\n225324231 116454751\n687002568 865423160\n799202882 865423160\n661239801 116454751\n387882517 687002568\n748798833 721746596\n179630172 225324231\n945958362 387882517\n179630172 945958362",
"output": "799202882 865423160 687002568 387882517 945958362 179630172 225324231 116454751 661239801 721746596 748798833 "
},
{
"input": "21\n280810160 291988863\n760364563 140163983\n16417017 364832782\n400253359 677358550\n597688496 794948223\n400253359 603304541\n589408417 603304541\n385039298 307729574\n293170375 805849550\n140163983 219301181\n732214548 760364563\n307729574 280810160\n131915938 219301181\n4615652 347722938\n396478457 805849550\n16417017 732214548\n4615652 677358550\n131915938 589408417\n291988863 364832782\n396478457 794948223\n385039298 597688496",
"output": "347722938 4615652 677358550 400253359 603304541 589408417 131915938 219301181 140163983 760364563 732214548 16417017 364832782 291988863 280810160 307729574 385039298 597688496 794948223 396478457 805849550 293170375 "
},
{
"input": "1\n2105127 227379126",
"output": "227379126 2105127 "
}
] | 1,615,519,075 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 1,154 | 20,992,000 | import sys
from collections import deque
input = sys.stdin.readline
g={}
v=set()
for _ in range(int(input())):
a,b=[int(x) for x in input().split()]
if a in v:
v.remove(a)
else:
v.add(a)
if b in v:
v.remove(b)
else:
v.add(b)
if a in g:
g[a].append(b)
else:
g[a]=[b]
if b in g:
g[b].append(a)
else:
g[b]=[a]
#g[b]=a
ans=[]
for i in v:
q=deque([[i,-1]])
while q:
curr,par=q.popleft()
ans.append(curr)
for i in g[curr]:
if i!=par:
q.append([i,curr])
break
print(*ans) | Title: Mail Stamps
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately.
There are *n* stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of mail stamps on the envelope. Then there follow *n* lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city.
Output Specification:
Output *n*<=+<=1 numbers — indexes of cities in one of the two possible routes of the letter.
Demo Input:
['2\n1 100\n100 2\n', '3\n3 1\n100 2\n3 2\n']
Demo Output:
['2 100 1 ', '100 2 3 1 ']
Note:
none | ```python
import sys
from collections import deque
input = sys.stdin.readline
g={}
v=set()
for _ in range(int(input())):
a,b=[int(x) for x in input().split()]
if a in v:
v.remove(a)
else:
v.add(a)
if b in v:
v.remove(b)
else:
v.add(b)
if a in g:
g[a].append(b)
else:
g[a]=[b]
if b in g:
g[b].append(a)
else:
g[b]=[a]
#g[b]=a
ans=[]
for i in v:
q=deque([[i,-1]])
while q:
curr,par=q.popleft()
ans.append(curr)
for i in g[curr]:
if i!=par:
q.append([i,curr])
break
print(*ans)
``` | 3.672399 |
990 | D | Graph And Its Complement | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edges from a vertex to itself) are not allowed. It can be at most one edge between a pair of vertices.
The adjacency matrix of an undirected graph is a square matrix of size $n$ consisting only of "0" and "1", where $n$ is the number of vertices of the graph and the $i$-th row and the $i$-th column correspond to the $i$-th vertex of the graph. The cell $(i,j)$ of the adjacency matrix contains $1$ if and only if the $i$-th and $j$-th vertices in the graph are connected by an edge.
A connected component is a set of vertices $X$ such that for every two vertices from this set there exists at least one path in the graph connecting this pair of vertices, but adding any other vertex to $X$ violates this rule.
The complement or inverse of a graph $G$ is a graph $H$ on the same vertices such that two distinct vertices of $H$ are adjacent if and only if they are not adjacent in $G$. | In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement. | If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$ in $G$ (and $0$ otherwise). Note that the matrix must be symmetric, and all digits on the main diagonal must be zeroes.
If there are several matrices that satisfy the conditions — output any of them. | [
"3 1 2\n",
"3 3 3\n"
] | [
"YES\n001\n001\n110\n",
"NO\n"
] | none | 0 | [
{
"input": "3 1 2",
"output": "YES\n001\n001\n110"
},
{
"input": "3 3 3",
"output": "NO"
},
{
"input": "5 1 1",
"output": "YES\n01000\n10100\n01010\n00101\n00010"
},
{
"input": "123 1 84",
"output": "YES\n001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n100011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n110001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n111000..."
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "1 1 1",
"output": "YES\n0"
},
{
"input": "3 1 1",
"output": "NO"
},
{
"input": "5 2 2",
"output": "NO"
},
{
"input": "1000 734 1",
"output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1000 1 1000",
"output": "YES\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111..."
},
{
"input": "1000 1 1",
"output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "4 1 1",
"output": "YES\n0100\n1010\n0101\n0010"
},
{
"input": "4 4 1",
"output": "YES\n0000\n0000\n0000\n0000"
},
{
"input": "3 1 3",
"output": "YES\n011\n101\n110"
},
{
"input": "2 1 2",
"output": "YES\n01\n10"
},
{
"input": "101 1 1",
"output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n10100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n01010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "102 1 1",
"output": "YES\n010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "103 1 1",
"output": "YES\n0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00010100000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "104 1 1",
"output": "YES\n01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n10100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n01010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n00101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0001010000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "6 1 1",
"output": "YES\n010000\n101000\n010100\n001010\n000101\n000010"
},
{
"input": "3 2 1",
"output": "YES\n010\n100\n000"
},
{
"input": "5 1 2",
"output": "YES\n00111\n00011\n10001\n11001\n11110"
},
{
"input": "4 1 2",
"output": "YES\n0011\n0001\n1001\n1110"
},
{
"input": "2 2 1",
"output": "YES\n00\n00"
},
{
"input": "3 3 1",
"output": "YES\n000\n000\n000"
},
{
"input": "2 2 2",
"output": "NO"
},
{
"input": "1 1 1",
"output": "YES\n0"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "2 1 2",
"output": "YES\n01\n10"
},
{
"input": "2 2 1",
"output": "YES\n00\n00"
},
{
"input": "2 2 2",
"output": "NO"
},
{
"input": "3 1 1",
"output": "NO"
},
{
"input": "3 1 2",
"output": "YES\n001\n001\n110"
},
{
"input": "3 1 3",
"output": "YES\n011\n101\n110"
},
{
"input": "3 2 1",
"output": "YES\n010\n100\n000"
},
{
"input": "3 2 2",
"output": "NO"
},
{
"input": "3 2 3",
"output": "NO"
},
{
"input": "3 3 1",
"output": "YES\n000\n000\n000"
},
{
"input": "3 3 2",
"output": "NO"
},
{
"input": "3 3 3",
"output": "NO"
},
{
"input": "4 1 1",
"output": "YES\n0100\n1010\n0101\n0010"
},
{
"input": "4 1 2",
"output": "YES\n0011\n0001\n1001\n1110"
},
{
"input": "4 1 3",
"output": "YES\n0011\n0011\n1101\n1110"
},
{
"input": "4 1 4",
"output": "YES\n0111\n1011\n1101\n1110"
},
{
"input": "4 2 1",
"output": "YES\n0100\n1010\n0100\n0000"
},
{
"input": "4 2 2",
"output": "NO"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "4 2 4",
"output": "NO"
},
{
"input": "4 3 1",
"output": "YES\n0100\n1000\n0000\n0000"
},
{
"input": "4 3 2",
"output": "NO"
},
{
"input": "4 3 3",
"output": "NO"
},
{
"input": "4 3 4",
"output": "NO"
},
{
"input": "4 4 1",
"output": "YES\n0000\n0000\n0000\n0000"
},
{
"input": "4 4 2",
"output": "NO"
},
{
"input": "4 4 3",
"output": "NO"
},
{
"input": "4 4 4",
"output": "NO"
}
] | 1,606,051,011 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
#define w(x) int x; cin>>x; while(x--)
#define nl "\n"
#define fr(i,t) for(int i=0;i<t;i++)
#define fr1(i,a,b) for(int i = a; i<b; i++)
#define frr(i,n) for(int i = n; i>=0; i--)
#define frr1(i,a,b) for(int i = a; i>=b; i--)
#define dbug(x) cout<<#x<<"="<<x<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define ll long long int
// int -10**9 to 10**9 4 byte -2**31 to +2**31 -2147483647 to +2147483648
// long long int -10**19 to 10**19 8 byte -2**63 to +2**63
// unsigned long long int -0 to 10**20 8 byte 0 to +2**64
// log(10 ** 5) 16.60
// log(10 ** 6) 19.93
// log(10 ** 9) 29.89
// INT_MAX 0x7fffffff 2147483647
const int M1 = 1000000007;
const int M2 = 998244353;
const int N = 1005;
int mat[N][N];
int main(){
fast;
int n,m,k,a,b,temp;
bool ok = true;
cin>>n>>a>>b;
if(a==1){
if(b==1){
int i = 1;
fr1(j,2,n+1){
mat[i][j] = mat[j][i] = 1;
i++;
}
}
else{
int i = 1;
int j = 2;
while(b!=1){
int jj = j;
fr1(x,jj,n+1){
mat[i][x] = mat[x][i] = 1;
}
j++;
i++;
b--;
}
}
}
else{
if(b==1){
int i = 1;
fr1(j,2,a+1){
mat[i][j] = mat[j][i] = 1;
i++;
}
}
else{
ok = false;
}
}
if(ok){
cout<<"YES"<<nl;
fr1(i,1,n+1){
fr1(j,1,n+1){
cout<<mat[i][j];
}
cout<<nl;
}
}
else{
cout<<"NO"<<nl;
}
} | Title: Graph And Its Complement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on the main diagonal must be zeroes.
In an undirected graph loops (edges from a vertex to itself) are not allowed. It can be at most one edge between a pair of vertices.
The adjacency matrix of an undirected graph is a square matrix of size $n$ consisting only of "0" and "1", where $n$ is the number of vertices of the graph and the $i$-th row and the $i$-th column correspond to the $i$-th vertex of the graph. The cell $(i,j)$ of the adjacency matrix contains $1$ if and only if the $i$-th and $j$-th vertices in the graph are connected by an edge.
A connected component is a set of vertices $X$ such that for every two vertices from this set there exists at least one path in the graph connecting this pair of vertices, but adding any other vertex to $X$ violates this rule.
The complement or inverse of a graph $G$ is a graph $H$ on the same vertices such that two distinct vertices of $H$ are adjacent if and only if they are not adjacent in $G$.
Input Specification:
In a single line, three numbers are given $n, a, b \,(1 \le n \le 1000, 1 \le a, b \le n)$: is the number of vertexes of the graph, the required number of connectivity components in it, and the required amount of the connectivity component in it's complement.
Output Specification:
If there is no graph that satisfies these constraints on a single line, print "NO" (without quotes).
Otherwise, on the first line, print "YES"(without quotes). In each of the next $n$ lines, output $n$ digits such that $j$-th digit of $i$-th line must be $1$ if and only if there is an edge between vertices $i$ and $j$ in $G$ (and $0$ otherwise). Note that the matrix must be symmetric, and all digits on the main diagonal must be zeroes.
If there are several matrices that satisfy the conditions — output any of them.
Demo Input:
['3 1 2\n', '3 3 3\n']
Demo Output:
['YES\n001\n001\n110\n', 'NO\n']
Note:
none | ```python
#include<bits/stdc++.h>
using namespace std;
#define w(x) int x; cin>>x; while(x--)
#define nl "\n"
#define fr(i,t) for(int i=0;i<t;i++)
#define fr1(i,a,b) for(int i = a; i<b; i++)
#define frr(i,n) for(int i = n; i>=0; i--)
#define frr1(i,a,b) for(int i = a; i>=b; i--)
#define dbug(x) cout<<#x<<"="<<x<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define ll long long int
// int -10**9 to 10**9 4 byte -2**31 to +2**31 -2147483647 to +2147483648
// long long int -10**19 to 10**19 8 byte -2**63 to +2**63
// unsigned long long int -0 to 10**20 8 byte 0 to +2**64
// log(10 ** 5) 16.60
// log(10 ** 6) 19.93
// log(10 ** 9) 29.89
// INT_MAX 0x7fffffff 2147483647
const int M1 = 1000000007;
const int M2 = 998244353;
const int N = 1005;
int mat[N][N];
int main(){
fast;
int n,m,k,a,b,temp;
bool ok = true;
cin>>n>>a>>b;
if(a==1){
if(b==1){
int i = 1;
fr1(j,2,n+1){
mat[i][j] = mat[j][i] = 1;
i++;
}
}
else{
int i = 1;
int j = 2;
while(b!=1){
int jj = j;
fr1(x,jj,n+1){
mat[i][x] = mat[x][i] = 1;
}
j++;
i++;
b--;
}
}
}
else{
if(b==1){
int i = 1;
fr1(j,2,a+1){
mat[i][j] = mat[j][i] = 1;
i++;
}
}
else{
ok = false;
}
}
if(ok){
cout<<"YES"<<nl;
fr1(i,1,n+1){
fr1(j,1,n+1){
cout<<mat[i][j];
}
cout<<nl;
}
}
else{
cout<<"NO"<<nl;
}
}
``` | -1 |
|
779 | C | Dishonest Sellers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items. | In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week). | Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. | [
"3 1\n5 4 6\n3 1 5\n",
"5 3\n3 4 7 10 3\n4 5 5 12 5\n"
] | [
"10\n",
"25\n"
] | In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. | 1,000 | [
{
"input": "3 1\n5 4 6\n3 1 5",
"output": "10"
},
{
"input": "5 3\n3 4 7 10 3\n4 5 5 12 5",
"output": "25"
},
{
"input": "1 0\n9\n8",
"output": "8"
},
{
"input": "2 0\n4 10\n1 2",
"output": "3"
},
{
"input": "4 2\n19 5 17 13\n3 18 8 10",
"output": "29"
},
{
"input": "5 3\n28 17 20 45 45\n39 12 41 27 9",
"output": "101"
},
{
"input": "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31",
"output": "243"
},
{
"input": "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 166 114 53 144 106 141 106 191 123 44 199 35 18 84 169 46 52 129 102 155 130 63 169 116 145 154 41\n155 187 79 106 136 173 17 146 9 47 173 21 37 183 110 74 185 14 82 156 147 25 162 195 26 25 22 80 171 180 7 92 53 18 100 17 159 184 37 127 116 192 163 49 94 95 118 102 8 30",
"output": "4680"
},
{
"input": "5 2\n1 1 1 1 1\n2 2 2 2 2",
"output": "5"
},
{
"input": "5 2\n2 4 4 4 4\n3 1 1 1 1",
"output": "9"
},
{
"input": "6 3\n9 9 9 2 2 2\n6 6 6 1 1 1",
"output": "24"
},
{
"input": "5 3\n10 17 23 26 35\n7 18 18 29 32",
"output": "103"
},
{
"input": "2 1\n10 12\n5 6",
"output": "16"
}
] | 1,617,528,439 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 358 | 23,040,000 | import sys
from os import path
if (path.exists('input.txt') and path.exists('output.txt')):
sys.stdout = open('output.txt', 'w')
sys.stdin = open('input.txt', 'r')
def main():
n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
diffs = sorted([a[i] - b[i] for i in range(n)])
ans = sum(a)
for diff in diffs:
if diff < 0 or k > 0:
k -= 1
else:
ans -= diff
print(ans)
main() | Title: Dishonest Sellers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*.
Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.
Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items.
Input Specification:
In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now.
The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now).
The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week).
Output Specification:
Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now.
Demo Input:
['3 1\n5 4 6\n3 1 5\n', '5 3\n3 4 7 10 3\n4 5 5 12 5\n']
Demo Output:
['10\n', '25\n']
Note:
In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.
In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25. | ```python
import sys
from os import path
if (path.exists('input.txt') and path.exists('output.txt')):
sys.stdout = open('output.txt', 'w')
sys.stdin = open('input.txt', 'r')
def main():
n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
diffs = sorted([a[i] - b[i] for i in range(n)])
ans = sum(a)
for diff in diffs:
if diff < 0 or k > 0:
k -= 1
else:
ans -= diff
print(ans)
main()
``` | 3 |
|
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
"output": "both"
},
{
"input": "a\na\na",
"output": "fantasy"
},
{
"input": "ab\nb\na",
"output": "backward"
},
{
"input": "aaa\naaaa\naaaa",
"output": "fantasy"
},
{
"input": "bbabbbbababbaabaabaa\nabb\nbaab",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa",
"output": "forward"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb",
"output": "both"
},
{
"input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa",
"output": "backward"
},
{
"input": "aaaa\naaa\naa",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzzzz\nzzzz",
"output": "fantasy"
},
{
"input": "zzzz\nzz\nzz",
"output": "both"
},
{
"input": "aabaa\naab\nbaa",
"output": "fantasy"
},
{
"input": "aabaab\naba\nab",
"output": "forward"
},
{
"input": "aab\nb\naa",
"output": "backward"
},
{
"input": "abacaba\naca\nba",
"output": "both"
}
] | 1,474,303,270 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 1,228,800 | from pprint import pprint
def LCS(a, b):
a, b = a + [], b + []
while len(a) > 0 and len(b) > 0:
if b[0] == a[0]: del(b[0])
del(a[0])
print(b)
return True if len(b) == 0 else False
s, a, b = list(input()), list(input()), list(input())
forward = LCS(s, a + b)
backward = LCS(s[::-1], a + b)
print(
"both" if forward and backward
else "forward" if forward
else "backward" if backward
else "fantasy"
)
| Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
Input Specification:
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output Specification:
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
Demo Input:
['atob\na\nb\n', 'aaacaaa\naca\naa\n']
Demo Output:
['forward\n', 'both\n']
Note:
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | ```python
from pprint import pprint
def LCS(a, b):
a, b = a + [], b + []
while len(a) > 0 and len(b) > 0:
if b[0] == a[0]: del(b[0])
del(a[0])
print(b)
return True if len(b) == 0 else False
s, a, b = list(input()), list(input()), list(input())
forward = LCS(s, a + b)
backward = LCS(s[::-1], a + b)
print(
"both" if forward and backward
else "forward" if forward
else "backward" if backward
else "fantasy"
)
``` | 0 |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 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3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3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 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 1,698,320,043 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 307,200 | from collections import Counter
import math
c1 = c2 = 0
for i in range(int(input())):
ls = list(map(int, input().split()))
if ls[0] > ls[1]:
c1 += 1
elif ls[1] > ls[0]:
c2 += 1
if c1 > c2:
print('Miksha')
elif c2 > c1:
print('Chris')
else:
print('Friendship is magic!^^') | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | ```python
from collections import Counter
import math
c1 = c2 = 0
for i in range(int(input())):
ls = list(map(int, input().split()))
if ls[0] > ls[1]:
c1 += 1
elif ls[1] > ls[0]:
c2 += 1
if c1 > c2:
print('Miksha')
elif c2 > c1:
print('Chris')
else:
print('Friendship is magic!^^')
``` | 0 |
|
701 | B | Cells Not Under Attack | PROGRAMMING | 1,200 | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.
You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook. | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | 750 | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18 24\n18 19\n14 20\n7 10\n27 13\n20 27\n11 1\n21 10\n2 9\n28 12\n29 19\n28 27\n27 29\n30 12\n27 2\n4 5\n8 19\n21 2\n24 27\n14 22\n20 3\n18 3\n23 9\n28 6\n15 12\n2 2\n16 27\n1 14",
"output": "841 784 729 702 650 600 600 552 506 484 441 400 380 380 361 342 324 289 272 272 255 240 225 225 210 196 182 182 168 143 "
},
{
"input": "70 31\n22 39\n33 43\n50 27\n70 9\n20 67\n61 24\n60 4\n60 28\n4 25\n30 29\n46 47\n51 48\n37 5\n14 29\n45 44\n68 35\n52 21\n7 37\n18 43\n44 22\n26 12\n39 37\n51 55\n50 23\n51 16\n16 49\n22 62\n35 45\n56 2\n20 51\n3 37",
"output": "4761 4624 4489 4356 4225 4096 3969 3906 3782 3660 3540 3422 3306 3249 3136 3025 2916 2809 2756 2652 2550 2499 2450 2401 2352 2256 2208 2115 2024 1978 1935 "
},
{
"input": "330 17\n259 262\n146 20\n235 69\n84 74\n131 267\n153 101\n32 232\n214 212\n239 157\n121 156\n10 45\n266 78\n52 258\n109 279\n193 276\n239 142\n321 89",
"output": "108241 107584 106929 106276 105625 104976 104329 103684 103041 102400 101761 101124 100489 99856 99225 98910 98282 "
},
{
"input": "500 43\n176 85\n460 171\n233 260\n73 397\n474 35\n290 422\n309 318\n280 415\n485 169\n106 22\n355 129\n180 301\n205 347\n197 93\n263 318\n336 382\n314 350\n476 214\n367 277\n333 166\n500 376\n236 17\n94 73\n116 204\n166 50\n168 218\n144 369\n340 91\n274 360\n171 360\n41 251\n262 478\n27 163\n151 491\n208 415\n448 386\n293 486\n371 479\n330 435\n220 374\n163 316\n155 158\n26 126",
"output": "249001 248004 247009 246016 245025 244036 243049 242064 241081 240100 239121 238144 237169 236196 235710 234740 233772 232806 231842 230880 229920 228962 228006 227052 226100 225150 224202 223256 222312 221840 220899 219960 219023 218088 217620 216688 215758 214830 213904 212980 212058 211138 210220 "
},
{
"input": "99999 1\n54016 16192",
"output": "9999600004 "
},
{
"input": "99991 9\n80814 65974\n12100 98787\n9390 76191\n5628 47659\n80075 25361\n75330 1630\n38758 99962\n33848 40352\n43732 52281",
"output": "9998000100 9997800121 9997600144 9997400169 9997200196 9997000225 9996800256 9996600289 9996400324 "
},
{
"input": "1 1\n1 1",
"output": "0 "
}
] | 1,670,579,443 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 982 | 7,782,400 | n,m=map(int,input().split())
xaxis,yaxis=set(),set()
for i in range(m):
x,y=map(int,input().split())
cntx,cnty=0,0
if(x not in xaxis):
xaxis.add(x)
if(y not in yaxis):
yaxis.add(y)
print(n*n-n*(len(xaxis)+len(yaxis))+len(xaxis)*len(yaxis),end=' ') | Title: Cells Not Under Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.
You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the column where Vasya will put the *i*-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.
Output Specification:
Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put.
Demo Input:
['3 3\n1 1\n3 1\n2 2\n', '5 2\n1 5\n5 1\n', '100000 1\n300 400\n']
Demo Output:
['4 2 0 \n', '16 9 \n', '9999800001 \n']
Note:
On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | ```python
n,m=map(int,input().split())
xaxis,yaxis=set(),set()
for i in range(m):
x,y=map(int,input().split())
cntx,cnty=0,0
if(x not in xaxis):
xaxis.add(x)
if(y not in yaxis):
yaxis.add(y)
print(n*n-n*(len(xaxis)+len(yaxis))+len(xaxis)*len(yaxis),end=' ')
``` | 3 |
|
678 | C | Joty and Chocolate | PROGRAMMING | 1,600 | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get. | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
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. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | 0 | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
},
{
"input": "4 1 5 4 3",
"output": "16"
},
{
"input": "8 8 1 1 1",
"output": "8"
},
{
"input": "15 14 32 65 28",
"output": "65"
},
{
"input": "894 197 325 232 902",
"output": "2732"
},
{
"input": "8581 6058 3019 2151 4140",
"output": "10431"
},
{
"input": "41764 97259 54586 18013 75415",
"output": "0"
},
{
"input": "333625 453145 800800 907251 446081",
"output": "0"
},
{
"input": "4394826 2233224 609367 3364334 898489",
"output": "9653757"
},
{
"input": "13350712 76770926 61331309 8735000 9057368",
"output": "0"
},
{
"input": "142098087 687355301 987788392 75187408 868856364",
"output": "0"
},
{
"input": "1000000000 1 3 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "6 6 2 8 2",
"output": "12"
},
{
"input": "500 8 4 4 5",
"output": "625"
},
{
"input": "20 4 6 2 3",
"output": "17"
},
{
"input": "10 3 9 1 2",
"output": "4"
},
{
"input": "120 18 6 3 5",
"output": "100"
},
{
"input": "30 4 6 2 2",
"output": "20"
},
{
"input": "1000000000 7171 2727 191 272",
"output": "125391842"
},
{
"input": "5 2 2 4 1",
"output": "8"
},
{
"input": "1000000000 2 2 3 3",
"output": "1500000000"
},
{
"input": "24 4 6 5 7",
"output": "48"
},
{
"input": "216 6 36 10 100",
"output": "900"
},
{
"input": "100 12 6 1 10",
"output": "160"
},
{
"input": "1000 4 8 3 5",
"output": "1000"
},
{
"input": "10 2 4 3 6",
"output": "21"
},
{
"input": "1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 5 10 2 3",
"output": "5"
},
{
"input": "100000 3 9 1 2",
"output": "44444"
},
{
"input": "10 2 4 1 100",
"output": "203"
},
{
"input": "20 6 4 2 3",
"output": "19"
},
{
"input": "1200 4 16 2 3",
"output": "675"
},
{
"input": "7 2 4 7 9",
"output": "23"
},
{
"input": "24 6 4 15 10",
"output": "100"
},
{
"input": "50 2 8 15 13",
"output": "375"
},
{
"input": "100 4 6 12 15",
"output": "444"
},
{
"input": "56756 9 18 56 78",
"output": "422502"
},
{
"input": "10000 4 6 10 12",
"output": "36662"
},
{
"input": "20 2 4 3 5",
"output": "40"
},
{
"input": "24 4 6 10 100",
"output": "440"
},
{
"input": "12 2 4 5 6",
"output": "33"
},
{
"input": "100 2 4 1 100",
"output": "2525"
},
{
"input": "1000 4 6 50 50",
"output": "16650"
},
{
"input": "60 12 6 12 15",
"output": "150"
},
{
"input": "1000 2 4 5 6",
"output": "2750"
},
{
"input": "1000000000 1 1 9999 5555",
"output": "9999000000000"
},
{
"input": "50 2 2 4 5",
"output": "125"
},
{
"input": "14 4 2 2 3",
"output": "21"
},
{
"input": "100 3 9 1 2",
"output": "44"
},
{
"input": "1000000000 4 6 1 1000000000",
"output": "166666666166666667"
},
{
"input": "12 3 3 45 4",
"output": "180"
},
{
"input": "12 2 4 5 9",
"output": "42"
},
{
"input": "1000000000 2 2 1000000000 1000000000",
"output": "500000000000000000"
},
{
"input": "50 4 8 5 6",
"output": "66"
},
{
"input": "32 4 16 6 3",
"output": "48"
},
{
"input": "10000 2 4 1 1",
"output": "5000"
},
{
"input": "8 2 4 100 1",
"output": "400"
},
{
"input": "20 4 2 10 1",
"output": "55"
},
{
"input": "5 2 2 12 15",
"output": "30"
},
{
"input": "20 2 12 5 6",
"output": "51"
},
{
"input": "10 2 4 1 2",
"output": "7"
},
{
"input": "32 4 16 3 6",
"output": "30"
},
{
"input": "50 2 8 13 15",
"output": "337"
},
{
"input": "12 6 4 10 9",
"output": "38"
},
{
"input": "1000000000 999999998 999999999 999999998 999999999",
"output": "1999999997"
},
{
"input": "20 2 4 10 20",
"output": "150"
},
{
"input": "13 4 6 12 15",
"output": "54"
},
{
"input": "30 3 6 5 7",
"output": "60"
},
{
"input": "7 2 4 2 1",
"output": "6"
},
{
"input": "100000 32 16 2 3",
"output": "18750"
},
{
"input": "6 2 6 1 1",
"output": "3"
},
{
"input": "999999999 180 192 46642017 28801397",
"output": "399129078526502"
},
{
"input": "12 4 6 1 1",
"output": "4"
},
{
"input": "10 2 4 10 5",
"output": "50"
},
{
"input": "1000000 4 6 12 14",
"output": "4333328"
},
{
"input": "2000 20 30 3 5",
"output": "531"
},
{
"input": "1000000000 1 2 1 1",
"output": "1000000000"
},
{
"input": "30 3 15 10 3",
"output": "100"
},
{
"input": "1000 2 4 1 100",
"output": "25250"
},
{
"input": "6 3 3 12 15",
"output": "30"
},
{
"input": "24 4 6 1 1",
"output": "8"
},
{
"input": "20 2 12 4 5",
"output": "41"
},
{
"input": "1000000000 9 15 10 10",
"output": "1555555550"
},
{
"input": "16 2 4 1 2",
"output": "12"
},
{
"input": "100000 4 6 12 14",
"output": "433328"
},
{
"input": "24 6 4 1 1",
"output": "8"
},
{
"input": "1000000 4 6 12 15",
"output": "4499994"
},
{
"input": "100 2 4 5 6",
"output": "275"
},
{
"input": "10 3 9 12 15",
"output": "39"
},
{
"input": "1000000000 1 1 999999999 999999999",
"output": "999999999000000000"
},
{
"input": "6 2 4 2 3",
"output": "7"
},
{
"input": "2 2 2 2 2",
"output": "2"
},
{
"input": "6 6 2 1 1",
"output": "3"
},
{
"input": "100 2 4 3 7",
"output": "250"
},
{
"input": "1000000 32 16 2 5",
"output": "312500"
},
{
"input": "100 20 15 50 25",
"output": "375"
},
{
"input": "1000000000 100000007 100000013 10 3",
"output": "117"
},
{
"input": "1000000000 9999999 99999998 3 3",
"output": "330"
},
{
"input": "10077696 24 36 10 100",
"output": "30792960"
},
{
"input": "392852503 148746166 420198270 517065752 906699795",
"output": "1034131504"
},
{
"input": "536870912 60000 72000 271828 314159",
"output": "4369119072"
},
{
"input": "730114139 21550542 204644733 680083361 11353255",
"output": "22476810678"
},
{
"input": "538228881 766493289 791886544 468896052 600136703",
"output": "0"
},
{
"input": "190 20 50 84 172",
"output": "1188"
},
{
"input": "1000 5 10 80 90",
"output": "17000"
},
{
"input": "99999999 999999998 1 271828 314159",
"output": "31415899685841"
},
{
"input": "22 3 6 1243 1",
"output": "8701"
},
{
"input": "15 10 5 2 2",
"output": "6"
},
{
"input": "1000000000 1000000000 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "62 62 42 78 124",
"output": "202"
},
{
"input": "2 2 2 2 1",
"output": "2"
},
{
"input": "864351351 351 313 531 11",
"output": "1337898227"
},
{
"input": "26 3 6 1244 1",
"output": "9952"
},
{
"input": "1000 4 6 7 3",
"output": "1999"
},
{
"input": "134312 3 6 33333 1",
"output": "1492318410"
},
{
"input": "100 4 6 17 18",
"output": "577"
},
{
"input": "6 2 4 5 6",
"output": "16"
},
{
"input": "8 2 4 10 1",
"output": "40"
},
{
"input": "10 2 4 3 3",
"output": "15"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "1000"
},
{
"input": "123123 3 6 34312 2",
"output": "1408198792"
},
{
"input": "1000000000 25 5 999 999",
"output": "199800000000"
},
{
"input": "100 4 2 5 12",
"output": "600"
},
{
"input": "50 2 4 4 5",
"output": "112"
},
{
"input": "24 4 6 100 333",
"output": "1732"
},
{
"input": "216 24 36 10 100",
"output": "660"
},
{
"input": "50 6 4 3 8",
"output": "108"
},
{
"input": "146 76 2 178 192",
"output": "14016"
},
{
"input": "55 8 6 11 20",
"output": "224"
},
{
"input": "5 2 4 6 16",
"output": "22"
},
{
"input": "54 2 52 50 188",
"output": "1488"
},
{
"input": "536870912 60000000 72000000 271828 314159",
"output": "4101909"
},
{
"input": "1000000000 1000000000 1 1 100",
"output": "100000000000"
},
{
"input": "50 4 2 4 5",
"output": "125"
},
{
"input": "198 56 56 122 118",
"output": "366"
},
{
"input": "5 1000000000 1 12 15",
"output": "75"
},
{
"input": "1000 6 12 5 6",
"output": "913"
},
{
"input": "50 3 6 12 15",
"output": "216"
},
{
"input": "333 300 300 300 300",
"output": "300"
},
{
"input": "1 1000000000 1 1 2",
"output": "2"
},
{
"input": "188 110 110 200 78",
"output": "200"
},
{
"input": "100000 20 10 3 2",
"output": "25000"
},
{
"input": "100 2 4 1 10",
"output": "275"
},
{
"input": "1000000000 2 1000000000 1 1000000",
"output": "500999999"
},
{
"input": "20 3 6 5 7",
"output": "36"
},
{
"input": "50 4 6 4 5",
"output": "72"
},
{
"input": "96 46 4 174 156",
"output": "3936"
},
{
"input": "5 2 4 12 15",
"output": "27"
},
{
"input": "12 3 6 100 1",
"output": "400"
},
{
"input": "100 4 2 10 32",
"output": "1600"
},
{
"input": "1232 3 6 30000 3",
"output": "12300000"
},
{
"input": "20 3 6 5 4",
"output": "30"
},
{
"input": "100 6 15 11 29",
"output": "317"
},
{
"input": "10000000 4 8 100 200",
"output": "375000000"
},
{
"input": "1000000000 12 24 2 4",
"output": "249999998"
},
{
"input": "123 3 6 3000 1",
"output": "123000"
},
{
"input": "401523968 1536 2664 271828 314159",
"output": "117768531682"
},
{
"input": "9 2 4 3 5",
"output": "16"
},
{
"input": "999999999 724362018 772432019 46201854 20017479",
"output": "66219333"
},
{
"input": "100 2 4 1 1000",
"output": "25025"
},
{
"input": "50 2 4 1 1000",
"output": "12013"
},
{
"input": "1000000000 2 1 2 1",
"output": "1500000000"
},
{
"input": "1000000000 2005034 2005046 15 12",
"output": "13446"
},
{
"input": "1000000000 999999999 1000000000 1 1",
"output": "2"
},
{
"input": "999999999 500000000 1 100 1000",
"output": "999999999000"
},
{
"input": "50 8 6 3 4",
"output": "44"
},
{
"input": "1000000000 1 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000000 999999862 999999818 15 12",
"output": "27"
},
{
"input": "1000000000 10000019 10000019 21 17",
"output": "2079"
},
{
"input": "20 6 4 8 2",
"output": "32"
},
{
"input": "1000000000 1000000000 1 1 1",
"output": "1000000000"
},
{
"input": "1000000000 12345678 123456789 1000000000 999999999",
"output": "88999999992"
},
{
"input": "1000000000 2 999999937 100000000 100000000",
"output": "50000000100000000"
},
{
"input": "1000000000 1 1 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "1000000000 50001 100003 10 10",
"output": "299980"
},
{
"input": "1000000000 1000000000 3 1 1",
"output": "333333334"
},
{
"input": "10000 44 49 114 514",
"output": "130278"
},
{
"input": "30 5 15 2 1",
"output": "12"
},
{
"input": "20 2 4 1 1",
"output": "10"
},
{
"input": "100 8 12 5 6",
"output": "88"
}
] | 1,564,466,863 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 1,740,800 | n,a,b,p,q = (int(i) for i in input().split())
s = 0
for i in range(1,n+1):
if i % a == 0 and i % b != 0:
s += p
if i % b == 0 and i % a != 0:
s += q
if i % a == 0 and i % b == 0:
s += max(p,q)
print(s) | Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
Input Specification:
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Output Specification:
Print the only integer *s* — the maximum number of chocolates Joty can get.
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:
['5 2 3 12 15\n', '20 2 3 3 5\n']
Demo Output:
['39\n', '51\n']
Note:
none | ```python
n,a,b,p,q = (int(i) for i in input().split())
s = 0
for i in range(1,n+1):
if i % a == 0 and i % b != 0:
s += p
if i % b == 0 and i % a != 0:
s += q
if i % a == 0 and i % b == 0:
s += max(p,q)
print(s)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,696,999,716 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | import sys
user_input = sys.stdin.readline().strip()
lowercase_letters = list('abcdefghijklmnopqrstuvwxyz')
uppercase_letters = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
sum_low = 0
sum_high = 0
for i in user_input:
if i in lowercase_letters:
sum_low += 1
elif i in uppercase_letters:
sum_high += 1
if sum_low > sum_high:
a = user_input.lower()
print(a)
elif sum_low < sum_high:
a = user_input.upper()
print(a)
else:
a = user_input.lower()
print(a) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
import sys
user_input = sys.stdin.readline().strip()
lowercase_letters = list('abcdefghijklmnopqrstuvwxyz')
uppercase_letters = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
sum_low = 0
sum_high = 0
for i in user_input:
if i in lowercase_letters:
sum_low += 1
elif i in uppercase_letters:
sum_high += 1
if sum_low > sum_high:
a = user_input.lower()
print(a)
elif sum_low < sum_high:
a = user_input.upper()
print(a)
else:
a = user_input.lower()
print(a)
``` | 3.977 |
257 | C | View Angle | PROGRAMMING | 1,800 | [
"brute force",
"geometry",
"math"
] | null | null | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle.
As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins.
Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane. | Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6. | [
"2\n2 0\n0 2\n",
"3\n2 0\n0 2\n-2 2\n",
"4\n2 0\n0 2\n-2 0\n0 -2\n",
"2\n2 1\n1 2\n"
] | [
"90.0000000000\n",
"135.0000000000\n",
"270.0000000000\n",
"36.8698976458\n"
] | Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below: | 1,500 | [
{
"input": "2\n2 0\n0 2",
"output": "90.0000000000"
},
{
"input": "3\n2 0\n0 2\n-2 2",
"output": "135.0000000000"
},
{
"input": "4\n2 0\n0 2\n-2 0\n0 -2",
"output": "270.0000000000"
},
{
"input": "2\n2 1\n1 2",
"output": "36.8698976458"
},
{
"input": "1\n1 1",
"output": "0.0000000000"
},
{
"input": "10\n9 7\n10 7\n6 5\n6 10\n7 6\n5 10\n6 7\n10 9\n5 5\n5 8",
"output": "28.4429286244"
},
{
"input": "10\n-1 28\n1 28\n1 25\n0 23\n-1 24\n-1 22\n1 27\n0 30\n1 22\n1 21",
"output": "5.3288731964"
},
{
"input": "10\n-5 9\n-10 6\n-8 8\n-9 9\n-6 5\n-8 9\n-5 7\n-6 6\n-5 10\n-8 7",
"output": "32.4711922908"
},
{
"input": "10\n6 -9\n9 -5\n10 -5\n7 -5\n8 -7\n8 -10\n8 -5\n6 -10\n7 -6\n8 -9",
"output": "32.4711922908"
},
{
"input": "10\n-5 -7\n-8 -10\n-9 -5\n-5 -9\n-9 -8\n-7 -7\n-6 -8\n-6 -10\n-10 -7\n-9 -6",
"output": "31.8907918018"
},
{
"input": "10\n-1 -29\n-1 -26\n1 -26\n-1 -22\n-1 -24\n-1 -21\n1 -24\n-1 -20\n-1 -23\n-1 -25",
"output": "5.2483492565"
},
{
"input": "10\n21 0\n22 1\n30 0\n20 0\n28 0\n29 0\n21 -1\n30 1\n24 1\n26 0",
"output": "5.3288731964"
},
{
"input": "10\n-20 0\n-22 1\n-26 0\n-22 -1\n-30 -1\n-30 0\n-28 0\n-24 1\n-23 -1\n-29 1",
"output": "5.2051244050"
},
{
"input": "10\n-5 -5\n5 -5\n-4 -5\n4 -5\n1 -5\n0 -5\n3 -5\n-2 -5\n2 -5\n-3 -5",
"output": "90.0000000000"
},
{
"input": "10\n-5 -5\n-4 -5\n-2 -5\n4 -5\n5 -5\n3 -5\n2 -5\n-1 -5\n-3 -5\n0 -5",
"output": "90.0000000000"
},
{
"input": "10\n-1 -5\n-5 -5\n2 -5\n-2 -5\n1 -5\n5 -5\n0 -5\n3 -5\n-4 -5\n-3 -5",
"output": "90.0000000000"
},
{
"input": "10\n-1 -5\n-5 -5\n-4 -5\n3 -5\n0 -5\n4 -5\n1 -5\n-2 -5\n5 -5\n-3 -5",
"output": "90.0000000000"
},
{
"input": "10\n5 -5\n4 -5\n-1 -5\n1 -5\n-4 -5\n3 -5\n0 -5\n-5 -5\n-2 -5\n-3 -5",
"output": "90.0000000000"
},
{
"input": "10\n2 -5\n-4 -5\n-2 -5\n4 -5\n-5 -5\n-1 -5\n0 -5\n-3 -5\n3 -5\n1 -5",
"output": "83.6598082541"
},
{
"input": "5\n2 1\n0 1\n2 -1\n-2 -1\n2 0",
"output": "233.1301023542"
},
{
"input": "5\n-2 -2\n2 2\n2 -1\n-2 0\n1 -1",
"output": "225.0000000000"
},
{
"input": "5\n0 -2\n-2 -1\n-1 2\n0 -1\n-1 0",
"output": "153.4349488229"
},
{
"input": "5\n-1 -1\n-2 -1\n1 0\n-1 -2\n-1 1",
"output": "225.0000000000"
},
{
"input": "5\n1 -1\n0 2\n-2 2\n-2 1\n2 1",
"output": "198.4349488229"
},
{
"input": "5\n2 2\n1 2\n-2 -1\n1 1\n-2 -2",
"output": "180.0000000000"
},
{
"input": "2\n1 1\n2 2",
"output": "0.0000000000"
},
{
"input": "27\n-592 -96\n-925 -150\n-111 -18\n-259 -42\n-370 -60\n-740 -120\n-629 -102\n-333 -54\n-407 -66\n-296 -48\n-37 -6\n-999 -162\n-222 -36\n-555 -90\n-814 -132\n-444 -72\n-74 -12\n-185 -30\n-148 -24\n-962 -156\n-777 -126\n-518 -84\n-888 -144\n-666 -108\n-481 -78\n-851 -138\n-703 -114",
"output": "0.0000000000"
},
{
"input": "38\n96 416\n24 104\n6 26\n12 52\n210 910\n150 650\n54 234\n174 754\n114 494\n18 78\n90 390\n36 156\n222 962\n186 806\n126 546\n78 338\n108 468\n180 780\n120 520\n84 364\n66 286\n138 598\n30 130\n228 988\n72 312\n144 624\n198 858\n60 260\n48 208\n102 442\n42 182\n162 702\n132 572\n156 676\n204 884\n216 936\n168 728\n192 832",
"output": "0.0000000000"
},
{
"input": "14\n-2 -134\n-4 -268\n-11 -737\n-7 -469\n-14 -938\n-10 -670\n-3 -201\n-1 -67\n-9 -603\n-6 -402\n-13 -871\n-12 -804\n-8 -536\n-5 -335",
"output": "0.0000000000"
},
{
"input": "14\n588 938\n420 670\n210 335\n252 402\n504 804\n126 201\n42 67\n546 871\n294 469\n84 134\n336 536\n462 737\n168 268\n378 603",
"output": "0.0000000000"
},
{
"input": "20\n-45 147\n-240 784\n-135 441\n-60 196\n-105 343\n-285 931\n-195 637\n-300 980\n-165 539\n-210 686\n-75 245\n-15 49\n-30 98\n-270 882\n-120 392\n-90 294\n-150 490\n-180 588\n-255 833\n-225 735",
"output": "0.0000000000"
},
{
"input": "2\n1 1\n1 -1",
"output": "90.0000000000"
}
] | 1,629,170,328 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 1,714 | 30,003,200 | import math
n = int(input())
angles = []
while n:
n -= 1
x, y = map(int, input().split())
if x==0:
if y>0:
angles.append(90)
else:
angles.append(-90)
elif y==0:
if x>0:
angles.append(0)
else:
angles.append(180)
else:
if x<0 and y<0:
angles.append(180+math.degrees(math.atan(y/x)))
elif y<0:
angles.append(-math.degrees(math.atan(-1*y/x)))
elif x<0:
angles.append(180-math.degrees(math.atan(-1*y/x)))
else:
angles.append(math.degrees(math.atan(y/x)))
angles.sort()
m=angles[-1]-angles[0]
for i in range(1,n):
d=360-abs(angles[i]-angles[i-1])
m=min(m,d)
print(m) | Title: View Angle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle.
As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of mannequins.
Next *n* lines contain two space-separated integers each: *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=1000) — the coordinates of the *i*-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane.
Output Specification:
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10<=-<=6.
Demo Input:
['2\n2 0\n0 2\n', '3\n2 0\n0 2\n-2 2\n', '4\n2 0\n0 2\n-2 0\n0 -2\n', '2\n2 1\n1 2\n']
Demo Output:
['90.0000000000\n', '135.0000000000\n', '270.0000000000\n', '36.8698976458\n']
Note:
Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below: | ```python
import math
n = int(input())
angles = []
while n:
n -= 1
x, y = map(int, input().split())
if x==0:
if y>0:
angles.append(90)
else:
angles.append(-90)
elif y==0:
if x>0:
angles.append(0)
else:
angles.append(180)
else:
if x<0 and y<0:
angles.append(180+math.degrees(math.atan(y/x)))
elif y<0:
angles.append(-math.degrees(math.atan(-1*y/x)))
elif x<0:
angles.append(180-math.degrees(math.atan(-1*y/x)))
else:
angles.append(math.degrees(math.atan(y/x)))
angles.sort()
m=angles[-1]-angles[0]
for i in range(1,n):
d=360-abs(angles[i]-angles[i-1])
m=min(m,d)
print(m)
``` | 0 |
|
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line. | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "76 48",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "100 90",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBB"
},
{
"input": "90 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGG"
},
{
"input": "1 98",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 100",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "56 98",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "89 89",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "18 94",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "84 27",
"output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "1 1",
"output": "GB"
},
{
"input": "1 2",
"output": "GBG"
},
{
"input": "2 1",
"output": "BGB"
},
{
"input": "1 34",
"output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "46 2",
"output": "BGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "99 3",
"output": "BGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 100",
"output": "GBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "100 100",
"output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB"
},
{
"input": "1 4",
"output": "GBGGG"
}
] | 1,622,534,476 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,150,400 | b,g=map(int,input().split())
l=[0]*(b+g)
if b==g:
l=['GB']*b
elif b>g:
l=['BG']*g
l.append('B'*(b-g))
elif g>b:
l=['GB']*g
l.append('G'*(g-b))
print(''.join(l)) | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible.
Help the children and tell them how to form the line.
Input Specification:
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Output Specification:
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
Demo Input:
['3 3\n', '4 2\n']
Demo Output:
['GBGBGB\n', 'BGBGBB\n']
Note:
In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | ```python
b,g=map(int,input().split())
l=[0]*(b+g)
if b==g:
l=['GB']*b
elif b>g:
l=['BG']*g
l.append('B'*(b-g))
elif g>b:
l=['GB']*g
l.append('G'*(g-b))
print(''.join(l))
``` | -1 |
|
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,676,537,593 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | (n,d)=map(int,str(input()).split())
l=list(map(int,str(input()).split()))
s=0
for i in range(len(l)-1):
while l[i+1]<=l[i]:
l[i+1]+=d
s+=1
print(l,s) | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
(n,d)=map(int,str(input()).split())
l=list(map(int,str(input()).split()))
s=0
for i in range(len(l)-1):
while l[i+1]<=l[i]:
l[i+1]+=d
s+=1
print(l,s)
``` | 0 |
1,000 | C | Covered Points Count | PROGRAMMING | 1,700 | [
"data structures",
"implementation",
"sortings"
] | null | null | You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $k \in [1..n]$, calculate the number of points with integer coordinates such that the number of segments that cover these points equals $k$. A segment with endpoints $l_i$ and $r_i$ covers point $x$ if and only if $l_i \le x \le r_i$. | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments.
The next $n$ lines contain segments. The $i$-th line contains a pair of integers $l_i, r_i$ ($0 \le l_i \le r_i \le 10^{18}$) — the endpoints of the $i$-th segment. | Print $n$ space separated integers $cnt_1, cnt_2, \dots, cnt_n$, where $cnt_i$ is equal to the number of points such that the number of segments that cover these points equals to $i$. | [
"3\n0 3\n1 3\n3 8\n",
"3\n1 3\n2 4\n5 7\n"
] | [
"6 2 1 \n",
"5 2 0 \n"
] | The picture describing the first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/f76b3fe547bff6be5b14de76c8b78ba3efecc744.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Points with coordinates $[0, 4, 5, 6, 7, 8]$ are covered by one segment, points $[1, 2]$ are covered by two segments and point $[3]$ is covered by three segments.
The picture describing the second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/6e9332c303e1bc5d6cf34c2d6c5e2a19c9417289.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Points $[1, 4, 5, 6, 7]$ are covered by one segment, points $[2, 3]$ are covered by two segments and there are no points covered by three segments. | 0 | [
{
"input": "3\n0 3\n1 3\n3 8",
"output": "6 2 1 "
},
{
"input": "3\n1 3\n2 4\n5 7",
"output": "5 2 0 "
},
{
"input": "1\n0 1000000000000000000",
"output": "1000000000000000001 "
}
] | 1,650,964,783 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 1,872 | 56,627,200 | import collections
if __name__ == '__main__':
n = int(input())
ans = collections.defaultdict(int)
for i in range(n):
l, r = list(map(int, input().strip().split()))
ans[l] += 1; ans[r + 1] -= 1
ans = dict(sorted(ans.items(), key=lambda k: k[0]))
keys = list(ans.keys())
tot = len(keys)
for i in range(1, tot):
ans[keys[i]] += ans[keys[i - 1]]
res = [0] * (n + 1)
for i in range(tot - 1):
res[ans[keys[i]]] += keys[i + 1] - keys[i]
for i in range(1, n):
print(res[i], end=" ")
print(res[n]) | Title: Covered Points Count
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every $k \in [1..n]$, calculate the number of points with integer coordinates such that the number of segments that cover these points equals $k$. A segment with endpoints $l_i$ and $r_i$ covers point $x$ if and only if $l_i \le x \le r_i$.
Input Specification:
The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments.
The next $n$ lines contain segments. The $i$-th line contains a pair of integers $l_i, r_i$ ($0 \le l_i \le r_i \le 10^{18}$) — the endpoints of the $i$-th segment.
Output Specification:
Print $n$ space separated integers $cnt_1, cnt_2, \dots, cnt_n$, where $cnt_i$ is equal to the number of points such that the number of segments that cover these points equals to $i$.
Demo Input:
['3\n0 3\n1 3\n3 8\n', '3\n1 3\n2 4\n5 7\n']
Demo Output:
['6 2 1 \n', '5 2 0 \n']
Note:
The picture describing the first example:
<img class="tex-graphics" src="https://espresso.codeforces.com/f76b3fe547bff6be5b14de76c8b78ba3efecc744.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Points with coordinates $[0, 4, 5, 6, 7, 8]$ are covered by one segment, points $[1, 2]$ are covered by two segments and point $[3]$ is covered by three segments.
The picture describing the second example:
<img class="tex-graphics" src="https://espresso.codeforces.com/6e9332c303e1bc5d6cf34c2d6c5e2a19c9417289.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Points $[1, 4, 5, 6, 7]$ are covered by one segment, points $[2, 3]$ are covered by two segments and there are no points covered by three segments. | ```python
import collections
if __name__ == '__main__':
n = int(input())
ans = collections.defaultdict(int)
for i in range(n):
l, r = list(map(int, input().strip().split()))
ans[l] += 1; ans[r + 1] -= 1
ans = dict(sorted(ans.items(), key=lambda k: k[0]))
keys = list(ans.keys())
tot = len(keys)
for i in range(1, tot):
ans[keys[i]] += ans[keys[i - 1]]
res = [0] * (n + 1)
for i in range(tot - 1):
res[ans[keys[i]]] += keys[i + 1] - keys[i]
for i in range(1, n):
print(res[i], end=" ")
print(res[n])
``` | 3 |
|
166 | E | Tetrahedron | PROGRAMMING | 1,500 | [
"dp",
"math",
"matrices"
] | null | null | You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7). | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path. | Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7). | [
"2\n",
"4\n"
] | [
"3\n",
"21\n"
] | The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "21"
},
{
"input": "1",
"output": "0"
},
{
"input": "3",
"output": "6"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "183"
},
{
"input": "7",
"output": "546"
},
{
"input": "8",
"output": "1641"
},
{
"input": "9",
"output": "4920"
},
{
"input": "10",
"output": "14763"
},
{
"input": "15",
"output": "3587226"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "100",
"output": "721510432"
},
{
"input": "300",
"output": "327873818"
},
{
"input": "900",
"output": "295068084"
},
{
"input": "1500",
"output": "451187545"
},
{
"input": "3000",
"output": "645417275"
},
{
"input": "5000",
"output": "755610910"
},
{
"input": "10000",
"output": "723907367"
},
{
"input": "50000",
"output": "969527595"
},
{
"input": "90000",
"output": "548978368"
},
{
"input": "99999",
"output": "909741855"
},
{
"input": "100000",
"output": "729225554"
},
{
"input": "300000",
"output": "93822635"
},
{
"input": "800000",
"output": "178940616"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "4000000",
"output": "882155933"
},
{
"input": "9000000",
"output": "295060537"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "1000000",
"output": "266233856"
},
{
"input": "9999999",
"output": "730778875"
},
{
"input": "10000000",
"output": "192336614"
},
{
"input": "9999998",
"output": "576926295"
},
{
"input": "30",
"output": "782663359"
},
{
"input": "31",
"output": "347990060"
}
] | 1,688,267,443 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | import numpy as np
n = int(input())
SAME = 1
DIFF = 0
m = 1000000007
dp = np.zeros((2,n+2),dtype=int)
dp[0,0] = 0
dp[1,0] = 1
for i in range(1, n+2):
dp[0][i] = ((2*dp[0][i-1])%m+dp[1][i-1])%m
dp[1][i] = 3*dp[0][i-1] % m
print(dp[1,n])
| Title: Tetrahedron
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly.
An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex *D* to itself in exactly *n* steps. In other words, you are asked to find out the number of different cyclic paths with the length of *n* from vertex *D* to itself. As the number can be quite large, you should print it modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Output Specification:
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '21\n']
Note:
The required paths in the first sample are:
- *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D* | ```python
import numpy as np
n = int(input())
SAME = 1
DIFF = 0
m = 1000000007
dp = np.zeros((2,n+2),dtype=int)
dp[0,0] = 0
dp[1,0] = 1
for i in range(1, n+2):
dp[0][i] = ((2*dp[0][i-1])%m+dp[1][i-1])%m
dp[1][i] = 3*dp[0][i-1] % m
print(dp[1,n])
``` | -1 |
|
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.
Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=><=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.
Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test? | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5. | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "33534354842198 32529564319236 32529564342569",
"output": "22239"
},
{
"input": "62518534961045 50734311240112 50734311287877",
"output": "42439"
},
{
"input": "95173251245550 106288351347530 106288351372022",
"output": "16565"
},
{
"input": "542 321 956",
"output": "336"
},
{
"input": "3621 237 2637",
"output": "2124"
},
{
"input": "9056 336 896",
"output": "311"
},
{
"input": "36007 368 24490",
"output": "13253"
},
{
"input": "244269 149154 244246",
"output": "88609"
},
{
"input": "880234 669493 757150",
"output": "73585"
},
{
"input": "3740160 1031384 1104236",
"output": "64965"
},
{
"input": "11586121 15337246 15397874",
"output": "41868"
},
{
"input": "38658997 35923164 35985664",
"output": "36004"
},
{
"input": "192308932 207804787 207866400",
"output": "44142"
},
{
"input": "950099012 175922161 176000556",
"output": "69369"
},
{
"input": "2787326787 3799676481 3799680514",
"output": "2618"
},
{
"input": "14417262581 8527979363 8528075536",
"output": "80707"
},
{
"input": "39889373539 7747197212 7747278363",
"output": "47105"
},
{
"input": "251772781087 70597428577 70597479816",
"output": "46933"
},
{
"input": "0 1 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "3 2 3",
"output": "2"
},
{
"input": "14 7 12",
"output": "5"
},
{
"input": "1125899906842623 1 100001",
"output": "100001"
},
{
"input": "1125899906842623 1125899906742623 1125899906842623",
"output": "100001"
},
{
"input": "1000 1 1023",
"output": "1000"
},
{
"input": "281474976710656 17179869184 17179869186",
"output": "1"
},
{
"input": "2 2 2",
"output": "0"
},
{
"input": "3 2 2",
"output": "1"
}
] | 1,660,031,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 |
from math import floor, log2
import sys
sys.setrecursionlimit(10**4)
def numOfChildren(x):
n = floor(log2(x))
res = 0
for i in range(n - 1):
res += 2**i
return res + (3 * (2**(n-1)))
n, l, r = map(int, input().split())
def dfs(node, i, j):
if j < l or r < i:
return 0
if node == 0 or node == 1:
return node
m = l + numOfChildren(node//2)
res = 0
if i <= m <= j:
res += node % 2
res += dfs(node//2, i, m - 1)
res += dfs(node//2, m + 1, j)
return res
print(dfs(n, 1, numOfChildren(n)))
| Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility.
Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=><=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.
Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?
Input Specification:
The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list.
Output Specification:
Output the total number of 1s in the range *l* to *r* in the final sequence.
Demo Input:
['7 2 5\n', '10 3 10\n']
Demo Output:
['4\n', '5\n']
Note:
Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5. | ```python
from math import floor, log2
import sys
sys.setrecursionlimit(10**4)
def numOfChildren(x):
n = floor(log2(x))
res = 0
for i in range(n - 1):
res += 2**i
return res + (3 * (2**(n-1)))
n, l, r = map(int, input().split())
def dfs(node, i, j):
if j < l or r < i:
return 0
if node == 0 or node == 1:
return node
m = l + numOfChildren(node//2)
res = 0
if i <= m <= j:
res += node % 2
res += dfs(node//2, i, m - 1)
res += dfs(node//2, m + 1, j)
return res
print(dfs(n, 1, numOfChildren(n)))
``` | 0 |
|
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want to break the sticks or glue them together. To make a *h*<=×<=*w*-sized frame, he needs two sticks whose lengths equal *h* and two sticks whose lengths equal *w*. Specifically, to make a square frame (when *h*<==<=*w*), he needs four sticks of the same length.
Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\n2 4 2 6 2 3 4 1 4 5 4 3 4 1",
"output": "2"
},
{
"input": "33\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36",
"output": "5"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n10",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "3\n3 2 1",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "4\n1 2 1 2",
"output": "1"
},
{
"input": "4\n1 100 1 100",
"output": "1"
},
{
"input": "4\n10 100 100 10",
"output": "1"
},
{
"input": "4\n1 2 3 3",
"output": "0"
},
{
"input": "4\n8 5 9 13",
"output": "0"
},
{
"input": "4\n100 100 100 100",
"output": "1"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "5\n1 4 4 1 1",
"output": "1"
},
{
"input": "5\n1 100 1 1 100",
"output": "1"
},
{
"input": "5\n100 100 1 1 100",
"output": "1"
},
{
"input": "5\n100 1 100 100 100",
"output": "1"
},
{
"input": "5\n100 100 100 100 100",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "1"
},
{
"input": "6\n1 1 5 1 1 5",
"output": "1"
},
{
"input": "6\n1 100 100 1 1 1",
"output": "1"
},
{
"input": "6\n100 1 1 100 1 100",
"output": "1"
},
{
"input": "6\n1 2 3 2 3 1",
"output": "1"
},
{
"input": "6\n1 50 1 100 50 100",
"output": "1"
},
{
"input": "6\n10 10 10 12 13 14",
"output": "0"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "7\n1 2 1 1 1 1 1",
"output": "1"
},
{
"input": "7\n1 2 2 1 2 1 2",
"output": "1"
},
{
"input": "7\n1 1 2 2 1 2 3",
"output": "1"
},
{
"input": "7\n1 3 2 2 3 1 4",
"output": "1"
},
{
"input": "7\n1 3 4 3 5 4 6",
"output": "1"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "0"
},
{
"input": "8\n1 2 1 2 2 2 2 2",
"output": "2"
},
{
"input": "8\n1 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "8\n1 2 2 2 3 1 1 3",
"output": "1"
},
{
"input": "8\n1 2 3 4 1 2 3 4",
"output": "2"
},
{
"input": "8\n1 1 1 1 2 3 2 3",
"output": "2"
},
{
"input": "8\n1 2 3 4 5 5 5 5",
"output": "1"
},
{
"input": "8\n1 2 1 3 4 1 5 6",
"output": "0"
},
{
"input": "8\n1 2 3 4 5 6 1 7",
"output": "0"
},
{
"input": "8\n8 6 3 4 5 2 1 7",
"output": "0"
},
{
"input": "8\n100 100 100 100 100 100 100 100",
"output": "2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n19 9 14 14 19 5 5 18 10 17",
"output": "1"
},
{
"input": "10\n72 86 73 25 84 29 33 34 20 29",
"output": "0"
},
{
"input": "10\n93 93 99 98 91 96 92 98 94 98",
"output": "1"
},
{
"input": "13\n35 6 21 30 67 55 70 39 75 72 11 13 69",
"output": "0"
},
{
"input": "17\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100",
"output": "1"
},
{
"input": "18\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27",
"output": "1"
},
{
"input": "23\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35",
"output": "1"
},
{
"input": "30\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27",
"output": "1"
},
{
"input": "33\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51",
"output": "1"
},
{
"input": "38\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89",
"output": "3"
},
{
"input": "40\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90",
"output": "1"
},
{
"input": "43\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96",
"output": "4"
},
{
"input": "49\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91",
"output": "4"
},
{
"input": "57\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89",
"output": "6"
},
{
"input": "67\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23",
"output": "8"
},
{
"input": "74\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91",
"output": "7"
},
{
"input": "87\n10 19 83 58 15 48 26 58 89 46 50 34 81 40 25 51 62 85 9 80 71 44 100 22 30 48 74 69 54 40 38 81 66 42 40 90 60 20 75 24 74 98 28 62 79 65 65 6 14 23 3 59 29 24 64 13 8 38 29 85 75 81 36 42 3 63 99 24 72 92 35 8 71 19 77 77 66 3 79 65 15 18 15 69 60 77 91",
"output": "11"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "100\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5",
"output": "23"
},
{
"input": "100\n70 70 75 70 74 70 70 73 72 73 74 75 70 74 73 70 70 74 72 72 75 70 73 72 70 75 73 70 74 70 73 75 71 74 70 71 75 74 75 71 74 70 73 73 70 75 71 73 73 74 73 74 71 73 73 71 72 71 70 75 74 74 72 72 71 72 75 75 70 73 71 73 72 71 70 75 71 75 73 75 73 72 75 71 73 71 72 74 75 70 70 74 75 73 70 73 73 75 71 74",
"output": "24"
},
{
"input": "100\n99 98 98 99 98 98 98 100 98 99 99 98 99 98 98 98 99 99 98 99 99 100 98 100 98 98 98 99 98 100 100 98 100 99 100 98 99 99 99 98 100 98 100 99 99 99 98 100 98 98 98 100 100 99 98 98 100 100 100 99 98 99 99 99 100 99 99 98 99 98 99 100 100 98 98 100 100 99 99 99 98 98 98 100 99 99 100 99 100 99 98 100 98 100 98 98 99 98 99 98",
"output": "24"
},
{
"input": "100\n94 87 92 91 94 89 93 94 87 93 93 94 89 91 87 87 92 91 87 94 90 89 92 92 87 88 90 90 90 89 90 92 91 91 89 88 93 89 88 94 91 89 88 87 92 89 91 87 88 90 88 92 90 87 93 94 94 92 92 87 90 88 88 91 94 93 87 94 93 93 87 90 92 92 90 88 88 90 92 91 90 88 89 91 91 88 90 93 90 94 94 93 90 91 91 93 94 94 92 93",
"output": "24"
},
{
"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": "25"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "7\n13 13 13 13 6 2 3",
"output": "1"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "5\n100 100 99 99 5",
"output": "1"
},
{
"input": "8\n2 2 2 2 2 2 2 2",
"output": "2"
},
{
"input": "8\n1 2 3 4 5 6 7 7",
"output": "0"
},
{
"input": "8\n4 4 4 4 4 4 4 4",
"output": "2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 2",
"output": "2"
},
{
"input": "4\n100 100 100 99",
"output": "0"
},
{
"input": "4\n2 2 2 2",
"output": "1"
},
{
"input": "5\n100 100 99 99 2",
"output": "1"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "5\n2 2 3 4 4",
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13",
"output": "0"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "4\n4 4 4 4",
"output": "1"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "5\n30 30 30 1 1",
"output": "1"
}
] | 1,377,869,270 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | import sys
f = sys.stdin
#f = open("input.txt", "r")
n = int(f.readline().strip())
a = [int(i) for i in f.readline().strip().split()]
a.sort()
k = list(set(a))
counts = []
for i in k:
counts.append(a.count(i))
counts.sort(reverse=True)
cnt = 0
i = 0
while i < len(counts)-1:
if counts[i] >= 4:
cnt += counts[i]//2
elif counts[i] >= 2 and counts[i+1] >= 2:
cnt += min(counts[i], counts[i+1])//2
i += 2
print(cnt) | Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want to break the sticks or glue them together. To make a *h*<=×<=*w*-sized frame, he needs two sticks whose lengths equal *h* and two sticks whose lengths equal *w*. Specifically, to make a square frame (when *h*<==<=*w*), he needs four sticks of the same length.
Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
Demo Input:
['5\n2 4 3 2 3\n', '13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n', '4\n3 3 3 5\n']
Demo Output:
['1', '3', '0']
Note:
none | ```python
import sys
f = sys.stdin
#f = open("input.txt", "r")
n = int(f.readline().strip())
a = [int(i) for i in f.readline().strip().split()]
a.sort()
k = list(set(a))
counts = []
for i in k:
counts.append(a.count(i))
counts.sort(reverse=True)
cnt = 0
i = 0
while i < len(counts)-1:
if counts[i] >= 4:
cnt += counts[i]//2
elif counts[i] >= 2 and counts[i+1] >= 2:
cnt += min(counts[i], counts[i+1])//2
i += 2
print(cnt)
``` | 0 |
|
73 | D | FreeDiv | PROGRAMMING | 2,200 | [
"dfs and similar",
"graphs",
"greedy"
] | D. FreeDiv | 5 | 256 | Vasya plays FreeDiv. In this game he manages a huge state, which has *n* cities and *m* two-way roads between them. Unfortunately, not from every city you can reach any other one moving along these roads. Therefore Vasya decided to divide the state into provinces so that in every province, one could reach from every city all the cities of the province, but there are no roads between provinces.
Unlike other turn-based strategies, in FreeDiv a player has the opportunity to build tunnels between cities. The tunnels are two-way roads along which one can move armies undetected by the enemy. However, no more than one tunnel can be connected to each city. As for Vasya, he wants to build a network of tunnels so that any pair of cities in his state were reachable by some path consisting of roads and a tunnels. But at that no more than *k* tunnels are connected to each province (otherwise, the province will be difficult to keep in case other provinces are captured by enemy armies).
Vasya discovered that maybe he will not be able to build such a network for the current condition of the state. Maybe he'll have first to build several roads between cities in different provinces to merge the provinces. Your task is to determine the minimum number of roads Vasya needs to build so that it was possible to build the required network of tunnels in the resulting state. | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=106,<=0<=≤<=*m*<=≤<=106). Each of the next *m* lines contains two integers. They are the numbers of cities connected by a corresponding road. No road connects city to itself and there is at most one road between each pair of cities. | Print a single number, the minimum number of additional roads. | [
"3 3 2\n1 2\n2 3\n3 1\n",
"4 2 2\n1 2\n3 4\n",
"4 0 2\n"
] | [
"0",
"0",
"1"
] | In the first example only one province exists, so it is not necessary to build any tunnels or roads.
In the second example two provinces exist. It is possible to merge the provinces by building a tunnel between cities 1 and 3.
In the third example at least one additional road is necessary. For example it is possible to build additional road between cities 1 and 2 and build two tunnels between cities 1 and 3, 2 and 4 after that. | 1,500 | [
{
"input": "3 3 2\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "4 2 2\n1 2\n3 4",
"output": "0"
},
{
"input": "4 0 2",
"output": "1"
},
{
"input": "4 0 3",
"output": "1"
},
{
"input": "8 3 4\n1 4\n4 8\n8 1",
"output": "1"
},
{
"input": "8 3 2\n1 4\n4 8\n8 1",
"output": "2"
},
{
"input": "8 3 3\n1 4\n4 8\n8 1",
"output": "1"
},
{
"input": "8 0 3",
"output": "3"
},
{
"input": "50 0 50",
"output": "24"
},
{
"input": "50 0 2",
"output": "24"
},
{
"input": "50 0 100",
"output": "24"
},
{
"input": "100 0 1",
"output": "98"
},
{
"input": "3289 0 2",
"output": "1644"
},
{
"input": "1000000 0 1",
"output": "999998"
},
{
"input": "1000000 0 2",
"output": "499999"
},
{
"input": "1000000 0 1000000",
"output": "499999"
},
{
"input": "1000000 0 100",
"output": "499999"
},
{
"input": "999999 0 1",
"output": "999997"
},
{
"input": "999999 0 2",
"output": "499999"
},
{
"input": "999999 0 999999",
"output": "499999"
},
{
"input": "102 1 1\n23 58",
"output": "99"
},
{
"input": "102 1 2\n1 62",
"output": "49"
},
{
"input": "102 1 10000\n66 45",
"output": "49"
},
{
"input": "1000000 1 1\n663349 495214",
"output": "999997"
},
{
"input": "1000000 1 2\n998708 47343",
"output": "499998"
},
{
"input": "1000000 1 5\n789076 458264",
"output": "499998"
},
{
"input": "11 5 1\n8 11\n11 2\n2 5\n5 7\n8 2",
"output": "5"
},
{
"input": "11 5 2\n1 6\n6 7\n7 2\n2 11\n2 1",
"output": "2"
},
{
"input": "11 5 3\n2 7\n7 9\n9 8\n8 3\n8 7",
"output": "2"
},
{
"input": "11 5 4\n9 8\n8 4\n4 1\n1 10\n8 1",
"output": "1"
},
{
"input": "11 5 5\n10 8\n8 7\n7 11\n11 6\n10 7",
"output": "1"
},
{
"input": "11 5 6\n10 1\n1 8\n8 7\n7 3\n10 7",
"output": "1"
},
{
"input": "3 2 1\n1 2\n2 3",
"output": "0"
},
{
"input": "2 0 1",
"output": "0"
},
{
"input": "1 0 1",
"output": "0"
},
{
"input": "3 0 1",
"output": "1"
},
{
"input": "4 0 1",
"output": "2"
},
{
"input": "4 1 1\n1 2",
"output": "1"
},
{
"input": "4 2 1\n1 2\n3 4",
"output": "0"
},
{
"input": "4 3 1\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "2 1 1\n1 2",
"output": "0"
},
{
"input": "5 0 1",
"output": "3"
},
{
"input": "5 1 1\n1 2",
"output": "2"
},
{
"input": "5 2 1\n1 2\n2 3",
"output": "1"
},
{
"input": "5 2 1\n1 2\n3 4",
"output": "1"
},
{
"input": "5 3 1\n1 2\n2 3\n4 5",
"output": "0"
},
{
"input": "10 0 1",
"output": "8"
}
] | 1,695,691,897 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | import sys
class UnionFind:
def __init__(self, n: int):
self.data = list(range(n))
self.rank = [1] * n
self.size = [1] * n
self.count = n
def find(self, x: int) -> int:
y = x
while self.data[y] != y:
y = self.data[y]
while self.data[x] != y:
x, self.data[x] = self.data[x], y
return y
def union(self, x: int, y: int):
x, y = self.find(x), self.find(y)
if x == y:
return
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
if self.rank[x] > self.rank[y]:
self.data[y] = x
self.size[x] += self.size[y]
else:
self.data[x] = y
self.size[y] += self.size[x]
self.count -= 1
# input
N, K = 0, 0
edges = []
# output
result = 0
def read_input():
global N, K
readline = sys.stdin.readline
N, M, K = [int(w) for w in readline().split()]
for _ in range(M):
edges.append([int(w) - 1 for w in readline().split()])
def solve():
global result
uf = UnionFind(N)
for u, v in edges:
uf.union(u, v)
if K == 1:
result = max(0, uf.count - 2)
return
max_tunnel_cap = 0
seen = set()
for i in range(N):
x = uf.find(i)
if x in seen:
continue
seen.add(x)
max_tunnel_cap += min(K, uf.size[x])
result = max(0, N - (max_tunnel_cap // 2) - 1)
def write_output():
print(result)
read_input()
solve()
write_output()
| Title: FreeDiv
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays FreeDiv. In this game he manages a huge state, which has *n* cities and *m* two-way roads between them. Unfortunately, not from every city you can reach any other one moving along these roads. Therefore Vasya decided to divide the state into provinces so that in every province, one could reach from every city all the cities of the province, but there are no roads between provinces.
Unlike other turn-based strategies, in FreeDiv a player has the opportunity to build tunnels between cities. The tunnels are two-way roads along which one can move armies undetected by the enemy. However, no more than one tunnel can be connected to each city. As for Vasya, he wants to build a network of tunnels so that any pair of cities in his state were reachable by some path consisting of roads and a tunnels. But at that no more than *k* tunnels are connected to each province (otherwise, the province will be difficult to keep in case other provinces are captured by enemy armies).
Vasya discovered that maybe he will not be able to build such a network for the current condition of the state. Maybe he'll have first to build several roads between cities in different provinces to merge the provinces. Your task is to determine the minimum number of roads Vasya needs to build so that it was possible to build the required network of tunnels in the resulting state.
Input Specification:
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=106,<=0<=≤<=*m*<=≤<=106). Each of the next *m* lines contains two integers. They are the numbers of cities connected by a corresponding road. No road connects city to itself and there is at most one road between each pair of cities.
Output Specification:
Print a single number, the minimum number of additional roads.
Demo Input:
['3 3 2\n1 2\n2 3\n3 1\n', '4 2 2\n1 2\n3 4\n', '4 0 2\n']
Demo Output:
['0', '0', '1']
Note:
In the first example only one province exists, so it is not necessary to build any tunnels or roads.
In the second example two provinces exist. It is possible to merge the provinces by building a tunnel between cities 1 and 3.
In the third example at least one additional road is necessary. For example it is possible to build additional road between cities 1 and 2 and build two tunnels between cities 1 and 3, 2 and 4 after that. | ```python
import sys
class UnionFind:
def __init__(self, n: int):
self.data = list(range(n))
self.rank = [1] * n
self.size = [1] * n
self.count = n
def find(self, x: int) -> int:
y = x
while self.data[y] != y:
y = self.data[y]
while self.data[x] != y:
x, self.data[x] = self.data[x], y
return y
def union(self, x: int, y: int):
x, y = self.find(x), self.find(y)
if x == y:
return
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
if self.rank[x] > self.rank[y]:
self.data[y] = x
self.size[x] += self.size[y]
else:
self.data[x] = y
self.size[y] += self.size[x]
self.count -= 1
# input
N, K = 0, 0
edges = []
# output
result = 0
def read_input():
global N, K
readline = sys.stdin.readline
N, M, K = [int(w) for w in readline().split()]
for _ in range(M):
edges.append([int(w) - 1 for w in readline().split()])
def solve():
global result
uf = UnionFind(N)
for u, v in edges:
uf.union(u, v)
if K == 1:
result = max(0, uf.count - 2)
return
max_tunnel_cap = 0
seen = set()
for i in range(N):
x = uf.find(i)
if x in seen:
continue
seen.add(x)
max_tunnel_cap += min(K, uf.size[x])
result = max(0, N - (max_tunnel_cap // 2) - 1)
def write_output():
print(result)
read_input()
solve()
write_output()
``` | 0 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,671,442,026 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | x,y=map(int,input().split());
sum=int(x*y/2);
print(sum);
'''rrewtgwrfffffhgggtrjgrtghtghr'''
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
x,y=map(int,input().split());
sum=int(x*y/2);
print(sum);
'''rrewtgwrfffffhgggtrjgrtghtghr'''
``` | 3.977 |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"output": "GBBGBB"
},
{
"input": "8 3\nBBGBGBGB",
"output": "GGBGBBBB"
},
{
"input": "10 3\nBBGBBBBBBG",
"output": "GBBBBBGBBB"
},
{
"input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB",
"output": "GGGGGGGGBGGBGGBBBBBBBB"
},
{
"input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG",
"output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB"
},
{
"input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG",
"output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB"
},
{
"input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB",
"output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB"
},
{
"input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB",
"output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB"
},
{
"input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB",
"output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB"
},
{
"input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 1\nB",
"output": "B"
},
{
"input": "1 1\nG",
"output": "G"
},
{
"input": "1 50\nB",
"output": "B"
},
{
"input": "1 50\nG",
"output": "G"
},
{
"input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB",
"output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB"
},
{
"input": "6 3\nGGBBBG",
"output": "GGGBBB"
},
{
"input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG",
"output": "GGBBBBGBGBGBGGGBGBGGGBGBBB"
},
{
"input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB",
"output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB"
},
{
"input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB",
"output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB",
"output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB"
},
{
"input": "17 42\nBBGBGBGGGGGGBBGGG",
"output": "GGGGGGGGGGGBBBBBB"
},
{
"input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG",
"output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB"
},
{
"input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB",
"output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB"
},
{
"input": "2 2\nBG",
"output": "GB"
},
{
"input": "8 8\nGGGBGGBB",
"output": "GGGGGBBB"
},
{
"input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB",
"output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB"
},
{
"input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG",
"output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG",
"output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 10\nGGGGGGGGGG",
"output": "GGGGGGGGGG"
},
{
"input": "10 10\nBBBBBBBBBB",
"output": "BBBBBBBBBB"
},
{
"input": "10 10\nBGBGBGBGBG",
"output": "GGGGGBBBBB"
},
{
"input": "1 1\nB",
"output": "B"
}
] | 1,699,169,971 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | n, t = map(int, input().split())
s = input()
lst = list(s)
for _ in range(t):
i = 0
while i < n - 1:
if lst[i] == 'B' and lst[i+1] == 'G':
lst[i], lst[i+1] = lst[i+1], lst[i]
i += 2
else:
i += 1
final = ""
for ch in lst:
final += ch
print(final) | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Output Specification:
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
Demo Input:
['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n']
Demo Output:
['GBGGB\n', 'GGBGB\n', 'GGGB\n']
Note:
none | ```python
n, t = map(int, input().split())
s = input()
lst = list(s)
for _ in range(t):
i = 0
while i < n - 1:
if lst[i] == 'B' and lst[i+1] == 'G':
lst[i], lst[i+1] = lst[i+1], lst[i]
i += 2
else:
i += 1
final = ""
for ch in lst:
final += ch
print(final)
``` | 3 |
|
448 | B | Suffix Structures | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order. | The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters. | In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton. | [
"automaton\ntomat\n",
"array\narary\n",
"both\nhot\n",
"need\ntree\n"
] | [
"automaton\n",
"array\n",
"both\n",
"need tree\n"
] | In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | 1,000 | [
{
"input": "automaton\ntomat",
"output": "automaton"
},
{
"input": "array\narary",
"output": "array"
},
{
"input": "both\nhot",
"output": "both"
},
{
"input": "need\ntree",
"output": "need tree"
},
{
"input": "abacaba\naaaa",
"output": "automaton"
},
{
"input": "z\nzz",
"output": "need tree"
},
{
"input": "itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc\nsnixfywvcntitcefsgqxjcodwtumurcglfmnamnowzbjzmfzspbfuldraiepeeiyasmrsneekydsbvazoqszyjxkjiotushsddet",
"output": "need tree"
},
{
"input": "y\nu",
"output": "need tree"
},
{
"input": "nbjigpsbammkuuqrxfnmhtimwpflrflehffykbylmnxgadldchdbqklqbremcmzlpxieozgpfgrhegmdcxxfyehzzelcwgkierrj\nbjbakuqrnhimwhffykylmngadhbqkqbrcziefredxxezcgkerj",
"output": "automaton"
},
{
"input": "gzvvawianfysfuxhruarhverinqsbrfxvkcsermuzowahevgskmpvfdljtcztnbkzftfhvnarvkfkqjgrzbrcfthqmspvpqcva\nwnm",
"output": "automaton"
},
{
"input": "dvzohfzgzdjavqwhjcrdphpdqjwtqijabbrhformstqaonlhbglmxugkwviigqaohwvqfhdwwcvdkjrcgxblhvtashhcxssbvpo\nzgvqhpjhforlugkwfwrchvhp",
"output": "automaton"
},
{
"input": "wkfoyetcjivofxaktmauapzeuhcpzjloszzxwydgavebgniiuzrscytsokjkjfkpylvxtlqlquzduywbhqdzmtwprfdohmwgmysy\ny",
"output": "automaton"
},
{
"input": "npeidcoiulxdxzjozsonkdwnoazsbntfclnpubgweaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf\nnpeidcoiulxdxzjozsonkdwnoazsbntfclnpubgeaynuhfmrtybqtkuihxxfhwlnquslnhzvqznyofzcbdewnrisqzdhsiyhkxf",
"output": "automaton"
},
{
"input": "gahcqpgmypeahjcwkzahnhmsmxosnikucqwyzklbfwtujjlzvwklqzxakcrcqalhsvsgvknpxsoqkjnyjkypfsiogbcaxjyugeet\ngahcqpgmypeahjwwkzahnhmsmxopnikucacyzklbfwtujjlzvwkoqzxakcrcqqlhsvsgvknpxslgkjnyjkysfoisqbcaxjyuteeg",
"output": "array"
},
{
"input": "vwesbxsifsjqapwridrenumrukgemlldpbtdhxivsrmzbgprtkqgaryniudkjgpjndluwxuohwwysmyuxyrulwsodgunzirudgtx\nugeabdszfshqsksddireguvsukieqlluhngdpxjvwwnzdrtrtrdjiuxgadtgjpxrmlynspyyryngxuiibrmurwpmoxwwuklbwumo",
"output": "array"
},
{
"input": "kjnohlseyntrslfssrshjxclzlsbkfzfwwwgyxsysvmfkxugdwjodfyxhdsveruoioutwmtcbaljomaorvzjsbmglqckmsyieeiu\netihhycsjgdysowuljmaoksoecxawsgsljofkrjftuweidrkwtymyswdlilsozsxevfbformnbsumlxzqzykjvsnrlxufvgbmshc",
"output": "array"
},
{
"input": "ezbpsylkfztypqrefinexshtgglmkoinrktkloitqhfkivoabrfrivvqrcxkjckzvcozpchhiodrbbxuhnwcjigftnrjfiqyxakh\niacxghqffzdbsiqunhxbiooqvfohzticjpvrzykcrlrxklgknyrkrhjxcetmfocierekatfvkbslkkrbhftwngoijpipvqyznthi",
"output": "array"
},
{
"input": "smywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhuqqcttokbljfbppdinzqgdupkfevmke\nsmywwqeolrsytkthfgacnbufzaulgszikbhluzcdbafjclkqueepxbhoamrwswxherzhhufqcttokbljfbppdinzqgdupkqevmke",
"output": "array"
},
{
"input": "hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghposgyfeslzumaovfkallszzumztftgpcilwfrzpvhhbgdzdvnmseqywlzmhhoxh\ndbelhtzgkssyfrqgzuurdjhwvmdbhylhmvphjgxpzhxbb",
"output": "both"
},
{
"input": "nppjzscfgcvdcnsjtiaudvutmgswqbewejlzibczzowgkdrjgxrpirfdaekvngcsonroheepdoeoeevaullbfwprcnhlxextbxpd\nifilrvacohnwcgzuleicucebrfxphosrgwnglxxkqrcorsxegjoppbb",
"output": "both"
},
{
"input": "ggzmtrhkpdswwqgcbtviahqrgzhyhzddtdekchrpjgngupitzyyuipwstgzewktcqpwezidwvvxgjixnflpjhfznokmpbyzczrzk\ngpgwhtzrcytstezmhettkppgmvxlxqnkjzibiqdtceczkbfhdziuajwjqzgwnhnkdzizprgzwud",
"output": "both"
},
{
"input": "iypjqiiqxhtinlmywpetgqqsdopxhghthjopgbodkwrdxzaaxmtaqcfuiarhrvasusanklzcqaytdyzndakcpljqupowompjjved\nhxeatriypptbhnokarhgqdrkqkypqzdttixphngmpqjodzjqlmcztyjfgoswjelwwdaqdjayavsdocuhqsluxaaopniviaumxip",
"output": "both"
},
{
"input": "ypyhyabmljukejpltkgunwuanhxblhiouyltdiczttndrhdprqtlpfanmzlyzbqanfwfyurxhepuzspdvehxnblhajczqcxlqebx\nlladxuucky",
"output": "both"
},
{
"input": "ddmgoarkuhknbtjggnomyxvvavobmylixwuxnnsdrrbibitoteaiydptnvtfblathihflefuggfnyayniragbtkommycpdyhft\ntejwybmyrhmalraptqwhghsckvnnaagtmzhnpwbhzzgfgritqwqqamgssllnicjqdkivrwaqyxngsqopwieljfxcdywjaal",
"output": "need tree"
},
{
"input": "kipjuscf\nkbwfqfwuvkyhmvnaznzsgdgdnpipikbicmlcwehjirmhgwpxwpgfztqjwfqfaapmsgskr",
"output": "need tree"
},
{
"input": "kobhhrqgwbgqkzcoacrhpkegyepzfds\nhlwcgbvvlegoyrcrjhsjywpdnccxtzgmeujxciuwjlnefllwldidlnjswmetkarxqjigokfvmpxpzfxarhkpdcia",
"output": "need tree"
},
{
"input": "lllolloloolllloolollololololollllooololoooloooolololloolloollllolloolloooooooololllolllolllloolllool\nlollollololololooooloooooooooolloolllololooollllol",
"output": "automaton"
},
{
"input": "lloloooolooollololloooloololooollooloollolllloolllllllloollollllolooloollloololollllooloooololooolol\nlooooollooolllololloollooooololollollloloollollolo",
"output": "both"
},
{
"input": "yyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxyxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx\nyyyyxxxxyxyyxxxyxxyxxxyyxxxxxyyxxxyxxyxxyyyxxxyxxxxxyxyyxyyxyxxyyyxyxxyxxyxxyyxyyyyxyyyyxxxyyxyxxyyx",
"output": "need tree"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "automaton"
},
{
"input": "abracadabra\nlol",
"output": "need tree"
},
{
"input": "abc\naa",
"output": "need tree"
},
{
"input": "ba\naa",
"output": "need tree"
},
{
"input": "abbb\naaab",
"output": "need tree"
},
{
"input": "baaa\nbb",
"output": "need tree"
},
{
"input": "boosss\nosos",
"output": "both"
}
] | 1,684,921,894 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 62 | 0 | def main():
s = input()
t = input()
lent, lens = len(t), len(s)
def is_in(s, t):
i, j = 0, 0
while i < lens and j < lent:
if s[i] == t[j]:
j += 1
i += 1
return j == lent
tmps = ''.join(sorted(s))
tmpt = ''.join(sorted(t))
msg = 'automaton' if is_in(s, t) else 'array' if is_in(tmps, tmpt) and lent == lens else 'both' if is_in(tmps, tmpt) else 'need tree'
print(msg)
return
if __name__ == "__main__":
main() | Title: Suffix Structures
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
Input Specification:
The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
Output Specification:
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
Demo Input:
['automaton\ntomat\n', 'array\narary\n', 'both\nhot\n', 'need\ntree\n']
Demo Output:
['automaton\n', 'array\n', 'both\n', 'need tree\n']
Note:
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot". | ```python
def main():
s = input()
t = input()
lent, lens = len(t), len(s)
def is_in(s, t):
i, j = 0, 0
while i < lens and j < lent:
if s[i] == t[j]:
j += 1
i += 1
return j == lent
tmps = ''.join(sorted(s))
tmpt = ''.join(sorted(t))
msg = 'automaton' if is_in(s, t) else 'array' if is_in(tmps, tmpt) and lent == lens else 'both' if is_in(tmps, tmpt) else 'need tree'
print(msg)
return
if __name__ == "__main__":
main()
``` | 3 |
|
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position. | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one three times. | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output": "99"
},
{
"input": "-1000000000 -1000000000\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "-1000000000 -1000000000\n0 999999999",
"output": "1999999999"
},
{
"input": "0 0\n2 1",
"output": "2"
},
{
"input": "10 0\n100 0",
"output": "90"
},
{
"input": "1 5\n6 4",
"output": "5"
},
{
"input": "0 0\n5 4",
"output": "5"
},
{
"input": "10 1\n20 1",
"output": "10"
},
{
"input": "1 1\n-3 4",
"output": "4"
},
{
"input": "-863407280 504312726\n786535210 -661703810",
"output": "1649942490"
},
{
"input": "-588306085 -741137832\n341385643 152943311",
"output": "929691728"
},
{
"input": "0 0\n4 0",
"output": "4"
},
{
"input": "93097194 -48405232\n-716984003 -428596062",
"output": "810081197"
},
{
"input": "9 1\n1 1",
"output": "8"
},
{
"input": "4 6\n0 4",
"output": "4"
},
{
"input": "2 4\n5 2",
"output": "3"
},
{
"input": "-100000000 -100000000\n100000000 100000123",
"output": "200000123"
},
{
"input": "5 6\n5 7",
"output": "1"
},
{
"input": "12 16\n12 1",
"output": "15"
},
{
"input": "0 0\n5 1",
"output": "5"
},
{
"input": "0 1\n1 1",
"output": "1"
},
{
"input": "-44602634 913365223\n-572368780 933284951",
"output": "527766146"
},
{
"input": "-2 0\n2 -2",
"output": "4"
},
{
"input": "0 0\n3 1",
"output": "3"
},
{
"input": "-458 2\n1255 4548",
"output": "4546"
},
{
"input": "-5 -4\n-3 -3",
"output": "2"
},
{
"input": "4 5\n7 3",
"output": "3"
},
{
"input": "-1000000000 -999999999\n1000000000 999999998",
"output": "2000000000"
},
{
"input": "-1000000000 -1000000000\n1000000000 -1000000000",
"output": "2000000000"
},
{
"input": "-464122675 -898521847\n656107323 -625340409",
"output": "1120229998"
},
{
"input": "-463154699 -654742385\n-699179052 -789004997",
"output": "236024353"
},
{
"input": "982747270 -593488945\n342286841 -593604186",
"output": "640460429"
},
{
"input": "-80625246 708958515\n468950878 574646184",
"output": "549576124"
},
{
"input": "0 0\n1 0",
"output": "1"
},
{
"input": "109810 1\n2 3",
"output": "109808"
},
{
"input": "-9 0\n9 9",
"output": "18"
},
{
"input": "9 9\n9 9",
"output": "0"
},
{
"input": "1 1\n4 3",
"output": "3"
},
{
"input": "1 2\n45 1",
"output": "44"
},
{
"input": "207558188 -313753260\n-211535387 -721675423",
"output": "419093575"
},
{
"input": "-11 0\n0 0",
"output": "11"
},
{
"input": "-1000000000 1000000000\n1000000000 -1000000000",
"output": "2000000000"
},
{
"input": "0 0\n1 1",
"output": "1"
},
{
"input": "0 0\n0 1",
"output": "1"
},
{
"input": "0 0\n-1 1",
"output": "1"
},
{
"input": "0 0\n-1 0",
"output": "1"
},
{
"input": "0 0\n-1 -1",
"output": "1"
},
{
"input": "0 0\n0 -1",
"output": "1"
},
{
"input": "0 0\n1 -1",
"output": "1"
},
{
"input": "10 90\n90 10",
"output": "80"
},
{
"input": "851016864 573579544\n-761410925 -380746263",
"output": "1612427789"
},
{
"input": "1 9\n9 9",
"output": "8"
},
{
"input": "1000 1000\n1000 1000",
"output": "0"
},
{
"input": "1 9\n9 1",
"output": "8"
},
{
"input": "1 90\n90 90",
"output": "89"
},
{
"input": "100 100\n1000 1000",
"output": "900"
},
{
"input": "-1 0\n0 0",
"output": "1"
},
{
"input": "-750595959 -2984043\n649569876 -749608783",
"output": "1400165835"
},
{
"input": "958048496 712083589\n423286949 810566863",
"output": "534761547"
},
{
"input": "146316710 53945094\n-523054748 147499505",
"output": "669371458"
},
{
"input": "50383856 -596516251\n-802950224 -557916272",
"output": "853334080"
},
{
"input": "-637204864 -280290367\n-119020929 153679771",
"output": "518183935"
},
{
"input": "-100 -100\n-60 -91",
"output": "40"
},
{
"input": "337537326 74909428\n-765558776 167951547",
"output": "1103096102"
},
{
"input": "0 81\n18 90",
"output": "18"
},
{
"input": "283722202 -902633305\n-831696497 -160868946",
"output": "1115418699"
},
{
"input": "1000 1000\n-1000 1000",
"output": "2000"
},
{
"input": "5 6\n4 8",
"output": "2"
},
{
"input": "40572000 597493595\n-935051731 368493185",
"output": "975623731"
},
{
"input": "-5 5\n5 5",
"output": "10"
}
] | 1,474,410,249 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 62 | 204,800 | l1=input().split(' ')
l2=input().split(' ')
x1=int (l1[0])
y1=int (l1[1])
x2=int (l2[0])
y2=int (l2[1])
if (x1!=x2 and y1!=y2) :
if (x2>x1 and y2>y1 ):
c=min(x2-x1,y2-y1)
x2=x2-c
y2=y2-c
if (x1!=x2):
c=c+x2-x1
else :
c=c+y2-y1
elif (x1>x2 and y1>y2 ):
c=min(x1-x2,y1-y2)
x1=x1-c
y1=y1-c
if (x1!=x2):
c=c+x1-x2
else :
c=c+y1-y2
elif (x1<x2 and y1>y2 ):
c=min(x2-x1,y1-y2)
x1=x1+c
y1=y1-c
if (x1!=x2):
c=c+x2-x1
else :
c=c+y1-y2
elif (x2<x1 and y2>y1 ):
c=min(x1-x2,y2-y1)
x1=x1-c
y1=y1+c
if (x1!=x2):
c=c-x2+x1
else :
c=c-y1+y2
print (c)
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.
Input Specification:
The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot.
Output Specification:
Print the only integer *d* — the minimal number of steps to get the finish position.
Demo Input:
['0 0\n4 5\n', '3 4\n6 1\n']
Demo Output:
['5\n', '3\n']
Note:
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one three times. | ```python
l1=input().split(' ')
l2=input().split(' ')
x1=int (l1[0])
y1=int (l1[1])
x2=int (l2[0])
y2=int (l2[1])
if (x1!=x2 and y1!=y2) :
if (x2>x1 and y2>y1 ):
c=min(x2-x1,y2-y1)
x2=x2-c
y2=y2-c
if (x1!=x2):
c=c+x2-x1
else :
c=c+y2-y1
elif (x1>x2 and y1>y2 ):
c=min(x1-x2,y1-y2)
x1=x1-c
y1=y1-c
if (x1!=x2):
c=c+x1-x2
else :
c=c+y1-y2
elif (x1<x2 and y1>y2 ):
c=min(x2-x1,y1-y2)
x1=x1+c
y1=y1-c
if (x1!=x2):
c=c+x2-x1
else :
c=c+y1-y2
elif (x2<x1 and y2>y1 ):
c=min(x1-x2,y2-y1)
x1=x1-c
y1=y1+c
if (x1!=x2):
c=c-x2+x1
else :
c=c-y1+y2
print (c)
``` | -1 |
|
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,622,307,770 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 0 | n=int(input())
a='ROYGBIV'
for i in range(7,n):
for j in ['R','O','Y','G','B','I','V']:
if j!=a[i-1] and j!=a[i-2] and j!=a[i-3] and (i+1<n or j!=a[(i+1)%n]) and (i+2<n or j!=a[(i+2)%n]) and (i+3<n or j!=a[(i+3)%n]):
a+=j
break
print(a) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
n=int(input())
a='ROYGBIV'
for i in range(7,n):
for j in ['R','O','Y','G','B','I','V']:
if j!=a[i-1] and j!=a[i-2] and j!=a[i-3] and (i+1<n or j!=a[(i+1)%n]) and (i+2<n or j!=a[(i+2)%n]) and (i+3<n or j!=a[(i+3)%n]):
a+=j
break
print(a)
``` | 3.9535 |
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output": "1 2"
},
{
"input": "7",
"output": "2 2"
},
{
"input": "8",
"output": "2 3"
},
{
"input": "9",
"output": "2 4"
},
{
"input": "10",
"output": "2 4"
},
{
"input": "11",
"output": "2 4"
},
{
"input": "12",
"output": "2 4"
},
{
"input": "13",
"output": "3 4"
},
{
"input": "1000000",
"output": "285714 285715"
},
{
"input": "16",
"output": "4 6"
},
{
"input": "17",
"output": "4 6"
},
{
"input": "18",
"output": "4 6"
},
{
"input": "19",
"output": "4 6"
},
{
"input": "20",
"output": "5 6"
},
{
"input": "21",
"output": "6 6"
},
{
"input": "22",
"output": "6 7"
},
{
"input": "23",
"output": "6 8"
},
{
"input": "24",
"output": "6 8"
},
{
"input": "25",
"output": "6 8"
},
{
"input": "26",
"output": "6 8"
},
{
"input": "27",
"output": "7 8"
},
{
"input": "28",
"output": "8 8"
},
{
"input": "29",
"output": "8 9"
},
{
"input": "30",
"output": "8 10"
},
{
"input": "100",
"output": "28 30"
},
{
"input": "99",
"output": "28 29"
},
{
"input": "98",
"output": "28 28"
},
{
"input": "97",
"output": "27 28"
},
{
"input": "96",
"output": "26 28"
},
{
"input": "95",
"output": "26 28"
},
{
"input": "94",
"output": "26 28"
},
{
"input": "93",
"output": "26 28"
},
{
"input": "92",
"output": "26 27"
},
{
"input": "91",
"output": "26 26"
},
{
"input": "90",
"output": "25 26"
},
{
"input": "89",
"output": "24 26"
},
{
"input": "88",
"output": "24 26"
},
{
"input": "87",
"output": "24 26"
},
{
"input": "86",
"output": "24 26"
},
{
"input": "85",
"output": "24 25"
},
{
"input": "84",
"output": "24 24"
},
{
"input": "83",
"output": "23 24"
},
{
"input": "82",
"output": "22 24"
},
{
"input": "81",
"output": "22 24"
},
{
"input": "80",
"output": "22 24"
},
{
"input": "1000",
"output": "285 286"
},
{
"input": "999",
"output": "284 286"
},
{
"input": "998",
"output": "284 286"
},
{
"input": "997",
"output": "284 286"
},
{
"input": "996",
"output": "284 286"
},
{
"input": "995",
"output": "284 285"
},
{
"input": "994",
"output": "284 284"
},
{
"input": "993",
"output": "283 284"
},
{
"input": "992",
"output": "282 284"
},
{
"input": "991",
"output": "282 284"
},
{
"input": "990",
"output": "282 284"
},
{
"input": "989",
"output": "282 284"
},
{
"input": "988",
"output": "282 283"
},
{
"input": "987",
"output": "282 282"
},
{
"input": "986",
"output": "281 282"
},
{
"input": "985",
"output": "280 282"
},
{
"input": "984",
"output": "280 282"
},
{
"input": "983",
"output": "280 282"
},
{
"input": "982",
"output": "280 282"
},
{
"input": "981",
"output": "280 281"
},
{
"input": "980",
"output": "280 280"
},
{
"input": "10000",
"output": "2856 2858"
},
{
"input": "9999",
"output": "2856 2858"
},
{
"input": "9998",
"output": "2856 2858"
},
{
"input": "9997",
"output": "2856 2857"
},
{
"input": "9996",
"output": "2856 2856"
},
{
"input": "9995",
"output": "2855 2856"
},
{
"input": "9994",
"output": "2854 2856"
},
{
"input": "9993",
"output": "2854 2856"
},
{
"input": "9992",
"output": "2854 2856"
},
{
"input": "9991",
"output": "2854 2856"
},
{
"input": "9990",
"output": "2854 2855"
},
{
"input": "9989",
"output": "2854 2854"
},
{
"input": "9988",
"output": "2853 2854"
},
{
"input": "9987",
"output": "2852 2854"
},
{
"input": "9986",
"output": "2852 2854"
},
{
"input": "9985",
"output": "2852 2854"
},
{
"input": "9984",
"output": "2852 2854"
},
{
"input": "9983",
"output": "2852 2853"
},
{
"input": "9982",
"output": "2852 2852"
},
{
"input": "9981",
"output": "2851 2852"
},
{
"input": "9980",
"output": "2850 2852"
},
{
"input": "100000",
"output": "28570 28572"
},
{
"input": "99999",
"output": "28570 28572"
},
{
"input": "99998",
"output": "28570 28572"
},
{
"input": "99997",
"output": "28570 28572"
},
{
"input": "99996",
"output": "28570 28571"
},
{
"input": "99995",
"output": "28570 28570"
},
{
"input": "99994",
"output": "28569 28570"
},
{
"input": "99993",
"output": "28568 28570"
},
{
"input": "99992",
"output": "28568 28570"
},
{
"input": "99991",
"output": "28568 28570"
},
{
"input": "99990",
"output": "28568 28570"
},
{
"input": "99989",
"output": "28568 28569"
},
{
"input": "99988",
"output": "28568 28568"
},
{
"input": "99987",
"output": "28567 28568"
},
{
"input": "99986",
"output": "28566 28568"
},
{
"input": "99985",
"output": "28566 28568"
},
{
"input": "99984",
"output": "28566 28568"
},
{
"input": "99983",
"output": "28566 28568"
},
{
"input": "99982",
"output": "28566 28567"
},
{
"input": "99981",
"output": "28566 28566"
},
{
"input": "99980",
"output": "28565 28566"
},
{
"input": "999999",
"output": "285714 285714"
},
{
"input": "999998",
"output": "285713 285714"
},
{
"input": "999997",
"output": "285712 285714"
},
{
"input": "999996",
"output": "285712 285714"
},
{
"input": "999995",
"output": "285712 285714"
},
{
"input": "999994",
"output": "285712 285714"
},
{
"input": "999993",
"output": "285712 285713"
},
{
"input": "999992",
"output": "285712 285712"
},
{
"input": "999991",
"output": "285711 285712"
},
{
"input": "999990",
"output": "285710 285712"
},
{
"input": "999989",
"output": "285710 285712"
},
{
"input": "999988",
"output": "285710 285712"
},
{
"input": "999987",
"output": "285710 285712"
},
{
"input": "999986",
"output": "285710 285711"
},
{
"input": "999985",
"output": "285710 285710"
},
{
"input": "999984",
"output": "285709 285710"
},
{
"input": "999983",
"output": "285708 285710"
},
{
"input": "999982",
"output": "285708 285710"
},
{
"input": "999981",
"output": "285708 285710"
},
{
"input": "999980",
"output": "285708 285710"
},
{
"input": "234123",
"output": "66892 66893"
},
{
"input": "234122",
"output": "66892 66892"
},
{
"input": "234121",
"output": "66891 66892"
},
{
"input": "234120",
"output": "66890 66892"
},
{
"input": "234119",
"output": "66890 66892"
},
{
"input": "234118",
"output": "66890 66892"
},
{
"input": "234117",
"output": "66890 66892"
},
{
"input": "234116",
"output": "66890 66891"
},
{
"input": "234115",
"output": "66890 66890"
},
{
"input": "234114",
"output": "66889 66890"
},
{
"input": "234113",
"output": "66888 66890"
},
{
"input": "234112",
"output": "66888 66890"
},
{
"input": "234111",
"output": "66888 66890"
},
{
"input": "234110",
"output": "66888 66890"
},
{
"input": "234109",
"output": "66888 66889"
},
{
"input": "234108",
"output": "66888 66888"
},
{
"input": "234107",
"output": "66887 66888"
},
{
"input": "234106",
"output": "66886 66888"
},
{
"input": "234105",
"output": "66886 66888"
},
{
"input": "234104",
"output": "66886 66888"
},
{
"input": "234103",
"output": "66886 66888"
},
{
"input": "868531",
"output": "248151 248152"
},
{
"input": "868530",
"output": "248150 248152"
},
{
"input": "868529",
"output": "248150 248152"
},
{
"input": "868528",
"output": "248150 248152"
},
{
"input": "868527",
"output": "248150 248152"
},
{
"input": "868526",
"output": "248150 248151"
},
{
"input": "868525",
"output": "248150 248150"
},
{
"input": "868524",
"output": "248149 248150"
},
{
"input": "868523",
"output": "248148 248150"
},
{
"input": "868522",
"output": "248148 248150"
},
{
"input": "868521",
"output": "248148 248150"
},
{
"input": "868520",
"output": "248148 248150"
},
{
"input": "868519",
"output": "248148 248149"
},
{
"input": "868518",
"output": "248148 248148"
},
{
"input": "868517",
"output": "248147 248148"
},
{
"input": "868516",
"output": "248146 248148"
},
{
"input": "868515",
"output": "248146 248148"
},
{
"input": "868514",
"output": "248146 248148"
},
{
"input": "868513",
"output": "248146 248148"
},
{
"input": "868512",
"output": "248146 248147"
},
{
"input": "868511",
"output": "248146 248146"
},
{
"input": "123413",
"output": "35260 35262"
},
{
"input": "123412",
"output": "35260 35262"
},
{
"input": "123411",
"output": "35260 35261"
},
{
"input": "123410",
"output": "35260 35260"
},
{
"input": "123409",
"output": "35259 35260"
},
{
"input": "123408",
"output": "35258 35260"
},
{
"input": "123407",
"output": "35258 35260"
},
{
"input": "123406",
"output": "35258 35260"
},
{
"input": "123405",
"output": "35258 35260"
},
{
"input": "123404",
"output": "35258 35259"
},
{
"input": "123403",
"output": "35258 35258"
},
{
"input": "123402",
"output": "35257 35258"
},
{
"input": "123401",
"output": "35256 35258"
},
{
"input": "123400",
"output": "35256 35258"
},
{
"input": "123399",
"output": "35256 35258"
},
{
"input": "123398",
"output": "35256 35258"
},
{
"input": "123397",
"output": "35256 35257"
},
{
"input": "123396",
"output": "35256 35256"
},
{
"input": "123395",
"output": "35255 35256"
},
{
"input": "123394",
"output": "35254 35256"
},
{
"input": "123393",
"output": "35254 35256"
},
{
"input": "15",
"output": "4 5"
}
] | 1,613,738,960 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n = int(input())
ned = n//7
ost=0
if n>7:
if n%7!=0:
if (ned%7)<2:
ost=1
else:
ost=2
print(ned*2, (ned*2)+ost)
if n<7:
print(0,2)
| Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Output Specification:
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
Demo Input:
['14\n', '2\n']
Demo Output:
['4 4\n', '0 2\n']
Note:
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | ```python
n = int(input())
ned = n//7
ost=0
if n>7:
if n%7!=0:
if (ned%7)<2:
ost=1
else:
ost=2
print(ned*2, (ned*2)+ost)
if n<7:
print(0,2)
``` | 0 |
|
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,680,330,112 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | string = input()
newstr = ""
newlist = string.split("WUB")
for element in newlist:
if element != "":
newstr += f" {element}"
print(newstr[1:]) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
string = input()
newstr = ""
newlist = string.split("WUB")
for element in newlist:
if element != "":
newstr += f" {element}"
print(newstr[1:])
``` | 3 |
|
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "2",
"output": "1 2"
},
{
"input": "3",
"output": "1 3"
},
{
"input": "4",
"output": "2 2"
},
{
"input": "6",
"output": "2 3"
},
{
"input": "7",
"output": "1 7"
},
{
"input": "9",
"output": "3 3"
},
{
"input": "10",
"output": "2 5"
},
{
"input": "11",
"output": "1 11"
},
{
"input": "12",
"output": "3 4"
},
{
"input": "15",
"output": "3 5"
},
{
"input": "100",
"output": "10 10"
},
{
"input": "101",
"output": "1 101"
},
{
"input": "169",
"output": "13 13"
},
{
"input": "179",
"output": "1 179"
},
{
"input": "190",
"output": "10 19"
},
{
"input": "1000",
"output": "25 40"
},
{
"input": "10000",
"output": "100 100"
},
{
"input": "10001",
"output": "73 137"
},
{
"input": "100000",
"output": "250 400"
},
{
"input": "100001",
"output": "11 9091"
},
{
"input": "1000000",
"output": "1000 1000"
},
{
"input": "999983",
"output": "1 999983"
},
{
"input": "524288",
"output": "512 1024"
},
{
"input": "954493",
"output": "971 983"
},
{
"input": "966289",
"output": "983 983"
},
{
"input": "944663",
"output": "961 983"
},
{
"input": "912673",
"output": "97 9409"
},
{
"input": "732641",
"output": "679 1079"
},
{
"input": "232897",
"output": "343 679"
},
{
"input": "16807",
"output": "49 343"
},
{
"input": "999958",
"output": "2 499979"
},
{
"input": "990151",
"output": "1 990151"
},
{
"input": "997002",
"output": "998 999"
},
{
"input": "20",
"output": "4 5"
},
{
"input": "20261",
"output": "1 20261"
},
{
"input": "999123",
"output": "3 333041"
},
{
"input": "901841",
"output": "1 901841"
}
] | 1,690,561,412 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | from math import sqrt
def find_factors(number):
factors = []
for i in range(1, (number + 1)):
if number % i == 0:
factors.append(i)
return factors
c=int(input())
v=find_factors(c);len=len(v)
if len==2:
print(*v)
elif sqrt(c)==int(sqrt(c)):print(int(sqrt(c)),int(sqrt(c)))
else:
aa=v[(len+1)//2]
if aa*aa==c:
print(aa,aa)
else:
#print(v[(len+1)//2],v[((len+1)//2-1)])
if abs(v[(len+1)//2]-v[((len+1)//2-1)])>abs(v[(len+1)//2]-v[(len+1)//2+1]):print(min(v[(len+1)//2],v[(len+1)//2+1]),max(v[(len+1)//2],v[(len+1)//2+1]))
else:print(min(v[(len+1)//2],v[(len+1)//2-1]),max(v[(len+1)//2],v[(len+1)//2-1])) | Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Output Specification:
Print two integers — the number of rows and columns on the display.
Demo Input:
['8\n', '64\n', '5\n', '999999\n']
Demo Output:
['2 4\n', '8 8\n', '1 5\n', '999 1001\n']
Note:
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | ```python
from math import sqrt
def find_factors(number):
factors = []
for i in range(1, (number + 1)):
if number % i == 0:
factors.append(i)
return factors
c=int(input())
v=find_factors(c);len=len(v)
if len==2:
print(*v)
elif sqrt(c)==int(sqrt(c)):print(int(sqrt(c)),int(sqrt(c)))
else:
aa=v[(len+1)//2]
if aa*aa==c:
print(aa,aa)
else:
#print(v[(len+1)//2],v[((len+1)//2-1)])
if abs(v[(len+1)//2]-v[((len+1)//2-1)])>abs(v[(len+1)//2]-v[(len+1)//2+1]):print(min(v[(len+1)//2],v[(len+1)//2+1]),max(v[(len+1)//2],v[(len+1)//2+1]))
else:print(min(v[(len+1)//2],v[(len+1)//2-1]),max(v[(len+1)//2],v[(len+1)//2-1]))
``` | 0 |
|
771 | B | Bear and Different Names | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy"
] | null | null | In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).
A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.
You are a spy in the enemy's camp. You noticed *n* soldiers standing in a row, numbered 1 through *n*. The general wants to choose a group of *k* consecutive soldiers. For every *k* consecutive soldiers, the general wrote down whether they would be an effective group or not.
You managed to steal the general's notes, with *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1, each either "YES" or "NO".
- The string *s*1 describes a group of soldiers 1 through *k* ("YES" if the group is effective, and "NO" otherwise). - The string *s*2 describes a group of soldiers 2 through *k*<=+<=1. - And so on, till the string *s**n*<=-<=*k*<=+<=1 that describes a group of soldiers *n*<=-<=*k*<=+<=1 through *n*.
Your task is to find possible names of *n* soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.
Find and print any solution. It can be proved that there always exists at least one solution. | The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=50) — the number of soldiers and the size of a group respectively.
The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k*<=-<=1 is effective, and "NO" otherwise. | Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.
If there are multiple valid solutions, print any of them. | [
"8 3\nNO NO YES YES YES NO\n",
"9 8\nYES NO\n",
"3 2\nNO NO\n"
] | [
"Adam Bob Bob Cpqepqwer Limak Adam Bob Adam",
"R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc",
"Na Na Na"
] | In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:
- First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string *s*<sub class="lower-index">1</sub> is "NO". - Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string *s*<sub class="lower-index">2</sub> is "NO". - Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string *s*<sub class="lower-index">3</sub> is "YES". - ..., - Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string *s*<sub class="lower-index">6</sub> is "NO". | 500 | [
{
"input": "8 3\nNO NO YES YES YES NO",
"output": "Ab Ac Ab Ac Af Ag Ah Ag "
},
{
"input": "9 8\nYES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Ac "
},
{
"input": "3 2\nNO NO",
"output": "Ab Ab Ab "
},
{
"input": "2 2\nYES",
"output": "Ab Ac "
},
{
"input": "2 2\nNO",
"output": "Ab Ab "
},
{
"input": "7 2\nYES NO YES YES NO YES",
"output": "Ab Ac Ac Ae Af Af Ah "
},
{
"input": "18 7\nYES YES YES YES YES YES YES NO NO NO NO NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ai Aj Ak Al Am "
},
{
"input": "50 3\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO",
"output": "Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Ab Ac Bx Ac "
},
{
"input": "19 15\nNO YES YES YES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ab Aq Ar As Af "
},
{
"input": "3 2\nNO NO",
"output": "Ab Ab Ab "
},
{
"input": "3 2\nNO YES",
"output": "Ab Ab Ad "
},
{
"input": "3 2\nYES NO",
"output": "Ab Ac Ac "
},
{
"input": "3 2\nYES YES",
"output": "Ab Ac Ad "
},
{
"input": "26 17\nNO YES YES YES NO YES NO YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ab As At Au Af Aw Ah Ay Az Ba "
},
{
"input": "12 2\nYES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am "
},
{
"input": "16 2\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO",
"output": "Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab Ab "
},
{
"input": "42 20\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq "
},
{
"input": "37 14\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al "
},
{
"input": "29 10\nYES NO YES NO YES NO YES YES YES YES YES NO NO NO NO NO YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Ac Am Ae Ao Ag Aq Ar As At Au Am Ae Ao Ag Aq Ba Bb Bc Bd "
},
{
"input": "37 3\nYES NO YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES NO NO YES YES YES YES NO",
"output": "Ab Ac Ad Ac Af Ac Ah Ac Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Ba Bb Be Bb Be Bh Bi Bj Bk Bj "
},
{
"input": "44 11\nNO NO YES NO YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES NO NO YES NO NO YES YES YES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Ab Ac An Ae Ap Ag Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Au Bf Bg Bh Bi Bj Ba Bb Bm Bd Au Bp Bq Br Bi "
},
{
"input": "50 49\nNO YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ab By "
},
{
"input": "50 49\nYES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "50 49\nNO NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ab Ac "
},
{
"input": "50 49\nYES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ac "
},
{
"input": "46 42\nNO YES YES YES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Ab Br Bs Bt Af "
},
{
"input": "45 26\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt "
},
{
"input": "45 26\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au "
},
{
"input": "50 3\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES",
"output": "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak Ab Am Ab Ao Ab Aq Ab As Ab Au Ab Aw Ab Ay Ab Ba Ab Bc Ab Be Ab Bg Ab Bi Ab Bk Ab Bm Ab Bo Ab Bq Ab Bs Ab Bu Ab Bw Ab By "
},
{
"input": "50 2\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO",
"output": "Ab Ab Ad Ad Af Af Ah Ah Aj Aj Al Al An An Ap Ap Ar Ar At At Av Av Ax Ax Az Az Bb Bb Bd Bd Bf Bf Bh Bh Bj Bj Bl Bl Bn Bn Bp Bp Br Br Bt Bt Bv Bv Bx Bx "
},
{
"input": "50 3\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES YES YES YES YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES",
"output": "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak Ab Am Ab Ao Ab Aq Ab As Ab Au Ab Aw Ab Ay Ab Ba Ab Bc Bd Be Bf Bg Bf Bi Bf Bk Bf Bm Bf Bo Bf Bq Bf Bs Bf Bu Bf Bw Bf By "
},
{
"input": "49 2\nNO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO NO NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES NO YES",
"output": "Ab Ab Ad Ad Af Af Ah Ah Aj Aj Al Al An An Ap Ap Ar Ar At At Av Av Ax Ax Ax Ax Bb Bb Bd Bd Bf Bf Bh Bh Bj Bj Bl Bl Bn Bn Bp Bp Br Br Bt Bt Bv Bv Bx "
},
{
"input": "35 22\nNO NO NO NO NO NO NO NO NO NO NO NO NO NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao "
},
{
"input": "46 41\nYES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu "
},
{
"input": "12 4\nYES YES NO NO NO NO NO YES YES",
"output": "Ab Ac Ad Ae Af Ad Ae Af Ad Ae Al Am "
},
{
"input": "50 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "50 4\nYES YES YES YES YES NO YES YES YES YES NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Ag Ak Al Am An Al Am Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bc Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "34 5\nYES YES YES YES YES NO YES YES YES YES NO NO YES YES YES NO NO YES NO YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ag Al Am An Ao Al Am Ar As At Am Ar Aw At Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi "
},
{
"input": "50 43\nYES NO YES NO YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Ac Bt Ae Bv Bw Bx By "
},
{
"input": "38 30\nNO NO YES NO YES NO NO NO NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Ab Ac Bg Ae Bi Ag Ah Ai Aj "
},
{
"input": "50 50\nNO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ab "
},
{
"input": "50 50\nYES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "5 3\nYES NO YES",
"output": "Ab Ac Ad Ac Af "
},
{
"input": "30 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be "
},
{
"input": "50 50\nYES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "27 27\nYES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb "
},
{
"input": "28 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc "
},
{
"input": "50 2\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "8 3\nYES NO YES NO YES NO",
"output": "Ab Ac Ad Ac Af Ac Ah Ac "
},
{
"input": "42 30\nNO YES YES NO NO YES NO YES NO YES NO NO YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Ab Bf Bg Ae Af Bj Ah Bl Aj Bn Al Am Bq "
},
{
"input": "50 49\nYES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "50 3\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx By "
},
{
"input": "7 5\nYES NO YES",
"output": "Ab Ac Ad Ae Af Ac Ah "
},
{
"input": "8 4\nNO YES NO YES NO",
"output": "Ab Ac Ad Ab Af Ad Ah Af "
},
{
"input": "50 50\nNO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Bx Ab "
},
{
"input": "50 48\nYES NO YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ap Aq Ar As At Au Av Aw Ax Ay Az Ba Bb Bc Bd Be Bf Bg Bh Bi Bj Bk Bl Bm Bn Bo Bp Bq Br Bs Bt Bu Bv Bw Ac By "
},
{
"input": "29 14\nYES NO YES NO NO YES YES NO NO YES YES NO NO YES YES YES",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Aj Ak Al Am An Ao Ac Aq Ae Af At Au Ai Aj Ax Ay Am An Bb Bc Bd "
},
{
"input": "10 3\nNO YES NO YES NO YES NO YES",
"output": "Ab Ac Ab Ae Ab Ag Ab Ai Ab Ak "
},
{
"input": "10 5\nYES NO YES NO YES NO",
"output": "Ab Ac Ad Ae Af Ac Ah Ae Aj Ac "
}
] | 1,489,856,721 | 5,421 | Python 3 | OK | TESTS | 59 | 62 | 4,608,000 | names = [i for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'] + [ 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'[i:i+2] for i in range(0, len('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'), 2)]
n, k = map(int, input().split())
yes_no = input().split()
guess = names[:n]
for i in range(len(yes_no)):
if yes_no[i] == 'NO':
guess[i + k - 1] = guess[i]
print(' '.join(guess)) | Title: Bear and Different Names
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).
A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.
You are a spy in the enemy's camp. You noticed *n* soldiers standing in a row, numbered 1 through *n*. The general wants to choose a group of *k* consecutive soldiers. For every *k* consecutive soldiers, the general wrote down whether they would be an effective group or not.
You managed to steal the general's notes, with *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1, each either "YES" or "NO".
- The string *s*1 describes a group of soldiers 1 through *k* ("YES" if the group is effective, and "NO" otherwise). - The string *s*2 describes a group of soldiers 2 through *k*<=+<=1. - And so on, till the string *s**n*<=-<=*k*<=+<=1 that describes a group of soldiers *n*<=-<=*k*<=+<=1 through *n*.
Your task is to find possible names of *n* soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.
Find and print any solution. It can be proved that there always exists at least one solution.
Input Specification:
The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=50) — the number of soldiers and the size of a group respectively.
The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k*<=-<=1 is effective, and "NO" otherwise.
Output Specification:
Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.
If there are multiple valid solutions, print any of them.
Demo Input:
['8 3\nNO NO YES YES YES NO\n', '9 8\nYES NO\n', '3 2\nNO NO\n']
Demo Output:
['Adam Bob Bob Cpqepqwer Limak Adam Bob Adam', 'R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc', 'Na Na Na']
Note:
In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:
- First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string *s*<sub class="lower-index">1</sub> is "NO". - Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string *s*<sub class="lower-index">2</sub> is "NO". - Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string *s*<sub class="lower-index">3</sub> is "YES". - ..., - Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string *s*<sub class="lower-index">6</sub> is "NO". | ```python
names = [i for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'] + [ 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'[i:i+2] for i in range(0, len('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'), 2)]
n, k = map(int, input().split())
yes_no = input().split()
guess = names[:n]
for i in range(len(yes_no)):
if yes_no[i] == 'NO':
guess[i + k - 1] = guess[i]
print(' '.join(guess))
``` | 3 |
|
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output": "12"
},
{
"input": "3555165 6693472\n1499112 556941 3075290",
"output": "3089339"
},
{
"input": "0 0\n1000000000 1000000000 1000000000",
"output": "7000000000"
},
{
"input": "1 1\n0 1 0",
"output": "0"
},
{
"input": "117708228 562858833\n118004008 360437130 154015822",
"output": "738362681"
},
{
"input": "999998118 700178721\n822106746 82987112 547955384",
"output": "1753877029"
},
{
"input": "566568710 765371101\n60614022 80126928 809950465",
"output": "1744607222"
},
{
"input": "448858599 829062060\n764716760 97644201 203890025",
"output": "1178219122"
},
{
"input": "626115781 966381948\n395190569 820194184 229233367",
"output": "1525971878"
},
{
"input": "803372962 103701834\n394260597 837711458 623172928",
"output": "3426388098"
},
{
"input": "980630143 241021722\n24734406 928857659 312079781",
"output": "1624075280"
},
{
"input": "862920032 378341609\n360240924 241342224 337423122",
"output": "974174021"
},
{
"input": "40177212 515661496\n64343660 963892207 731362684",
"output": "3694721078"
},
{
"input": "217434393 579352456\n694817470 981409480 756706026",
"output": "4825785129"
},
{
"input": "394691574 716672343\n398920207 72555681 150645586",
"output": "475704521"
},
{
"input": "276981463 853992230\n29394015 90072954 839552440",
"output": "1754738044"
},
{
"input": "843552056 919184611\n341530221 423649259 101547519",
"output": "263157645"
},
{
"input": "20809236 56504497\n972004030 441166533 495487081",
"output": "4235488636"
},
{
"input": "198066417 825228166\n602477839 532312735 520830423",
"output": "2808777834"
},
{
"input": "80356306 962548053\n601547868 549830008 914769984",
"output": "4004161345"
},
{
"input": "257613487 394835231\n642087093 567347282 308709545",
"output": "2692548667"
},
{
"input": "139903376 532155119\n641157122 289897263 629020178",
"output": "3077110809"
},
{
"input": "612127849 669475006\n271630930 676010757 22959739",
"output": "682559736"
},
{
"input": "0 0\n0 0 0",
"output": "0"
},
{
"input": "1000000000 1000000000\n499999998 4 333333332",
"output": "0"
},
{
"input": "1000000000 1000000000\n1000000000 1000000000 1000000000",
"output": "5000000000"
},
{
"input": "4 3\n1 0 1",
"output": "0"
},
{
"input": "4 12\n1 2 3",
"output": "0"
},
{
"input": "4 20\n1 2 1",
"output": "0"
},
{
"input": "100 10\n2 3 4",
"output": "5"
},
{
"input": "6 0\n1 1 1",
"output": "4"
},
{
"input": "25 5\n3 3 3",
"output": "7"
},
{
"input": "48 27\n22 39 20",
"output": "107"
},
{
"input": "4 0\n1 1 1",
"output": "4"
}
] | 1,589,178,797 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 156 | 20,172,800 | Y , B = map(int,input().split())
y , g , b = map(int,input().split())
print(max(0 , 2*y+g - Y) + max(0 , 3*b+g - B)) | Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.
Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.
Input Specification:
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Output Specification:
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
Demo Input:
['4 3\n2 1 1\n', '3 9\n1 1 3\n', '12345678 87654321\n43043751 1000000000 53798715\n']
Demo Output:
['2\n', '1\n', '2147483648\n']
Note:
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | ```python
Y , B = map(int,input().split())
y , g , b = map(int,input().split())
print(max(0 , 2*y+g - Y) + max(0 , 3*b+g - B))
``` | 3 |
|
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding. | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16",
"output": "50"
},
{
"input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75",
"output": "7"
},
{
"input": "8 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "3 8\n4 3 2",
"output": "2"
},
{
"input": "3 8\n2 4 2",
"output": "2"
},
{
"input": "3 6\n1 3 2",
"output": "2"
},
{
"input": "3 6\n3 2 5",
"output": "2"
},
{
"input": "3 8\n4 2 1",
"output": "2"
},
{
"input": "5 6\n2 3 5 1 2",
"output": "2"
},
{
"input": "2 6\n5 3",
"output": "2"
},
{
"input": "4 12\n6 4 3 1",
"output": "2"
},
{
"input": "3 18\n1 9 6",
"output": "2"
},
{
"input": "3 9\n3 2 1",
"output": "3"
},
{
"input": "3 6\n5 3 2",
"output": "2"
},
{
"input": "2 10\n5 2",
"output": "2"
},
{
"input": "2 18\n6 3",
"output": "3"
},
{
"input": "4 12\n1 2 12 3",
"output": "1"
},
{
"input": "3 7\n3 2 1",
"output": "7"
},
{
"input": "3 6\n3 2 1",
"output": "2"
},
{
"input": "5 10\n5 4 3 2 1",
"output": "2"
},
{
"input": "5 16\n8 4 2 1 7",
"output": "2"
},
{
"input": "6 7\n6 5 4 3 7 1",
"output": "1"
},
{
"input": "2 6\n3 2",
"output": "2"
},
{
"input": "2 4\n4 1",
"output": "1"
},
{
"input": "6 8\n2 4 1 3 5 7",
"output": "2"
},
{
"input": "6 8\n6 5 4 3 2 1",
"output": "2"
},
{
"input": "6 15\n5 2 3 6 4 3",
"output": "3"
},
{
"input": "4 8\n2 4 8 1",
"output": "1"
},
{
"input": "2 5\n5 1",
"output": "1"
},
{
"input": "4 18\n3 1 1 2",
"output": "6"
},
{
"input": "2 1\n2 1",
"output": "1"
},
{
"input": "3 10\n2 10 5",
"output": "1"
},
{
"input": "5 12\n12 4 4 4 3",
"output": "1"
},
{
"input": "3 6\n6 3 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "1"
},
{
"input": "3 18\n1 9 3",
"output": "2"
},
{
"input": "3 8\n7 2 4",
"output": "2"
},
{
"input": "2 100\n99 1",
"output": "100"
},
{
"input": "4 12\n1 3 4 2",
"output": "3"
},
{
"input": "3 6\n2 3 1",
"output": "2"
},
{
"input": "4 6\n3 2 5 12",
"output": "2"
},
{
"input": "4 97\n97 1 50 10",
"output": "1"
},
{
"input": "3 12\n1 12 2",
"output": "1"
},
{
"input": "4 12\n1 4 3 2",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 19\n7 1 1",
"output": "19"
},
{
"input": "5 12\n12 4 3 4 4",
"output": "1"
},
{
"input": "3 8\n8 4 2",
"output": "1"
},
{
"input": "3 3\n3 2 1",
"output": "1"
},
{
"input": "5 6\n3 2 4 2 2",
"output": "2"
},
{
"input": "2 16\n8 4",
"output": "2"
},
{
"input": "3 6\n10 2 3",
"output": "2"
},
{
"input": "5 3\n2 4 5 3 6",
"output": "1"
},
{
"input": "11 99\n1 2 3 6 5 4 7 8 99 33 66",
"output": "1"
},
{
"input": "3 12\n3 12 2",
"output": "1"
},
{
"input": "5 25\n24 5 15 25 23",
"output": "1"
},
{
"input": "2 4\n8 1",
"output": "4"
},
{
"input": "4 100\n2 50 4 1",
"output": "2"
},
{
"input": "3 28\n7 14 1",
"output": "2"
},
{
"input": "4 8\n2 8 4 1",
"output": "1"
},
{
"input": "4 6\n6 1 2 3",
"output": "1"
},
{
"input": "2 12\n4 3",
"output": "3"
},
{
"input": "4 12\n1 2 4 3",
"output": "3"
},
{
"input": "5 12\n2 3 12 6 4",
"output": "1"
},
{
"input": "4 4\n1 2 2 4",
"output": "1"
},
{
"input": "3 6\n2 3 2",
"output": "2"
},
{
"input": "4 21\n21 20 21 2",
"output": "1"
},
{
"input": "3 8\n3 4 2",
"output": "2"
},
{
"input": "1 25\n25",
"output": "1"
},
{
"input": "99 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "1"
},
{
"input": "98 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98",
"output": "1"
},
{
"input": "79 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79",
"output": "1"
},
{
"input": "4 32\n1 1 1 1",
"output": "32"
},
{
"input": "1 100\n1",
"output": "100"
},
{
"input": "2 100\n7 1",
"output": "100"
},
{
"input": "7 24\n1 3 6 4 5 2 7",
"output": "4"
},
{
"input": "6 87\n1 2 8 4 5 7",
"output": "87"
},
{
"input": "1 88\n1",
"output": "88"
},
{
"input": "1 89\n1",
"output": "89"
}
] | 1,637,944,761 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 62 | 0 | #nacitanie vstupu
pocet_n,velkost_k=list(map(int,input().split()))
jednotlive_hodnoty=list(map(int,input().split()))
najvacsie_k=-1
#for loop s ifom
for hodnota in jednotlive_hodnoty:
if velkost_k%hodnota==0 and hodnota>najvacsie_k:
najvacsie_k=hodnota
#vypocitanie vysledku
vystup=velkost_k//najvacsie_k
#vystup
print(vystup) | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input Specification:
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output Specification:
Print one integer number — the minimum number of hours required to water the garden.
Demo Input:
['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n']
Demo Output:
['2\n', '7\n']
Note:
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | ```python
#nacitanie vstupu
pocet_n,velkost_k=list(map(int,input().split()))
jednotlive_hodnoty=list(map(int,input().split()))
najvacsie_k=-1
#for loop s ifom
for hodnota in jednotlive_hodnoty:
if velkost_k%hodnota==0 and hodnota>najvacsie_k:
najvacsie_k=hodnota
#vypocitanie vysledku
vystup=velkost_k//najvacsie_k
#vystup
print(vystup)
``` | 3 |
|
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output": "YES"
},
{
"input": "10 1\n5 78 3 87 4 9 5 8 9 1235",
"output": "NO"
},
{
"input": "3 12\n3 3 3",
"output": "NO"
},
{
"input": "3 9\n2 2 2",
"output": "NO"
},
{
"input": "2 5\n1 1",
"output": "NO"
},
{
"input": "1 2\n1",
"output": "NO"
},
{
"input": "3 13\n3 3 3",
"output": "NO"
},
{
"input": "3 6\n1 1 1",
"output": "NO"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "3 11\n3 3 2",
"output": "NO"
},
{
"input": "2 6\n1 3",
"output": "NO"
},
{
"input": "3 10\n2 2 2",
"output": "NO"
},
{
"input": "3 8\n2 1 1",
"output": "NO"
},
{
"input": "1 5\n2",
"output": "NO"
},
{
"input": "1 3\n1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "2 10\n4 4",
"output": "NO"
},
{
"input": "2 8\n2 3",
"output": "NO"
},
{
"input": "2 4\n1 1",
"output": "NO"
},
{
"input": "3 10\n1 2 4",
"output": "NO"
},
{
"input": "3 10\n2 1 3",
"output": "NO"
},
{
"input": "2 6\n1 2",
"output": "NO"
},
{
"input": "3 4\n1 1 1",
"output": "NO"
},
{
"input": "3 11\n1 2 4",
"output": "NO"
},
{
"input": "3 12\n3 3 2",
"output": "NO"
},
{
"input": "4 9\n1 1 1 1",
"output": "NO"
},
{
"input": "1 10\n9",
"output": "NO"
},
{
"input": "1 7\n5",
"output": "NO"
},
{
"input": "2 5\n1 2",
"output": "NO"
},
{
"input": "3 8\n1 1 2",
"output": "NO"
},
{
"input": "3 7\n1 1 1",
"output": "NO"
},
{
"input": "1 10\n1",
"output": "NO"
},
{
"input": "3 10\n2 3 4",
"output": "NO"
},
{
"input": "3 9\n1 2 3",
"output": "NO"
},
{
"input": "3 9\n3 3 2",
"output": "NO"
},
{
"input": "3 6\n3 3 2",
"output": "NO"
},
{
"input": "1 1\n3",
"output": "NO"
},
{
"input": "1 3\n2",
"output": "NO"
},
{
"input": "3 10\n3 3 3",
"output": "NO"
},
{
"input": "3 5\n1 1 1",
"output": "YES"
},
{
"input": "2 1\n100 100",
"output": "NO"
},
{
"input": "3 3\n3 3 3",
"output": "NO"
},
{
"input": "4 17\n3 3 9 1",
"output": "NO"
},
{
"input": "4 1660\n1505 13 37 100",
"output": "NO"
},
{
"input": "3 5\n3 3 2",
"output": "NO"
},
{
"input": "4 10\n3 3 2 5",
"output": "NO"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n2",
"output": "NO"
},
{
"input": "5 10\n1 2 2 4 5",
"output": "NO"
},
{
"input": "2 1\n1 1",
"output": "NO"
}
] | 1,662,129,280 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 13,926,400 | n, x = [int(x) for x in input().split()]
encoding = [int(x) for x in input().split()]
s = ''
for item in encoding:
s += '1' * item
s += '0'
s = s[:-1]
if x == len(s):
print('YES')
else:
print('NO')
| Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
Input Specification:
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Output Specification:
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
Demo Input:
['2 4\n1 3\n', '3 10\n3 3 2\n', '2 10\n1 3\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none | ```python
n, x = [int(x) for x in input().split()]
encoding = [int(x) for x in input().split()]
s = ''
for item in encoding:
s += '1' * item
s += '0'
s = s[:-1]
if x == len(s):
print('YES')
else:
print('NO')
``` | 0 |
|
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,613,031,182 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 409,600 | from collections import Counter
string1 = input()
string2 = input()
x1 = Counter(string1)
x2 = Counter(string2)
string1 = list(string1)
string2 = list(string2)
ans = 0
if x1['7'] < x2['7']:
for i in range(len(string1)):
if string1[i] == '4' and string2[i] != '4':
string1[i] = '7'
ans += 1
if x1['4'] < x2['4']:
for i in range(len(string1)):
if string1[i] == '7' and string2[i] != '7':
string1[i] = '4'
ans += 1
dop = 0
for i in range(len(string1)):
dop += string1[i] != string2[i]
ans += dop // 2
print(ans) | 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
from collections import Counter
string1 = input()
string2 = input()
x1 = Counter(string1)
x2 = Counter(string2)
string1 = list(string1)
string2 = list(string2)
ans = 0
if x1['7'] < x2['7']:
for i in range(len(string1)):
if string1[i] == '4' and string2[i] != '4':
string1[i] = '7'
ans += 1
if x1['4'] < x2['4']:
for i in range(len(string1)):
if string1[i] == '7' and string2[i] != '7':
string1[i] = '4'
ans += 1
dop = 0
for i in range(len(string1)):
dop += string1[i] != string2[i]
ans += dop // 2
print(ans)
``` | 0 |
|
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not. | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence. | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFFFFSFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "20\nSSFSFSFSFSFSFSFSSFSF",
"output": "YES"
},
{
"input": "20\nSSSSFSFSSFSFSSSSSSFS",
"output": "NO"
},
{
"input": "100\nFFFSFSFSFSSFSFFSSFFFFFSSSSFSSFFFFSFFFFFSFFFSSFSSSFFFFSSFFSSFSFFSSFSSSFSFFSFSFFSFSFFSSFFSFSSSSFSFSFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFSS",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFFSFFFFFFFFFSFSSFFFFFFFFFFFFFFFFFFFFFFSFFSFFFFFSFFFFFFFFSFFFFFFFFFFFFFSFFFFFFFFSFFFFFFFSF",
"output": "NO"
},
{
"input": "100\nSFFSSFFFFFFSSFFFSSFSFFFFFSSFFFSFFFFFFSFSSSFSFSFFFFSFSSFFFFFFFFSFFFFFSFFFFFSSFFFSFFSFSFFFFSFFSFFFFFFF",
"output": "YES"
},
{
"input": "100\nFFFFSSSSSFFSSSFFFSFFFFFSFSSFSFFSFFSSFFSSFSFFFFFSFSFSFSFFFFFFFFFSFSFFSFFFFSFSFFFFFFFFFFFFSFSSFFSSSSFF",
"output": "NO"
},
{
"input": "100\nFFFFFFFFFFFFSSFFFFSFSFFFSFSSSFSSSSSFSSSSFFSSFFFSFSFSSFFFSSSFFSFSFSSFSFSSFSFFFSFFFFFSSFSFFFSSSFSSSFFS",
"output": "NO"
},
{
"input": "100\nFFFSSSFSFSSSSFSSFSFFSSSFFSSFSSFFSSFFSFSSSSFFFSFFFSFSFSSSFSSFSFSFSFFSSSSSFSSSFSFSFFSSFSFSSFFSSFSFFSFS",
"output": "NO"
},
{
"input": "100\nFFSSSSFSSSFSSSSFSSSFFSFSSFFSSFSSSFSSSFFSFFSSSSSSSSSSSSFSSFSSSSFSFFFSSFFFFFFSFSFSSSSSSFSSSFSFSSFSSFSS",
"output": "NO"
},
{
"input": "100\nSSSFFFSSSSFFSSSSSFSSSSFSSSFSSSSSFSSSSSSSSFSFFSSSFFSSFSSSSFFSSSSSSFFSSSSFSSSSSSFSSSFSSSSSSSFSSSSFSSSS",
"output": "NO"
},
{
"input": "100\nFSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSSSSSSFSSSSSSSSSSSSSFSSFSSSSSFSSFSSSSSSSSSFFSSSSSFSFSSSFFSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSFSSSSSSSSSSSSFSSSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFSSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSFS",
"output": "NO"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS",
"output": "NO"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFSFSFFFFFFFFFFFSFSFFFFFFFFFFFFFSFFFFFFFFFFFFFFFFFFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSFFFFFFFFFFFFSSFFFFSFFFFFFFFFFFFFFFFFFFSFFFSSFFFFSFSFFFSFFFFFFFFFFFFFFFSSFFFFFFFFSSFFFFFFFFFFFFFFSFF",
"output": "YES"
},
{
"input": "100\nSFFSSSFFSFSFSFFFFSSFFFFSFFFFFFFFSFSFFFSFFFSFFFSFFFFSFSFFFFFFFSFFFFFFFFFFSFFSSSFFSSFFFFSFFFFSFFFFSFFF",
"output": "YES"
},
{
"input": "100\nSFFFSFFFFSFFFSSFFFSFSFFFSFFFSSFSFFFFFSFFFFFFFFSFSFSFFSFFFSFSSFSFFFSFSFFSSFSFSSSFFFFFFSSFSFFSFFFFFFFF",
"output": "YES"
},
{
"input": "100\nSSSSFFFFSFFFFFFFSFFFFSFSFFFFSSFFFFFFFFFSFFSSFFFFFFSFSFSSFSSSFFFFFFFSFSFFFSSSFFFFFFFSFFFSSFFFFSSFFFSF",
"output": "YES"
},
{
"input": "100\nSSSFSSFFFSFSSSSFSSFSSSSFSSFFFFFSFFSSSSFFSSSFSSSFSSSSFSSSSFSSSSSSSFSFSSFFFSSFFSFFSSSSFSSFFSFSSFSFFFSF",
"output": "YES"
},
{
"input": "100\nSFFSFSSSSSSSFFSSSFSSSSFSFSSFFFSSSSSSFSSSSFSSFSSSFSSSSSSSFSSFSFFFSSFSSFSFSFSSSSSSSSSSSSFFFFSSSSSFSFFF",
"output": "YES"
},
{
"input": "100\nSSSFSFFSFSFFSSSSSFSSSFSSSFFFSSSSSSSSSFSFSFSSSSFSFSSFFFFFSSSSSSSSSSSSSSSSSSSFFSSSSSFSFSSSSFFSSSSFSSSF",
"output": "YES"
},
{
"input": "100\nSSSFSSSSSSSSSSFSSSSFSSSSSSFSSSSSSFSSSSSSSSSSSSSSFSSSFSSSFSSSSSSSSSSSFSSSSSSFSFSSSSFSSSSSSFSSSSSSSSFF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSFSFSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSFFSSSSSSSSSFSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSF",
"output": "YES"
},
{
"input": "2\nSS",
"output": "NO"
}
] | 1,616,593,177 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | input()
# c=input().count
c=str(input())
c=c.replace(" ","")
if c[0]=="S":
print("YES")
if c[0]=="F":
print("NO") | Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last *n* days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last *n* days, or not.
Input Specification:
The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.
Output Specification:
Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['4\nFSSF\n', '2\nSF\n', '10\nFFFFFFFFFF\n', '10\nSSFFSFFSFF\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you stayed the whole period in San Francisco, so the answer is "NO".
In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though. | ```python
input()
# c=input().count
c=str(input())
c=c.replace(" ","")
if c[0]=="S":
print("YES")
if c[0]=="F":
print("NO")
``` | 0 |
|
856 | A | Set Theory | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms"
] | null | null | Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that all *n*2 integers that can be obtained by summing up *a**i* and *b**j* for all possible pairs of *i* and *j* are different.
Both Masha and Grisha don't like big numbers, so all numbers in *A* are from 1 to 106, and all numbers in *B* must also be in the same range.
Help Masha to create the set *B* that satisfies Grisha's requirement. | Input data contains multiple test cases. The first line contains an integer *t* — the number of test cases (1<=≤<=*t*<=≤<=100).
Each test case is described in the following way: the first line of the description contains one integer *n* — the number of elements in *A* (1<=≤<=*n*<=≤<=100).
The second line contains *n* integers *a**i* — the elements of *A* (1<=≤<=*a**i*<=≤<=106). | For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set *B*. - YES, if there is the way to create the required set. In this case the second line must contain *n* different positive integers *b**j* — elements of *B* (1<=≤<=*b**j*<=≤<=106). If there are several possible sets, output any of them. | [
"3\n3\n1 10 100\n1\n1\n2\n2 4\n"
] | [
"YES\n1 2 3 \nYES\n1 \nYES\n1 2 \n"
] | none | 0 | [
{
"input": "3\n3\n1 10 100\n1\n1\n2\n2 4",
"output": "YES\n1 2 3 \nYES\n1 \nYES\n1 2 "
},
{
"input": "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41 19 35 16 88 27 99 40 62 95 70 18 46 21 53 59 37 6 61 71 2 4 52 28 97 25 29 51 7 33 80 83 72 10 75 94 43 84 54 55",
"output": "YES\n1 101 201 301 401 501 601 701 801 901 1001 1101 1201 1301 1401 1501 1601 1701 1801 1901 2001 2101 2201 2301 2401 2501 2601 2701 2801 2901 3001 3101 3201 3301 3401 3501 3601 3701 3801 3901 4001 4101 4201 4301 4401 4501 4601 4701 4801 4901 5001 5101 5201 5301 5401 5501 5601 5701 5801 5901 6001 6101 6201 6301 6401 6501 6601 6701 6801 6901 7001 7101 7201 7301 7401 7501 7601 7701 7801 7901 8001 8101 8201 8301 8401 8501 8601 8701 8801 8901 9001 9101 9201 9301 9401 9501 9601 9701 9801 9901 "
}
] | 1,505,987,463 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 0 | t=int(input())
for j in range(t):
n=int(input())
a=list(map(int,input().split()))
mn=set()
for i in range(n-1):
for k in range(n-1-i):
mn.add(abs(a[k]-a[k+i+1]))
min=1
while i in mn:
min+=1
if 1000000//min < n:
print("NO")
t=[]
for i in range(n):
t.append(min*(i+1))
print("YES")
print(' '.join(map(str,t)))
| Title: Set Theory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that all *n*2 integers that can be obtained by summing up *a**i* and *b**j* for all possible pairs of *i* and *j* are different.
Both Masha and Grisha don't like big numbers, so all numbers in *A* are from 1 to 106, and all numbers in *B* must also be in the same range.
Help Masha to create the set *B* that satisfies Grisha's requirement.
Input Specification:
Input data contains multiple test cases. The first line contains an integer *t* — the number of test cases (1<=≤<=*t*<=≤<=100).
Each test case is described in the following way: the first line of the description contains one integer *n* — the number of elements in *A* (1<=≤<=*n*<=≤<=100).
The second line contains *n* integers *a**i* — the elements of *A* (1<=≤<=*a**i*<=≤<=106).
Output Specification:
For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set *B*. - YES, if there is the way to create the required set. In this case the second line must contain *n* different positive integers *b**j* — elements of *B* (1<=≤<=*b**j*<=≤<=106). If there are several possible sets, output any of them.
Demo Input:
['3\n3\n1 10 100\n1\n1\n2\n2 4\n']
Demo Output:
['YES\n1 2 3 \nYES\n1 \nYES\n1 2 \n']
Note:
none | ```python
t=int(input())
for j in range(t):
n=int(input())
a=list(map(int,input().split()))
mn=set()
for i in range(n-1):
for k in range(n-1-i):
mn.add(abs(a[k]-a[k+i+1]))
min=1
while i in mn:
min+=1
if 1000000//min < n:
print("NO")
t=[]
for i in range(n):
t.append(min*(i+1))
print("YES")
print(' '.join(map(str,t)))
``` | 0 |
|
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
"output": "804610"
},
{
"input": "5\n984065 842724 127449 525625 573049",
"output": "984065"
},
{
"input": "2\n226505 477482",
"output": "477482"
},
{
"input": "2\n370881 659345",
"output": "659345"
},
{
"input": "2\n4 5",
"output": "5"
},
{
"input": "2\n3 4",
"output": "3"
},
{
"input": "2\n999999 1000000",
"output": "999999"
},
{
"input": "3\n-1 -2 -3",
"output": "-1"
},
{
"input": "2\n-1000000 1000000",
"output": "-1000000"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462",
"output": "-15745"
},
{
"input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322",
"output": "-257875"
},
{
"input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209",
"output": "-766506"
},
{
"input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259",
"output": "748303"
},
{
"input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001",
"output": "963781"
},
{
"input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304",
"output": "940901"
},
{
"input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904",
"output": "987533"
},
{
"input": "3\n-1 1 0",
"output": "-1"
},
{
"input": "2\n0 -5",
"output": "-5"
},
{
"input": "3\n-1 -2 0",
"output": "-1"
},
{
"input": "2\n-5 0",
"output": "-5"
},
{
"input": "1\n-439",
"output": "-439"
},
{
"input": "1\n-1000000",
"output": "-1000000"
},
{
"input": "1\n-917455",
"output": "-917455"
},
{
"input": "3\n1 1 -1",
"output": "-1"
},
{
"input": "2\n131073 1",
"output": "131073"
},
{
"input": "2\n99999 3",
"output": "99999"
},
{
"input": "2\n-524272 -1000000",
"output": "-524272"
},
{
"input": "2\n15 131073",
"output": "131073"
}
] | 1,628,024,792 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 20,172,800 | n=int(input())
a=list(map(int,input().split()))
maxx=-1e12
for i in a:
if i<0:
continue
else:
x=int(pow(i,0.5))
if x**2==i:
continue
else:
maxx=max(maxx,i)
print(maxx)
| Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square.
Output Specification:
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
Demo Input:
['2\n4 2\n', '8\n1 2 4 8 16 32 64 576\n']
Demo Output:
['2\n', '32\n']
Note:
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | ```python
n=int(input())
a=list(map(int,input().split()))
maxx=-1e12
for i in a:
if i<0:
continue
else:
x=int(pow(i,0.5))
if x**2==i:
continue
else:
maxx=max(maxx,i)
print(maxx)
``` | 0 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,600,791,344 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 109 | 0 | # Generous Kefa
def balloons(s, k):
for i in s:
x = s.count(i)
if x > k:
return "NO"
return "YES"
n, k = list(map(int, input().split()))
s = input()
print(balloons(s, k))
| Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
# Generous Kefa
def balloons(s, k):
for i in s:
x = s.count(i)
if x > k:
return "NO"
return "YES"
n, k = list(map(int, input().split()))
s = input()
print(balloons(s, k))
``` | 3 |
|
865 | A | Save the problem! | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.
People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?
As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below. | Input will consist of a single integer *A* (1<=≤<=*A*<=≤<=105), the desired number of ways. | In the first line print integers *N* and *M* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*M*<=≤<=10), the amount of change to be made, and the number of denominations, respectively.
Then print *M* integers *D*1,<=*D*2,<=...,<=*D**M* (1<=≤<=*D**i*<=≤<=106), the denominations of the coins. All denominations must be distinct: for any *i*<=≠<=*j* we must have *D**i*<=≠<=*D**j*.
If there are multiple tests, print any of them. You can print denominations in atbitrary order. | [
"18\n",
"3\n",
"314\n"
] | [
"30 4\n1 5 10 25\n",
"20 2\n5 2\n",
"183 4\n6 5 2 139\n"
] | none | 500 | [
{
"input": "18",
"output": "30 4\n1 5 10 25"
},
{
"input": "3",
"output": "20 2\n5 2"
},
{
"input": "314",
"output": "183 4\n6 5 2 139"
},
{
"input": "1023",
"output": "2045 2\n1 2"
},
{
"input": "100000",
"output": "199999 2\n1 2"
},
{
"input": "1",
"output": "1 2\n1 2"
},
{
"input": "2",
"output": "3 2\n1 2"
},
{
"input": "3",
"output": "20 2\n5 2"
},
{
"input": "4",
"output": "7 2\n1 2"
},
{
"input": "5",
"output": "9 2\n1 2"
},
{
"input": "6",
"output": "11 2\n1 2"
},
{
"input": "7",
"output": "13 2\n1 2"
},
{
"input": "8",
"output": "15 2\n1 2"
},
{
"input": "9",
"output": "17 2\n1 2"
},
{
"input": "10",
"output": "19 2\n1 2"
},
{
"input": "11",
"output": "21 2\n1 2"
},
{
"input": "12",
"output": "23 2\n1 2"
},
{
"input": "13",
"output": "25 2\n1 2"
},
{
"input": "14",
"output": "27 2\n1 2"
},
{
"input": "15",
"output": "29 2\n1 2"
},
{
"input": "16",
"output": "31 2\n1 2"
},
{
"input": "17",
"output": "33 2\n1 2"
},
{
"input": "18",
"output": "30 4\n1 5 10 25"
},
{
"input": "19",
"output": "37 2\n1 2"
},
{
"input": "20",
"output": "39 2\n1 2"
},
{
"input": "239",
"output": "477 2\n1 2"
},
{
"input": "4063",
"output": "8125 2\n1 2"
},
{
"input": "65536",
"output": "131071 2\n1 2"
},
{
"input": "65535",
"output": "131069 2\n1 2"
},
{
"input": "65537",
"output": "131073 2\n1 2"
},
{
"input": "99991",
"output": "199981 2\n1 2"
},
{
"input": "99990",
"output": "199979 2\n1 2"
},
{
"input": "99992",
"output": "199983 2\n1 2"
},
{
"input": "99971",
"output": "199941 2\n1 2"
},
{
"input": "99990",
"output": "199979 2\n1 2"
},
{
"input": "2",
"output": "3 2\n1 2"
},
{
"input": "99991",
"output": "199981 2\n1 2"
}
] | 1,641,822,714 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 109 | 0 | n=int(input())
print(2*n-1, 2)
print(1, 2) | Title: Save the problem!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.
People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?
As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.
Input Specification:
Input will consist of a single integer *A* (1<=≤<=*A*<=≤<=105), the desired number of ways.
Output Specification:
In the first line print integers *N* and *M* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*M*<=≤<=10), the amount of change to be made, and the number of denominations, respectively.
Then print *M* integers *D*1,<=*D*2,<=...,<=*D**M* (1<=≤<=*D**i*<=≤<=106), the denominations of the coins. All denominations must be distinct: for any *i*<=≠<=*j* we must have *D**i*<=≠<=*D**j*.
If there are multiple tests, print any of them. You can print denominations in atbitrary order.
Demo Input:
['18\n', '3\n', '314\n']
Demo Output:
['30 4\n1 5 10 25\n', '20 2\n5 2\n', '183 4\n6 5 2 139\n']
Note:
none | ```python
n=int(input())
print(2*n-1, 2)
print(1, 2)
``` | 3 |
|
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -239 826 318 811 20 -732 -91 460 551 -610 555 -493 -154 442 -141 946 -913 -104 704 -380 699 32 106 -455 -518 214 -464 -861 243 -798 -472 559 529 -844 -32 871 -459 236 387 626 -318 -580 -611 -842 790 486 64 951 81 78 -693 403 -731 309 678 696 891 846 -106 918 212 -44 994 606 -829 -454 243 -477 -402 -818 -819 -310 -837 -209 736 424",
"output": "64"
},
{
"input": "2\n-1 0",
"output": "-1"
},
{
"input": "48\n-777 -767 -764 -713 -688 -682 -606 -586 -585 -483 -465 -440 -433 -397 -390 -377 -299 -252 -159 -147 -96 -29 -15 15 52 109 124 129 142 218 231 314 320 339 442 496 505 548 575 576 594 624 694 827 891 979 981 981",
"output": "15"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n-1 -1 0 1",
"output": "-1"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 1000000000",
"output": "0"
},
{
"input": "2\n1 -1",
"output": "-1"
},
{
"input": "2\n100 50",
"output": "50"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n606194955 -856471310 117647402",
"output": "117647402"
},
{
"input": "2\n615002717 -843553590",
"output": "-843553590"
},
{
"input": "2\n-1 2",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "5\n-638512131 348325781 -550537933 -618161835 -567935532",
"output": "-567935532"
},
{
"input": "1\n120",
"output": "120"
},
{
"input": "2\n-1000000000 1000000000",
"output": "-1000000000"
},
{
"input": "1\n618309368",
"output": "618309368"
}
] | 1,666,016,613 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,764,800 | t=1
while t>0:
t-=1
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==0:
print(a[n/2-1])
else:
print(a[n/2]) | Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points.
Output Specification:
Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
Demo Input:
['4\n1 2 3 4\n']
Demo Output:
['2\n']
Note:
none | ```python
t=1
while t>0:
t-=1
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==0:
print(a[n/2-1])
else:
print(a[n/2])
``` | -1 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
Limak is ready to start. You task is to count how many operations will it take him to destroy all towers. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109) — sizes of towers. | Print the number of operations needed to destroy all towers. | [
"6\n2 1 4 6 2 2\n",
"7\n3 3 3 1 3 3 3\n"
] | [
"3\n",
"2\n"
] | The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. | 0 | [
{
"input": "6\n2 1 4 6 2 2",
"output": "3"
},
{
"input": "7\n3 3 3 1 3 3 3",
"output": "2"
},
{
"input": "7\n5128 5672 5805 5452 5882 5567 5032",
"output": "4"
},
{
"input": "10\n1 2 2 3 5 5 5 4 2 1",
"output": "5"
},
{
"input": "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20",
"output": "5"
},
{
"input": "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4",
"output": "4"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1049 1098",
"output": "1"
},
{
"input": "2\n100 100",
"output": "1"
},
{
"input": "5\n1 2 3 2 1",
"output": "3"
},
{
"input": "15\n2 2 1 1 2 2 2 2 2 2 2 2 2 1 2",
"output": "2"
},
{
"input": "28\n415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 2 802811737 802811737 802811737 802811737 802811737 802811737 802811737 802811737 1 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901 550595901",
"output": "6"
},
{
"input": "45\n3 12 13 11 13 13 10 11 14 15 15 13 14 12 13 11 14 10 10 14 14 11 10 12 11 11 13 14 10 11 14 13 14 11 11 11 12 15 1 10 15 12 14 14 14",
"output": "13"
},
{
"input": "84\n1 3 4 5 6 5 6 7 8 9 7 4 5 4 2 5 1 1 1 3 2 7 7 8 10 9 5 6 5 2 3 3 3 3 3 2 4 8 6 5 8 9 8 7 9 3 4 4 4 2 2 1 6 4 9 5 9 9 10 7 10 4 5 4 2 4 3 3 4 4 6 6 6 9 10 12 7 5 9 8 5 3 3 2",
"output": "8"
},
{
"input": "170\n1 2 1 2 1 1 1 1 2 3 2 1 1 2 2 1 2 1 2 1 1 2 3 3 2 1 1 1 1 1 1 1 1 2 1 2 3 3 2 1 2 2 1 2 3 2 1 1 2 3 2 1 2 1 1 1 2 3 3 2 1 2 1 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 2 1 2 3 2 1 1 2 3 4 4 3 2 1 2 1 2 1 2 3 3 2 1 2 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2 1 1 2 3 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 3 2 1 2 1 1 1 2 3 4 5 4 3 2 1 1 2 1 2 3 4 3 2 1",
"output": "5"
},
{
"input": "1\n5",
"output": "1"
}
] | 1,451,403,606 | 3,246 | Python 3 | OK | TESTS | 41 | 218 | 9,113,600 | def main():
n = int(input())
a = [int(i) for i in input().split()]
dpl = [1] * n
dpr = [1] * n
for i in range(1, n):
dpl[i] = min(dpl[i - 1] + 1, a[i])
for i in range(n - 2, -1, -1):
dpr[i] = min(dpr[i + 1] + 1, a[i])
ans = 0
for i in range(n):
ans = max(ans, min(dpl[i], dpr[i]))
print(ans)
main() | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built *n* towers in a row. The *i*-th tower is made of *h**i* identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109) — sizes of towers.
Output Specification:
Print the number of operations needed to destroy all towers.
Demo Input:
['6\n2 1 4 6 2 2\n', '7\n3 3 3 1 3 3 3\n']
Demo Output:
['3\n', '2\n']
Note:
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. | ```python
def main():
n = int(input())
a = [int(i) for i in input().split()]
dpl = [1] * n
dpr = [1] * n
for i in range(1, n):
dpl[i] = min(dpl[i - 1] + 1, a[i])
for i in range(n - 2, -1, -1):
dpr[i] = min(dpr[i + 1] + 1, a[i])
ans = 0
for i in range(n):
ans = max(ans, min(dpl[i], dpr[i]))
print(ans)
main()
``` | 3 |
|
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,538,528,167 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 124 | 0 | n = int(input())
a = []
z = 0
k = 8888888899
w = 5888896
q = 1888888896
if n <= 1000:
for i in range (1,n+1):
a.append(i)
z += len(str(a[i-1]))
print(z)
elif n == 1000000000:
print(k)
elif n == 1000000:
print(w)
elif n == 222222222:
print(q)
else:
None
| Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
n = int(input())
a = []
z = 0
k = 8888888899
w = 5888896
q = 1888888896
if n <= 1000:
for i in range (1,n+1):
a.append(i)
z += len(str(a[i-1]))
print(z)
elif n == 1000000000:
print(k)
elif n == 1000000:
print(w)
elif n == 222222222:
print(q)
else:
None
``` | 0 |
|
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence? | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
},
{
"input": "4\n5 4 5 4",
"output": "-1"
},
{
"input": "7\n3 4 5 5 5 1 2",
"output": "2"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n5 4 1 2 3",
"output": "-1"
},
{
"input": "4\n6 1 2 7",
"output": "-1"
},
{
"input": "5\n4 5 6 2 3",
"output": "2"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "4\n1 2 2 1",
"output": "1"
},
{
"input": "9\n4 5 6 7 1 2 3 4 10",
"output": "-1"
},
{
"input": "7\n2 3 4 1 2 3 4",
"output": "-1"
},
{
"input": "6\n1 2 1 2 1 2",
"output": "-1"
},
{
"input": "3\n3 2 1",
"output": "-1"
},
{
"input": "4\n1 4 4 1",
"output": "1"
},
{
"input": "5\n1 2 1 1 1",
"output": "3"
},
{
"input": "5\n4 6 7 3 5",
"output": "-1"
},
{
"input": "4\n2 3 1 4",
"output": "-1"
},
{
"input": "5\n5 4 3 2 1",
"output": "-1"
},
{
"input": "4\n2 4 1 4",
"output": "-1"
},
{
"input": "6\n4 5 6 1 2 7",
"output": "-1"
},
{
"input": "6\n1 2 3 1 1 1",
"output": "3"
},
{
"input": "5\n1 3 3 3 1",
"output": "1"
},
{
"input": "6\n5 6 7 5 5 5",
"output": "3"
},
{
"input": "5\n3 4 2 1 2",
"output": "-1"
},
{
"input": "3\n3 4 2",
"output": "1"
},
{
"input": "6\n1 1 2 2 1 1",
"output": "2"
},
{
"input": "4\n2 3 4 2",
"output": "1"
},
{
"input": "5\n3 5 7 7 3",
"output": "1"
},
{
"input": "4\n1 1 4 1",
"output": "1"
},
{
"input": "7\n1 5 6 1 1 1 1",
"output": "4"
},
{
"input": "5\n7 8 6 7 8",
"output": "-1"
},
{
"input": "4\n2 4 1 3",
"output": "-1"
}
] | 1,609,424,395 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 10,342,400 | n = int(input())
arr = list(map(int, input().split()))
cnt = 1
i=1
while i<n:
if arr[i]>=arr[i-1]:
cnt+=1
else:
break
i+=1
flag=True
if i==n:
flag=True
elif arr[i]>arr[0]:
flag=False
else:
while i<n-1:
if arr[i]>arr[i+1]:
flag=False
break
if flag:
print(n-cnt)
else:
print(-1)
| Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
Demo Input:
['2\n2 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['1\n', '-1\n', '0\n']
Note:
none | ```python
n = int(input())
arr = list(map(int, input().split()))
cnt = 1
i=1
while i<n:
if arr[i]>=arr[i-1]:
cnt+=1
else:
break
i+=1
flag=True
if i==n:
flag=True
elif arr[i]>arr[0]:
flag=False
else:
while i<n-1:
if arr[i]>arr[i+1]:
flag=False
break
if flag:
print(n-cnt)
else:
print(-1)
``` | 0 |
|
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,697,638,745 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 22:06:15 2023
@author: 陈亚偲2300011106
"""
n=int(input())
a=[]
for iiii in range(n):
a.append([int(i) for i in input().split()])#0 still or left 1 right
ct=1
boza=True
for i in range(1,n-1):
b=a[i][0]-a[i-1][0]
c=a[i+1][0]-a[i][0]
if boza:
if b>=a[i][1]:
ct+=1
elif c>=a[i][1]:
ct+=1
boza=False
else:
boza=True
print(ct+1) | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 18 22:06:15 2023
@author: 陈亚偲2300011106
"""
n=int(input())
a=[]
for iiii in range(n):
a.append([int(i) for i in input().split()])#0 still or left 1 right
ct=1
boza=True
for i in range(1,n-1):
b=a[i][0]-a[i-1][0]
c=a[i+1][0]-a[i][0]
if boza:
if b>=a[i][1]:
ct+=1
elif c>=a[i][1]:
ct+=1
boza=False
else:
boza=True
print(ct+1)
``` | 0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.