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
932
C
Permutation Cycle
PROGRAMMING
1,600
[ "brute force", "constructive algorithms" ]
null
null
For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows: Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists. For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=*N*, *g*(*i*) equals either *A* or *B*.
The only line contains three integers *N*,<=*A*,<=*B* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*A*,<=*B*<=≤<=*N*).
If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to *N*.
[ "9 2 5\n", "3 2 1\n" ]
[ "6 5 8 3 4 1 9 2 7", "1 2 3 " ]
In the first example, *g*(1) = *g*(6) = *g*(7) = *g*(9) = 2 and *g*(2) = *g*(3) = *g*(4) = *g*(5) = *g*(8) = 5 In the second example, *g*(1) = *g*(2) = *g*(3) = 1
1,500
[ { "input": "9 2 5", "output": "2 1 4 3 6 7 8 9 5 " }, { "input": "3 2 1", "output": "1 2 3 " }, { "input": "7 4 4", "output": "-1" }, { "input": "1000000 999998 3", "output": "-1" }, { "input": "1 1 1", "output": "1 " }, { "input": "993012 997 1001", "output": "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 155 1..." }, { "input": "1000000 2017 881", "output": "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 155 1..." }, { "input": "390612 20831 55790", "output": "-1" }, { "input": "689292 69319 96267", "output": "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 155 1..." }, { "input": "99929 99929 2", "output": "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 155 1..." }, { "input": "807990 72713 11616", "output": "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 155 1..." }, { "input": "514004 50866 26101", "output": "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 155 1..." }, { "input": "631610 7702 63553", "output": "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 155 1..." }, { "input": "391861 47354 60383", "output": "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 155 1..." }, { "input": "822954 53638 55936", "output": "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 155 1..." }, { "input": "794948 794948 85946", "output": "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 155 1..." }, { "input": "786009 37429 59524", "output": "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 155 1..." }, { "input": "402440 201220 220895", "output": "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 155 1..." }, { "input": "701502 342867 350751", "output": "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 155 1..." }, { "input": "865746 865746 634846", "output": "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 155 1..." }, { "input": "562825 562825 145593", "output": "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 155 1..." }, { "input": "960677 797144 960677", "output": "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 155 1..." }, { "input": "228456 38076 136364", "output": "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 155 1..." }, { "input": "465111 297688 155037", "output": "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 155 1..." }, { "input": "1000000 3 999997", "output": "2 3 1 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 155 1..." }, { "input": "474441 99291 77277", "output": "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 155 1..." }, { "input": "542226 90371 64993", "output": "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 155 1..." }, { "input": "911106 51038 78188", "output": "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 155 1..." }, { "input": "800577 56373 62017", "output": "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 155 1..." }, { "input": "667141 63085 50338", "output": "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 155 1..." }, { "input": "321361 79845 81826", "output": "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 155 1..." }, { "input": "439365 78717 87873", "output": "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 155 1..." }, { "input": "436061 59464 79277", "output": "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 155 1..." }, { "input": "482184 56941 83597", "output": "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 155 1..." }, { "input": "253274 82704 85285", "output": "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 155 1..." }, { "input": "679275 59632 75475", "output": "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 155 1..." }, { "input": "279013 56717 52145", "output": "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 155 1..." }, { "input": "91401 88756 91401", "output": "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 155 1..." }, { "input": "414372 59196 93713", "output": "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 155 1..." }, { "input": "482120 96424 93248", "output": "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 155 1..." }, { "input": "505383 77277 99291", "output": "-1" }, { "input": "276681 90371 92227", "output": "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 155 1..." }, { "input": "201292 78188 62600", "output": "-1" }, { "input": "223899 74633 69608", "output": "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 155 1..." }, { "input": "726152 70146 71567", "output": "-1" }, { "input": "432613 95501 84278", "output": "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 155 1..." }, { "input": "383151 97630 81017", "output": "-1" }, { "input": "663351 51961 83597", "output": "-1" }, { "input": "255855 82704 85285", "output": "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 155 1..." }, { "input": "210582 59632 75475", "output": "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 155 1..." }, { "input": "422699 52145 56717", "output": "-1" }, { "input": "734965 91401 69490", "output": "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 155 1..." }, { "input": "732687 59196 63663", "output": "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 155 1..." }, { "input": "432316 96424 86324", "output": "-1" }, { "input": "674504 89149 64156", "output": "-1" }, { "input": "449238 72357 77951", "output": "-1" }, { "input": "500754 60855 65493", "output": "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 155 1..." }, { "input": "510382 53668 84117", "output": "-1" }, { "input": "536156 82311 68196", "output": "-1" }, { "input": "620908 51298 77886", "output": "-1" }, { "input": "9 7 9", "output": "2 3 4 5 6 7 8 9 1 " }, { "input": "10 7 5", "output": "2 3 4 5 1 7 8 9 10 6 " }, { "input": "4 3 2", "output": "2 1 4 3 " }, { "input": "5 4 5", "output": "2 3 4 5 1 " }, { "input": "5 3 4", "output": "-1" }, { "input": "1000000 3 3", "output": "-1" }, { "input": "999999 2 4", "output": "-1" }, { "input": "1000000 1 500001", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 155..." }, { "input": "999999 2 2", "output": "-1" } ]
1,589,619,107
2,147,483,647
PyPy 3
OK
TESTS
69
826
70,348,800
n, a, b = map(int, input().split()) for i in range(n//a + 1): if (n - i*a) % b == 0: res = [] for j in range(i): t = [j*a + k for k in range(1, a+1)] res += t[1:] + [t[0]] for j in range((n - i*a) // b): t = [i*a + j*b + k for k in range(1, b+1)] res += t[1:] + [t[0]] print(*res) break else: print(-1)
Title: Permutation Cycle Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows: Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists. For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=*N*, *g*(*i*) equals either *A* or *B*. Input Specification: The only line contains three integers *N*,<=*A*,<=*B* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*A*,<=*B*<=≤<=*N*). Output Specification: If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to *N*. Demo Input: ['9 2 5\n', '3 2 1\n'] Demo Output: ['6 5 8 3 4 1 9 2 7', '1 2 3 '] Note: In the first example, *g*(1) = *g*(6) = *g*(7) = *g*(9) = 2 and *g*(2) = *g*(3) = *g*(4) = *g*(5) = *g*(8) = 5 In the second example, *g*(1) = *g*(2) = *g*(3) = 1
```python n, a, b = map(int, input().split()) for i in range(n//a + 1): if (n - i*a) % b == 0: res = [] for j in range(i): t = [j*a + k for k in range(1, a+1)] res += t[1:] + [t[0]] for j in range((n - i*a) // b): t = [i*a + j*b + k for k in range(1, b+1)] res += t[1:] + [t[0]] print(*res) break else: print(-1) ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,677,892,017
2,147,483,647
Python 3
OK
TESTS
40
92
0
s=input() t=input() rev="" for i in s[::-1]: rev+=i if(rev==t): print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python s=input() t=input() rev="" for i in s[::-1]: rev+=i if(rev==t): print("YES") else: print("NO") ```
3.977
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days?
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697681824", "output": "14" }, { "input": "41313494", "output": "14" }, { "input": "673935585", "output": "13" }, { "input": "117422204", "output": "19" }, { "input": "954746654", "output": "15" }, { "input": "536838144", "output": "14" }, { "input": "1000000000", "output": "13" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "1" }, { "input": "6", "output": "2" }, { "input": "7", "output": "3" }, { "input": "9", "output": "2" }, { "input": "10", "output": "2" }, { "input": "999999999", "output": "21" }, { "input": "999999998", "output": "20" }, { "input": "999999997", "output": "20" }, { "input": "999999996", "output": "19" }, { "input": "999999995", "output": "20" }, { "input": "999999994", "output": "19" }, { "input": "999999993", "output": "19" }, { "input": "999999992", "output": "18" }, { "input": "999999991", "output": "20" }, { "input": "999999990", "output": "19" }, { "input": "536870910", "output": "28" }, { "input": "536870912", "output": "1" }, { "input": "536870913", "output": "2" }, { "input": "536870914", "output": "2" }, { "input": "22", "output": "3" }, { "input": "14", "output": "3" } ]
1,691,062,233
2,147,483,647
Python 3
OK
TESTS
36
46
0
x = input() counter = 0 y = int(x) while y > 0: if y % 2 != 0: counter +=1 y = y // 2 print(counter)
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? Input Specification: The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). Output Specification: The only line containing one integer: the answer. Demo Input: ['5\n', '8\n'] Demo Output: ['2\n', '1\n'] Note: For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.
```python x = input() counter = 0 y = int(x) while y > 0: if y % 2 != 0: counter +=1 y = y // 2 print(counter) ```
3
837
A
Text Volume
PROGRAMMING
800
[ "implementation" ]
null
null
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text.
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
[ "7\nNonZERO\n", "24\nthis is zero answer text\n", "24\nHarbour Space University\n" ]
[ "5\n", "0\n", "1\n" ]
In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
0
[ { "input": "7\nNonZERO", "output": "5" }, { "input": "24\nthis is zero answer text", "output": "0" }, { "input": "24\nHarbour Space University", "output": "1" }, { "input": "2\nWM", "output": "2" }, { "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz", "output": "105" }, { "input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g", "output": "1" }, { "input": "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSajdlNPccOOtWrez", "output": "50" }, { "input": "1\ne", "output": "0" }, { "input": "1\nA", "output": "1" }, { "input": "200\nABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU VWXYZABCDE KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KLMNOPRSTU KZ", "output": "10" }, { "input": "200\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "200" }, { "input": "200\nffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "output": "0" }, { "input": "24\nHarbour Space UniversitY", "output": "2" }, { "input": "5\naA AA", "output": "2" }, { "input": "10\nas AS ASDA", "output": "4" }, { "input": "10\nas AS ASDZ", "output": "4" }, { "input": "3\na A", "output": "1" }, { "input": "24\nHarbour space UniversitY", "output": "2" }, { "input": "10\nas AS ASAa", "output": "3" }, { "input": "15\naAb ABCDFGRHTJS", "output": "11" }, { "input": "53\nsdfAZEZR AZE dfdf dsdRFGSDF ZZDZSD dfsd ERBGF dsfsdfR", "output": "6" }, { "input": "10\nABC ABc AB", "output": "3" }, { "input": "10\nA c de CDE", "output": "3" }, { "input": "4\nA AB", "output": "2" }, { "input": "18\nHARbour Space UNIV", "output": "4" }, { "input": "13\na b c d e f A", "output": "1" }, { "input": "6\nA B CA", "output": "2" }, { "input": "4\naa A", "output": "1" }, { "input": "3\nA a", "output": "1" } ]
1,502,143,681
2,147,483,647
Python 3
OK
TESTS
29
62
4,608,000
'''input 24 Harbour Space University ''' n = int(input()) s = input().split() m = 0 for x in s: c = 0 for l in x: if l == l.upper(): c += 1 m = max(m, c) print(m)
Title: Text Volume Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text. Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. Output Specification: Print one integer number — volume of text. Demo Input: ['7\nNonZERO\n', '24\nthis is zero answer text\n', '24\nHarbour Space University\n'] Demo Output: ['5\n', '0\n', '1\n'] Note: In the first example there is only one word, there are 5 capital letters in it. In the second example all of the words contain 0 capital letters.
```python '''input 24 Harbour Space University ''' n = int(input()) s = input().split() m = 0 for x in s: c = 0 for l in x: if l == l.upper(): c += 1 m = max(m, c) print(m) ```
3
346
B
Lucky Common Subsequence
PROGRAMMING
2,000
[ "dp", "strings" ]
null
null
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF. You are given two strings *s*1, *s*2 and another string called *virus*. Your task is to find the longest common subsequence of *s*1 and *s*2, such that it doesn't contain *virus* as a substring.
The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=≤<=|*s*1|,<=|*s*2|,<=|*virus*|<=≤<=100). Each string consists only of uppercase English letters.
Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0.
[ "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n", "AA\nA\nA\n" ]
[ "ORZ\n", "0\n" ]
none
1,000
[ { "input": "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "output": "ORZ" }, { "input": "AA\nA\nA", "output": "0" }, { "input": "PWBJTZPQHA\nZJMKLWSROQ\nUQ", "output": "WQ" }, { "input": "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCUEPHXM\nRRFCZUGFDRKKMQTOETNELXMEWGOCDHFKIXOPVHHEWTCDNXVFKFKTKNWKEIKTCMHMHDNCLLVQSGKHBCDDYVVVQIRPZEOPUGQUGRHH\nR", "output": "QNHFPHEXNETMHMHLLSGKCYPOPUH" }, { "input": "CGPWTAPEVBTGANLCLVSHQIIKHDPVUHRSQPXHSNYAHPGBECICFQYDFRTRELLLEDZYWJSLOBSKDGRRDHNRRGIXAMEBGFJJTEIGUGRU\nHAWYVKRRBEIWNOGYMIYQXDCFXMMCSAYSOXQFHHIFRRCJRAWHLDDHHHAKHXVKCVPBFGGEXUKWTFWMOUUGMXTSBUTHXCJCWHCQQTYQ\nANKFDWLYSX", "output": "WVBGCSSQHHIFRRWLDDHXBGFUGU" }, { "input": "AUNBEKNURNUPHXQYKUTAHCOLMPRQZZTVDUYCTNIRACQQTQAIDTAWJXBUTIZUASDIJZWLHAQVGCAHKTZMXSDVVWAIGQEALRFKFYTT\nQBVRFKPKLYZLYNRFTRJZZQEYAEKPFXVICUVFVQSDENBJYYNCFTOZHULSWJQTNELYLKCZTGHOARDCFXBXQGGSQIVUCJVNGFZEEZQE\nN", "output": "BKPYTRZZVICQDJTZUSJZHAQGSVVGQE" }, { "input": "BGIIURZTEUJJULBWKHDQBRFGEUOMQSREOTILICRSBUHBGTSRDHKVDDEBVHGMHXUVFJURSMFDJOOOWCYPJDVRVKLDHICPNKTBFXDJ\nXOADNTKNILGNHHBNFYNDWUNXBGDFUKUVHLPDOGOYRMOTAQELLRMHFAQEOXFWGAQUROVUSWOAWFRVIRJQVXPCXLSCQLCUWKBZUFQP\nYVF", "output": "ILBWKHDGOMQELRHEGUVUSOWVRVLCKBF" }, { "input": "AXBPBDEYIYKKCZBTLKBUNEQLCXXLKIUTOOATYDXYYQCLFAXAEIGTFMNTTQKCQRMEEFRYVYXAOLMUQNPJBMFBUGVXFZAJSBXWALSI\nVWFONLLKSHGHHQSFBBFWTXAITPUKNDANOCLMNFTAAMJVDLXYPILPCJCFWTNBQWEOMMXHRYHEGBJIVSXBBGQKXRIYNZFIWSZPPUUM\nPPKKLHXWWT", "output": "BBITKNCLTADXYCFTNQMRYVXBBGXFWS" }, { "input": "XKTAOCPCVMIOGCQKPENDKIZRZBZVRTBTGCDRQUIMVHABDIHSCGWPUTQKLPBOXAYICPWJBFLFSEPERGJZHRINEHQMYTOTKLCQCSMZ\nAITFIOUTUVZLSSIYWXSYTQMFLICCXOFSACHTKGPXRHRCGXFZXPYWKWPUOIDNEEZOKMOUYGVUJRQTIRQFCSBCWXVFCIAOLZDGENNI\nDBHOIORVCPNXCDOJKSYYIENQRJGZFHOWBYQIITMTVWXRMAMYILTHBBAJRJELWMIZOZBGPDGSTIRTQIILJRYICMUQTUAFKDYGECPY", "output": "TOVMIOCKPRRCGWPUOIEEGJRQTQCSZ" }, { "input": "UNGXODEEINVYVPHYVGSWPIPFMFLZJYRJIPCUSWVUDLLSLRPJJFWCUOYDUGXBRKWPARGLXFJCNNFUIGEZUCTPFYUIMQMJLQHTIVPO\nBWDEGORKXYCXIDWZKGFCUYIDYLTWLCDBUVHPAPFLIZPEUINQSTNRAOVYKZCKFWIJQVLSVCGLTCOEMAYRCDVVQWQENTWZALWUKKKA\nXDGPZXADAFCHKILONSXFGRHIQVMIYWUTJUPCCEKYQVYAENRHVWERJSNPVEMRYSZGYBNTQLIFKFISKZJQIQQGSKVGCNMPNIJDRTXI", "output": "GODIYVHPPFLZPUSWVLSLCOYDWALU" }, { "input": "KOROXDDWEUVYWJIXSFPEJFYZJDDUXISOFJTIFJSBTWIJQHMTQWLAGGMXTFALRXYCMGZNKYQRCDVTPRQDBAALTWAXTNLDPYWNSFKE\nNHZGRZFMFQGSAYOJTFKMMUPOOQXWCPPAIVRJHINJPHXTTBWRIYNOHMJKBBGXVXYZDBVBBTQRXTOFLBBCXGNICBKAAGOKAYCCJYCW\nXCXLBESCRBNKWYGFDZFKWYNLFAKEWWGRUIAQGNCFDQXCHDBEQDSWSNGVKUFOGGSPFFZWTXGZQMMFJXDWOPUEZCMZEFDHXTRJTNLW", "output": "KOOXWVJIPXTBWIHMTQXTFLCGNCBAAAYW" }, { "input": "ESQZPIRAWBTUZSOWLYKIYCHZJPYERRXPJANKPZVPEDCXCJIDTLCARMAOTZMHJVDJXRDNQRIIOFIUTALVSCKDUSAKANKKOFKWINLQ\nGKSTYEAXFJQQUTKPZDAKHZKXCJDONKBZOTYGLYQJOGKOYMYNNNQRRVAGARKBQYJRVYYPFXTIBJJYQUWJUGAUQZUVMUHXLIQWGRMP\nUFPHNRDXLNYRIIYVOFRKRUQCWAICQUUBPHHEGBCILXHHGLOBKADQVPSQCMXJRLIZQPSRLZJNZVQPIURDQUKNHVVYNVBYGXXXXJDI", "output": "STYEXJKPZDXCJDTLOMVRQRFIUAVUIQ" }, { "input": "UAYQUMTSNGMYBORUYXJJQZVAGBRVDWUTGUYYYOTWAHVKGGOHADXULFUFQULSAGDWFJCSDKPWBROYZIFRGGRVZQMEHKHCKNHTQSMK\nSVKVTPUZOBRKGLEAAXMIUSRISOTDIFFUCODYGNYIPSWEEBHGNWRZETXSVVMQTRBVFZMYHOHUCMLBUXBMPMSNCSHFZTAFUVTMQFGL\nTNICVANBEBOQASUEJJAOJXWNMDGAAVYNHRPSMKGMXZDJHCZHFHRRMIDWUOQCZSBKDPLSGHNHFKFYDRGVKXOLPOOWBPOWSDFLEJVX", "output": "SVVTUOKGAXUFFUCDPWBRZRVZMHHCNHTQ" }, { "input": "KEJHTOKHMKWTYSJEAJAXGADRHUKBCRHACSRDNSZIHTPQNLOSRKYBGYIIJDINTXRPMWSVMMBODAYPVVDDTIXGDIOMWUAKZVFKDAUM\nWTEVPIFAAJYIDTZSZKPPQKIOMHDZTKDMFVKSJRUFMNHZJPVSQYELWYAFACGGNRORSLGYVXAEYVLZBLDEHYDGOFDSWUYCXLXDKFSU\nTUZEQBWVBVTKETQ", "output": "EJTOKMKSJRUHZPQLYGNRSVAYVDDGDWUKFU" }, { "input": "EGQYYSKTFTURZNRDVIWBYXMRDGFWMYKFXGIFOGYJSXKDCJUAGZPVTYCHIXVFTVTCXMKHZFTXSMMQVFXZGKHCIYODDRZEYECDLKNG\nPEXXCTRFJAAKPOTBAEFRLDRZKORNMXHHXTLKMKCGPVPUOBELPLFQFXOBZWIVIQCHEJQPXKGSCQAWIMETCJVTAGXJIINTADDXJTKQ\nQURSEKPMSSEVQZI", "output": "EKTFRZNXMGFFXIJXKCATCVTXTDDK" }, { "input": "ZFFBNYVXOZCJPSRAEACVPAUKVTCVZYQPHVENTKOCMHNIYYMIKKLNKHLWHHWAQMWFTSYEOQQFEYAAYGMPNZCRYBVNAQTDSLXZGBCG\nPIQHLNEWAMFAKGHBGZAWRWAXCSKUDZBDOCTXAHSVFZACXGFMDSYBYYDDNQNBEZCYCULSMMPBTQOJQNRPZTRCSDLIYPLVUGJPKDTG\nZBFJPLNAKWQBTUVJKMHVBATAM", "output": "FBZRACUZOCHAMSYYYNZCYBNTDLGG" }, { "input": "BTWZLIKDACZVLCKMVTIQHLFBNRCBDSWPFFKGPCQFPTOIJLPFCDMFGQKFHTDFFCCULUAYPXXIIIWBZIDMOPNHPZBEXLVARJFTBFOE\nMDXYKKWZVASJPPWRCYNMRAOBBLUNBSMQAPCPSFAGLXWJRBQTBRWXYNQGWECYNFIAJXDMUHIIMDFMSHLPIMYQXNRRUSSNXALGNWIK\nKNFVBVAOWXMZVUHAVUDKDBUVAKNHACZBGBHMUOPHWGQSDFXLHB", "output": "WZACLMQLBRWGCFIJDMHDFLPIMNXL" }, { "input": "GOZVMIRQIGYGVAGOREQTXFXPEZYOJOXPNDGAESICXHMKQDXQPRLMRVWHXFEJVCWZDLYMQLDURUXZPTLEHPTSKXGSNEQDKLVFFLDX\nIMEVFCZXACKRRJVXDRKFWTLTRTLQQDHEBZLCOCNVPABQMIWJHRLKFUKWOVVWGGNWCJNRYOYOAJFQWCLHQIQRBZTVWKBFOXKEHHQP\nSZ", "output": "MVARXFEZOPAIHRLVWFCLQRZTKXEQ" }, { "input": "BBYUVCIYLNUJPSEYCAAPQSDNSDDTNEHQZDPBEKQAWNAKEYFBNEEBGPDPRLCSVOWYDEDRPPEDOROCHRCNQUSPNVXGRXHNLKDETWQC\nBQCQXCAHADGJHBYIKEUWNXFUOOTVCCKJPJJCMWLAWWKSDGHFNZTCPSQNRTPCBLXDTSJLRHSCCZXQXCVLVGTROOUCUQASIQHZGNEI\nRYE", "output": "BBYUVCJPCASDNTPQNBDRLVROOCQSGNE" }, { "input": "WZRKLETJRBBRZKGHEFBVEFVLIERBPSEGJVSNUZUICONWWBOOTHCOJLLZFNOCNOFJQZTZWBLKHGIWWWPBUYWBAHYJGEBJZJDTNBGN\nZINFGDCNKHYFZYYWHTIHZTKWXXXMSWOVOPQDTRWSQKBWWCPEMYFVGARELELBLGEVJCMOCFTTUVCYUQUSFONAMWKVDWMGXVNZJBWH\nAFPA", "output": "WZKTRBEFVELEBEJCOTCFONWKWGZJB" }, { "input": "ABABABB\nABABABB\nABABB", "output": "ABABAB" }, { "input": "ABBB\nABBB\nABB", "output": "BBB" }, { "input": "A\nBABAABAAABABABABABABAABABABABBABABABABAABBABBABAABABAABAABBAAAAAABBABABABABAABABAABABABABAABAABABABA\nB", "output": "A" }, { "input": "ABBAABAAABABAABAABABABABAABBBABABABAAABBABAAABABABABBABBABABAABABABABABABBABAABABAABABABAAABBABABABA\nA\nB", "output": "A" }, { "input": "ABBBABABABABABBABAABAAABABAABABABABBABAAAABABABBABAABABAAABAABBAAABAABABBABBABABBABAABABABAAAAABABAB\nB\nBABBABAABABABABABABABABABBAABABBABABBAAABAAABABBAABAABBABABBABABAABBABAABABBAABAABAABABABABABBABABAB", "output": "B" }, { "input": "AABABAABAAABABAAABAAAABBAAABABAAABABAABAABAAAABAABAAAABAAAABAAAABBAABAAAAABAAAAABABAAAAAABABAABAAAAA\nABAABABABAAABABAABABBAABAABAABABAABABAAABBAABAAAABABABAAAAABAAAAABABABABAABAABAABAABABAABABAABAABAAB\nBABAAABABBAABABAABAA", "output": "ABAABABABAAABAAAABBAABAAAABABAABABAAABAABAAAABAAAAAAABAAAAAAABAAAAABAAAAAAABABAABAAAA" }, { "input": "AABABABABAAAABBAAAABABABABAAAAABABAAAA\nAABABAAABABABAAABAAAAABAAABAAABABABBBABBAAABAABAAAAABABBABAAABAABAABABAAAABABAAABAAABAABABBBABBABABA\nAAAAA", "output": "AABABABABAAAABBAAAABABABABAAAABABAAAA" }, { "input": "ZZXXAAZZAXAAZZAZZXXAAZZAXAXZZXXAAZZZZXXAZZXXAAAZZXXAAAZZXXZZXXXAAAZZXZZXXAZZXXZXXAAXAAZZZXXAXAXAZZXZ\nAZZXXAAZZXXAAXZXXAZZXAZZXZZXXAAZZXXAAZAAZZAAZZXXAA\nAAZZXAAXXAAAZZXXAZZXXAAZZXXAAAZZXXZ", "output": "ZZXXAAZZXXAAXZXXAZZXAZZXZZXXAAZZXXAAZAZZAAZZXXAA" }, { "input": "SDASSDADASDASDASDSDADASASDAAASDASDDASDDASDADASDASDSSDASDD\nSDASDASDDASDASDASDSDSDASDASDASDASDASDASDASDADASDASDASDSDASDASDDDASSD\nSDASDSDDAA", "output": "SDASSDADASDASDSDSDADASASDAAASDASDDASDDASDDASDASDDASD" }, { "input": "DASSDASDASDDAASDASDADASDASASDAS\nSDADASDASSDAASDASDASDADASSDDA\nSD", "output": "DADADADAADADADADASSA" }, { "input": "ASDASSDASDS\nDASDASDDDASDADASDASDASDASSDADASDDAASDA\nDSD", "output": "ASDASSDASDS" }, { "input": "ASDASASDASDASDAASDASDASDASASDDAASDASSASDSDAD\nDASDASSSDASDASDASASDASSDAASDASSDDSASDASDAASDDAASDASDAASDASDDASDASDASDASDASS\nDASD", "output": "ASDASASDASASDAASDASASDASASDDAASDASSASDSDAD" }, { "input": "DASDSDASDADASDDDSDASSDDAASDA\nDASDDASDSDADSDASDADSDSDADDASDASDDASDASDASDSDASD\nDAASD", "output": "DASDSDASDADASDDDSDASSDDASDA" }, { "input": "ABAAAABABADABAABAABCCABADABACABACABCABADABADABACABBACAADABACABABACABADABACABABA\nBACAACABABABACABCABADABAACABADABACABAA\nABBAB", "output": "BAAACABABABACABCABADABAACABADABACABAA" }, { "input": "ABAABACABADAACADABACAAB\nBAACABADABACABAAAADADAABACABACABADABABADABACABAADABBADABACAAACAABACABADABBBAA\nDABACA", "output": "ABAABACABADAACADABAAAB" }, { "input": "BACABACABAACABADABABACAABACABBACAACAACABCABADAACABAABAABBADABACABADABCABAD\nBACAABADABABADABACABABACABADABACABCBADABACADABCABABADAABA\nBADABAA", "output": "BACAABAAABADABACAABACABAAACABCBADAACADABCABADAABA" }, { "input": "ACABADABACABCABAAB\nBADAB\nACAACABA", "output": "BADAB" }, { "input": "ABABAC\nABABAC\nABAC", "output": "ABABA" }, { "input": "BCBCBC\nBCBCBC\nBC", "output": "CCB" }, { "input": "AAACAAACAAADAAAAAAA\nAADAAAAAAAACDAAAAAAAAAAACAAAAABCACAAACAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADA\nAAACAADAAAAADD", "output": "AAACAAACAAAAAAAAAA" }, { "input": "ABABBB\nABABBB\nABB", "output": "ABAB" }, { "input": "ABABABAC\nABABABAC\nABABAC", "output": "ABABABA" }, { "input": "BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB\nBBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB\nBBBAA", "output": "BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBABBABBBABAABBBBBBABAAAAAAAAABABAAABBABBAAAAAABAABABBAAABB" }, { "input": "ABABC\nABABC\nABC", "output": "ABAB" }, { "input": "BABBB\nBABBB\nABB", "output": "BBBB" }, { "input": "ABCCCCCCCC\nABCCCCCCCC\nABC", "output": "BCCCCCCCC" } ]
1,634,348,672
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
3,000
70,041,600
s1 = input() s2 = input() virus = input() if len(s1) > len(s2): s1, s2 = s2, s1 d = {} y = 1 for w in s1: x = s2.find(w) achou = False if x != -1: for k in d.keys(): if d[k][-1][1] < x: d[k].append([w, x]) achou = True if not achou: l_aux = d.copy() for k in l_aux.keys(): s = [] for e in d[k]: if e[1] < x: s.append(e) else: break s.append([w, x]) d[s[0][0]+str(y)] = s y += 1 d[w] = [[w, x]] s2 = s2[:x] + "*" + s2[x+1:] l = [] for k in d.keys(): s = "" for e in d[k]: s += e[0] l.append(s) max = "" for e in l: x = e.find(virus) while x != -1: e = e[:x] + e[x+1:] x = e.find(virus) if len(e) > len(max): max = e print(max if max != "" else 0)
Title: Lucky Common Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF. You are given two strings *s*1, *s*2 and another string called *virus*. Your task is to find the longest common subsequence of *s*1 and *s*2, such that it doesn't contain *virus* as a substring. Input Specification: The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=≤<=|*s*1|,<=|*s*2|,<=|*virus*|<=≤<=100). Each string consists only of uppercase English letters. Output Specification: Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0. Demo Input: ['AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n', 'AA\nA\nA\n'] Demo Output: ['ORZ\n', '0\n'] Note: none
```python s1 = input() s2 = input() virus = input() if len(s1) > len(s2): s1, s2 = s2, s1 d = {} y = 1 for w in s1: x = s2.find(w) achou = False if x != -1: for k in d.keys(): if d[k][-1][1] < x: d[k].append([w, x]) achou = True if not achou: l_aux = d.copy() for k in l_aux.keys(): s = [] for e in d[k]: if e[1] < x: s.append(e) else: break s.append([w, x]) d[s[0][0]+str(y)] = s y += 1 d[w] = [[w, x]] s2 = s2[:x] + "*" + s2[x+1:] l = [] for k in d.keys(): s = "" for e in d[k]: s += e[0] l.append(s) max = "" for e in l: x = e.find(virus) while x != -1: e = e[:x] + e[x+1:] x = e.find(virus) if len(e) > len(max): max = e print(max if max != "" else 0) ```
0
992
C
Nastya and a Wardrobe
PROGRAMMING
1,600
[ "math" ]
null
null
Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer.
The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland.
In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7.
[ "2 0\n", "2 1\n", "3 2\n" ]
[ "4\n", "7\n", "21\n" ]
In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
1,500
[ { "input": "2 0", "output": "4" }, { "input": "2 1", "output": "7" }, { "input": "3 2", "output": "21" }, { "input": "1 411", "output": "485514976" }, { "input": "1 692", "output": "860080936" }, { "input": "16 8", "output": "7937" }, { "input": "18 12", "output": "143361" }, { "input": "1 1000000000000000000", "output": "719476261" }, { "input": "0 24", "output": "0" }, { "input": "24 0", "output": "48" }, { "input": "1000000000000000000 1", "output": "195" }, { "input": "348612312017571993 87570063840727716", "output": "551271547" }, { "input": "314647997243943415 107188213956410843", "output": "109575135" }, { "input": "375000003 2", "output": "0" }, { "input": "451 938", "output": "598946958" }, { "input": "4 1669", "output": "185365669" }, { "input": "24 347", "output": "860029201" }, { "input": "1619 1813", "output": "481568710" }, { "input": "280 472", "output": "632090765" }, { "input": "1271 237", "output": "27878991" }, { "input": "626 560", "output": "399405853" }, { "input": "167 887", "output": "983959273" }, { "input": "1769 422", "output": "698926874" }, { "input": "160 929", "output": "752935252" }, { "input": "1075 274", "output": "476211777" }, { "input": "1332 332", "output": "47520583" }, { "input": "103872254428948073 97291596742897547", "output": "283633261" }, { "input": "157600018563121064 54027847222622605", "output": "166795759" }, { "input": "514028642164226185 95344332761644668", "output": "718282571" }, { "input": "91859547444219924 75483775868568438", "output": "462306789" }, { "input": "295961633522750187 84483303945499729", "output": "11464805" }, { "input": "8814960236468055 86463151557693391", "output": "430718856" }, { "input": "672751296745170589 13026894786355983", "output": "260355651" }, { "input": "909771081413191574 18862935031728197", "output": "800873185" }, { "input": "883717267463724670 29585639347346605", "output": "188389362" }, { "input": "431620727626880523 47616788361847228", "output": "311078131" }, { "input": "816689044159694273 6475970360049048", "output": "211796030" }, { "input": "313779810374175108 13838123840048842", "output": "438854949" }, { "input": "860936792402722414 59551033597232946", "output": "359730003" }, { "input": "332382902893992163 15483141652464187", "output": "719128379" }, { "input": "225761360057436129 49203610094504526", "output": "54291755" }, { "input": "216006901533424028 8313457244750219", "output": "362896012" }, { "input": "568001660010321225 97167523790774710", "output": "907490480" }, { "input": "904089164817530426 53747406876903279", "output": "702270335" }, { "input": "647858974461637674 18385058205826214", "output": "375141527" }, { "input": "720433754707338458 94180351080265292", "output": "273505123" }, { "input": "268086842387268316 76502855388264782", "output": "288717798" }, { "input": "488603693655520686 79239542983498430", "output": "316399174" }, { "input": "152455635055802121 50394545488662355", "output": "697051907" }, { "input": "585664029992038779 34972826534657555", "output": "699566354" }, { "input": "349532090641396787 12248820623854158", "output": "233938854" }, { "input": "353579407209009179 74469254935824590", "output": "771349161" }, { "input": "491414900908765740 49509676303815755", "output": "237095803" }, { "input": "91142854626119420 900651524977956", "output": "211575546" }, { "input": "73543340229981083 66918326344192076", "output": "710215652" }, { "input": "463958371369193376 89203995753927042", "output": "41857490" }, { "input": "911873413622533246 54684577459651780", "output": "926432198" }, { "input": "316313018463929883 78259904441946885", "output": "36284201" }, { "input": "889560480100219043 54181377424922141", "output": "281123162" }, { "input": "0 3259862395629356", "output": "0" }, { "input": "1 3", "output": "9" }, { "input": "3 1", "output": "11" }, { "input": "1000000007 1", "output": "1000000006" }, { "input": "1000000007 2", "output": "1000000004" }, { "input": "1000000007 0", "output": "0" }, { "input": "1000000007 12", "output": "999995912" }, { "input": "1000000007 70", "output": "729983755" }, { "input": "250000002 1", "output": "0" }, { "input": "1000000007 3", "output": "1000000000" }, { "input": "999999999 0", "output": "999999991" }, { "input": "1000000007 5", "output": "999999976" }, { "input": "1000000007 1000000007", "output": "1000000006" }, { "input": "10000000000000000 0", "output": "860000007" }, { "input": "1000000000000 0", "output": "999986007" }, { "input": "99999999999999999 0", "output": "600000012" }, { "input": "1000000000000000 0", "output": "986000007" } ]
1,568,394,275
6,275
Python 3
WRONG_ANSWER
TESTS
8
124
0
def solve1(z1,z2): k = (z2-z1)//2 + 1 return ((k//2)*(z1+z2)) x,k = map(int,input().split()) m = 10**9 + 7 print((pow(2,k,m)*((x-1)%m))%m+(pow(2,k,m)*(x)%m)%m + 1)
Title: Nastya and a Wardrobe Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year. Nastya owns *x* dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for *k*<=+<=1 months. Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109<=+<=7, because it is easy to see that it is always integer. Input Specification: The only line contains two integers *x* and *k* (0<=≤<=*x*,<=*k*<=≤<=1018), where *x* is the initial number of dresses and *k*<=+<=1 is the number of months in a year in Byteland. Output Specification: In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109<=+<=7. Demo Input: ['2 0\n', '2 1\n', '3 2\n'] Demo Output: ['4\n', '7\n', '21\n'] Note: In the first example a year consists on only one month, so the wardrobe does not eat dresses at all. In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.
```python def solve1(z1,z2): k = (z2-z1)//2 + 1 return ((k//2)*(z1+z2)) x,k = map(int,input().split()) m = 10**9 + 7 print((pow(2,k,m)*((x-1)%m))%m+(pow(2,k,m)*(x)%m)%m + 1) ```
0
56
A
Bar
PROGRAMMING
1,000
[ "implementation" ]
A. Bar
2
256
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol.
Print a single number which is the number of people Vasya should check to guarantee the law enforcement.
[ "5\n18\nVODKA\nCOKE\n19\n17\n" ]
[ "2\n" ]
In the sample test the second and fifth clients should be checked.
500
[ { "input": "5\n18\nVODKA\nCOKE\n19\n17", "output": "2" }, { "input": "2\n2\nGIN", "output": "2" }, { "input": "3\nWHISKEY\n3\nGIN", "output": "3" }, { "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW", "output": "1" }, { "input": "4\nSAKE\nSAKE\n13\n2", "output": "4" }, { "input": "2\n0\n17", "output": "2" }, { "input": "1\n0", "output": "1" } ]
1,592,975,069
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
186
6,656,000
x=['ABSINTH', 'BEER', 'BRANDY', ' CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'] c=0 num='0123456789' for _ in range(int(input())): y=input() if y[0] in num: if int(y)<18: c+=1 elif y in x: c+=1 print(c)
Title: Bar Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol. Output Specification: Print a single number which is the number of people Vasya should check to guarantee the law enforcement. Demo Input: ['5\n18\nVODKA\nCOKE\n19\n17\n'] Demo Output: ['2\n'] Note: In the sample test the second and fifth clients should be checked.
```python x=['ABSINTH', 'BEER', 'BRANDY', ' CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE'] c=0 num='0123456789' for _ in range(int(input())): y=input() if y[0] in num: if int(y)<18: c+=1 elif y in x: c+=1 print(c) ```
0
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "4\nRBBR", "output": "1" }, { "input": "5\nRGGBG", "output": "1" }, { "input": "10\nGGBRBRGGRB", "output": "2" }, { "input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB", "output": "18" }, { "input": "15\nBRRBRGGBBRRRRGR", "output": "6" }, { "input": "20\nRRGBBRBRGRGBBGGRGRRR", "output": "6" }, { "input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB", "output": "6" }, { "input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB", "output": "9" }, { "input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB", "output": "14" }, { "input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG", "output": "20" }, { "input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG", "output": "11" }, { "input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG", "output": "17" }, { "input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB", "output": "16" }, { "input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG", "output": "19" }, { "input": "10\nGRRBRBRBGR", "output": "1" }, { "input": "10\nBRBGBGRRBR", "output": "1" }, { "input": "20\nGBGBGGRRRRGRBBGRGRGR", "output": "5" }, { "input": "20\nRRGGRBBGBBRBGRRBRRBG", "output": "6" }, { "input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB", "output": "8" }, { "input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB", "output": "11" }, { "input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB", "output": "9" }, { "input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG", "output": "13" }, { "input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG", "output": "13" }, { "input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB", "output": "12" }, { "input": "2\nBB", "output": "1" }, { "input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "49" }, { "input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "47" }, { "input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR", "output": "43" } ]
1,699,856,214
2,147,483,647
Python 3
OK
TESTS
34
92
0
n= int(input()) s = input() res = 0 for i in range(len(s)-1): if s[i] == s[i+1]: res +=1 print(res)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python n= int(input()) s = input() res = 0 for i in range(len(s)-1): if s[i] == s[i+1]: res +=1 print(res) ```
3
456
A
Laptops
PROGRAMMING
1,100
[ "sortings" ]
null
null
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
[ "2\n1 2\n2 1\n" ]
[ "Happy Alex\n" ]
none
500
[ { "input": "2\n1 2\n2 1", "output": "Happy Alex" }, { "input": "2\n1 1\n2 2", "output": "Poor Alex" }, { "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex" }, { "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex" }, { "input": "1\n1 1", "output": "Poor Alex" }, { "input": "3\n2 3\n1 1\n3 2", "output": "Happy Alex" }, { "input": "4\n4 1\n3 2\n2 3\n1 4", "output": "Happy Alex" }, { "input": "2\n2 1\n1 2", "output": "Happy Alex" }, { "input": "3\n3 2\n1 1\n2 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" }, { "input": "3\n1 2\n2 1\n3 3", "output": "Happy Alex" }, { "input": "3\n1 2\n2 3\n3 1", "output": "Happy Alex" } ]
1,695,289,835
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
307,200
import copy n=int(input()) ck=0 ps=[] qs=[] for i in range(n): p,q=map(int,input().split()) ps.append(p) qs.append(q) nps=ps.copy() nps.sort() nqs=[] for i in nps: nqs.append(qs[nps.index(i)]) for j in range(n-1): if nqs[j]>nqs[j+1]: ck=1 if ck==0: print('Poor Alex') else: print('Happy Alex')
Title: Laptops Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. Output Specification: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Demo Input: ['2\n1 2\n2 1\n'] Demo Output: ['Happy Alex\n'] Note: none
```python import copy n=int(input()) ck=0 ps=[] qs=[] for i in range(n): p,q=map(int,input().split()) ps.append(p) qs.append(q) nps=ps.copy() nps.sort() nqs=[] for i in nps: nqs.append(qs[nps.index(i)]) for j in range(n-1): if nqs[j]>nqs[j+1]: ck=1 if ck==0: print('Poor Alex') else: print('Happy Alex') ```
0
496
A
Minimum Difficulty
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height. Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions. Help Mike determine the minimum difficulty of the track after removing one hold.
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one).
Print a single number — the minimum difficulty of the track after removing a single hold.
[ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ]
[ "5\n", "2\n", "4\n" ]
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.
500
[ { "input": "3\n1 4 6", "output": "5" }, { "input": "5\n1 2 3 4 5", "output": "2" }, { "input": "5\n1 2 3 7 8", "output": "4" }, { "input": "3\n1 500 1000", "output": "999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2" }, { "input": "10\n1 4 9 16 25 36 49 64 81 100", "output": "19" }, { "input": "10\n300 315 325 338 350 365 379 391 404 416", "output": "23" }, { "input": "15\n87 89 91 92 93 95 97 99 101 103 105 107 109 111 112", "output": "2" }, { "input": "60\n3 5 7 8 15 16 18 21 24 26 40 41 43 47 48 49 50 51 52 54 55 60 62 71 74 84 85 89 91 96 406 407 409 412 417 420 423 424 428 431 432 433 436 441 445 446 447 455 458 467 469 471 472 475 480 485 492 493 497 500", "output": "310" }, { "input": "3\n159 282 405", "output": "246" }, { "input": "81\n6 7 22 23 27 38 40 56 59 71 72 78 80 83 86 92 95 96 101 122 125 127 130 134 154 169 170 171 172 174 177 182 184 187 195 197 210 211 217 223 241 249 252 253 256 261 265 269 274 277 291 292 297 298 299 300 302 318 338 348 351 353 381 386 387 397 409 410 419 420 428 430 453 460 461 473 478 493 494 500 741", "output": "241" }, { "input": "10\n218 300 388 448 535 629 680 740 836 925", "output": "111" }, { "input": "100\n6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 206 216 226 236 246 256 266 276 286 296 306 316 326 336 346 356 366 376 386 396 406 416 426 436 446 456 466 476 486 496 506 516 526 536 546 556 566 576 586 596 606 616 626 636 646 656 666 676 686 696 706 716 726 736 746 756 766 776 786 796 806 816 826 836 846 856 866 876 886 896 906 916 926 936 946 956 966 976 986 996", "output": "20" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000", "output": "901" }, { "input": "100\n1 9 15 17 28 29 30 31 32 46 48 49 52 56 62 77 82 85 90 91 94 101 102 109 111 113 116 118 124 125 131 132 136 138 139 143 145 158 161 162 165 167 171 173 175 177 179 183 189 196 801 802 804 806 817 819 827 830 837 840 842 846 850 855 858 862 863 866 869 870 878 881 883 884 896 898 899 901 904 906 908 909 910 911 912 917 923 924 925 935 939 943 945 956 963 964 965 972 976 978", "output": "605" }, { "input": "100\n2 43 47 49 50 57 59 67 74 98 901 903 904 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 938 939 940 942 943 944 945 946 947 948 949 950 952 953 954 956 957 958 959 960 961 962 963 965 966 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 998 999", "output": "803" }, { "input": "72\n178 186 196 209 217 226 236 248 260 273 281 291 300 309 322 331 343 357 366 377 389 399 409 419 429 442 450 459 469 477 491 501 512 524 534 548 557 568 582 593 602 616 630 643 652 660 670 679 693 707 715 728 737 750 759 768 776 789 797 807 815 827 837 849 863 873 881 890 901 910 920 932", "output": "17" }, { "input": "38\n1 28 55 82 109 136 163 190 217 244 271 298 325 352 379 406 433 460 487 514 541 568 595 622 649 676 703 730 757 784 811 838 865 892 919 946 973 1000", "output": "54" }, { "input": "28\n1 38 75 112 149 186 223 260 297 334 371 408 445 482 519 556 593 630 667 704 741 778 815 852 889 926 963 1000", "output": "74" } ]
1,511,409,360
2,147,483,647
Python 3
OK
TESTS
19
61
0
n = int(input()) dist = [int(x) for x in input().split()] _min = dist[-1] - dist[0] removed = dist[1] for i in range(n-2): atual = dist[i+2] - dist[i] if atual < _min: _min = atual removed = dist[i+1] dist.remove(removed) _max = dist[1] - dist[0] for i in range(n-2): atual = dist[i+1] - dist[i] if _max < atual: _max = atual print(_max)
Title: Minimum Difficulty Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height. Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions. Help Mike determine the minimum difficulty of the track after removing one hold. Input Specification: The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). Output Specification: Print a single number — the minimum difficulty of the track after removing a single hold. Demo Input: ['3\n1 4 6\n', '5\n1 2 3 4 5\n', '5\n1 2 3 7 8\n'] Demo Output: ['5\n', '2\n', '4\n'] Note: In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.
```python n = int(input()) dist = [int(x) for x in input().split()] _min = dist[-1] - dist[0] removed = dist[1] for i in range(n-2): atual = dist[i+2] - dist[i] if atual < _min: _min = atual removed = dist[i+1] dist.remove(removed) _max = dist[1] - dist[0] for i in range(n-2): atual = dist[i+1] - dist[i] if _max < atual: _max = atual print(_max) ```
3
665
C
Simple Strings
PROGRAMMING
1,300
[ "dp", "greedy", "strings" ]
null
null
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task!
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters.
[ "aab\n", "caaab\n", "zscoder\n" ]
[ "bab\n", "cabab\n", "zscoder\n" ]
none
0
[ { "input": "aab", "output": "bab" }, { "input": "caaab", "output": "cabab" }, { "input": "zscoder", "output": "zscoder" }, { "input": "u", "output": "u" }, { "input": "h", "output": "h" }, { "input": "dtottttotd", "output": "dtotataotd" }, { "input": "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr", "output": "rxaxraxrxaxaxrararxaxararaxrxarxarxrxrarxraxraxrxaxrxraxraxrxrxaxaxrxaxararxrxarxarxaxrararxraxraxra" }, { "input": "aazz", "output": "baza" }, { "input": "zz", "output": "za" }, { "input": "gg", "output": "ga" }, { "input": "qasdasd", "output": "qasdasd" }, { "input": "aa", "output": "ba" }, { "input": "ab", "output": "ab" }, { "input": "zza", "output": "zba" }, { "input": "g", "output": "g" }, { "input": "nnop", "output": "naop" }, { "input": "xx", "output": "xa" } ]
1,608,017,918
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
6
202
2,048,000
import sys def get_list():return list(map(int, sys.stdin.readline().split())) def get_string():return input() def get_int():return int(input()) def get_ints(): return map(int, sys.stdin.readline().split()) for _ in range(1): s=['0']+[i for i in input()] n=len(s) for i in range(1,n): if s[i]!=s[i-1]:continue else: for j in range(26): l=chr(97+j) #print(l) if i+1<=n and s[i-1]!=l and s[i+1]!=l: s[i]=l break print(''.join(s)[1:])
Title: Simple Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! Input Specification: The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. Output Specification: Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters. Demo Input: ['aab\n', 'caaab\n', 'zscoder\n'] Demo Output: ['bab\n', 'cabab\n', 'zscoder\n'] Note: none
```python import sys def get_list():return list(map(int, sys.stdin.readline().split())) def get_string():return input() def get_int():return int(input()) def get_ints(): return map(int, sys.stdin.readline().split()) for _ in range(1): s=['0']+[i for i in input()] n=len(s) for i in range(1,n): if s[i]!=s[i-1]:continue else: for j in range(26): l=chr(97+j) #print(l) if i+1<=n and s[i-1]!=l and s[i+1]!=l: s[i]=l break print(''.join(s)[1:]) ```
-1
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,695,534,807
2,147,483,647
Python 3
OK
TESTS
32
92
0
import sys t = 1; #t = int(sys.stdin.readline()) def solve() -> None: n = int(sys.stdin.readline()) arr = [int(x)for x in sys.stdin.readline().split()] even,odd = [],[] for i in range(1,n+1):even.append((arr[i-1],i)) if ~arr[i-1]&1 else odd.append((arr[i-1],i)) del arr print(even[0][1])if len(even)==1 else print(odd[0][1]) for _ in [0] * t : solve()
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python import sys t = 1; #t = int(sys.stdin.readline()) def solve() -> None: n = int(sys.stdin.readline()) arr = [int(x)for x in sys.stdin.readline().split()] even,odd = [],[] for i in range(1,n+1):even.append((arr[i-1],i)) if ~arr[i-1]&1 else odd.append((arr[i-1],i)) del arr print(even[0][1])if len(even)==1 else print(odd[0][1]) for _ in [0] * t : solve() ```
3.977
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input": "17 100 100 1", "output": "1" }, { "input": "17 2 3 100", "output": "5" }, { "input": "18 1 3 3", "output": "2" }, { "input": "19 1 1 1", "output": "1" }, { "input": "999999997 999999990 1000000000 1000000000", "output": "1000000000" }, { "input": "999999998 1000000000 999999990 1000000000", "output": "999999990" }, { "input": "634074578 336470888 481199252 167959139", "output": "335918278" }, { "input": "999999999 1000000000 1000000000 999999990", "output": "1000000000" }, { "input": "804928248 75475634 54748096 641009859", "output": "0" }, { "input": "535590429 374288891 923264237 524125987", "output": "524125987" }, { "input": "561219907 673102149 496813081 702209411", "output": "673102149" }, { "input": "291882089 412106895 365329221 585325539", "output": "585325539" }, { "input": "757703054 5887448 643910770 58376259", "output": "11774896" }, { "input": "783332532 449924898 72235422 941492387", "output": "0" }, { "input": "513994713 43705451 940751563 824608515", "output": "131116353" }, { "input": "539624191 782710197 514300407 2691939", "output": "8075817" }, { "input": "983359971 640274071 598196518 802030518", "output": "640274071" }, { "input": "8989449 379278816 26521171 685146646", "output": "405799987" }, { "input": "34618927 678092074 895037311 863230070", "output": "678092074" }, { "input": "205472596 417096820 468586155 41313494", "output": "0" }, { "input": "19 5 1 2", "output": "3" }, { "input": "17 1 2 2", "output": "2" }, { "input": "18 3 3 1", "output": "2" }, { "input": "19 4 3 1", "output": "3" }, { "input": "936134778 715910077 747167704 219396918", "output": "438793836" }, { "input": "961764255 454914823 615683844 102513046", "output": "307539138" }, { "input": "692426437 48695377 189232688 985629174", "output": "146086131" }, { "input": "863280107 347508634 912524637 458679894", "output": "347508634" }, { "input": "593942288 86513380 486073481 341796022", "output": "0" }, { "input": "914539062 680293934 764655030 519879446", "output": "764655030" }, { "input": "552472140 509061481 586588704 452405440", "output": "0" }, { "input": "723325809 807874739 160137548 335521569", "output": "335521569" }, { "input": "748955287 546879484 733686393 808572289", "output": "546879484" }, { "input": "774584765 845692742 162011045 691688417", "output": "691688417" }, { "input": "505246946 439473295 30527185 869771841", "output": "30527185" }, { "input": "676100616 178478041 604076030 752887969", "output": "0" }, { "input": "701730093 477291299 177624874 930971393", "output": "654916173" }, { "input": "432392275 216296044 751173719 109054817", "output": "216296044" }, { "input": "458021753 810076598 324722563 992170945", "output": "992170945" }, { "input": "188683934 254114048 48014511 170254369", "output": "48014511" }, { "input": "561775796 937657403 280013594 248004555", "output": "0" }, { "input": "1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 10000 10000 3", "output": "9" }, { "input": "3 12 3 4", "output": "7" }, { "input": "3 10000 10000 1", "output": "3" }, { "input": "3 1000 1000 1", "output": "3" }, { "input": "3 10 10 1", "output": "3" }, { "input": "3 100 100 1", "output": "3" }, { "input": "3 100000 10000 1", "output": "3" }, { "input": "7 10 2 3", "output": "5" }, { "input": "3 1000 1000 2", "output": "6" }, { "input": "1 100000 1 100000", "output": "100000" }, { "input": "7 4 3 1", "output": "3" }, { "input": "3 1000 1000 3", "output": "9" }, { "input": "3 1000 1 1", "output": "2" }, { "input": "3 10 1 1", "output": "2" }, { "input": "3 100000 1 1", "output": "2" }, { "input": "3 100 1 1", "output": "2" }, { "input": "3 100000 100000 1", "output": "3" }, { "input": "3 1000 1 100", "output": "101" }, { "input": "3 1000000000 1 1000000000", "output": "1000000000" }, { "input": "3 1000 1 10", "output": "11" }, { "input": "3 200 1 100", "output": "101" }, { "input": "7 4 1 1", "output": "2" }, { "input": "7 4 12 1", "output": "3" }, { "input": "3 9 1 1", "output": "2" }, { "input": "3 10000000 1000000 1", "output": "3" }, { "input": "7 1000 1000 1", "output": "3" }, { "input": "3 10000 1 30", "output": "31" }, { "input": "3 1000 1 2", "output": "3" }, { "input": "7 12 6 1", "output": "3" }, { "input": "3 100000 1 1000", "output": "1001" }, { "input": "7 1000 1000 3", "output": "9" }, { "input": "3 4 3 1", "output": "3" }, { "input": "3 3000000 1 100000", "output": "100001" }, { "input": "3 3 1 1", "output": "2" }, { "input": "3 10 1 5", "output": "6" }, { "input": "3 2000 2000 1", "output": "3" }, { "input": "3 10000000 10000000 1", "output": "3" }, { "input": "3 5 1 1", "output": "2" }, { "input": "3 100 1 33", "output": "34" }, { "input": "7 9 2 7", "output": "9" }, { "input": "4448 2 3 6", "output": "0" }, { "input": "2228 1 6 3", "output": "0" } ]
1,505,350,272
2,147,483,647
Python 3
OK
TESTS
89
77
0
##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) [n, a, b, c] = list(map(int, input().split())) res = 1e12 for i in range(0, 12): for j in range(0, 6): for k in range(0, 4): x = n+i+2*j+3*k if x%4 == 0: res = min(res, i*a+j*b+k*c) print(res)
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input Specification: The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). Output Specification: Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Demo Input: ['1 1 3 4\n', '6 2 1 1\n', '4 4 4 4\n', '999999999 1000000000 1000000000 1000000000\n'] Demo Output: ['3\n', '1\n', '0\n', '1000000000\n'] Note: In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
```python ##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) [n, a, b, c] = list(map(int, input().split())) res = 1e12 for i in range(0, 12): for j in range(0, 6): for k in range(0, 4): x = n+i+2*j+3*k if x%4 == 0: res = min(res, i*a+j*b+k*c) print(res) ```
3
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "output": "11 9 8 2 2 1 5 5 0 0 1" }, { "input": "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "output": "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11" }, { "input": "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "output": "1 1 2 2 3 3 4 4 5" }, { "input": "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "output": "1" }, { "input": "5 1\n1 3 3 3 5\n3", "output": "4" }, { "input": "4 5\n1 1 1 4\n1 5 5 4 3", "output": "3 4 4 4 3" }, { "input": "5 4\n0 5 5 5 6\n5 1 6 3", "output": "4 1 5 1" }, { "input": "1 3\n0\n-1 0 1", "output": "0 1 1" }, { "input": "96 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1", "output": "96" }, { "input": "7 1\n1 2 3 4 5 6 7\n1", "output": "1" }, { "input": "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "output": "7 13 7 13 7 13 7 13 7 13 7 13 7" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "output": "1 2 3 4 5" }, { "input": "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "output": "3 3 3 3 3 3 3 3" }, { "input": "1 1\n-11111\n-5938", "output": "1" }, { "input": "1 1\n1\n400000009", "output": "1" }, { "input": "1 1\n1\n300000009", "output": "1" }, { "input": "1 1\n1\n200000009", "output": "1" }, { "input": "1 1\n1\n200000003", "output": "1" } ]
1,683,310,109
2,147,483,647
Python 3
OK
TESTS
60
686
49,152,000
from bisect import bisect_right input() l = sorted(map(int, input().split())) m = list(map(int, input().split())) d = {x:bisect_right(l, x) for x in set(m)} print(*[d[x] for x in m])
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. Input Specification: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). Output Specification: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Demo Input: ['5 4\n1 3 5 7 9\n6 4 2 8\n', '5 5\n1 2 1 2 5\n3 1 4 1 5\n'] Demo Output: ['3 2 1 4\n', '4 2 4 2 5\n'] Note: none
```python from bisect import bisect_right input() l = sorted(map(int, input().split())) m = list(map(int, input().split())) d = {x:bisect_right(l, x) for x in set(m)} print(*[d[x] for x in m]) ```
3
688
A
Opponents
PROGRAMMING
800
[ "implementation" ]
null
null
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya. For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents. Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively. The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day.
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.
[ "2 2\n10\n00\n", "4 1\n0100\n", "4 5\n1101\n1111\n0110\n1011\n1111\n" ]
[ "2\n", "1\n", "2\n" ]
In the first and the second samples, Arya will beat all present opponents each of the *d* days. In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
500
[ { "input": "2 2\n10\n00", "output": "2" }, { "input": "4 1\n0100", "output": "1" }, { "input": "4 5\n1101\n1111\n0110\n1011\n1111", "output": "2" }, { "input": "3 2\n110\n110", "output": "2" }, { "input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111", "output": "1" }, { "input": "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111", "output": "1" }, { "input": "10 10\n0000100011\n0100001111\n1111111111\n1100011111\n1111111111\n1000111000\n1111000010\n0111001001\n1101010110\n1111111111", "output": "4" }, { "input": "10 10\n1100110010\n0000000001\n1011100111\n1111111111\n1111111111\n1111111111\n1100010110\n1111111111\n1001001010\n1111111111", "output": "3" }, { "input": "10 7\n0000111001\n1111111111\n0110110001\n1111111111\n1111111111\n1000111100\n0110000111", "output": "2" }, { "input": "5 10\n00110\n11000\n10010\n00010\n11110\n01101\n11111\n10001\n11111\n01001", "output": "6" }, { "input": "5 9\n11111\n11101\n11111\n11111\n01010\n01010\n00000\n11111\n00111", "output": "3" }, { "input": "5 10\n11111\n00010\n11010\n11111\n11111\n00100\n11111\n11111\n01000\n11111", "output": "2" }, { "input": "5 9\n11111\n11111\n11111\n11111\n11100\n11111\n11111\n11111\n00000", "output": "1" }, { "input": "5 8\n11111\n10110\n01001\n11111\n01100\n10010\n11111\n11111", "output": "2" }, { "input": "1 1\n1", "output": "0" }, { "input": "100 1\n0011001100100010000011001100000001011101110110010001110001101100110011111101001011011001000010001111", "output": "1" }, { "input": "100 1\n1011011100000101000111110000110111010101110010010011110010001110100011001110110101111100100110000000", "output": "1" }, { "input": "100 1\n1110000011110101010111111100011001100000101101010110100101110000011100110110110101011100110110010011", "output": "1" }, { "input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "0" }, { "input": "1 100\n1\n0\n0\n0\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n0\n0", "output": "6" }, { "input": "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "49" }, { "input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "0" }, { "input": "1 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "100" }, { "input": "2 2\n11\n10", "output": "1" }, { "input": "1 1\n0", "output": "1" } ]
1,626,949,183
2,147,483,647
PyPy 3
OK
TESTS
56
124
20,172,800
n,d=map(int,input().split()) ar=[ ] c=0 m=0 for i in range(0,d): ar.append(input()) for i in ar: if ('0' in i): c+=1 m=max(c,m) else: c=0 print(m)
Title: Opponents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya. For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents. Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents. Input Specification: The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively. The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day. Output Specification: Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. Demo Input: ['2 2\n10\n00\n', '4 1\n0100\n', '4 5\n1101\n1111\n0110\n1011\n1111\n'] Demo Output: ['2\n', '1\n', '2\n'] Note: In the first and the second samples, Arya will beat all present opponents each of the *d* days. In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
```python n,d=map(int,input().split()) ar=[ ] c=0 m=0 for i in range(0,d): ar.append(input()) for i in ar: if ('0' in i): c+=1 m=max(c,m) else: c=0 print(m) ```
3
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "7" }, { "input": "1000000000000 500000000001", "output": "2" }, { "input": "999999999997 499999999999", "output": "999999999997" }, { "input": "999999999999 999999999999", "output": "999999999998" }, { "input": "1000000000000 1", "output": "1" }, { "input": "999999999999 1", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000 1000000000000", "output": "1000000000000" }, { "input": "1000000000000 500000000000", "output": "999999999999" }, { "input": "1000000000000 499999999999", "output": "999999999997" }, { "input": "999999999997 499999999998", "output": "999999999995" }, { "input": "619234238 556154835", "output": "493075432" }, { "input": "38151981 36650624", "output": "35149266" }, { "input": "680402465 442571217", "output": "204739968" }, { "input": "109135284 9408714", "output": "18817427" }, { "input": "603701841 56038951", "output": "112077901" }, { "input": "356764822 321510177", "output": "286255532" }, { "input": "284911189 142190783", "output": "284381565" }, { "input": "91028405 61435545", "output": "31842684" } ]
1,696,514,731
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
112,128,000
a, b = map(int, input().split()) lst = [] lst_2 = [] for i in range(a+1): if i % 2 != 0: lst += [i] elif i % 2 == 0 and i != 0: lst_2 += [i] print((lst+lst_2)[b-1])
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. Input Specification: The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the number that will stand at the position number *k* after Volodya's manipulations. Demo Input: ['10 3\n', '7 7\n'] Demo Output: ['5', '6'] Note: In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
```python a, b = map(int, input().split()) lst = [] lst_2 = [] for i in range(a+1): if i % 2 != 0: lst += [i] elif i % 2 == 0 and i != 0: lst_2 += [i] print((lst+lst_2)[b-1]) ```
0
574
A
Bear and Elections
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?
The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
[ "5\n5 1 11 2 8\n", "4\n1 8 8 8\n", "2\n7 6\n" ]
[ "4\n", "6\n", "0\n" ]
In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
500
[ { "input": "5\n5 1 11 2 8", "output": "4" }, { "input": "4\n1 8 8 8", "output": "6" }, { "input": "2\n7 6", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "10\n100 200 57 99 1 1000 200 200 200 500", "output": "451" }, { "input": "16\n7 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "932" }, { "input": "100\n47 64 68 61 68 66 69 61 69 65 69 63 62 60 68 65 64 65 65 62 63 68 60 70 63 63 65 67 70 69 68 69 61 65 63 60 60 65 61 60 70 66 66 65 62 60 65 68 61 62 67 64 66 65 67 68 60 69 70 63 65 62 64 65 67 67 69 68 66 69 70 67 65 70 60 66 70 67 67 64 69 69 66 68 60 64 62 62 68 69 67 69 60 70 69 68 62 63 68 66", "output": "23" }, { "input": "2\n96 97", "output": "1" }, { "input": "2\n1000 1000", "output": "1" }, { "input": "3\n999 1000 1000", "output": "2" }, { "input": "3\n1 2 3", "output": "2" }, { "input": "7\n10 940 926 990 946 980 985", "output": "817" }, { "input": "10\n5 3 4 5 5 2 1 8 4 1", "output": "2" }, { "input": "15\n17 15 17 16 13 17 13 16 14 14 17 17 13 15 17", "output": "1" }, { "input": "20\n90 5 62 9 50 7 14 43 44 44 56 13 71 22 43 35 52 60 73 54", "output": "0" }, { "input": "30\n27 85 49 7 77 38 4 68 23 28 81 100 40 9 78 38 1 60 60 49 98 44 45 92 46 39 98 24 37 39", "output": "58" }, { "input": "51\n90 47 100 12 21 96 2 68 84 60 2 9 33 8 45 13 59 50 100 93 22 97 4 81 51 2 3 78 19 16 25 63 52 34 79 32 34 87 7 42 96 93 30 33 33 43 69 8 63 58 57", "output": "8" }, { "input": "77\n1000 2 2 3 1 1 1 3 3 2 1 1 3 2 2 2 3 2 3 1 3 1 1 2 2 2 3 1 1 2 2 2 3 2 1 3 3 1 2 3 3 3 2 1 3 2 1 3 3 2 3 3 2 1 3 1 1 1 2 3 2 3 1 3 1 2 1 2 2 2 1 2 2 3 2 2 2", "output": "0" }, { "input": "91\n3 92 89 83 85 80 91 94 95 82 92 95 80 88 90 85 81 90 87 86 94 88 90 87 88 82 95 84 84 93 83 95 91 85 89 88 88 85 87 90 93 80 89 95 94 92 93 86 83 82 86 84 91 80 90 95 84 86 84 85 84 92 82 84 83 91 87 95 94 95 90 95 86 92 86 80 95 86 88 80 82 87 84 83 91 93 81 81 91 89 88", "output": "89" }, { "input": "100\n1 3 71 47 64 82 58 61 61 35 52 36 57 62 63 54 52 21 78 100 24 94 4 80 99 62 43 72 21 70 90 4 23 14 72 4 76 49 71 96 96 99 78 7 32 11 14 61 19 69 1 68 100 77 86 54 14 86 47 53 30 88 67 66 61 70 17 63 40 5 99 53 38 31 91 18 41 5 77 61 53 30 87 21 23 54 52 17 23 75 58 99 99 63 20 1 78 72 28 11", "output": "90" }, { "input": "100\n1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "99" }, { "input": "94\n3 100 100 99 99 99 100 99 99 99 99 99 100 99 100 100 99 100 99 99 100 99 100 99 100 100 100 99 100 99 100 99 100 99 99 99 100 99 99 99 99 99 100 99 100 100 99 100 99 99 99 99 100 99 100 99 99 99 100 100 99 100 100 99 99 100 100 100 99 100 99 99 99 99 99 100 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 99 100 100", "output": "97" }, { "input": "97\n99 99 98 98 100 98 99 99 98 100 100 100 99 99 100 99 99 98 99 99 98 98 98 100 100 99 98 99 100 98 99 98 98 100 98 99 100 98 98 99 98 98 99 98 100 99 99 99 99 98 98 98 100 99 100 100 99 99 100 99 99 98 98 98 100 100 98 100 100 99 98 99 100 98 98 98 98 99 99 98 98 99 100 100 98 98 99 98 99 100 98 99 100 98 99 99 100", "output": "2" }, { "input": "100\n100 55 70 81 73 51 6 75 45 85 33 61 98 63 11 59 1 8 14 28 78 74 44 80 7 69 7 5 90 73 43 78 64 64 43 92 59 70 80 19 33 39 31 70 38 85 24 23 86 79 98 56 92 63 92 4 36 8 79 74 2 81 54 13 69 44 49 63 17 76 78 99 42 36 47 71 19 90 9 58 83 53 27 2 35 51 65 59 90 51 74 87 84 48 98 44 84 100 84 93", "output": "1" }, { "input": "100\n100 637 498 246 615 901 724 673 793 33 282 908 477 185 185 969 34 859 90 70 107 492 227 918 919 131 620 182 802 703 779 184 403 891 448 499 628 553 905 392 70 396 8 575 66 908 992 496 792 174 667 355 836 610 855 377 244 827 836 808 667 354 800 114 746 556 75 894 162 367 99 718 394 273 833 776 151 433 315 470 759 12 552 613 85 793 775 649 225 86 296 624 557 201 209 595 697 527 282 168", "output": "749" }, { "input": "100\n107 172 549 883 564 56 399 970 173 990 224 217 601 381 948 631 159 958 512 136 61 584 633 202 652 355 26 723 663 237 410 721 688 552 699 24 748 186 461 88 34 243 872 205 471 298 654 693 244 33 359 533 471 116 386 653 654 887 531 303 335 829 319 340 827 89 602 191 422 289 361 200 593 421 592 402 256 813 606 589 741 9 148 893 3 142 50 169 219 360 642 45 810 818 507 624 561 743 303 111", "output": "729" }, { "input": "90\n670 694 651 729 579 539 568 551 707 638 604 544 502 531 775 805 558 655 506 729 802 778 653 737 591 770 594 535 588 604 658 713 779 705 504 563 513 651 529 572 505 553 515 750 621 574 727 774 714 725 665 798 670 747 751 635 755 798 635 717 583 682 517 546 740 802 743 507 658 700 645 671 533 594 506 633 768 584 672 666 703 522 530 501 592 528 678 708 619 786", "output": "111" }, { "input": "90\n10 265 429 431 343 305 806 746 284 313 503 221 594 351 83 653 232 431 427 610 458 88 255 215 529 205 492 549 55 694 535 104 45 327 816 432 595 549 454 141 216 557 250 415 531 494 190 749 718 380 78 447 784 347 196 814 16 780 262 462 776 315 160 307 593 694 692 41 528 725 376 777 337 44 438 630 345 502 384 184 742 429 570 361 394 267 820 778 662 377", "output": "714" }, { "input": "95\n800 280 176 472 587 763 588 838 760 378 667 231 566 278 713 305 354 815 140 220 188 409 109 180 251 268 474 590 853 143 235 691 313 785 386 92 783 471 43 342 718 592 678 404 256 362 239 504 163 85 521 81 356 73 754 589 380 159 196 862 838 509 149 42 366 630 467 292 698 123 187 796 576 37 689 800 186 518 488 432 159 860 349 799 282 304 880 283 23 312 55 507 734 370 490", "output": "52" }, { "input": "100\n95 88 84 85 74 97 100 52 91 94 62 66 90 56 86 66 95 73 79 68 54 67 99 52 82 62 81 71 93 85 72 72 95 52 72 63 57 90 92 89 88 77 84 78 95 59 72 86 98 64 89 64 80 70 54 93 88 86 79 78 94 64 89 66 50 90 54 82 52 96 99 54 81 66 83 79 69 80 51 73 81 69 93 82 76 52 58 87 93 92 52 67 78 63 63 87 77 95 58 78", "output": "4" }, { "input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "1" }, { "input": "100\n999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "2" }, { "input": "100\n901 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "99" }, { "input": "4\n8 5 11 3", "output": "2" }, { "input": "3\n3 10 1", "output": "4" } ]
1,531,678,293
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
0
n = int(input()) a = list(map(int,input().strip().split())) b = a[0] c = sorted(a[1:],reverse=True) e=0 if b > c[0]: print("0") else: if len(c)>1: e += (c[0]-b)+(c[0]-c[1])-b print(abs(e)) else: e += (c[0]-b)-b print(abs(e))
Title: Bear and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. Output Specification: Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Demo Input: ['5\n5 1 11 2 8\n', '4\n1 8 8 8\n', '2\n7 6\n'] Demo Output: ['4\n', '6\n', '0\n'] Note: In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8. In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6. In the third sample Limak is a winner without bribing any citizen.
```python n = int(input()) a = list(map(int,input().strip().split())) b = a[0] c = sorted(a[1:],reverse=True) e=0 if b > c[0]: print("0") else: if len(c)>1: e += (c[0]-b)+(c[0]-c[1])-b print(abs(e)) else: e += (c[0]-b)-b print(abs(e)) ```
0
384
A
Coder
PROGRAMMING
800
[ "implementation" ]
null
null
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
[ "2\n" ]
[ "2\nC.\n.C\n" ]
none
500
[ { "input": "2", "output": "2\nC.\n.C" }, { "input": "3", "output": "5\nC.C\n.C.\nC.C" }, { "input": "4", "output": "8\nC.C.\n.C.C\nC.C.\n.C.C" }, { "input": "10", "output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C" }, { "input": "15", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C" }, { "input": "100", "output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "101", "output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "500", "output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...." }, { "input": "501", "output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..." }, { "input": "755", "output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "888", "output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "998", "output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "999", "output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1000", "output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1", "output": "1\nC" } ]
1,423,462,752
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) if n%2 == 0: res = (n*(n//2)) else: res = (n*(n//2) + (n//2) + 1) print (res) turn = 0 for i in range(n): if n%2 == 0: turn = 1-turn for j in range(n): if turn == 1: print ("C", end="") turn = 0 else: print (".", end="") turn = 1 print ()
Title: Coder Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. Demo Input: ['2\n'] Demo Output: ['2\nC.\n.C\n'] Note: none
```python n = int(input()) if n%2 == 0: res = (n*(n//2)) else: res = (n*(n//2) + (n//2) + 1) print (res) turn = 0 for i in range(n): if n%2 == 0: turn = 1-turn for j in range(n): if turn == 1: print ("C", end="") turn = 0 else: print (".", end="") turn = 1 print () ```
0
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,615,438,549
2,147,483,647
Python 3
OK
TESTS
43
109
0
s = input() n = len(s) i=0 cnt = 0 while i < n: j = i + 1 i += 1 while j < n: k = j + 1 j += 1 while k < n: if s[i-1] == 'Q' and s[j-1] == 'A' and s[k] == 'Q': cnt += 1 k += 1 print(cnt)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. Input Specification: The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. Output Specification: Print a single integer — the number of subsequences "QAQ" in the string. Demo Input: ['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n'] Demo Output: ['4\n', '3\n'] Note: In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
```python s = input() n = len(s) i=0 cnt = 0 while i < n: j = i + 1 i += 1 while j < n: k = j + 1 j += 1 while k < n: if s[i-1] == 'Q' and s[j-1] == 'A' and s[k] == 'Q': cnt += 1 k += 1 print(cnt) ```
3
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,622,978,223
423
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; #define debug(T) { cout << ">> " << #T << " = " << (T) << endl; } #define println() { cout << endl; } #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define sz(c) int((c).size()) typedef long long ll; typedef unsigned long long ull; template<typename T> void read(vector<T>& v); template<typename T> void read(T* arr, int n); template<typename T> void print(const vector<T>& v); template<typename T> void print(T* arr, int n); template<typename T> void print(const T& c); template<typename T> inline T ceil(T x, T y); const ll MOD = 1'000'000'007; void precalc() {} void solve() { int n, m; cin >> n >> m; int p = 0, t = 1; while (t <= m) { ++p; t <<= 1; } n = min(p, n); int ans = m % (1<<n); cout << ans << "\n"; } int main() { // for fast I/O ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // redirect I/O // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int T = 1; // cin >> T; // precalc(); for (int tc = 1; tc <= T; ++tc) { solve(); // println(); } // cout << "All OK!" << endl; return 0; } template<typename T> void read(vector<T>& v) { for (auto &it : v) cin >> it; } template<typename T> void read(T* arr, int n) { for (int i = 0; i < n; ++i) cin >> arr[i]; } template<typename T> void print(const vector<T>& v) { for (auto &it : v) cout << it << " "; cout << "\n"; } template<typename T> void print(T* arr, int n) { for (int i = 0; i < n; ++i) { cout << arr[i] << " "; } cout << "\n"; } template<typename T> void print(const T& c) { for (auto& it : c) cout << it << " "; cout << "\n"; } template<typename T> inline T ceil(T x, T y) { return (x + y - 1) / y; }
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 #include <bits/stdc++.h> using namespace std; #define debug(T) { cout << ">> " << #T << " = " << (T) << endl; } #define println() { cout << endl; } #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define sz(c) int((c).size()) typedef long long ll; typedef unsigned long long ull; template<typename T> void read(vector<T>& v); template<typename T> void read(T* arr, int n); template<typename T> void print(const vector<T>& v); template<typename T> void print(T* arr, int n); template<typename T> void print(const T& c); template<typename T> inline T ceil(T x, T y); const ll MOD = 1'000'000'007; void precalc() {} void solve() { int n, m; cin >> n >> m; int p = 0, t = 1; while (t <= m) { ++p; t <<= 1; } n = min(p, n); int ans = m % (1<<n); cout << ans << "\n"; } int main() { // for fast I/O ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // redirect I/O // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int T = 1; // cin >> T; // precalc(); for (int tc = 1; tc <= T; ++tc) { solve(); // println(); } // cout << "All OK!" << endl; return 0; } template<typename T> void read(vector<T>& v) { for (auto &it : v) cin >> it; } template<typename T> void read(T* arr, int n) { for (int i = 0; i < n; ++i) cin >> arr[i]; } template<typename T> void print(const vector<T>& v) { for (auto &it : v) cout << it << " "; cout << "\n"; } template<typename T> void print(T* arr, int n) { for (int i = 0; i < n; ++i) { cout << arr[i] << " "; } cout << "\n"; } template<typename T> void print(const T& c) { for (auto& it : c) cout << it << " "; cout << "\n"; } template<typename T> inline T ceil(T x, T y) { return (x + y - 1) / y; } ```
-1
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,698,323,466
2,147,483,647
PyPy 3-64
OK
TESTS
18
154
0
n,m = list(map(int,input().split(' '))) l = list(map(int,input().split())) l.sort() ds = [] for i in range(m+1-n): ds.append(l[i+n-1]-l[i]) print(min(ds))
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python n,m = list(map(int,input().split(' '))) l = list(map(int,input().split())) l.sort() ds = [] for i in range(m+1-n): ds.append(l[i+n-1]-l[i]) print(min(ds)) ```
3
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,575,548,447
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
202
2,355,200
import sys sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n=int(input()) s=input() c=0 for i in range(n-1): if s[i]=='S' and s[i+1]=='F': c+=1 if s[i]=='F' and s[i+1]=='S': c-=1 if c>0: print("YES") else: 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 import sys sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') n=int(input()) s=input() c=0 for i in range(n-1): if s[i]=='S' and s[i+1]=='F': c+=1 if s[i]=='F' and s[i+1]=='S': c-=1 if c>0: print("YES") else: print("NO") ```
-1
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "25 9712", "output": "11" }, { "input": "9 7601", "output": "5" }, { "input": "1 9058", "output": "0" }, { "input": "29 7772", "output": "26" }, { "input": "45 9465", "output": "14" }, { "input": "46 866", "output": "5" }, { "input": "29 1241", "output": "20" }, { "input": "17 4248", "output": "12" }, { "input": "20 8082", "output": "11" }, { "input": "50 9555", "output": "0" }, { "input": "4 7455", "output": "2" }, { "input": "36 880", "output": "4" }, { "input": "24 7440", "output": "9" }, { "input": "44 7888", "output": "12" }, { "input": "1 1", "output": "0" }, { "input": "50 10000", "output": "40" }, { "input": "1 10000", "output": "0" }, { "input": "50 1", "output": "0" }, { "input": "50 50", "output": "5" } ]
1,618,643,378
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
import sys def get_single_int (): return int (sys.stdin.readline ().strip ()) def get_string (): return sys.stdin.readline ().strip () def get_ints (): return map (int, sys.stdin.readline ().strip ().split ()) def get_list (): return list (map (int, sys.stdin.readline ().strip ().split ())) #code starts here n, m = get_ints () rem = (m % (n*(n + 1)//2)) for i in range (1, n + 1): if rem - i <= 0: print (rem) break rem -= i
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. Output Specification: Print the number of chips the presenter ended up with. Demo Input: ['4 11\n', '17 107\n', '3 8\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
```python import sys def get_single_int (): return int (sys.stdin.readline ().strip ()) def get_string (): return sys.stdin.readline ().strip () def get_ints (): return map (int, sys.stdin.readline ().strip ().split ()) def get_list (): return list (map (int, sys.stdin.readline ().strip ().split ())) #code starts here n, m = get_ints () rem = (m % (n*(n + 1)//2)) for i in range (1, n + 1): if rem - i <= 0: print (rem) break rem -= i ```
0
496
C
Removing Columns
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table   we obtain the table:   A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
The first line contains two integers  — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* small English letters each — the characters of the table.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
[ "1 10\ncodeforces\n", "4 4\ncase\ncare\ntest\ncode\n", "5 4\ncode\nforc\nesco\ndefo\nrces\n" ]
[ "0\n", "2\n", "4\n" ]
In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings *s* and *t* have equal length. Then, *s* is lexicographically larger than *t* if they are not equal and the character following the largest common prefix of *s* and *t* (the prefix may be empty) in *s* is alphabetically larger than the corresponding character of *t*.
1,750
[ { "input": "1 10\ncodeforces", "output": "0" }, { "input": "4 4\ncase\ncare\ntest\ncode", "output": "2" }, { "input": "5 4\ncode\nforc\nesco\ndefo\nrces", "output": "4" }, { "input": "2 2\nfb\nye", "output": "0" }, { "input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrzh", "output": "0" }, { "input": "10 10\nddorannorz\nmdrnzqvqgo\ngdtdjmlsuf\neoxbrntqdp\nhribwlslgo\newlqrontvk\nnxibmnawnh\nvxiwdjvdom\nhyhhewmzmp\niysgvzayst", "output": "1" }, { "input": "9 7\nygqartj\nlgwxlqv\nancjjpr\nwnnhkpx\ncnnhvty\nxsfrbqp\nxsolyne\nbsoojiq\nxstetjb", "output": "1" }, { "input": "4 50\nulkteempxafxafcvfwmwhsixwzgbmubcqqceevbbwijeerqbsj\neyqxsievaratndjoekltlqwppfgcukjwxdxexhejbfhzklppkk\npskatxpbjdbmjpwhussetytneohgzxgirluwnbraxtxmaupuid\neappatavdzktqlrjqttmwwroathnulubpjgsjazcycecwmxwvn", "output": "20" }, { "input": "5 50\nvlrkwhvbigkhihwqjpvmohdsszvndheqlmdsspkkxxiedobizr\nmhnzwdefqmttclfxocdmvvtdjtvqhmdllrtrrlnewuqowmtrmp\nrihlhxrqfhpcddslxepesvjqmlqgwyehvxjcsytevujfegeewh\nqrdyiymanvbdjomyruspreihahjhgkcixwowfzczundxqydldq\nkgnrbjlrmkuoiuzeiqwhnyjpuzfnsinqiamlnuzksrdnlvaxjd", "output": "50" }, { "input": "100 1\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\ni\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nv\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx", "output": "0" }, { "input": "1 100\nteloaetuldspjqdlcktjlishwynmjjhlomvemhoyyplbltfwmrlnazbbjvyvwvoxjvvoadkznvxqubgwesoxrznvbdizjdzixecb", "output": "0" }, { "input": "4 100\ngdgmmejiigzsmlarrnfsypvlbutvoxazcigpcospgztqkowfhhbnnbxxrbmwbxwkvxlxzabjjjdtbebedukdelooqlxnadjwjpnp\ndmtsnsbsfdzqvydxcdcnkkfcbseicxhvclsligbhqlkccwujpirymoshkqcosbtlxdypsdqkqaolrqtiibymavcwmbfryttdckhw\njtdmpdljcpciuuoznvqqmafvoqychzfslmwqouuarxctunlzegxsucrwontjplkkxhgixgdbvnewphnatxnwqxqshcexpxlyjuwq\nvhdtvexkyhjmahejbhyfeaompjkdvxmbtdbmvrxrixhnkkjgyvfbxlviatbikfejnqhkrtafftmsgyznpsfxsnzaqdzhxridzilo", "output": "4" }, { "input": "5 2\nab\ndc\ngd\ngc\nhx", "output": "1" }, { "input": "2 1\nb\na", "output": "1" }, { "input": "4 3\nabd\nacc\nbdx\nbcy", "output": "2" }, { "input": "4 2\nad\nac\nbd\nbc", "output": "1" }, { "input": "3 3\naac\nabb\nbba", "output": "0" }, { "input": "3 3\nadc\nbdb\ncda", "output": "0" }, { "input": "4 3\nabz\ndby\ngbx\nhbw", "output": "0" }, { "input": "3 3\naac\nbab\ncaa", "output": "0" }, { "input": "5 6\naaaeaa\nababab\nacacac\nadadad\naeaeae", "output": "0" }, { "input": "3 2\naa\nbc\nba", "output": "1" }, { "input": "3 3\naaz\ndaa\nbaa", "output": "2" }, { "input": "3 3\nabc\nbbb\ncba", "output": "0" }, { "input": "2 3\naxc\nbxa", "output": "0" } ]
1,636,238,423
2,147,483,647
PyPy 3-64
OK
TESTS
49
93
30,617,600
n, m = map(int, input().split()) ans = 0 s = ['']*n ls = [input() for i in range(n)] for j in range(m): chk=0 for i in range(n-1): if(s[i]+ls[i][j] > s[i+1]+ls[i+1][j]): ans += 1 break chk+=1 if chk==n-1: for k in range(n): s[k]+=ls[k][j] print(ans)
Title: Removing Columns Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table   we obtain the table:   A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input Specification: The first line contains two integers  — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* small English letters each — the characters of the table. Output Specification: Print a single number — the minimum number of columns that you need to remove in order to make the table good. Demo Input: ['1 10\ncodeforces\n', '4 4\ncase\ncare\ntest\ncode\n', '5 4\ncode\nforc\nesco\ndefo\nrces\n'] Demo Output: ['0\n', '2\n', '4\n'] Note: In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings *s* and *t* have equal length. Then, *s* is lexicographically larger than *t* if they are not equal and the character following the largest common prefix of *s* and *t* (the prefix may be empty) in *s* is alphabetically larger than the corresponding character of *t*.
```python n, m = map(int, input().split()) ans = 0 s = ['']*n ls = [input() for i in range(n)] for j in range(m): chk=0 for i in range(n-1): if(s[i]+ls[i][j] > s[i+1]+ls[i+1][j]): ans += 1 break chk+=1 if chk==n-1: for k in range(n): s[k]+=ls[k][j] print(ans) ```
3
0
none
none
none
0
[ "none" ]
null
null
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis. Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct. Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task. Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7. Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct.
Print a single integer — the required sum modulo 109<=+<=7.
[ "2\n4 7\n", "3\n4 3 1\n" ]
[ "3\n", "9\n" ]
There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3. There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
0
[ { "input": "2\n4 7", "output": "3" }, { "input": "3\n4 3 1", "output": "9" }, { "input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95", "output": "83396599" }, { "input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73", "output": "68059140" }, { "input": "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97", "output": "92743989" }, { "input": "1\n78091781", "output": "0" }, { "input": "2\n1000000000 1", "output": "999999999" }, { "input": "3\n999999998 999999999 999999992", "output": "21" }, { "input": "3\n465343471 465343474 465343473", "output": "9" }, { "input": "10\n10 3 6 2 1 9 8 4 5 7", "output": "7181" }, { "input": "10\n756734546 756734524 756734550 756734529 756734553 756734538 756734541 756734536 756734579 756734537", "output": "36489" }, { "input": "10\n877105545 939360757 849826701 845946140 803128820 926787996 967305000 904694971 921301848 971203310", "output": "861364152" }, { "input": "5\n4 7 13 17 18", "output": "270" }, { "input": "5\n20 17 13 7 2", "output": "330" }, { "input": "5\n3 17 2 5 4", "output": "237" }, { "input": "5\n999999980 999999985 999999986 999999990 999999992", "output": "210" }, { "input": "5\n1000000000 999999988 999999982 999999981 999999980", "output": "342" }, { "input": "5\n999999984 999999997 999999994 999999991 999999982", "output": "285" }, { "input": "1\n2", "output": "0" }, { "input": "5\n9 10 7 4 5", "output": "114" } ]
1,495,339,519
2,147,483,647
PyPy 3
OK
TESTS
69
1,435
25,292,800
n = int(input()) a = list(map(int,input().split())) m = 1000000007 s = 0 a.sort() for i in range(n): s = (s + a[i]*(pow(2,i,m) - pow(2,n-1-i,m)))%m print(s)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis. Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to *n*. So the *i*-th hacked computer is located at the point *x**i*. Moreover the coordinates of all computers are distinct. Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task. Leha should calculate a sum of *F*(*a*) for all *a*, where *a* is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote *A* the set of all integers from 1 to *n*. Noora asks the hacker to find value of the expression . Here *F*(*a*) is calculated as the maximum among the distances between all pairs of computers from the set *a*. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109<=+<=7. Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct. Output Specification: Print a single integer — the required sum modulo 109<=+<=7. Demo Input: ['2\n4 7\n', '3\n4 3 1\n'] Demo Output: ['3\n', '9\n'] Note: There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c86b3e28ddb8aaca28a7cdd219a8c.png" style="max-width: 100.0%;max-height: 100.0%;"/> and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7d0f73b3e94e13cb797f39e93d9da74835c5a02d.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3. There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f368c407c8e85e2b5fedfffaff39d471d765f026.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bb8f2118a3ac352db393b1f067b28e398ce7f816.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/049032074c04b16bc0cc153f95471c40b222072b.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc93c7f5b3d122314c9c5a707fae556a8f72a574.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
```python n = int(input()) a = list(map(int,input().split())) m = 1000000007 s = 0 a.sort() for i in range(n): s = (s + a[i]*(pow(2,i,m) - pow(2,n-1-i,m)))%m print(s) ```
3
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,670,251,067
2,147,483,647
Python 3
OK
TESTS
35
46
0
n,k = map(int,input().split()) q = list (map(int,input().split())) cnt=0 for x in range (len(q)): if q[x] <=5-k: cnt+=1 print (cnt//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python n,k = map(int,input().split()) q = list (map(int,input().split())) cnt=0 for x in range (len(q)): if q[x] <=5-k: cnt+=1 print (cnt//3) ```
3
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,689,846,013
2,147,483,647
Python 3
OK
TESTS
71
92
0
s = input() a = [x for x in s.split("WUB")] ans = '' for x in a : if x != '' : ans =ans + x +" " ; print(ans)
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python s = input() a = [x for x in s.split("WUB")] ans = '' for x in a : if x != '' : ans =ans + x +" " ; print(ans) ```
3
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 6" }, { "input": "5\n1 1 1 1 1", "output": "0 10" }, { "input": "5\n2 2 2 2 2", "output": "0 10" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0 45" }, { "input": "3\n2 2 2", "output": "0 3" }, { "input": "3\n3 3 3", "output": "0 3" }, { "input": "2\n10000000 100000000", "output": "90000000 1" }, { "input": "5\n5 5 5 5 5", "output": "0 10" }, { "input": "5\n3 3 3 3 3", "output": "0 10" }, { "input": "6\n1 1 1 1 1 1", "output": "0 15" }, { "input": "2\n5 6", "output": "1 1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0 45" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0 45" }, { "input": "4\n4 4 4 4", "output": "0 6" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0 21" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "0 55" }, { "input": "8\n8 8 8 8 8 8 8 8", "output": "0 28" }, { "input": "2\n3 2", "output": "1 1" } ]
1,665,477,829
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
t=int(input()) l=list(map(int,input().split())) maxa=max(l) mini=min(l) a=l.count(maxa) b=l.count(mini) ans=0 if maxa==1 and mini==1: ans=1 elif (maxa-mini)==0: ans=maxa(maxa-1)//2 else: ans=a*b print((maxa-mini),ans) print(a)
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). Output Specification: The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. Demo Input: ['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n'] Demo Output: ['1 1', '4 1', '2 4'] Note: In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
```python t=int(input()) l=list(map(int,input().split())) maxa=max(l) mini=min(l) a=l.count(maxa) b=l.count(mini) ans=0 if maxa==1 and mini==1: ans=1 elif (maxa-mini)==0: ans=maxa(maxa-1)//2 else: ans=a*b print((maxa-mini),ans) print(a) ```
0
515
A
Drazil and Date
PROGRAMMING
1,000
[ "math" ]
null
null
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes".
[ "5 5 11\n", "10 15 25\n", "0 5 1\n", "0 0 2\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "5 5 11", "output": "No" }, { "input": "10 15 25", "output": "Yes" }, { "input": "0 5 1", "output": "No" }, { "input": "0 0 2", "output": "Yes" }, { "input": "999999999 999999999 2000000000", "output": "Yes" }, { "input": "-606037695 998320124 820674098", "output": "No" }, { "input": "948253616 -83299062 1031552680", "output": "Yes" }, { "input": "711980199 216568284 928548487", "output": "Yes" }, { "input": "-453961301 271150176 725111473", "output": "No" }, { "input": "0 0 2000000000", "output": "Yes" }, { "input": "0 0 1999999999", "output": "No" }, { "input": "1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 2000000000", "output": "Yes" }, { "input": "-1000000000 -1000000000 1000000000", "output": "No" }, { "input": "-1 -1 3", "output": "No" }, { "input": "919785634 216774719 129321944", "output": "No" }, { "input": "-467780354 -721273539 1369030008", "output": "No" }, { "input": "-232833910 -880680184 1774549792", "output": "Yes" }, { "input": "45535578 402686155 1011249824", "output": "No" }, { "input": "-203250176 -30379840 233630015", "output": "No" }, { "input": "-814516648 -75830576 890347222", "output": "No" }, { "input": "869184175 -511854751 1381038923", "output": "No" }, { "input": "552884998 -262338193 815223187", "output": "No" }, { "input": "-133874494 857573117 991447611", "output": "Yes" }, { "input": "169406792 786701289 956108082", "output": "No" }, { "input": "30237137 -989203246 1019440385", "output": "Yes" }, { "input": "576608216 -617624133 1194232352", "output": "No" }, { "input": "-662360368 97618995 759979367", "output": "Yes" }, { "input": "-115989290 321714461 437703756", "output": "No" }, { "input": "-1 -3 2", "output": "No" }, { "input": "-2 -2 2", "output": "No" }, { "input": "0 0 1", "output": "No" }, { "input": "0 -1 7", "output": "Yes" }, { "input": "1 2 7", "output": "Yes" }, { "input": "0 5 6", "output": "No" }, { "input": "0 -4 2", "output": "No" }, { "input": "-5 5 2", "output": "No" }, { "input": "-5 -2 7", "output": "Yes" }, { "input": "5 -5 2", "output": "No" } ]
1,595,778,380
2,147,483,647
Python 3
OK
TESTS
40
108
6,656,000
a, b, s = map(int, input().split()) if s < abs(a) + abs(b): print('NO') elif s == a + b: print('YES') else: if s % 2 == (abs(a)+abs(b)) % 2: print('YES') else: print('NO')
Title: Drazil and Date Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? Input Specification: You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. Output Specification: If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes". Demo Input: ['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n'] Demo Output: ['No\n', 'Yes\n', 'No\n', 'Yes\n'] Note: In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python a, b, s = map(int, input().split()) if s < abs(a) + abs(b): print('NO') elif s == a + b: print('YES') else: if s % 2 == (abs(a)+abs(b)) % 2: print('YES') else: print('NO') ```
3
630
C
Lucky Numbers
PROGRAMMING
1,100
[ "combinatorics", "math" ]
null
null
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits.
The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold.
Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits.
[ "2\n" ]
[ "6" ]
none
0
[ { "input": "2", "output": "6" }, { "input": "1", "output": "2" }, { "input": "3", "output": "14" }, { "input": "5", "output": "62" }, { "input": "12", "output": "8190" }, { "input": "34", "output": "34359738366" }, { "input": "43", "output": "17592186044414" }, { "input": "49", "output": "1125899906842622" }, { "input": "54", "output": "36028797018963966" }, { "input": "55", "output": "72057594037927934" } ]
1,693,749,652
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n = int(input()) result = 2 ** n print(result)
Title: Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. Input Specification: The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. Output Specification: Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. Demo Input: ['2\n'] Demo Output: ['6'] Note: none
```python n = int(input()) result = 2 ** n print(result) ```
0
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", "output": "21223442" }, { "input": "91730629", "output": "91230320" }, { "input": "420062703497", "output": "420032203402" }, { "input": "332711047202", "output": "332211042202" }, { "input": "3395184971407775", "output": "3304114021402224" }, { "input": "8464062628894325", "output": "1434032321104324" }, { "input": "164324828731963982", "output": "134324121231033012" }, { "input": "384979173822804784", "output": "314020123122104214" }, { "input": "41312150450968417", "output": "41312140440031412" }, { "input": "2156", "output": "2143" }, { "input": "1932", "output": "1032" }, { "input": "5902", "output": "4002" }, { "input": "5728", "output": "4221" }, { "input": "8537", "output": "1432" }, { "input": "55403857", "output": "44403142" }, { "input": "270739", "output": "220230" }, { "input": "28746918", "output": "21243011" }, { "input": "10279211", "output": "10220211" }, { "input": "40289679", "output": "40210320" }, { "input": "545203238506", "output": "444203231403" }, { "input": "461117063340", "output": "431112033340" }, { "input": "658492686568", "output": "341402313431" }, { "input": "857373361868", "output": "142323331131" }, { "input": "429325660016", "output": "420324330013" }, { "input": "9894448650287940", "output": "9104441340212040" }, { "input": "6354510839296263", "output": "3344410130203233" }, { "input": "6873575462224593", "output": "3123424432224403" }, { "input": "4237951492601449", "output": "4232041402301440" }, { "input": "2680352384836991", "output": "2310342314133001" }, { "input": "606187734191890310", "output": "303112234101100310" }, { "input": "351499943576823355", "output": "341400043423123344" }, { "input": "180593481782177068", "output": "110403411212122031" }, { "input": "999999999999999999", "output": "900000000000000000" }, { "input": "1000000000000000000", "output": "1000000000000000000" }, { "input": "9999", "output": "9000" }, { "input": "99", "output": "90" }, { "input": "9991", "output": "9001" } ]
1,691,831,689
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
x=input() for i in range (len(x)): d=int(x[i]) c=9-d if c==0: continue if c<d: print(c,end="") else: print(x[i],end="")
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. Input Specification: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. Output Specification: Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. Demo Input: ['27\n', '4545\n'] Demo Output: ['22\n', '4444\n'] Note: none
```python x=input() for i in range (len(x)): d=int(x[i]) c=9-d if c==0: continue if c<d: print(c,end="") else: print(x[i],end="") ```
0
801
B
Valued Keys
PROGRAMMING
900
[ "constructive algorithms", "greedy", "strings" ]
null
null
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
[ "ab\naa\n", "nzwzl\nniwel\n", "ab\nba\n" ]
[ "ba\n", "xiyez\n", "-1\n" ]
The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
1,000
[ { "input": "ab\naa", "output": "ba" }, { "input": "nzwzl\nniwel", "output": "xiyez" }, { "input": "ab\nba", "output": "-1" }, { "input": "r\nl", "output": "l" }, { "input": "d\ny", "output": "-1" }, { "input": "yvowz\ncajav", "output": "cajav" }, { "input": "lwzjp\ninjit", "output": "-1" }, { "input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "output": "eodnlemiicdedmkcgavqbnqmm" }, { "input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "output": "-1" }, { "input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf" }, { "input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen", "output": "-1" }, { "input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb" }, { "input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym", "output": "-1" }, { "input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib" }, { "input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew", "output": "-1" }, { "input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv" }, { "input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns", "output": "-1" }, { "input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf" }, { "input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp", "output": "-1" }, { "input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp" }, { "input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej", "output": "-1" }, { "input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe" }, { "input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang", "output": "-1" }, { "input": "ftfr\nftfr", "output": "ftfr" }, { "input": "ftr\nftr", "output": "ftr" }, { "input": "shftr\nshftr", "output": "shftr" }, { "input": "vkvkkv\nvkvkkv", "output": "vkvkkv" }, { "input": "ftrd\nftrd", "output": "ftrd" }, { "input": "fztr\nfztr", "output": "fztr" }, { "input": "frtr\nfrtr", "output": "frtr" }, { "input": "shdftr\nshdftr", "output": "shdftr" }, { "input": "zzz\nzzz", "output": "zzz" }, { "input": "shtr\nshtr", "output": "shtr" }, { "input": "aaaaa\nzzzzz", "output": "-1" }, { "input": "efr\nefr", "output": "efr" } ]
1,683,696,216
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
x = input() y = input() z = "" for i in range(len(x)): if x[i] > y[i]: z += x[i] elif x[i] < y[i]: z += y[i] else: z += x[i] if x[i] != 'a' else 'b' if f(x, z) == y: print(z) else: print("-1")
Title: Valued Keys Time Limit: None seconds Memory Limit: None megabytes Problem Description: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. Input Specification: The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. Output Specification: If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. Demo Input: ['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n'] Demo Output: ['ba\n', 'xiyez\n', '-1\n'] Note: The first case is from the statement. Another solution for the second case is "zizez" There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) =  "ba".
```python x = input() y = input() z = "" for i in range(len(x)): if x[i] > y[i]: z += x[i] elif x[i] < y[i]: z += y[i] else: z += x[i] if x[i] != 'a' else 'b' if f(x, z) == y: print(z) else: print("-1") ```
-1
384
A
Coder
PROGRAMMING
800
[ "implementation" ]
null
null
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.
[ "2\n" ]
[ "2\nC.\n.C\n" ]
none
500
[ { "input": "2", "output": "2\nC.\n.C" }, { "input": "3", "output": "5\nC.C\n.C.\nC.C" }, { "input": "4", "output": "8\nC.C.\n.C.C\nC.C.\n.C.C" }, { "input": "10", "output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C" }, { "input": "15", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C" }, { "input": "100", "output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "101", "output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "500", "output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...." }, { "input": "501", "output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..." }, { "input": "755", "output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "888", "output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "998", "output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "999", "output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1000", "output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..." }, { "input": "1", "output": "1\nC" } ]
1,645,187,484
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
2,969,600
t = int(input()) ans = 0 a = [['.' for _ in range(t+3)] for _ in range(t+3)] for i in range(1, t+1): for j in range(1, t+1): if not 'C' in [a[i][j-1], a[i][j+1], a[i-1][j], a[i+1][j]]: a[i][j] = 'C' ans += 1 print(ans) for i in range(1, t+1): for j in range(1, t+1): print(a[i][j], end='') print()
Title: Coder Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. Demo Input: ['2\n'] Demo Output: ['2\nC.\n.C\n'] Note: none
```python t = int(input()) ans = 0 a = [['.' for _ in range(t+3)] for _ in range(t+3)] for i in range(1, t+1): for j in range(1, t+1): if not 'C' in [a[i][j-1], a[i][j+1], a[i-1][j], a[i+1][j]]: a[i][j] = 'C' ans += 1 print(ans) for i in range(1, t+1): for j in range(1, t+1): print(a[i][j], end='') print() ```
0
0
none
none
none
0
[ "none" ]
null
null
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that *q*2<==<=*q*<=+<=1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression *a*0*a*1...*a**n* equals to . Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help. Given two numbers written in golden system notation, determine which of them has larger decimal value.
Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000.
Print "&gt;" if the first number is larger, "&lt;" if it is smaller and "=" if they are equal.
[ "1000\n111\n", "00100\n11\n", "110\n101\n" ]
[ "&lt;\n", "=\n", "&gt;\n" ]
In the first example first number equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9c955eec678d6e7dcdc7c94fb203e922d2ad19ad.png" style="max-width: 100.0%;max-height: 100.0%;"/>, while second number is approximately 1.618033988<sup class="upper-index">2</sup> + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number. In the second example numbers are equal. Each of them is  ≈ 2.618.
0
[ { "input": "1000\n111", "output": "<" }, { "input": "00100\n11", "output": "=" }, { "input": "110\n101", "output": ">" }, { "input": "0\n0", "output": "=" }, { "input": "1\n10", "output": "<" }, { "input": "11\n10", "output": ">" }, { "input": "00111\n10100", "output": "<" }, { "input": "00\n1", "output": "<" }, { "input": "01\n010", "output": "<" }, { "input": "111\n00", "output": ">" }, { "input": "1100\n11", "output": ">" }, { "input": "0110\n001", "output": ">" }, { "input": "1111\n0110", "output": ">" }, { "input": "01010\n0011", "output": ">" }, { "input": "0\n1", "output": "<" }, { "input": "1\n0", "output": ">" }, { "input": "1\n1", "output": "=" }, { "input": "010000100010100000100010001000001100100010110000101010000010010011001111101101001\n001011100001110101111001100110001011011100000000100111011010010011010100101011111", "output": "=" }, { "input": "11111001000\n1011100100", "output": ">" }, { "input": "1001111010001100001010001010010010100010100011101101110011110101011000010111101100111000110110110010\n01111001101111100111111001110110100101001111010001000000001001001111100101101100001101111111100111101", "output": "<" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0", "output": ">" }, { "input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1", "output": ">" }, { "input": "1\n100000000000000000000000000000000000000000000000000", "output": "<" }, { "input": "1\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "<" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": ">" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n100000000000000000000", "output": ">" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111011011011001101111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": ">" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111011011011001101111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": ">" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0", "output": ">" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110", "output": ">" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1000", "output": ">" }, { "input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1000", "output": ">" }, { "input": "1\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "<" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0", "output": ">" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n10000", "output": ">" }, { "input": "10000100001000010000100001000010000100001000010000\n1", "output": ">" }, { "input": "101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010\n1", "output": ">" }, { "input": "10100\n01011", "output": ">" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n01111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "<" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n0000001010101011", "output": ">" }, { "input": "110010010101001001001010100100010101010101011111111111111010101000000000000000000010110111111110101010111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": ">" }, { "input": "1100\n0111", "output": ">" }, { "input": "1111111111111111111111111111111111111111111111111\n0", "output": ">" }, { "input": "1100100101010010010010101001000101010101010111111111111110101010000000000000000000101101111111101010101111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": ">" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n100000000000000000000", "output": ">" }, { "input": "100001000010000100001000010000100001000010000100001111111111111111111111111111111111111111111111111111111111111111111111\n1", "output": ">" }, { "input": "11111111111111111111111111111111111111111111111111111111111111\n1", "output": ">" }, { "input": "1011\n0100", "output": ">" }, { "input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "<" }, { "input": "1000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "<" }, { "input": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011", "output": ">" }, { "input": "1000000000000000000000000\n0101010101010101010101011", "output": "=" }, { "input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1", "output": ">" }, { "input": "101010101010101010101010101010101010101010101010101010101010101010101010\n1000000000000000000000000000000000000000000000000000000000000000000000000", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n0", "output": ">" }, { "input": "111\n1000", "output": ">" }, { "input": "1000000000000000000000000000000000000000000000000\n000", "output": ">" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10", "output": ">" }, { "input": "111111111111111111111111111111111111111111111111\n11", "output": ">" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n000", "output": ">" }, { "input": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": ">" }, { "input": "100000000000000000000000000000000000000000000000\n0", "output": ">" } ]
1,407,691,172
1,172
Python 3
MEMORY_LIMIT_EXCEEDED
PRETESTS
0
1,045
268,390,400
a = input().strip()[::-1] b = input().strip()[::-1] from math import sqrt q = (sqrt(5) + 1) * 0.5 DP1 = [0] * 100500 DP2 = [0] * 100500 DP1[0] = 1 for i in range(1, 100100): DP1[i] = DP1[i - 1] + DP2[i - 1] DP2[i] = DP1[i - 1] q1, q2, e1, e2 = 0, 0, 0, 0 for i in range(len(a)): if i == 0: if a[i] == '1': e1 += 1 elif a[i] == '1': q1 += DP1[i - 1] e1 += DP2[i - 1] for i in range(len(b)): if i == 0: if b[i] == '1': e2 += 1 elif b[i] == '1': q2 += DP1[i - 1] e2 += DP2[i - 1] aval = q * q1 + e1 bval = q * q2 + e2 if abs(aval - bval) < 1e-9: print('=') elif aval < bval: print("<") else: print(">")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that *q*2<==<=*q*<=+<=1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression *a*0*a*1...*a**n* equals to . Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help. Given two numbers written in golden system notation, determine which of them has larger decimal value. Input Specification: Input consists of two lines — one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000. Output Specification: Print "&gt;" if the first number is larger, "&lt;" if it is smaller and "=" if they are equal. Demo Input: ['1000\n111\n', '00100\n11\n', '110\n101\n'] Demo Output: ['&lt;\n', '=\n', '&gt;\n'] Note: In the first example first number equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9c955eec678d6e7dcdc7c94fb203e922d2ad19ad.png" style="max-width: 100.0%;max-height: 100.0%;"/>, while second number is approximately 1.618033988<sup class="upper-index">2</sup> + 1.618033988 + 1 ≈ 5.236, which is clearly a bigger number. In the second example numbers are equal. Each of them is  ≈ 2.618.
```python a = input().strip()[::-1] b = input().strip()[::-1] from math import sqrt q = (sqrt(5) + 1) * 0.5 DP1 = [0] * 100500 DP2 = [0] * 100500 DP1[0] = 1 for i in range(1, 100100): DP1[i] = DP1[i - 1] + DP2[i - 1] DP2[i] = DP1[i - 1] q1, q2, e1, e2 = 0, 0, 0, 0 for i in range(len(a)): if i == 0: if a[i] == '1': e1 += 1 elif a[i] == '1': q1 += DP1[i - 1] e1 += DP2[i - 1] for i in range(len(b)): if i == 0: if b[i] == '1': e2 += 1 elif b[i] == '1': q2 += DP1[i - 1] e2 += DP2[i - 1] aval = q * q1 + e1 bval = q * q2 + e2 if abs(aval - bval) < 1e-9: print('=') elif aval < bval: print("<") else: print(">") ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, 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,605,206,162
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
78
0
s=input() s1='hello' j=0 c=0 for i in range(len(s)): if j==len(s1): break elif s1[j]==s[i]: c=c+1 i=i+1 j=j+1 s.replace(s[i],'0') else: i=i+1 if c==5: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s=input() s1='hello' j=0 c=0 for i in range(len(s)): if j==len(s1): break elif s1[j]==s[i]: c=c+1 i=i+1 j=j+1 s.replace(s[i],'0') else: i=i+1 if c==5: print("YES") else: print("NO") ```
-1
112
A
Petya and Strings
PROGRAMMING
800
[ "implementation", "strings" ]
A. Petya and Strings
2
256
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
[ "aaaa\naaaA\n", "abs\nAbz\n", "abcdefg\nAbCdEfF\n" ]
[ "0\n", "-1\n", "1\n" ]
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
500
[ { "input": "aaaa\naaaA", "output": "0" }, { "input": "abs\nAbz", "output": "-1" }, { "input": "abcdefg\nAbCdEfF", "output": "1" }, { "input": "asadasdasd\nasdwasdawd", "output": "-1" }, { "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0" }, { "input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp", "output": "0" }, { "input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH", "output": "-1" }, { "input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt", "output": "1" }, { "input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL", "output": "1" }, { "input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo", "output": "1" }, { "input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja", "output": "-1" }, { "input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy", "output": "1" }, { "input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR", "output": "1" }, { "input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd", "output": "1" }, { "input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI", "output": "-1" }, { "input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC", "output": "-1" }, { "input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl", "output": "-1" }, { "input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo", "output": "-1" }, { "input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV", "output": "-1" }, { "input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ", "output": "-1" }, { "input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK", "output": "-1" }, { "input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys", "output": "1" }, { "input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy", "output": "-1" }, { "input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK", "output": "-1" }, { "input": "UG\nak", "output": "1" }, { "input": "JZR\nVae", "output": "-1" }, { "input": "a\nZ", "output": "-1" }, { "input": "rk\nkv", "output": "1" }, { "input": "RvuT\nbJzE", "output": "1" }, { "input": "PPS\nydq", "output": "-1" }, { "input": "q\nq", "output": "0" }, { "input": "peOw\nIgSJ", "output": "1" }, { "input": "PyK\noKN", "output": "1" }, { "input": "O\ni", "output": "1" }, { "input": "NmGY\npDlP", "output": "-1" }, { "input": "nG\nZf", "output": "-1" }, { "input": "m\na", "output": "1" }, { "input": "MWyB\nWZEV", "output": "-1" }, { "input": "Gre\nfxc", "output": "1" }, { "input": "Ooq\nwap", "output": "-1" }, { "input": "XId\nlbB", "output": "1" }, { "input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF", "output": "0" }, { "input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD", "output": "0" }, { "input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA", "output": "0" }, { "input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ", "output": "0" }, { "input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG", "output": "0" }, { "input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ", "output": "0" }, { "input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ", "output": "0" }, { "input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi", "output": "0" }, { "input": "abac\nadaa", "output": "-1" }, { "input": "Bbc\nabc", "output": "1" }, { "input": "aaaba\naaaab", "output": "1" } ]
1,698,901,492
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
s=input() str=s[0].upper()+s[1:] print(str) #erfgh
Title: Petya and Strings Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Specification: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output Specification: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Demo Input: ['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n'] Demo Output: ['0\n', '-1\n', '1\n'] Note: If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: - http://en.wikipedia.org/wiki/Lexicographical_order
```python s=input() str=s[0].upper()+s[1:] print(str) #erfgh ```
0
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10000", "output": "10800100" }, { "input": "2333", "output": "310060" }, { "input": "9139", "output": "10134010" }, { "input": "9859", "output": "10422001" }, { "input": "5987", "output": "2221201" }, { "input": "3", "output": "37" }, { "input": "4", "output": "46" }, { "input": "5", "output": "55" }, { "input": "7", "output": "73" }, { "input": "9", "output": "91" }, { "input": "10", "output": "109" }, { "input": "15", "output": "154" }, { "input": "51", "output": "613" }, { "input": "99", "output": "1414" }, { "input": "138", "output": "2224" }, { "input": "233", "output": "5050" }, { "input": "666", "output": "27100" }, { "input": "1234", "output": "110206" }, { "input": "3567", "output": "1033003" }, { "input": "4445", "output": "1221301" }, { "input": "5689", "output": "2114002" }, { "input": "6666", "output": "3102004" }, { "input": "7777", "output": "5300200" }, { "input": "8888", "output": "10110061" }, { "input": "9411", "output": "10214200" }, { "input": "5539", "output": "2101114" }, { "input": "6259", "output": "2511100" }, { "input": "2387", "output": "312220" }, { "input": "8515", "output": "10030114" } ]
1,699,443,127
2,147,483,647
PyPy 3
OK
TESTS
35
436
1,843,200
# -*- coding: utf-8 -*- """ Created on Wed Nov 8 11:00:33 2023 @author: lakne """ k = int(input()) x = 10 i = 0 while i != k: digits_sum = 0 x += 9 digits = str(x) for digit in digits: digits_sum += int(digit) if digits_sum == 10: i += 1 print(x)
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). Output Specification: A single number, denoting the $k$-th smallest perfect integer. Demo Input: ['1\n', '2\n'] Demo Output: ['19\n', '28\n'] Note: The first perfect integer is $19$ and the second one is $28$.
```python # -*- coding: utf-8 -*- """ Created on Wed Nov 8 11:00:33 2023 @author: lakne """ k = int(input()) x = 10 i = 0 while i != k: digits_sum = 0 x += 9 digits = str(x) for digit in digits: digits_sum += int(digit) if digits_sum == 10: i += 1 print(x) ```
3
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them.
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, { "input": "1 1000000000", "output": "NO" }, { "input": "999999999 1000000000", "output": "NO" }, { "input": "1 2", "output": "YES\n2\n1 2 " }, { "input": "1 536870912", "output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 " }, { "input": "11111 11111111", "output": "YES\n4\n11111 111111 1111111 11111111 " }, { "input": "59139 946224", "output": "YES\n5\n59139 118278 236556 473112 946224 " }, { "input": "9859 19718", "output": "YES\n2\n9859 19718 " }, { "input": "25987 51974222", "output": "YES\n5\n25987 259871 2598711 25987111 51974222 " }, { "input": "9411 188222222", "output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 " }, { "input": "25539 510782222", "output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 " }, { "input": "76259 610072", "output": "YES\n4\n76259 152518 305036 610072 " }, { "input": "92387 184774", "output": "YES\n2\n92387 184774 " }, { "input": "8515 85151111", "output": "YES\n5\n8515 85151 851511 8515111 85151111 " }, { "input": "91939 9193911", "output": "YES\n3\n91939 919391 9193911 " }, { "input": "30518 610361", "output": "YES\n3\n30518 61036 610361 " }, { "input": "46646 373168844", "output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 " }, { "input": "30070 300701", "output": "YES\n2\n30070 300701 " }, { "input": "13494 1079528", "output": "YES\n5\n13494 134941 269882 539764 1079528 " }, { "input": "96918 775344422", "output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 " }, { "input": "13046 260921", "output": "YES\n3\n13046 26092 260921 " }, { "input": "29174 5834811", "output": "YES\n4\n29174 58348 583481 5834811 " }, { "input": "79894 319576421", "output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 " }, { "input": "96022 1920442", "output": "YES\n3\n96022 960221 1920442 " }, { "input": "79446 6355681", "output": "YES\n5\n79446 158892 317784 635568 6355681 " }, { "input": "5440 27853056", "output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 " }, { "input": "250000000 705032705", "output": "NO" }, { "input": "17 35", "output": "NO" }, { "input": "1 3", "output": "NO" }, { "input": "2 11", "output": "NO" } ]
1,595,721,076
2,147,483,647
Python 3
OK
TESTS
33
202
14,131,200
lis = input().split() a,b = int(lis[0]),int(lis[1]) parent = {} parent[a]=None stack = [a] flag = False while stack: node = stack.pop() if(node==b): flag = True break elif(node<b): n = [2*node,10*node+1] for i in n: parent[i]=node stack.append(i) if not flag: print("NO") else: print("YES") lis = [] curr = b while(curr!=None): lis.append(curr) curr = parent[curr] lis.reverse() print(len(lis)) for i in lis: print(i,end = " ") print()
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. Input Specification: The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. Output Specification: If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them. Demo Input: ['2 162\n', '4 42\n', '100 40021\n'] Demo Output: ['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n'] Note: none
```python lis = input().split() a,b = int(lis[0]),int(lis[1]) parent = {} parent[a]=None stack = [a] flag = False while stack: node = stack.pop() if(node==b): flag = True break elif(node<b): n = [2*node,10*node+1] for i in n: parent[i]=node stack.append(i) if not flag: print("NO") else: print("YES") lis = [] curr = b while(curr!=None): lis.append(curr) curr = parent[curr] lis.reverse() print(len(lis)) for i in lis: print(i,end = " ") print() ```
3
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "input": "xulsyfkuizjauadjjopu", "output": "526" }, { "input": "e", "output": "51" }, { "input": "zv", "output": "76" }, { "input": "jgv", "output": "101" }, { "input": "zsfo", "output": "126" }, { "input": "jselr", "output": "151" }, { "input": "dwemig", "output": "176" }, { "input": "mddoxsf", "output": "201" }, { "input": "jgirkrmi", "output": "226" }, { "input": "spkxurcum", "output": "251" }, { "input": "fykkiubdkt", "output": "276" }, { "input": "fznbcxsxygs", "output": "301" }, { "input": "qcrvrdqcbtou", "output": "326" }, { "input": "qktrbjzrqgmlr", "output": "351" }, { "input": "foamodbvptlxxg", "output": "376" }, { "input": "ydzpjhsidipricw", "output": "401" }, { "input": "lpfpndmjfvqejdgf", "output": "426" }, { "input": "ofkvparuvjtggnmab", "output": "451" }, { "input": "xxncfutrtxcwdzwbgs", "output": "476" }, { "input": "zovhffccflkgqncsdte", "output": "501" }, { "input": "cskgsxywlvfeicoueglr", "output": "526" }, { "input": "gggggggggggggggggggg", "output": "526" }, { "input": "qdqdddqddqqddqddqdqd", "output": "526" }, { "input": "takttttaakaaktakttkt", "output": "526" }, { "input": "coccoooogogcgocccmcg", "output": "526" }, { "input": "kskkskkkssksssk", "output": "401" }, { "input": "lllllllllllllll", "output": "401" } ]
1,544,440,367
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
n = len(input()) + 3 print(int((5*n**2 + 5*n + 2) / 2))
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. Output Specification: Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Demo Input: ['a\n', 'hi\n'] Demo Output: ['51\n', '76\n'] Note: In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
```python n = len(input()) + 3 print(int((5*n**2 + 5*n + 2) / 2)) ```
0
559
C
Gerald and Giant Chess
PROGRAMMING
2,200
[ "combinatorics", "dp", "math", "number theory" ]
null
null
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=×<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of giant chess against his friend Pollard. Gerald has almost won, and the only thing he needs to win is to bring the pawn from the upper left corner of the board, where it is now standing, to the lower right corner. Gerald is so confident of victory that he became interested, in how many ways can he win? The pawn, which Gerald has got left can go in two ways: one cell down or one cell to the right. In addition, it can not go to the black cells, otherwise the Gerald still loses. There are no other pawns or pieces left on the field, so that, according to the rules of giant chess Gerald moves his pawn until the game is over, and Pollard is just watching this process.
The first line of the input contains three integers: *h*,<=*w*,<=*n* — the sides of the board and the number of black cells (1<=≤<=*h*,<=*w*<=≤<=105,<=1<=≤<=*n*<=≤<=2000). Next *n* lines contain the description of black cells. The *i*-th of these lines contains numbers *r**i*,<=*c**i* (1<=≤<=*r**i*<=≤<=*h*,<=1<=≤<=*c**i*<=≤<=*w*) — the number of the row and column of the *i*-th cell. It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct.
Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109<=+<=7.
[ "3 4 2\n2 2\n2 3\n", "100 100 3\n15 16\n16 15\n99 88\n" ]
[ "2\n", "545732279\n" ]
none
1,500
[ { "input": "3 4 2\n2 2\n2 3", "output": "2" }, { "input": "100 100 3\n15 16\n16 15\n99 88", "output": "545732279" }, { "input": "1000 1000 4\n50 50\n51 50\n50 51\n51 51", "output": "899660737" }, { "input": "100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000", "output": "999612315" }, { "input": "2 2 2\n2 1\n1 2", "output": "0" }, { "input": "100 10 30\n40 4\n15 3\n75 3\n88 10\n32 1\n16 5\n81 8\n45 2\n72 8\n11 6\n86 4\n50 2\n9 4\n11 1\n20 3\n47 3\n2 4\n68 3\n90 5\n85 2\n88 1\n88 5\n86 3\n70 9\n49 3\n34 4\n5 7\n77 5\n50 1\n87 5", "output": "402737011" }, { "input": "100000 100000 2\n1 2\n2 1", "output": "0" }, { "input": "100000 100000 2\n99999 100000\n100000 99999", "output": "0" }, { "input": "100000 100000 3\n99998 100000\n99999 99999\n100000 99998", "output": "0" } ]
1,643,817,613
4,513
PyPy 3-64
RUNTIME_ERROR
TESTS
3
124
11,571,200
p = 10**9+7 fact_dict = [1] for i in range(1, 10**5+2): fact_dict.append((fact_dict[-1]*i) % p) def power(x, y, p): b = bin(y)[2:] start = x % p answer = 1 for i in range(len(b)): if b[len(b)-1-i]=='1': answer = (start*answer) % p start = (start*start) % p return answer def binom(a, b): num = fact_dict[a] den = (fact_dict[b]*fact_dict[a-b]) den1 = power(den, p-2, p) return (num*den1) % p def dist(x1, y1, x2, y2): return binom(x2+y2-x1-y1, x2-x1) def process(h, w, A): answer = dist(1, 1, h, w) n = len(A) A.sort() bad_dict = [] for i in range(n): x1, y1 = A[i] bad = dist(1, 1, x1, y1) for j in range(n): x2, y2 = A[j] if x2 <= x1 and y2 <= y1 and i != j: bad2 = bad_dict[j]*dist(x2, y2, x1, y1) bad-=bad2 bad_dict.append(bad) answer-=bad*dist(x1, y1, h, w) answer= answer % p return answer h, w, n = [int(x) for x in input().split()] A = [] for i in range(n): x, y = [int(x) for x in input().split()] A.append([x, y]) print(process(h, w, A))
Title: Gerald and Giant Chess Time Limit: None seconds Memory Limit: None megabytes Problem Description: Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an *h*<=×<=*w* field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of giant chess against his friend Pollard. Gerald has almost won, and the only thing he needs to win is to bring the pawn from the upper left corner of the board, where it is now standing, to the lower right corner. Gerald is so confident of victory that he became interested, in how many ways can he win? The pawn, which Gerald has got left can go in two ways: one cell down or one cell to the right. In addition, it can not go to the black cells, otherwise the Gerald still loses. There are no other pawns or pieces left on the field, so that, according to the rules of giant chess Gerald moves his pawn until the game is over, and Pollard is just watching this process. Input Specification: The first line of the input contains three integers: *h*,<=*w*,<=*n* — the sides of the board and the number of black cells (1<=≤<=*h*,<=*w*<=≤<=105,<=1<=≤<=*n*<=≤<=2000). Next *n* lines contain the description of black cells. The *i*-th of these lines contains numbers *r**i*,<=*c**i* (1<=≤<=*r**i*<=≤<=*h*,<=1<=≤<=*c**i*<=≤<=*w*) — the number of the row and column of the *i*-th cell. It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct. Output Specification: Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109<=+<=7. Demo Input: ['3 4 2\n2 2\n2 3\n', '100 100 3\n15 16\n16 15\n99 88\n'] Demo Output: ['2\n', '545732279\n'] Note: none
```python p = 10**9+7 fact_dict = [1] for i in range(1, 10**5+2): fact_dict.append((fact_dict[-1]*i) % p) def power(x, y, p): b = bin(y)[2:] start = x % p answer = 1 for i in range(len(b)): if b[len(b)-1-i]=='1': answer = (start*answer) % p start = (start*start) % p return answer def binom(a, b): num = fact_dict[a] den = (fact_dict[b]*fact_dict[a-b]) den1 = power(den, p-2, p) return (num*den1) % p def dist(x1, y1, x2, y2): return binom(x2+y2-x1-y1, x2-x1) def process(h, w, A): answer = dist(1, 1, h, w) n = len(A) A.sort() bad_dict = [] for i in range(n): x1, y1 = A[i] bad = dist(1, 1, x1, y1) for j in range(n): x2, y2 = A[j] if x2 <= x1 and y2 <= y1 and i != j: bad2 = bad_dict[j]*dist(x2, y2, x1, y1) bad-=bad2 bad_dict.append(bad) answer-=bad*dist(x1, y1, h, w) answer= answer % p return answer h, w, n = [int(x) for x in input().split()] A = [] for i in range(n): x, y = [int(x) for x in input().split()] A.append([x, y]) print(process(h, w, A)) ```
-1
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,699,293,768
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
6
124
0
a=int(input()) k=0 for x in range (a+1,9001): for i in range (10): if str(x).count(str(i))==1: k+=1 if k==4: print(x) break k=0
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()) k=0 for x in range (a+1,9001): for i in range (10): if str(x).count(str(i))==1: k+=1 if k==4: print(x) break k=0 ```
0
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "YES" }, { "input": "qxolmbkkt\naovlajmlf", "output": "NO" }, { "input": "b\ng", "output": "NO" }, { "input": "ab\naba", "output": "NO" }, { "input": "ba\na", "output": "NO" }, { "input": "a\nab", "output": "NO" }, { "input": "a\naa", "output": "NO" }, { "input": "a\nz", "output": "NO" }, { "input": "aabb\nbbaa", "output": "NO" }, { "input": "ab\nbd", "output": "NO" }, { "input": "bac\ndae", "output": "NO" }, { "input": "abc\nakl", "output": "NO" }, { "input": "cb\naa", "output": "NO" }, { "input": "abaab\naabba", "output": "NO" }, { "input": "aab\naaa", "output": "NO" }, { "input": "abcde\nedcba", "output": "NO" }, { "input": "abab\nbaba", "output": "NO" }, { "input": "ab\nbac", "output": "NO" }, { "input": "abcd\naqcb", "output": "NO" }, { "input": "abc\nbad", "output": "NO" }, { "input": "ab\nca", "output": "NO" }, { "input": "abc\nab", "output": "NO" }, { "input": "ab\nbae", "output": "NO" }, { "input": "aaaabcccca\naaaadccccb", "output": "NO" }, { "input": "acaa\nabca", "output": "NO" }, { "input": "aba\naab", "output": "YES" }, { "input": "ah\nla", "output": "NO" }, { "input": "aab\naa", "output": "NO" }, { "input": "abab\nabcd", "output": "NO" }, { "input": "ed\nab", "output": "NO" } ]
1,601,530,553
2,147,483,647
Python 3
OK
TESTS
53
342
4,608,000
s1=str(input()) s2=str(input()) if len(s1)!=len(s2): print('NO') else: key=[] count=0 for i in range(len(s1)): if s1[i]!=s2[i] and count==0: key.append([s1[i],s2[i]]) count+=1 elif s1[i]!=s2[i] and count>0: count+=1 key.append([s2[i],s1[i]]) if count!=2 : print('NO') elif len(key)!=2: print('NO') elif key[1]!=key[0]: print('NO') else: print('YES')
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. Input Specification: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. Output Specification: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Demo Input: ['ab\nba\n', 'aa\nab\n'] Demo Output: ['YES\n', 'NO\n'] Note: - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
```python s1=str(input()) s2=str(input()) if len(s1)!=len(s2): print('NO') else: key=[] count=0 for i in range(len(s1)): if s1[i]!=s2[i] and count==0: key.append([s1[i],s2[i]]) count+=1 elif s1[i]!=s2[i] and count>0: count+=1 key.append([s2[i],s1[i]]) if count!=2 : print('NO') elif len(key)!=2: print('NO') elif key[1]!=key[0]: print('NO') else: print('YES') ```
3
794
B
Cutting Carrot
PROGRAMMING
1,200
[ "geometry", "math" ]
null
null
Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area?
The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105).
The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "3 2\n", "2 100000\n" ]
[ "1.154700538379 1.632993161855\n", "70710.678118654752\n" ]
Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
1,000
[ { "input": "3 2", "output": "1.154700538379 1.632993161855" }, { "input": "2 100000", "output": "70710.678118654752" }, { "input": "1000 100000", "output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8944.271909999159 9486.832980505138 10000.000000000000 10488.088481701515 10954.451150103322 11401.754250991380 11832.159566199232 12247.448713915890 12649.110640673517 13038.404810405297 13416.407864998738 13784.048752090222 14142.135623730950 14491.376746189439 14832.396974191326 15165.750888103101 15491.933384829668 15811.388300841897 16124.515496597099 16431.676725154983 16733.2..." }, { "input": "2 1", "output": "0.707106781187" }, { "input": "1000 1", "output": "0.031622776602 0.044721359550 0.054772255751 0.063245553203 0.070710678119 0.077459666924 0.083666002653 0.089442719100 0.094868329805 0.100000000000 0.104880884817 0.109544511501 0.114017542510 0.118321595662 0.122474487139 0.126491106407 0.130384048104 0.134164078650 0.137840487521 0.141421356237 0.144913767462 0.148323969742 0.151657508881 0.154919333848 0.158113883008 0.161245154966 0.164316767252 0.167332005307 0.170293863659 0.173205080757 0.176068168617 0.178885438200 0.181659021246 0.184390889146 0..." }, { "input": "20 17", "output": "3.801315561750 5.375872022286 6.584071688553 7.602631123499 8.500000000000 9.311283477588 10.057335631269 10.751744044572 11.403946685249 12.020815280171 12.607537428063 13.168143377105 13.705838172108 14.223220451079 14.722431864335 15.205262246999 15.673225577398 16.127616066859 16.569550386175" }, { "input": "999 1", "output": "0.031638599858 0.044743737014 0.054799662435 0.063277199717 0.070746059996 0.077498425829 0.083707867056 0.089487474029 0.094915799575 0.100050037531 0.104933364623 0.109599324870 0.114074594073 0.118380800867 0.122535770349 0.126554399434 0.130449289063 0.134231211043 0.137909459498 0.141492119993 0.144986278734 0.148398187395 0.151733394554 0.154996851658 0.158192999292 0.161325838061 0.164398987305 0.167415734111 0.170379074505 0.173291748303 0.176156268782 0.178974948057 0.181749918935 0.184483153795 0..." }, { "input": "998 99999", "output": "3165.413034717700 4476.570044210349 5482.656203071844 6330.826069435401 7078.078722492680 7753.646760213179 8374.895686665300 8953.140088420697 9496.239104153101 10009.914924893578 10498.487342658843 10965.312406143687 11413.059004696742 11843.891063542002 12259.591967329534 12661.652138870802 13051.332290848021 13429.710132631046 13797.715532900862 14156.157444985360 14505.744837393740 14847.103184390411 15180.787616204127 15507.293520426358 15827.065173588502 16140.502832606510 16447.968609215531 16749.7..." }, { "input": "574 29184", "output": "1218.116624752432 1722.677051277028 2109.839883615525 2436.233249504864 2723.791577469041 2983.764177844748 3222.833656968322 3445.354102554056 3654.349874257297 3852.022989934325 4040.035795197963 4219.679767231051 4391.981950040022 4557.775066957079 4717.745401404559 4872.466499009729 5022.423508175150 5168.031153831084 5309.647268742708 5447.583154938083 5582.111638212139 5713.473414041731 5841.882108059006 5967.528355689497 6090.583123762161 6211.200439444432 6329.519650846576 6445.667313936643 6559.75..." }, { "input": "2 5713", "output": "4039.701040918746" }, { "input": "937 23565", "output": "769.834993893392 1088.711089153444 1333.393322867831 1539.669987786784 1721.403377803760 1885.702921177414 2036.791944396843 2177.422178306887 2309.504981680176 2434.432003204934 2553.253825229922 2666.786645735663 2775.679544129132 2880.458791498282 2981.558110676796 3079.339975573568 3174.110994119182 3266.133267460331 3355.632941582547 3442.806755607520 3527.827132142336 3610.846187821139 3691.998931463184 3771.405842354828 3849.174969466960 3925.403656108988 4000.179968603494 4073.583888793686 4145.688..." }, { "input": "693 39706", "output": "1508.306216302128 2133.067107306117 2612.463000007259 3016.612432604256 3372.675230537060 3694.580605808168 3990.603149268227 4266.134214612233 4524.918648906384 4769.683052505315 5002.485788434792 5224.926000014517 5438.275401978402 5643.565095743912 5841.644856719264 6033.224865208513 6218.905845589392 6399.201321918350 6574.554372775177 6745.350461074120 6911.927407376938 7074.583247583148 7233.582498950279 7389.161211616337 7541.531081510641 7690.882829397851 7837.389000021776 7981.206298536455 8122.47..." }, { "input": "449 88550", "output": "4178.932872810542 5909.903544975429 7238.124057127628 8357.865745621084 9344.377977012855 10236.253207728862 11056.417127089408 11819.807089950858 12536.798618431626 13214.946067032045 13859.952363194553 14476.248114255256 15067.356749640443 15636.135052384012 16184.937421313947 16715.731491242168 17230.181636963718 17729.710634926286 18215.546084421264 18688.755954025709 19150.276213793575 19600.932605874766 20041.458005232581 20472.506415457724 20894.664364052710 21308.460264455309 21714.372171382883 221..." }, { "input": "642 37394", "output": "1475.823459881026 2087.129552632132 2556.201215516026 2951.646919762052 3300.041579082908 3615.014427137354 3904.661853880105 4174.259105264265 4427.470379643078 4666.963557534173 4894.752673229489 5112.402431032051 5321.157158133711 5522.025750238117 5715.839682061424 5903.293839524104 6084.976009853978 6261.388657896397 6432.965320127946 6600.083158165816 6763.072717296425 6922.225614943105 7077.800671741869 7230.028854274709 7379.117299405130 7525.252620551370 7668.603646548077 7809.323707760210 7947.55..." }, { "input": "961 53535", "output": "1726.935483870968 2442.255582633666 2991.139999458060 3453.870967741935 3861.545134691976 4230.110754190240 4569.041820575576 4884.511165267332 5180.806451612903 5461.049501197232 5727.597037150849 5982.279998916119 6226.554436514989 6461.600909707837 6688.392369006905 6907.741935483871 7120.337408627144 7326.766747900998 7527.537256208063 7723.090269383951 7913.812575143900 8100.045409746687 8282.091632275692 8460.221508380480 8634.677419354839 8805.677730973862 8973.419998374179 9138.083641151152 9299.83..." }, { "input": "4 31901", "output": "15950.500000000000 22557.413426632053 27627.076406127377" }, { "input": "4 23850", "output": "11925.000000000000 16864.496731299158 20654.705880258862" }, { "input": "4 72694", "output": "36347.000000000000 51402.420351574886 62954.850702705983" }, { "input": "4 21538", "output": "10769.000000000000 15229.665853195861 18652.455146709240" }, { "input": "4 70383", "output": "35191.500000000000 49768.296580252774 60953.465994560145" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "5 1", "output": "0.447213595500 0.632455532034 0.774596669241 0.894427191000" }, { "input": "20 1", "output": "0.223606797750 0.316227766017 0.387298334621 0.447213595500 0.500000000000 0.547722557505 0.591607978310 0.632455532034 0.670820393250 0.707106781187 0.741619848710 0.774596669241 0.806225774830 0.836660026534 0.866025403784 0.894427191000 0.921954445729 0.948683298051 0.974679434481" }, { "input": "775 1", "output": "0.035921060405 0.050800050800 0.062217101684 0.071842120811 0.080321932890 0.087988269013 0.095038192662 0.101600101600 0.107763181216 0.113592366849 0.119136679436 0.124434203368 0.129515225161 0.134404301006 0.139121668728 0.143684241621 0.148106326235 0.152400152400 0.156576272252 0.160643865780 0.164610978351 0.168484707835 0.172271353843 0.175976538026 0.179605302027 0.183162187956 0.186651305051 0.190076385325 0.193440830330 0.196747750735 0.200000000000 0.203200203200 0.206350781829 0.209453975235 0..." }, { "input": "531 1", "output": "0.043396303660 0.061371641193 0.075164602800 0.086792607321 0.097037084957 0.106298800691 0.114815827305 0.122743282386 0.130188910981 0.137231161599 0.143929256529 0.150329205601 0.156467598013 0.162374100149 0.168073161363 0.173585214641 0.178927543753 0.184114923580 0.189160102178 0.194074169913 0.198866846404 0.203546706606 0.208121361089 0.212597601381 0.216981518301 0.221278599182 0.225493808401 0.229631654609 0.233696247231 0.237691344271 0.241620392998 0.245486564773 0.249292785005 0.253041759057 0..." }, { "input": "724 1", "output": "0.037164707312 0.052558833123 0.064371161313 0.074329414625 0.083102811914 0.091034569355 0.098328573097 0.105117666246 0.111494121937 0.117525123681 0.123261389598 0.128742322627 0.133999257852 0.139057601643 0.143938292487 0.148658829249 0.153234013794 0.157676499368 0.161997203441 0.166205623829 0.170310084440 0.174317928887 0.178235674883 0.182069138710 0.185823536562 0.189503567803 0.193113483940 0.196657146194 0.200138073886 0.203559485381 0.206924332929 0.210235332491 0.213494989396 0.216705620524 0..." }, { "input": "917 1", "output": "0.033022909334 0.046701446249 0.057197356781 0.066045818668 0.073841470086 0.080889277691 0.087370405666 0.093402892499 0.099068728003 0.104427608461 0.109524599747 0.114394713561 0.119065792869 0.123560412643 0.127897177895 0.132091637337 0.136156943250 0.140104338748 0.143943524609 0.147682940172 0.151329981692 0.154891174376 0.158372309576 0.161778555382 0.165114546671 0.168384459091 0.171592070342 0.174740811332 0.177833809176 0.180873923568 0.183863777748 0.186805784998 0.189702171441 0.192554995756 0..." }, { "input": "458 100", "output": "4.672693135160 6.608186004551 8.093341918275 9.345386270320 10.448459488214 11.445713905748 12.362783988552 13.216372009102 14.018079405480 14.776353114139 15.497569889795 16.186683836551 16.847634693328 17.483616785299 18.097262694412 18.690772540640 19.266007352363 19.824558013653 20.367797170339 20.896918976429 21.412969991171 21.916873521973 22.409449036367 22.891427811495 23.363465675800 23.826153477212 24.280025754826 24.725567977104 25.163222626003 25.593394344267 26.016454316384 26.432744018204 26...." } ]
1,494,668,823
723
PyPy 3
OK
TESTS
31
109
819,200
from math import sqrt n, h = map(int, input().split()) s = [] for i in range(1,n): s.append(h*sqrt(i/n)) print(*s)
Title: Cutting Carrot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area? Input Specification: The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). Output Specification: The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . Demo Input: ['3 2\n', '2 100000\n'] Demo Output: ['1.154700538379 1.632993161855\n', '70710.678118654752\n'] Note: Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle).
```python from math import sqrt n, h = map(int, input().split()) s = [] for i in range(1,n): s.append(h*sqrt(i/n)) print(*s) ```
3
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him.
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nckcccbj\nccbcbcc\ncccbccc\nccbcbcc\ncbcccbc\nbccccdt", "output": "NO" }, { "input": "13\nsooooooooooos\nosoooooooooso\noosooooooosoo\nooosooooosooo\noooosooosoooo\nooooososooooo\noooooosoooooo\nooooososooooo\noooosooosoooo\nooosooooosooo\noosooooooosoo\nosoooooooooso\nsooooooooooos", "output": "YES" }, { "input": "3\naaa\naaa\naaa", "output": "NO" }, { "input": "3\naca\noec\nzba", "output": "NO" }, { "input": "15\nrxeeeeeeeeeeeer\nereeeeeeeeeeere\needeeeeeeeeeoee\neeereeeeeeeewee\neeeereeeeebeeee\nqeeeereeejedyee\neeeeeerereeeeee\neeeeeeereeeeeee\neeeeeerereeeeze\neeeeereeereeeee\neeeereeeeegeeee\neeereeeeeeereee\neereeeeeeqeeved\ncreeeeeeceeeere\nreeerneeeeeeeer", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\nxxxxx\nxxxxx\nxoxxx\nxxxxx\nxxxxx", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxxxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxoox\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\nxxaxx\nxoxox\noxxxo", "output": "NO" }, { "input": "5\noxxxo\nxoxox\noxoxx\nxoxox\noxxxo", "output": "NO" }, { "input": "3\nxxx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxx\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxxx", "output": "NO" }, { "input": "3\nxax\nxxa\nxax", "output": "NO" }, { "input": "3\nxax\naaa\nxax", "output": "NO" }, { "input": "3\naax\naxa\nxax", "output": "NO" }, { "input": "3\nxaa\naxa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\naax", "output": "NO" }, { "input": "3\nxax\naxa\nxaa", "output": "NO" }, { "input": "3\nxfx\naxa\nxax", "output": "NO" }, { "input": "3\nxax\nafa\nxax", "output": "NO" }, { "input": "3\nxax\naxa\nxaf", "output": "NO" }, { "input": "3\nxox\nxxx\nxxx", "output": "NO" }, { "input": "3\naxa\naax\nxxa", "output": "NO" }, { "input": "3\nxox\noxx\nxox", "output": "NO" }, { "input": "3\nxox\nooo\nxox", "output": "NO" }, { "input": "3\naaa\naab\nbbb", "output": "NO" }, { "input": "3\nxxx\nsxs\nxsx", "output": "NO" }, { "input": "5\nabbba\nbabab\nbbbbb\nbaaab\nabbba", "output": "NO" }, { "input": "5\nabaaa\nbbbbb\nbbabb\nbabab\nabbba", "output": "NO" }, { "input": "5\nxoxox\noxoxo\nooxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nxox\noxx\nxxx", "output": "NO" }, { "input": "5\nxoooo\noxooo\nooxoo\noooxo\noooox", "output": "NO" }, { "input": "5\nxoooo\noxoxx\nooxoo\noxoxo\noxoox", "output": "NO" }, { "input": "3\naaa\nbab\naba", "output": "NO" } ]
1,620,968,624
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
6,963,200
n = int(input()) l = [] for i in range(n): l.append(input()) a = l[i][0] b = l[i][1] if(a==b): print("NO") exit() j = 0 k = -1 for i in range(n): if(i!=j and i!=k): if(l[i]!=b): print("NO") exit() else: if(l[i]!=a): print("NO") exit() if(i<n//2+1): j+=1 k-=1 else: j-=1 k+=1 print("YES")
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals *n* squares (*n* is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: - on both diagonals of the square paper all letters are the same; - all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. Output Specification: Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. Demo Input: ['5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n', '3\nwsw\nsws\nwsw\n', '3\nxpx\npxp\nxpe\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python n = int(input()) l = [] for i in range(n): l.append(input()) a = l[i][0] b = l[i][1] if(a==b): print("NO") exit() j = 0 k = -1 for i in range(n): if(i!=j and i!=k): if(l[i]!=b): print("NO") exit() else: if(l[i]!=a): print("NO") exit() if(i<n//2+1): j+=1 k-=1 else: j-=1 k+=1 print("YES") ```
0
959
A
Mahmoud and Ehab and the even-odd game
PROGRAMMING
800
[ "games", "math" ]
null
null
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
[ "1\n", "2\n" ]
[ "Ehab", "Mahmoud" ]
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
500
[ { "input": "1", "output": "Ehab" }, { "input": "2", "output": "Mahmoud" }, { "input": "10000", "output": "Mahmoud" }, { "input": "33333", "output": "Ehab" }, { "input": "5", "output": "Ehab" }, { "input": "1000000000", "output": "Mahmoud" }, { "input": "999999999", "output": "Ehab" }, { "input": "123123123", "output": "Ehab" }, { "input": "22222221", "output": "Ehab" }, { "input": "22222220", "output": "Mahmoud" }, { "input": "3", "output": "Ehab" }, { "input": "4", "output": "Mahmoud" }, { "input": "6", "output": "Mahmoud" }, { "input": "7", "output": "Ehab" }, { "input": "8", "output": "Mahmoud" }, { "input": "9", "output": "Ehab" }, { "input": "10", "output": "Mahmoud" }, { "input": "536870912", "output": "Mahmoud" }, { "input": "536870913", "output": "Ehab" }, { "input": "536870911", "output": "Ehab" } ]
1,664,713,883
2,147,483,647
PyPy 3
OK
TESTS
20
77
0
if __name__ == "__main__": n = int(input()) print("Ehab" if n%2==1 else "Mahmoud")
Title: Mahmoud and Ehab and the even-odd game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. Output Specification: Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. Demo Input: ['1\n', '2\n'] Demo Output: ['Ehab', 'Mahmoud'] Note: In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
```python if __name__ == "__main__": n = int(input()) print("Ehab" if n%2==1 else "Mahmoud") ```
3
688
A
Opponents
PROGRAMMING
800
[ "implementation" ]
null
null
Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya. For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents. Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively. The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day.
Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.
[ "2 2\n10\n00\n", "4 1\n0100\n", "4 5\n1101\n1111\n0110\n1011\n1111\n" ]
[ "2\n", "1\n", "2\n" ]
In the first and the second samples, Arya will beat all present opponents each of the *d* days. In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
500
[ { "input": "2 2\n10\n00", "output": "2" }, { "input": "4 1\n0100", "output": "1" }, { "input": "4 5\n1101\n1111\n0110\n1011\n1111", "output": "2" }, { "input": "3 2\n110\n110", "output": "2" }, { "input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111", "output": "1" }, { "input": "10 10\n1111111111\n0001001000\n1111111111\n1111111111\n1111111111\n1000000100\n1111111111\n0000011100\n1111111111\n1111111111", "output": "1" }, { "input": "10 10\n0000100011\n0100001111\n1111111111\n1100011111\n1111111111\n1000111000\n1111000010\n0111001001\n1101010110\n1111111111", "output": "4" }, { "input": "10 10\n1100110010\n0000000001\n1011100111\n1111111111\n1111111111\n1111111111\n1100010110\n1111111111\n1001001010\n1111111111", "output": "3" }, { "input": "10 7\n0000111001\n1111111111\n0110110001\n1111111111\n1111111111\n1000111100\n0110000111", "output": "2" }, { "input": "5 10\n00110\n11000\n10010\n00010\n11110\n01101\n11111\n10001\n11111\n01001", "output": "6" }, { "input": "5 9\n11111\n11101\n11111\n11111\n01010\n01010\n00000\n11111\n00111", "output": "3" }, { "input": "5 10\n11111\n00010\n11010\n11111\n11111\n00100\n11111\n11111\n01000\n11111", "output": "2" }, { "input": "5 9\n11111\n11111\n11111\n11111\n11100\n11111\n11111\n11111\n00000", "output": "1" }, { "input": "5 8\n11111\n10110\n01001\n11111\n01100\n10010\n11111\n11111", "output": "2" }, { "input": "1 1\n1", "output": "0" }, { "input": "100 1\n0011001100100010000011001100000001011101110110010001110001101100110011111101001011011001000010001111", "output": "1" }, { "input": "100 1\n1011011100000101000111110000110111010101110010010011110010001110100011001110110101111100100110000000", "output": "1" }, { "input": "100 1\n1110000011110101010111111100011001100000101101010110100101110000011100110110110101011100110110010011", "output": "1" }, { "input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "0" }, { "input": "1 100\n1\n0\n0\n0\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n0\n0", "output": "6" }, { "input": "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "49" }, { "input": "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "0" }, { "input": "1 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "100" }, { "input": "2 2\n11\n10", "output": "1" }, { "input": "1 1\n0", "output": "1" } ]
1,578,335,430
2,147,483,647
Python 3
OK
TESTS
56
109
0
n,d=map(int,input().split()) c=0 l=[] for i in range(d): a=input() a=list(a) if '0' in a: c=c+1 else: l.append(c) c=0 l.append(c) print(max(l))
Title: Opponents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya. For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents. Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents. Input Specification: The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively. The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day. Output Specification: Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. Demo Input: ['2 2\n10\n00\n', '4 1\n0100\n', '4 5\n1101\n1111\n0110\n1011\n1111\n'] Demo Output: ['2\n', '1\n', '2\n'] Note: In the first and the second samples, Arya will beat all present opponents each of the *d* days. In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
```python n,d=map(int,input().split()) c=0 l=[] for i in range(d): a=input() a=list(a) if '0' in a: c=c+1 else: l.append(c) c=0 l.append(c) print(max(l)) ```
3
986
A
Fair
PROGRAMMING
1,600
[ "graphs", "greedy", "number theory", "shortest paths" ]
null
null
Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads. There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s$ different types of goods. It costs $d(u,v)$ coins to bring goods from town $u$ to town $v$ where $d(u,v)$ is the length of the shortest path from $u$ to $v$. Length of a path is the number of roads in this path. The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of $n$ towns.
There are $4$ integers $n$, $m$, $k$, $s$ in the first line of input ($1 \le n \le 10^{5}$, $0 \le m \le 10^{5}$, $1 \le s \le k \le min(n, 100)$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair. In the next line there are $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_{i} \le k$), where $a_i$ is the type of goods produced in the $i$-th town. It is guaranteed that all integers between $1$ and $k$ occur at least once among integers $a_{i}$. In the next $m$ lines roads are described. Each road is described by two integers $u$ $v$ ($1 \le u, v \le n$, $u \ne v$) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.
Print $n$ numbers, the $i$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $i$. Separate numbers with spaces.
[ "5 5 4 3\n1 2 4 3 2\n1 2\n2 3\n3 4\n4 1\n4 5\n", "7 6 3 2\n1 2 3 3 2 2 1\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n" ]
[ "2 2 2 2 3 \n", "1 1 1 2 2 1 1 \n" ]
Let's look at the first sample. To hold a fair in town $1$ you can bring goods from towns $1$ ($0$ coins), $2$ ($1$ coin) and $4$ ($1$ coin). Total numbers of coins is $2$. Town $2$: Goods from towns $2$ ($0$), $1$ ($1$), $3$ ($1$). Sum equals $2$. Town $3$: Goods from towns $3$ ($0$), $2$ ($1$), $4$ ($1$). Sum equals $2$. Town $4$: Goods from towns $4$ ($0$), $1$ ($1$), $5$ ($1$). Sum equals $2$. Town $5$: Goods from towns $5$ ($0$), $4$ ($1$), $3$ ($2$). Sum equals $3$.
500
[]
1,620,263,390
890
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
234,393,600
from collections import deque n, m, k, s = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) E = [[] for u in range(n)] for j in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 E[u].append(v) E[v].append(u) inf = 10 ** 10 costs = [] for x in range(k): dist = [-1] * n q = deque() for u in range(n): if a[u] == x: dist[u] = 0 q.append(u) while q: u = q.popleft() for v in E[u]: if dist[v] == -1: dist[v] = dist[u] + 1 q.append(v) for u in range(n): costs.append((dist[u], u)) cnt = [0] * (m + 1) for x, u in costs: cnt[x] += 1 for x in range(1, m + 1): cnt[x] += cnt[x - 1] sorted_costs = [0] * (n * k) for x, u in costs: cnt[x] -= 1 sorted_costs[cnt[x]] = (x, u) ans = [0] * n taken = [0] * n for x, u in sorted_costs: if taken[u] < s: taken[u] += 1 ans[u] += x print(*ans)
Title: Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads. There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s$ different types of goods. It costs $d(u,v)$ coins to bring goods from town $u$ to town $v$ where $d(u,v)$ is the length of the shortest path from $u$ to $v$. Length of a path is the number of roads in this path. The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of $n$ towns. Input Specification: There are $4$ integers $n$, $m$, $k$, $s$ in the first line of input ($1 \le n \le 10^{5}$, $0 \le m \le 10^{5}$, $1 \le s \le k \le min(n, 100)$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair. In the next line there are $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_{i} \le k$), where $a_i$ is the type of goods produced in the $i$-th town. It is guaranteed that all integers between $1$ and $k$ occur at least once among integers $a_{i}$. In the next $m$ lines roads are described. Each road is described by two integers $u$ $v$ ($1 \le u, v \le n$, $u \ne v$) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads. Output Specification: Print $n$ numbers, the $i$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $i$. Separate numbers with spaces. Demo Input: ['5 5 4 3\n1 2 4 3 2\n1 2\n2 3\n3 4\n4 1\n4 5\n', '7 6 3 2\n1 2 3 3 2 2 1\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n'] Demo Output: ['2 2 2 2 3 \n', '1 1 1 2 2 1 1 \n'] Note: Let's look at the first sample. To hold a fair in town $1$ you can bring goods from towns $1$ ($0$ coins), $2$ ($1$ coin) and $4$ ($1$ coin). Total numbers of coins is $2$. Town $2$: Goods from towns $2$ ($0$), $1$ ($1$), $3$ ($1$). Sum equals $2$. Town $3$: Goods from towns $3$ ($0$), $2$ ($1$), $4$ ($1$). Sum equals $2$. Town $4$: Goods from towns $4$ ($0$), $1$ ($1$), $5$ ($1$). Sum equals $2$. Town $5$: Goods from towns $5$ ($0$), $4$ ($1$), $3$ ($2$). Sum equals $3$.
```python from collections import deque n, m, k, s = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) E = [[] for u in range(n)] for j in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 E[u].append(v) E[v].append(u) inf = 10 ** 10 costs = [] for x in range(k): dist = [-1] * n q = deque() for u in range(n): if a[u] == x: dist[u] = 0 q.append(u) while q: u = q.popleft() for v in E[u]: if dist[v] == -1: dist[v] = dist[u] + 1 q.append(v) for u in range(n): costs.append((dist[u], u)) cnt = [0] * (m + 1) for x, u in costs: cnt[x] += 1 for x in range(1, m + 1): cnt[x] += cnt[x - 1] sorted_costs = [0] * (n * k) for x, u in costs: cnt[x] -= 1 sorted_costs[cnt[x]] = (x, u) ans = [0] * n taken = [0] * n for x, u in sorted_costs: if taken[u] < s: taken[u] += 1 ans[u] += x print(*ans) ```
0
278
A
Circle Line
PROGRAMMING
800
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.
Print a single number — the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
500
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "input": "6\n89 82 87 32 67 33\n4 4", "output": "0" }, { "input": "7\n2 3 17 10 2 2 2\n4 2", "output": "18" }, { "input": "3\n4 37 33\n3 3", "output": "0" }, { "input": "8\n87 40 96 7 86 86 72 97\n6 8", "output": "158" }, { "input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8", "output": "348" }, { "input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7", "output": "0" }, { "input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16", "output": "452" }, { "input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6", "output": "337" }, { "input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64", "output": "1740" }, { "input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5", "output": "2127" }, { "input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57", "output": "932" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6", "output": "997" }, { "input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24", "output": "195" }, { "input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10", "output": "60" }, { "input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25", "output": "2523" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n1 51", "output": "5000" }, { "input": "4\n1 1 1 1\n2 4", "output": "2" }, { "input": "4\n1 1 2 1\n2 4", "output": "2" } ]
1,589,258,579
2,147,483,647
Python 3
OK
TESTS
23
218
0
n = int(input()) L = [int(x) for x in input().split()] [s, t] = sorted([int(x) for x in input().split()]) print(min(sum(L[(s-1):(t-1)]), sum(L)-sum(L[(s-1):(t-1)])))
Title: Circle Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station. The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces. Output Specification: Print a single number — the length of the shortest path between stations number *s* and *t*. Demo Input: ['4\n2 3 4 9\n1 3\n', '4\n5 8 2 100\n4 1\n', '3\n1 1 1\n3 1\n', '3\n31 41 59\n1 1\n'] Demo Output: ['5\n', '15\n', '1\n', '0\n'] Note: In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
```python n = int(input()) L = [int(x) for x in input().split()] [s, t] = sorted([int(x) for x in input().split()]) print(min(sum(L[(s-1):(t-1)]), sum(L)-sum(L[(s-1):(t-1)]))) ```
3
402
B
Trees in a Row
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=&lt;<=*n*), *a**i*<=+<=1<=-<=*a**i*<==<=*k*, where *k* is the number the Queen chose. Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?
The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row.
In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions. If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, print on the corresponding line "- j x". If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.
[ "4 1\n1 2 1 5\n", "4 1\n1 2 3 4\n" ]
[ "2\n+ 3 2\n- 4 1\n", "0\n" ]
none
1,000
[ { "input": "4 1\n1 2 1 5", "output": "2\n+ 3 2\n- 4 1" }, { "input": "4 1\n1 2 3 4", "output": "0" }, { "input": "50 1\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", "output": "0" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "0" }, { "input": "50 5\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 131 136 141 146 151 156 161 166 755 176 181 186 191 196 201 206 211 216 221 226 231 236 241 246", "output": "5\n- 1 231\n- 11 614\n- 17 521\n- 20 616\n- 35 584" }, { "input": "10 99\n1 100 199 298 397 496 364 694 793 676", "output": "2\n+ 7 231\n+ 10 216" }, { "input": "1 99\n1", "output": "0" }, { "input": "2 99\n1 100", "output": "0" }, { "input": "3 99\n1 100 199", "output": "0" }, { "input": "4 99\n1 100 199 298", "output": "0" }, { "input": "3 99\n295 566 992", "output": "2\n- 2 172\n- 3 499" }, { "input": "2 99\n307 854", "output": "1\n- 2 448" }, { "input": "7 1\n1 1 2 3 4 5 6", "output": "6\n+ 2 1\n+ 3 1\n+ 4 1\n+ 5 1\n+ 6 1\n+ 7 1" }, { "input": "5 1\n1 1 2 3 4", "output": "4\n+ 2 1\n+ 3 1\n+ 4 1\n+ 5 1" }, { "input": "4 2\n1 1 3 5", "output": "3\n+ 2 2\n+ 3 2\n+ 4 2" }, { "input": "4 1\n1 1 2 3", "output": "3\n+ 2 1\n+ 3 1\n+ 4 1" }, { "input": "5 1\n1 1 1 2 3", "output": "4\n+ 2 1\n+ 3 2\n+ 4 2\n+ 5 2" }, { "input": "3 1\n1 1 2", "output": "2\n+ 2 1\n+ 3 1" } ]
1,436,122,552
3,651
Python 3
WRONG_ANSWER
TESTS
5
62
512,000
n, k = map(int, input().split()) a = input().split() for i in range(n): a[i] = int(a[i]) lent = [] l = 0 r = 0 for i in range(1,n): if a[i] == a[i-1]+k: r+=1 else: lent.append([l,r]) l = i r = i if i == n-1: lent.append([l,r]) def ke(n): return n[1]-n[0] dnttch = max(lent, key = ke) print(n-ke(dnttch)-1) for i in range(dnttch[1]+1,n): if a[i-1]+k<a[i]: print('-',i+1,abs(a[i]-k-a[i-1])) a[i]-=abs(a[i]-k-a[i-1]) elif a[i-1]+k>a[i]: print('+',i+1,abs(a[i]-k-a[i-1])) a[i]+=abs(a[i]-k-a[i-1]) for i in reversed(range(1,dnttch[0]+1)): if a[i-1]+k<a[i]: print('+',i,abs(a[i]-k-a[i-1])) a[i-1]+=abs(a[i]-k-a[i-1]) elif a[i-1]+k>a[i]: print('-',i,abs(a[i]-k-a[i-1])) a[i-1]-=abs(a[i]-k-a[i-1])
Title: Trees in a Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=&lt;<=*n*), *a**i*<=+<=1<=-<=*a**i*<==<=*k*, where *k* is the number the Queen chose. Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes? Input Specification: The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row. Output Specification: In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions. If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, print on the corresponding line "- j x". If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them. Demo Input: ['4 1\n1 2 1 5\n', '4 1\n1 2 3 4\n'] Demo Output: ['2\n+ 3 2\n- 4 1\n', '0\n'] Note: none
```python n, k = map(int, input().split()) a = input().split() for i in range(n): a[i] = int(a[i]) lent = [] l = 0 r = 0 for i in range(1,n): if a[i] == a[i-1]+k: r+=1 else: lent.append([l,r]) l = i r = i if i == n-1: lent.append([l,r]) def ke(n): return n[1]-n[0] dnttch = max(lent, key = ke) print(n-ke(dnttch)-1) for i in range(dnttch[1]+1,n): if a[i-1]+k<a[i]: print('-',i+1,abs(a[i]-k-a[i-1])) a[i]-=abs(a[i]-k-a[i-1]) elif a[i-1]+k>a[i]: print('+',i+1,abs(a[i]-k-a[i-1])) a[i]+=abs(a[i]-k-a[i-1]) for i in reversed(range(1,dnttch[0]+1)): if a[i-1]+k<a[i]: print('+',i,abs(a[i]-k-a[i-1])) a[i-1]+=abs(a[i]-k-a[i-1]) elif a[i-1]+k>a[i]: print('-',i,abs(a[i]-k-a[i-1])) a[i-1]-=abs(a[i]-k-a[i-1]) ```
0
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "YES" }, { "input": "qxolmbkkt\naovlajmlf", "output": "NO" }, { "input": "b\ng", "output": "NO" }, { "input": "ab\naba", "output": "NO" }, { "input": "ba\na", "output": "NO" }, { "input": "a\nab", "output": "NO" }, { "input": "a\naa", "output": "NO" }, { "input": "a\nz", "output": "NO" }, { "input": "aabb\nbbaa", "output": "NO" }, { "input": "ab\nbd", "output": "NO" }, { "input": "bac\ndae", "output": "NO" }, { "input": "abc\nakl", "output": "NO" }, { "input": "cb\naa", "output": "NO" }, { "input": "abaab\naabba", "output": "NO" }, { "input": "aab\naaa", "output": "NO" }, { "input": "abcde\nedcba", "output": "NO" }, { "input": "abab\nbaba", "output": "NO" }, { "input": "ab\nbac", "output": "NO" }, { "input": "abcd\naqcb", "output": "NO" }, { "input": "abc\nbad", "output": "NO" }, { "input": "ab\nca", "output": "NO" }, { "input": "abc\nab", "output": "NO" }, { "input": "ab\nbae", "output": "NO" }, { "input": "aaaabcccca\naaaadccccb", "output": "NO" }, { "input": "acaa\nabca", "output": "NO" }, { "input": "aba\naab", "output": "YES" }, { "input": "ah\nla", "output": "NO" }, { "input": "aab\naa", "output": "NO" }, { "input": "abab\nabcd", "output": "NO" }, { "input": "ed\nab", "output": "NO" } ]
1,677,140,142
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
from collections import Counter a=input();b=input();print(Counter(a)==Counter(b))
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. Input Specification: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. Output Specification: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Demo Input: ['ab\nba\n', 'aa\nab\n'] Demo Output: ['YES\n', 'NO\n'] Note: - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
```python from collections import Counter a=input();b=input();print(Counter(a)==Counter(b)) ```
0
0
none
none
none
0
[ "none" ]
null
null
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly. Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did. The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types: 1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter. All words consist only of lowercase English letters. The total length of all words does not exceed 105. It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
[ "5\n! abc\n. ad\n. b\n! cd\n? c\n", "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n", "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n" ]
[ "1\n", "2\n", "0\n" ]
In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock. In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis. In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
0
[ { "input": "5\n! abc\n. ad\n. b\n! cd\n? c", "output": "1" }, { "input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e", "output": "2" }, { "input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h", "output": "0" }, { "input": "4\n! abcd\n! cdef\n? d\n? c", "output": "0" }, { "input": "1\n? q", "output": "0" }, { "input": "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q", "output": "2" }, { "input": "3\n. abcdefghijklmnopqrstuvwxy\n? a\n? z", "output": "1" }, { "input": "3\n. abcdefghijklmnopqrstuvwxy\n! z\n? z", "output": "1" } ]
1,514,044,549
6,649
Python 3
WRONG_ANSWER
PRETESTS
6
62
5,939,200
n = int(input()) lst = [] for x in range(n): (s, w) = map(str, input().split()) lst.append((s, w)) k = 0 true = set() flag = False FLAG = True array = set() for (s, w) in lst: #print((s, w), true, k, flag) if len(true) == 1: flag = True if flag: if s != '.' and not w in true: k += 1 else: if s == '!': if FLAG: for x in w: if not x in array: true.add(x) FLAG = False else: p = set() for x in w: if x in true: p.add(x) true = set() for x in p: true.add(x) elif s == '.': for x in w: array.add(x) if x in true: true.remove(x) print(k)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly. Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did. The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types: 1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter. All words consist only of lowercase English letters. The total length of all words does not exceed 105. It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter. Output Specification: Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. Demo Input: ['5\n! abc\n. ad\n. b\n! cd\n? c\n', '8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n', '7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock. In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis. In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
```python n = int(input()) lst = [] for x in range(n): (s, w) = map(str, input().split()) lst.append((s, w)) k = 0 true = set() flag = False FLAG = True array = set() for (s, w) in lst: #print((s, w), true, k, flag) if len(true) == 1: flag = True if flag: if s != '.' and not w in true: k += 1 else: if s == '!': if FLAG: for x in w: if not x in array: true.add(x) FLAG = False else: p = set() for x in w: if x in true: p.add(x) true = set() for x in p: true.add(x) elif s == '.': for x in w: array.add(x) if x in true: true.remove(x) print(k) ```
0
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "output": "11 13" }, { "input": "17", "output": "8 9" }, { "input": "10", "output": "3 7" }, { "input": "69", "output": "34 35" }, { "input": "100", "output": "49 51" }, { "input": "57", "output": "28 29" }, { "input": "1000", "output": "499 501" }, { "input": "999", "output": "499 500" }, { "input": "998", "output": "497 501" }, { "input": "997", "output": "498 499" }, { "input": "996", "output": "497 499" }, { "input": "995", "output": "497 498" }, { "input": "994", "output": "495 499" }, { "input": "5", "output": "2 3" }, { "input": "6", "output": "1 5" }, { "input": "8", "output": "3 5" }, { "input": "9", "output": "4 5" }, { "input": "423", "output": "211 212" }, { "input": "876", "output": "437 439" }, { "input": "29", "output": "14 15" } ]
1,541,593,894
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
def checkCoPrime(nomi,denomi): if((denomi/nomi)%2==0 or (denomi/nomi)%2==1): return 0 else: return 1 sumN=int(input()) maxNomi=sumN//2 storeNomi=0 storeDenomi=0 for i in range(1,(maxNomi)): denomi=sumN-i if(i==1): storeNomi=i storeDenomi=denomi else: if(checkCoPrime(i,denomi)==1): if((i/denomi)>(storeNomi/storeDenomi)): storeNomi=i storeDenomi=denomi else: continue string=str(storeNomi)+' '+str(storeDenomi) print(string)
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1). During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. Input Specification: In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. Output Specification: Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. Demo Input: ['3\n', '4\n', '12\n'] Demo Output: ['1 2\n', '1 3\n', '5 7\n'] Note: none
```python def checkCoPrime(nomi,denomi): if((denomi/nomi)%2==0 or (denomi/nomi)%2==1): return 0 else: return 1 sumN=int(input()) maxNomi=sumN//2 storeNomi=0 storeDenomi=0 for i in range(1,(maxNomi)): denomi=sumN-i if(i==1): storeNomi=i storeDenomi=denomi else: if(checkCoPrime(i,denomi)==1): if((i/denomi)>(storeNomi/storeDenomi)): storeNomi=i storeDenomi=denomi else: continue string=str(storeNomi)+' '+str(storeDenomi) print(string) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,684,675,917
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
s=input().split() #n,m,a=map(int, input().split()) n,m,a=int(s[0]),int(s[1]),int(s[2]) fsl=n/a if fsl!=int(fsl): fsl=int(fsl)+1 fsw=m/a if fsw!=int(fsw): fsw=int(fsw)+1 nfs=fsl*fsw print(nfs)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python s=input().split() #n,m,a=map(int, input().split()) n,m,a=int(s[0]),int(s[1]),int(s[2]) fsl=n/a if fsl!=int(fsl): fsl=int(fsl)+1 fsw=m/a if fsw!=int(fsw): fsw=int(fsw)+1 nfs=fsl*fsw print(nfs) ```
0
349
B
Color the Fence
PROGRAMMING
1,700
[ "data structures", "dp", "greedy", "implementation" ]
null
null
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence.
The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105).
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
[ "5\n5 4 3 2 1 2 3 4 5\n", "2\n9 11 1 12 5 8 9 10 6\n", "0\n1 1 1 1 1 1 1 1 1\n" ]
[ "55555\n", "33\n", "-1\n" ]
none
1,000
[ { "input": "5\n5 4 3 2 1 2 3 4 5", "output": "55555" }, { "input": "2\n9 11 1 12 5 8 9 10 6", "output": "33" }, { "input": "0\n1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "50\n5 3 10 2 2 4 3 6 5", "output": "5555555555555555555555555" }, { "input": "22\n405 343 489 474 385 23 100 94 276", "output": "-1" }, { "input": "62800\n867 936 2 888 474 530 287 822 220", "output": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..." }, { "input": "27\n836 637 966 929 82 678 213 465 688", "output": "-1" }, { "input": "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000", "output": "9999999999" }, { "input": "898207\n99745 99746 99748 99752 99760 99776 99808 99872 100000", "output": "987654321" }, { "input": "80910\n64537 83748 97081 82722 12334 3056 9491 59130 28478", "output": "66666666666666666666666666" }, { "input": "120081\n11268 36403 73200 12674 83919 74218 74172 91581 68432", "output": "4444411111" }, { "input": "839851\n29926 55862 57907 51153 56350 86145 1909 22622 89861", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "751233\n69761 51826 91095 73642 98995 93262 377 38818 97480", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "306978\n95955 99204 81786 41258 96065 46946 64532 36297 70808", "output": "88888888" }, { "input": "366313\n18486 12701 92334 95391 61480 14118 20465 69784 13592", "output": "9999999999922222222222222222" }, { "input": "320671\n95788 46450 97582 95928 47742 15508 10466 10301 38822", "output": "8888888888888888888888888888888" }, { "input": "913928\n80373 47589 53204 68236 44060 97485 82241 44149 59825", "output": "99888888888888855555" }, { "input": "630384\n19652 11530 20316 3161 87360 64207 74067 77894 81452", "output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "95\n22076 12056 63350 12443 43123 585 52908 18372 96799", "output": "-1" }, { "input": "271380\n19135 80309 23783 48534 98990 37278 85258 67602 40288", "output": "11111111111111" }, { "input": "80085\n56973 29725 30219 17439 53162 6051 41388 35555 39392", "output": "6666666666666" }, { "input": "201332\n20008 22829 30296 1967 32154 67760 11437 90972 79865", "output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "3402\n64151 98148 81468 82342 48823 93464 5989 58868 77138", "output": "-1" }, { "input": "432544\n95724 98294 23292 24174 57778 95072 81898 50019 86824", "output": "444444444444444333" }, { "input": "1000000\n1 1 1 1 1 1 1 1 1", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "1000000\n2 2 2 2 2 2 2 2 2", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "1000000\n2 3 2 2 3 2 2 3 2", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..." }, { "input": "999999\n2 3 2 2 3 2 2 3 3", "output": "9777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..." }, { "input": "153\n85 91 28 53 29 30 92 36 89", "output": "86653" }, { "input": "26531\n64 93 48 49 86 57 93 60 96", "output": "8864433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..." }, { "input": "17186\n50 90 76 51 91 54 71 90 73", "output": "9666411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, { "input": "11213\n51 82 49 50 99 52 69 96 85", "output": "964433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "20075\n57 42 99 45 56 80 76 71 63", "output": "954422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "21069\n31 19 49 30 28 43 21 25 28", "output": "9872222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222..." }, { "input": "4822\n35 36 21 13 34 36 14 16 20", "output": "9877444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" } ]
1,627,478,717
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
6,963,200
v=int(input()) a=list(map(int,input().split())) d = 8 p = a[8] for i in range(8,-1,-1): if a[i] < p: d = i p = a[i] d = d+1 l = v//d if v < p: print(-1) else: v = v%p ans = [str(d)]*l i = 0 j = 8 while not (i == l or j == d-2 or v==0): if a[j] <= v+p: ans[i] = str(j+1) i = i+1 v = v + p - a[j] else: j = j-1 print(''.join(ans))
Title: Color the Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number. Help Igor find the maximum number he can write on the fence. Input Specification: The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). Output Specification: Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. Demo Input: ['5\n5 4 3 2 1 2 3 4 5\n', '2\n9 11 1 12 5 8 9 10 6\n', '0\n1 1 1 1 1 1 1 1 1\n'] Demo Output: ['55555\n', '33\n', '-1\n'] Note: none
```python v=int(input()) a=list(map(int,input().split())) d = 8 p = a[8] for i in range(8,-1,-1): if a[i] < p: d = i p = a[i] d = d+1 l = v//d if v < p: print(-1) else: v = v%p ans = [str(d)]*l i = 0 j = 8 while not (i == l or j == d-2 or v==0): if a[j] <= v+p: ans[i] = str(j+1) i = i+1 v = v + p - a[j] else: j = j-1 print(''.join(ans)) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output": "2" }, { "input": "4\n75 13 94 77", "output": "3" }, { "input": "4\n97 8 27 3", "output": "2" }, { "input": "10\n95 51 12 91 85 3 1 31 25 7", "output": "3" }, { "input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46", "output": "4" }, { "input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36", "output": "26" }, { "input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83", "output": "48" }, { "input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25", "output": "1" }, { "input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46", "output": "25" }, { "input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73", "output": "13" }, { "input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76", "output": "99" }, { "input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14", "output": "1" }, { "input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22", "output": "93" }, { "input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23", "output": "1" }, { "input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98", "output": "1" }, { "input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94", "output": "93" }, { "input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29", "output": "32" }, { "input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47", "output": "26" }, { "input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72", "output": "56" }, { "input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86", "output": "97" }, { "input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42", "output": "79" }, { "input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52", "output": "25" }, { "input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86", "output": "78" }, { "input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68", "output": "70" }, { "input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81", "output": "39" }, { "input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83", "output": "88" }, { "input": "3\n100 100 1", "output": "3" } ]
1,621,336,517
2,147,483,647
Python 3
OK
TESTS
32
124
0
n = int(input()) a = list(map(int, input().split())) lista = [] lista1 = [] for x in range(len(a)): if a[x] % 2 == 0: lista.append(x+1) else: lista1.append(x+1) if len(lista) == 1: print(lista[0]) if len(lista1) == 1: print(lista1[0])
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n = int(input()) a = list(map(int, input().split())) lista = [] lista1 = [] for x in range(len(a)): if a[x] % 2 == 0: lista.append(x+1) else: lista1.append(x+1) if len(lista) == 1: print(lista[0]) if len(lista1) == 1: print(lista1[0]) ```
3.969
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,662,141,049
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
8,806,400
N = int(input()) s = input() while ('10' in s) or ('01' in s): s = s.replace('10', '', 1) s = s.replace('01', '', 1) print(len(s))
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()) s = input() while ('10' in s) or ('01' in s): s = s.replace('10', '', 1) s = s.replace('01', '', 1) print(len(s)) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,686,673,102
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n,m,a=map(int,input().split()) print(n, m, a)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python n,m,a=map(int,input().split()) print(n, m, a) ```
0
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", "output": "9" }, { "input": "10\n10 5 8 9 5 6 8 7 2 8", "output": "46" }, { "input": "10\n1 1 1 1 1 1 2 3 4 4", "output": "14" }, { "input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4", "output": "296" }, { "input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2", "output": "313" }, { "input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9", "output": "298" }, { "input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5", "output": "312" }, { "input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2", "output": "287" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2", "output": "265" }, { "input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9", "output": "328" }, { "input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9", "output": "324" }, { "input": "10\n7 4 5 3 9 1 10 3 4 5", "output": "34" }, { "input": "10\n8 9 6 5 6 4 10 9 1 4", "output": "39" }, { "input": "10\n1 7 1 4 9 10 8 2 9 9", "output": "40" }, { "input": "1\n100000", "output": "100000" } ]
1,668,867,258
2,147,483,647
Python 3
OK
TESTS
47
202
7,065,600
n = int(input()) li = [int(a) for a in input().split()] x = max(li) lis = [0]*(x) for i in li: lis[i-1] += 1 ans = [] for i in range(x): a = lis[i]*(i+1) ans.append(a) dp = [0]*x dp[0] = ans[0] dp[1] = max(ans[1],ans[0]) if x<=2: print(max(dp)) if x>2: for i in range(2,x): dp[i] = max(dp[i-1],dp[i-2]+ans[i]) print(max(dp))
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a single integer — the maximum number of points that Alex can earn. Demo Input: ['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n'] Demo Output: ['2\n', '4\n', '10\n'] Note: Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
```python n = int(input()) li = [int(a) for a in input().split()] x = max(li) lis = [0]*(x) for i in li: lis[i-1] += 1 ans = [] for i in range(x): a = lis[i]*(i+1) ans.append(a) dp = [0]*x dp[0] = ans[0] dp[1] = max(ans[1],ans[0]) if x<=2: print(max(dp)) if x>2: for i in range(2,x): dp[i] = max(dp[i-1],dp[i-2]+ans[i]) print(max(dp)) ```
3
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "input": "2 2\n20 10", "output": "1" }, { "input": "2 1\n20 1", "output": "2" }, { "input": "3 1\n1 2 3", "output": "1" }, { "input": "3 1\n2 1 3", "output": "2" }, { "input": "3 1\n3 2 1", "output": "3" }, { "input": "3 2\n1 2 3", "output": "1" }, { "input": "3 2\n3 2 1", "output": "2" }, { "input": "3 3\n1 2 3", "output": "1" }, { "input": "4 2\n9 8 11 7", "output": "1" }, { "input": "4 2\n10 1 2 3", "output": "2" }, { "input": "6 3\n56 56 56 2 1 2", "output": "4" }, { "input": "8 3\n1 1 1 1 2 60 90 1", "output": "1" }, { "input": "4 1\n1 5 2 2", "output": "1" }, { "input": "4 2\n4 6 7 4", "output": "1" }, { "input": "10 4\n1 1 1 4 4 4 4 4 4 3", "output": "1" }, { "input": "6 3\n1 2 1 3 1 1", "output": "1" }, { "input": "5 2\n100 100 100 1 1", "output": "4" } ]
1,677,878,297
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
a = list(map(int,input().split(" "))) b = list(map(int,input().split(" "))) n = a[0] k = a[1] f = [0 for i in range(a[0])] f[0]=b[0] for j in range(1,a[0]): f[j]=f[j-1]+b[j] minm = f[k-1] for i in range(k,n): if minm > f[j] - f[j-k]: minm = f[j] - f[j-k] print(f.index(minm)+1)
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). Input Specification: The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. Output Specification: Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. Demo Input: ['7 3\n1 2 6 1 1 7 1\n'] Demo Output: ['3\n'] Note: In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
```python a = list(map(int,input().split(" "))) b = list(map(int,input().split(" "))) n = a[0] k = a[1] f = [0 for i in range(a[0])] f[0]=b[0] for j in range(1,a[0]): f[j]=f[j-1]+b[j] minm = f[k-1] for i in range(k,n): if minm > f[j] - f[j-k]: minm = f[j] - f[j-k] print(f.index(minm)+1) ```
0
764
B
Timofey and cubes
PROGRAMMING
900
[ "constructive algorithms", "implementation" ]
null
null
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1. After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
[ "7\n4 3 7 6 9 1 2\n", "8\n6 1 4 2 5 6 9 2\n" ]
[ "2 3 9 6 7 1 4", "2 1 6 2 5 4 9 6" ]
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
1,000
[ { "input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4" }, { "input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6" }, { "input": "1\n1424", "output": "1424" }, { "input": "9\n-7 9 -4 9 -6 11 15 2 -10", "output": "-10 9 15 9 -6 11 -4 2 -7" }, { "input": "2\n21968 5686", "output": "5686 21968" }, { "input": "5\n241218936 -825949895 -84926813 491336344 -872198236", "output": "-872198236 -825949895 -84926813 491336344 241218936" }, { "input": "42\n-557774624 828320986 -345782722 -62979938 -681259411 -945983652 -139095040 832293378 -82572118 432027535 88438103 568183540 961782904 73543295 615958219 -5050584 322982437 -146046730 759453379 129267920 -819827396 -348156048 805080102 390723009 -771277251 -79011872 -592313207 528489973 656201270 -127795621 17284747 145139617 -565641608 83452176 -223074608 545811186 -657981923 -204657836 154779765 -476867246 180386291 202782486", "output": "202782486 828320986 -476867246 -62979938 -204657836 -945983652 545811186 832293378 83452176 432027535 145139617 568183540 -127795621 73543295 528489973 -5050584 -79011872 -146046730 390723009 129267920 -348156048 -819827396 805080102 759453379 -771277251 322982437 -592313207 615958219 656201270 961782904 17284747 88438103 -565641608 -82572118 -223074608 -139095040 -657981923 -681259411 154779765 -345782722 180386291 -557774624" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "6\n1 2 3 4 5 6", "output": "6 2 4 3 5 1" }, { "input": "4\n0 1 2 3", "output": "3 1 2 0" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10 2 8 4 6 5 7 3 9 1" }, { "input": "2\n4 5", "output": "5 4" }, { "input": "2\n1 5", "output": "5 1" }, { "input": "2\n2 5", "output": "5 2" }, { "input": "2\n3 4", "output": "4 3" }, { "input": "2\n10 0", "output": "0 10" }, { "input": "66\n8229 5299 5562 1259 2258 1126 5026 8796 3497 7111 6680 1180 1426 4821 3322 3502 400 2951 4187 417 5234 1266 7525 7648 417 9297 174 670 1790 4121 9737 938 4616 3402 2009 2461 474 3728 327 3353 9773 6818 8781 874 2209 1260 1647 6126 9287 9638 5049 1256 4459 863 1835 4822 6809 348 5053 7784 6927 2140 9173 7817 5095 4184", "output": "4184 5299 7817 1259 2140 1126 7784 8796 348 7111 4822 1180 863 4821 1256 3502 9638 2951 6126 417 1260 1266 874 7648 6818 9297 3353 670 3728 4121 2461 938 3402 4616 2009 9737 474 1790 327 174 9773 417 8781 7525 2209 5234 1647 4187 9287 400 5049 3322 4459 1426 1835 6680 6809 3497 5053 5026 6927 2258 9173 5562 5095 8229" } ]
1,661,945,698
2,147,483,647
Python 3
OK
TESTS
34
358
18,329,600
import math import sys from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n: return "YES" else: return "NO" def fn(arr,n): for i in range(0,n//2,2): arr[i],arr[n-i-1]=arr[n-i-1],arr[i] return arr def main(): n=int(inp()) arr=lis() print(*fn(arr,n)) if __name__=="__main__": main()
Title: Timofey and cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1. After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. Output Specification: Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique. Demo Input: ['7\n4 3 7 6 9 1 2\n', '8\n6 1 4 2 5 6 9 2\n'] Demo Output: ['2 3 9 6 7 1 4', '2 1 6 2 5 4 9 6'] Note: Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
```python import math import sys from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n: return "YES" else: return "NO" def fn(arr,n): for i in range(0,n//2,2): arr[i],arr[n-i-1]=arr[n-i-1],arr[i] return arr def main(): n=int(inp()) arr=lis() print(*fn(arr,n)) if __name__=="__main__": main() ```
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,572,545,776
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
0
l=[];m=dict() for _ in range(int(input())): l.append(input()) for i in set(l): m[i]=l.count(i) print(max(m))
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python l=[];m=dict() for _ in range(int(input())): l.append(input()) for i in set(l): m[i]=l.count(i) print(max(m)) ```
0
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased. You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars. As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses. It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars.
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away.
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "output": "20" }, { "input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20", "output": "10" }, { "input": "7 5 1\n0 100 2 2 0 2 1", "output": "20" }, { "input": "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "10" }, { "input": "100 50 1\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 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "490" }, { "input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0", "output": "10" }, { "input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0", "output": "980" }, { "input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 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": "10" }, { "input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98", "output": "890" }, { "input": "7 4 5\n1 0 6 0 5 6 0", "output": "10" }, { "input": "7 4 5\n1 6 5 0 0 6 0", "output": "10" }, { "input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0", "output": "90" }, { "input": "2 1 100\n0 1", "output": "10" }, { "input": "2 2 100\n1 0", "output": "10" }, { "input": "10 1 88\n0 95 0 0 0 0 0 94 0 85", "output": "90" }, { "input": "10 2 14\n2 0 1 26 77 39 41 100 13 32", "output": "10" }, { "input": "10 3 11\n0 0 0 0 0 62 0 52 1 35", "output": "60" }, { "input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88", "output": "10" }, { "input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82", "output": "70" }, { "input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1", "output": "180" }, { "input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0", "output": "210" }, { "input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37", "output": "80" }, { "input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77", "output": "190" }, { "input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84", "output": "190" }, { "input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15", "output": "580" }, { "input": "97 44 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 51 19", "output": "520" }, { "input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67", "output": "490" }, { "input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23", "output": "890" }, { "input": "100 1 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 91 70 14", "output": "970" }, { "input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10", "output": "990" }, { "input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10", "output": "490" }, { "input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2", "output": "500" }, { "input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20", "output": "50" }, { "input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0", "output": "990" }, { "input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0", "output": "10" }, { "input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51", "output": "140" }, { "input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4", "output": "390" }, { "input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68", "output": "130" }, { "input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59", "output": "10" }, { "input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32", "output": "10" }, { "input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98", "output": "160" }, { "input": "5 2 20\n27 0 32 21 19", "output": "30" }, { "input": "6 4 10\n10 0 0 0 0 10", "output": "20" }, { "input": "8 7 100\n1 0 0 0 0 0 0 1", "output": "10" }, { "input": "5 3 20\n1 21 0 0 1", "output": "20" }, { "input": "4 3 1\n0 0 0 1", "output": "10" }, { "input": "5 2 3\n4 0 5 6 1", "output": "30" }, { "input": "5 3 87\n88 89 0 1 90", "output": "10" }, { "input": "5 3 20\n15 30 0 15 35", "output": "10" }, { "input": "6 3 50\n0 0 0 1 2 0", "output": "10" }, { "input": "6 4 9\n100 9 10 0 0 9", "output": "20" }, { "input": "5 4 20\n0 20 0 0 20", "output": "10" }, { "input": "6 3 3\n1 5 0 2 2 0", "output": "10" }, { "input": "5 4 100\n0 1 0 0 1", "output": "10" } ]
1,583,659,565
2,147,483,647
Python 3
OK
TESTS
58
109
307,200
n, m, k = map(int, input().split()) a = list(map(int, input().split())) ans = 10 ** 10 for i in range(n): if a[i] != 0 and a[i] <= k: ans = min(ans, abs(i - (m - 1)) * 10) print(ans)
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=&lt;<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased. You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars. As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. Input Specification: The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses. It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. Output Specification: Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. Demo Input: ['5 1 20\n0 27 32 21 19\n', '7 3 50\n62 0 0 0 99 33 22\n', '10 5 100\n1 0 1 0 0 0 0 0 1 1\n'] Demo Output: ['40', '30', '20'] Note: In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away.
```python n, m, k = map(int, input().split()) a = list(map(int, input().split())) ans = 10 ** 10 for i in range(n): if a[i] != 0 and a[i] <= k: ans = min(ans, abs(i - (m - 1)) * 10) print(ans) ```
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "output": "840" }, { "input": "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "output": "922" }, { "input": "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "output": "674" }, { "input": "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "output": "848" }, { "input": "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "output": "902" }, { "input": "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "output": "798" }, { "input": "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "output": "632" }, { "input": "1\n4", "output": "4" }, { "input": "2\n1 4", "output": "4" }, { "input": "3\n1 2 4", "output": "6" }, { "input": "2\n9 3", "output": "12" }, { "input": "2\n1000000000 1001", "output": "1000000000" }, { "input": "3\n1 8 4", "output": "12" }, { "input": "3\n7 4 4", "output": "8" }, { "input": "5\n2 3 4 5 3", "output": "14" }, { "input": "2\n4 5", "output": "4" }, { "input": "3\n2 4 5", "output": "6" }, { "input": "3\n2 2 3", "output": "4" }, { "input": "2\n2 3", "output": "2" }, { "input": "4\n2 3 7 7", "output": "16" }, { "input": "2\n999999999 2", "output": "2" }, { "input": "2\n2 5", "output": "2" }, { "input": "3\n5 3 1", "output": "8" }, { "input": "4\n3 2 5 7", "output": "14" } ]
1,560,674,862
2,147,483,647
Python 3
OK
TESTS
87
187
8,499,200
# import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("out.out",'w') n=int(input()) a=list(map(int,input().split())) s=sum(a) if s%2==0: print(s) else: o=[] for i in range(n): if a[i]%2!=0: o.append(a[i]) o.sort() s-=o[0] print(s)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. Input Specification: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. Output Specification: Print the maximum possible even sum that can be obtained if we use some of the given integers. Demo Input: ['3\n1 2 3\n', '5\n999999999 999999999 999999999 999999999 999999999\n'] Demo Output: ['6', '3999999996'] Note: In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
```python # import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("out.out",'w') n=int(input()) a=list(map(int,input().split())) s=sum(a) if s%2==0: print(s) else: o=[] for i in range(n): if a[i]%2!=0: o.append(a[i]) o.sort() s-=o[0] print(s) ```
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,591,824,558
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
def main(): n,k = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) b.sort(reverse = True) for x in b: if k % x == 0 print (k // num) return main()
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 def main(): n,k = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) b.sort(reverse = True) for x in b: if k % x == 0 print (k // num) return main() ```
-1
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above.
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { "input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543", "output": "NO" }, { "input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869", "output": "YES" }, { "input": "3\n408 410 409", "output": "YES" }, { "input": "3\n903 902 904", "output": "YES" }, { "input": "3\n399 400 398", "output": "YES" }, { "input": "3\n450 448 449", "output": "YES" }, { "input": "3\n390 389 388", "output": "YES" }, { "input": "3\n438 439 440", "output": "YES" }, { "input": "11\n488 688 490 94 564 615 641 170 489 517 669", "output": "YES" }, { "input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954", "output": "YES" }, { "input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318", "output": "YES" }, { "input": "6\n10 79 306 334 304 305", "output": "YES" }, { "input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365", "output": "YES" }, { "input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73", "output": "YES" }, { "input": "11\n325 325 324 324 324 325 325 324 324 324 324", "output": "NO" }, { "input": "7\n517 517 518 517 518 518 518", "output": "NO" }, { "input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710", "output": "NO" }, { "input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29", "output": "NO" }, { "input": "7\n880 880 514 536 881 881 879", "output": "YES" }, { "input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375", "output": "YES" }, { "input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404", "output": "YES" }, { "input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987", "output": "YES" }, { "input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116", "output": "NO" }, { "input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995", "output": "NO" }, { "input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22", "output": "YES" }, { "input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952", "output": "YES" }, { "input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "3\n500 999 1000", "output": "NO" }, { "input": "10\n101 102 104 105 107 109 110 112 113 115", "output": "NO" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "output": "NO" }, { "input": "3\n1000 999 998", "output": "YES" }, { "input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456", "output": "NO" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3", "output": "YES" }, { "input": "3\n999 999 1000", "output": "NO" }, { "input": "9\n2 4 5 13 25 100 200 300 400", "output": "NO" }, { "input": "9\n1 1 1 2 2 2 3 3 3", "output": "YES" }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n998 999 1000", "output": "YES" }, { "input": "12\n1 1 1 1 1 1 1 1 1 2 2 4", "output": "NO" }, { "input": "4\n4 3 4 5", "output": "YES" }, { "input": "6\n1 1 1 2 2 2", "output": "NO" }, { "input": "3\n2 3 2", "output": "NO" }, { "input": "5\n10 5 6 3 2", "output": "NO" }, { "input": "3\n1 2 1", "output": "NO" }, { "input": "3\n1 2 3", "output": "YES" }, { "input": "4\n998 999 1000 1000", "output": "YES" }, { "input": "5\n2 3 9 9 4", "output": "YES" }, { "input": "4\n1 2 4 4", "output": "NO" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n2 2 3", "output": "NO" }, { "input": "7\n1 2 2 2 4 5 6", "output": "YES" }, { "input": "5\n1 3 10 3 10", "output": "NO" }, { "input": "3\n1 2 2", "output": "NO" }, { "input": "4\n1000 1000 999 998", "output": "YES" }, { "input": "3\n5 3 7", "output": "NO" }, { "input": "6\n1 1 2 2 3 3", "output": "YES" }, { "input": "9\n6 6 6 5 5 5 4 4 4", "output": "YES" }, { "input": "7\n5 6 6 6 7 7 7", "output": "YES" }, { "input": "5\n2 3 3 3 4", "output": "YES" }, { "input": "5\n2 1 2 1 3", "output": "YES" }, { "input": "3\n1 2 7", "output": "NO" }, { "input": "3\n1000 1000 1000", "output": "NO" }, { "input": "5\n1 100 2 100 3", "output": "YES" }, { "input": "5\n5 4 6 5 5", "output": "YES" }, { "input": "12\n1 1 1 1 2 2 2 2 3 3 3 3", "output": "YES" }, { "input": "5\n9 9 1 2 3", "output": "YES" }, { "input": "6\n1 2 3 1 2 3", "output": "YES" }, { "input": "7\n1 1 1 1 2 3 3", "output": "YES" }, { "input": "3\n13 13 13", "output": "NO" }, { "input": "3\n42 42 42", "output": "NO" }, { "input": "8\n1 1 1 1 2 2 2 2", "output": "NO" }, { "input": "6\n1 1 1 1 2 3", "output": "YES" }, { "input": "6\n1 1 2 2 6 6", "output": "NO" }, { "input": "6\n1 2 5 5 5 5", "output": "NO" }, { "input": "9\n1 2 3 1 2 3 1 2 3", "output": "YES" }, { "input": "4\n1 2 1 100", "output": "NO" }, { "input": "5\n1 1 2 2 3", "output": "YES" } ]
1,599,447,062
2,147,483,647
PyPy 3
OK
TESTS
84
156
1,331,200
n = int(input()) l = list(map(int,input().split())) l.sort() for i in range(len(l)): for j in range(i,len(l)): if l[j] - l[i] == 1: for k in range(j,len(l)): if l[k] - l[j] == 1: print("YES") exit(0) print("NO")
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above. Input Specification: The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. Output Specification: Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). Demo Input: ['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose balls: 1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971.
```python n = int(input()) l = list(map(int,input().split())) l.sort() for i in range(len(l)): for j in range(i,len(l)): if l[j] - l[i] == 1: for k in range(j,len(l)): if l[k] - l[j] == 1: print("YES") exit(0) print("NO") ```
3
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" }, { "input": "999", "output": "9" }, { "input": "100", "output": "5" }, { "input": "123", "output": "6" }, { "input": "8", "output": "8" }, { "input": "157", "output": "3" }, { "input": "289", "output": "1" }, { "input": "179", "output": "4" }, { "input": "942", "output": "0" }, { "input": "879", "output": "9" }, { "input": "394", "output": "1" }, { "input": "423", "output": "7" }, { "input": "952", "output": "3" }, { "input": "121", "output": "5" }, { "input": "613", "output": "2" }, { "input": "945", "output": "1" }, { "input": "270", "output": "6" }, { "input": "781", "output": "2" }, { "input": "453", "output": "7" }, { "input": "171", "output": "0" }, { "input": "643", "output": "2" }, { "input": "570", "output": "6" }, { "input": "750", "output": "6" }, { "input": "500", "output": "0" }, { "input": "2", "output": "2" }, { "input": "1", "output": "1" }, { "input": "108", "output": "5" }, { "input": "500", "output": "0" }, { "input": "189", "output": "9" }, { "input": "491", "output": "0" }, { "input": "191", "output": "0" } ]
1,547,725,089
2,147,483,647
Python 3
OK
TESTS
37
109
0
a='1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000' b=int(input()) print(a[b-1])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1. Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. Output Specification: Print the *n*-th digit of the line. Demo Input: ['3\n', '11\n'] Demo Output: ['3\n', '0\n'] Note: In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
```python a='1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000' b=int(input()) print(a[b-1]) ```
3
644
B
Processing Queries
PROGRAMMING
1,700
[ "*special", "constructive algorithms", "data structures", "two pointers" ]
null
null
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed. As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears. For each query find the moment when the server will finish to process it or print -1 if this query will be rejected.
The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue. Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=&lt;<=*t**i* for all *i*<=&gt;<=1.
Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected.
[ "5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n", "4 1\n2 8\n4 8\n10 9\n15 2\n" ]
[ "11 19 -1 21 22 \n", "10 18 27 -1 \n" ]
Consider the first sample. 1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22.
1,000
[ { "input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1", "output": "11 19 -1 21 22 " }, { "input": "4 1\n2 8\n4 8\n10 9\n15 2", "output": "10 18 27 -1 " }, { "input": "1 1\n1000000000 1000000000", "output": "2000000000 " }, { "input": "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000", "output": "1999999996 2999999996 3999999996 4999999996 " }, { "input": "5 1\n2 1\n3 6\n4 5\n6 4\n7 2", "output": "3 9 14 -1 -1 " }, { "input": "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2", "output": "18 20 26 -1 -1 -1 -1 -1 -1 28 " }, { "input": "6 4\n2 4\n4 2\n5 2\n6 2\n7 2\n9 2", "output": "6 8 10 12 14 16 " }, { "input": "8 3\n1 2\n3 1\n4 3\n5 3\n6 1\n7 2\n8 8\n9 7", "output": "3 4 7 10 11 13 21 -1 " }, { "input": "10 3\n1 14\n3 2\n5 4\n6 9\n9 1\n12 22\n15 11\n18 8\n28 2\n29 4", "output": "15 17 21 30 -1 -1 41 49 51 -1 " }, { "input": "5 2\n2 7\n3 3\n7 4\n9 1\n10 2", "output": "9 12 16 17 -1 " }, { "input": "4 1\n2 1\n6 5\n9 2\n10 3", "output": "3 11 13 -1 " }, { "input": "4 1\n1 2\n2 1\n3 1\n4 3", "output": "3 4 5 8 " }, { "input": "6 3\n1 2\n2 3\n100 200\n200 300\n10000 20000\n20000 30000", "output": "3 6 300 600 30000 60000 " } ]
1,458,142,693
23,893
Python 3
COMPILATION_ERROR
PRETESTS
0
0
0
#include <bits/stdc++.h> #include <tr1/unordered_map> typedef long long ll; typedef unsigned long long ull; #define clr(ma) memset(ma,-1,sizeof ma) #define inf 30000000; #define vi vector<int> #define pi pair<int,int> #define T2 pair<pi ,pi > #define mk make_pair #define getBit(m,i) ((m&(1<<i))==(1<<i)) #define setBit(m,i) (m|(1<<i)) #define setBit2(m,i) (m|(1ull<<i)) #define cont(i,ma) ((ma.find(i))!=(ma.end())) #define in(i) scanf("%d",&i) #define in2(i,j) scanf("%d%d",&i,&j) #define in3(i,j,k) scanf("%d%d%d",&i,&j,&k) #define in4(i,j,k,l) scanf("%d%d%d%d",&i,&j,&k,&l) #define il(i) scanf("%I64d",&i) #define itr map<ll,ll>::iterator #define itr2 map<ll,map<ll,ll> >::iterator #define id(k) scanf("%9lf",&k) #define fi(ss) freopen (ss,"r",stdin) #define fo(ss) freopen (ss,"w",stdout) #define clean(vis) memset(vis,0,sizeof vis) using namespace std; int t [200000+10]; int d[200000+10]; int n,b; int state; int pos; queue<int> q; ll res[200000+10]; ll ct; int main(){ in2(n,b); for(int i=0;i<n;i++)in2(t[i],d[i]); state=1; pos=0; ct=0; while(1){ if (state==1){ if (q.empty() && pos>=n)break; if (q.empty()){ res[pos]=t[pos]+d[pos]; ct=t[pos]+d[pos]; pos++; } else{ int v=q.front(); q.pop(); res[v]=ct+d[v]; if (pos<n && t[pos]==ct){ q.push(pos++); } ct=ct+d[v]; } state=2; } else{ while (pos<n && t[pos]<ct){ if (q.size()<b)q.push(pos); else res[pos]=-1; pos++; } state=1; } } for (int i=0;i<n;i++)cout<<res[i]<<" "; }
Title: Processing Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed. As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears. For each query find the moment when the server will finish to process it or print -1 if this query will be rejected. Input Specification: The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue. Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=&lt;<=*t**i* for all *i*<=&gt;<=1. Output Specification: Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. Demo Input: ['5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n', '4 1\n2 8\n4 8\n10 9\n15 2\n'] Demo Output: ['11 19 -1 21 22 \n', '10 18 27 -1 \n'] Note: Consider the first sample. 1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22.
```python #include <bits/stdc++.h> #include <tr1/unordered_map> typedef long long ll; typedef unsigned long long ull; #define clr(ma) memset(ma,-1,sizeof ma) #define inf 30000000; #define vi vector<int> #define pi pair<int,int> #define T2 pair<pi ,pi > #define mk make_pair #define getBit(m,i) ((m&(1<<i))==(1<<i)) #define setBit(m,i) (m|(1<<i)) #define setBit2(m,i) (m|(1ull<<i)) #define cont(i,ma) ((ma.find(i))!=(ma.end())) #define in(i) scanf("%d",&i) #define in2(i,j) scanf("%d%d",&i,&j) #define in3(i,j,k) scanf("%d%d%d",&i,&j,&k) #define in4(i,j,k,l) scanf("%d%d%d%d",&i,&j,&k,&l) #define il(i) scanf("%I64d",&i) #define itr map<ll,ll>::iterator #define itr2 map<ll,map<ll,ll> >::iterator #define id(k) scanf("%9lf",&k) #define fi(ss) freopen (ss,"r",stdin) #define fo(ss) freopen (ss,"w",stdout) #define clean(vis) memset(vis,0,sizeof vis) using namespace std; int t [200000+10]; int d[200000+10]; int n,b; int state; int pos; queue<int> q; ll res[200000+10]; ll ct; int main(){ in2(n,b); for(int i=0;i<n;i++)in2(t[i],d[i]); state=1; pos=0; ct=0; while(1){ if (state==1){ if (q.empty() && pos>=n)break; if (q.empty()){ res[pos]=t[pos]+d[pos]; ct=t[pos]+d[pos]; pos++; } else{ int v=q.front(); q.pop(); res[v]=ct+d[v]; if (pos<n && t[pos]==ct){ q.push(pos++); } ct=ct+d[v]; } state=2; } else{ while (pos<n && t[pos]<ct){ if (q.size()<b)q.push(pos); else res[pos]=-1; pos++; } state=1; } } for (int i=0;i<n;i++)cout<<res[i]<<" "; } ```
-1
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,694,612,981
2,147,483,647
Python 3
OK
TESTS
83
46
0
#বিসমিল্লাহির রাহমানির রাহিম #بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ #Bismillahir Rahmanir Rahim #PROBLEM :A. Garden n,k=map(int,input().split()) l=list(map(int,input().split())) m=0 for i in l: if i>m and k%i==0: m=i print(k//m)
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 #বিসমিল্লাহির রাহমানির রাহিম #بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ #Bismillahir Rahmanir Rahim #PROBLEM :A. Garden n,k=map(int,input().split()) l=list(map(int,input().split())) m=0 for i in l: if i>m and k%i==0: m=i print(k//m) ```
3
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*.
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them.
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, { "input": "1 1000000000", "output": "NO" }, { "input": "999999999 1000000000", "output": "NO" }, { "input": "1 2", "output": "YES\n2\n1 2 " }, { "input": "1 536870912", "output": "YES\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 " }, { "input": "11111 11111111", "output": "YES\n4\n11111 111111 1111111 11111111 " }, { "input": "59139 946224", "output": "YES\n5\n59139 118278 236556 473112 946224 " }, { "input": "9859 19718", "output": "YES\n2\n9859 19718 " }, { "input": "25987 51974222", "output": "YES\n5\n25987 259871 2598711 25987111 51974222 " }, { "input": "9411 188222222", "output": "YES\n6\n9411 94111 941111 9411111 94111111 188222222 " }, { "input": "25539 510782222", "output": "YES\n6\n25539 255391 2553911 25539111 255391111 510782222 " }, { "input": "76259 610072", "output": "YES\n4\n76259 152518 305036 610072 " }, { "input": "92387 184774", "output": "YES\n2\n92387 184774 " }, { "input": "8515 85151111", "output": "YES\n5\n8515 85151 851511 8515111 85151111 " }, { "input": "91939 9193911", "output": "YES\n3\n91939 919391 9193911 " }, { "input": "30518 610361", "output": "YES\n3\n30518 61036 610361 " }, { "input": "46646 373168844", "output": "YES\n7\n46646 466461 932922 9329221 93292211 186584422 373168844 " }, { "input": "30070 300701", "output": "YES\n2\n30070 300701 " }, { "input": "13494 1079528", "output": "YES\n5\n13494 134941 269882 539764 1079528 " }, { "input": "96918 775344422", "output": "YES\n7\n96918 193836 1938361 3876722 38767221 387672211 775344422 " }, { "input": "13046 260921", "output": "YES\n3\n13046 26092 260921 " }, { "input": "29174 5834811", "output": "YES\n4\n29174 58348 583481 5834811 " }, { "input": "79894 319576421", "output": "YES\n6\n79894 798941 1597882 15978821 31957642 319576421 " }, { "input": "96022 1920442", "output": "YES\n3\n96022 960221 1920442 " }, { "input": "79446 6355681", "output": "YES\n5\n79446 158892 317784 635568 6355681 " }, { "input": "5440 27853056", "output": "YES\n11\n5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056 " }, { "input": "250000000 705032705", "output": "NO" }, { "input": "17 35", "output": "NO" }, { "input": "1 3", "output": "NO" }, { "input": "2 11", "output": "NO" } ]
1,672,862,350
70
Python 3
WRONG_ANSWER
TESTS
4
31
0
a = list(map(int, input().split())) first = a[0] second = a[1] flag = False list = [second] x = 1 while second > first and flag == False and second > 0: if second % 2 != 0: second = (second - 1) // 10 x +=1 list.append(second) if second % 2 == 0: second = second // 2 x += 1 list.append(second) if second == first: flag = True if flag == True: print("YES") print(x) print(*reversed(list)) else: print("NO")
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. Input Specification: The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. Output Specification: If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≤<=*k*). If there are multiple answers, print any of them. Demo Input: ['2 162\n', '4 42\n', '100 40021\n'] Demo Output: ['YES\n5\n2 4 8 81 162 \n', 'NO\n', 'YES\n5\n100 200 2001 4002 40021 \n'] Note: none
```python a = list(map(int, input().split())) first = a[0] second = a[1] flag = False list = [second] x = 1 while second > first and flag == False and second > 0: if second % 2 != 0: second = (second - 1) // 10 x +=1 list.append(second) if second % 2 == 0: second = second // 2 x += 1 list.append(second) if second == first: flag = True if flag == True: print("YES") print(x) print(*reversed(list)) else: print("NO") ```
0
268
B
Buttons
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock. Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
In a single line print the number of times Manao has to push a button in the worst-case scenario.
[ "2\n", "3\n" ]
[ "3\n", "7\n" ]
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
1,000
[ { "input": "2", "output": "3" }, { "input": "3", "output": "7" }, { "input": "4", "output": "14" }, { "input": "1", "output": "1" }, { "input": "10", "output": "175" }, { "input": "2000", "output": "1333335000" }, { "input": "1747", "output": "888644743" }, { "input": "889", "output": "117099969" }, { "input": "1999", "output": "1331335999" }, { "input": "914", "output": "127259419" }, { "input": "996", "output": "164675486" }, { "input": "17", "output": "833" }, { "input": "50", "output": "20875" }, { "input": "91", "output": "125671" }, { "input": "92", "output": "129858" }, { "input": "256", "output": "2796416" }, { "input": "512", "output": "22370048" }, { "input": "666", "output": "49235271" }, { "input": "667", "output": "49457383" }, { "input": "314", "output": "5160119" }, { "input": "1241", "output": "318541121" }, { "input": "1500", "output": "562501250" }, { "input": "1837", "output": "1033182073" }, { "input": "1000", "output": "166667500" } ]
1,698,495,213
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
60
0
n = int(input()) ans = 0 x = 1 for i in range(n,1,-1): ans += i * x x += 1 print(ans + 3 - n)
Title: Buttons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens. Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock. Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario. Input Specification: A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. Output Specification: In a single line print the number of times Manao has to push a button in the worst-case scenario. Demo Input: ['2\n', '3\n'] Demo Output: ['3\n', '7\n'] Note: Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.
```python n = int(input()) ans = 0 x = 1 for i in range(n,1,-1): ans += i * x x += 1 print(ans + 3 - n) ```
0
936
A
Save Energy!
PROGRAMMING
1,700
[ "binary search", "implementation", "math" ]
null
null
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs *t* minutes to be cooked on the stove, if it is turned on, and 2*t* minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018).
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9. Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if .
[ "3 2 6\n", "4 2 20\n" ]
[ "6.5\n", "20.0\n" ]
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a10fa55d1324328f9ba60c9343ed0ecb0506d678.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, after four minutes the chicken will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6fcc8bd6c2188b260d9d18e7b6c9e3908848df71.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a86c8e9632089279245fff912c077126c4e704.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
500
[ { "input": "3 2 6", "output": "6.5" }, { "input": "4 2 20", "output": "20.0" }, { "input": "8 10 9", "output": "10.0" }, { "input": "43 50 140", "output": "150.5" }, { "input": "251 79 76", "output": "76.0" }, { "input": "892 67 1000", "output": "1023.0" }, { "input": "1000 1000 1000", "output": "1000.0" }, { "input": "87 4 1000", "output": "1005.5" }, { "input": "1 629 384378949109878497", "output": "767537647587662141" }, { "input": "2124 6621 12695", "output": "19018" }, { "input": "27548 68747 111", "output": "111.0" }, { "input": "74974 46016 1000000000", "output": "1102134775.0" }, { "input": "223 844 704", "output": "1014.5" }, { "input": "1 558 743", "output": "1483" }, { "input": "43 387 402", "output": "718" }, { "input": "972 2 763", "output": "763.0" }, { "input": "330 167 15", "output": "15.0" }, { "input": "387 43 650", "output": "650.0" }, { "input": "1 314 824", "output": "1642" }, { "input": "2 4 18", "output": "24.0" }, { "input": "3 5 127", "output": "158.0" }, { "input": "3260 4439 6837", "output": "7426.5" }, { "input": "3950 7386 195", "output": "195.0" }, { "input": "18036 47899 1000000000", "output": "1452914012" }, { "input": "29 46 1000000000", "output": "1226666661.0" }, { "input": "403 957 1000000000000000000", "output": "1407352941176470446" }, { "input": "999999999999999999 1000000000000000000 1000000000000000000", "output": "1000000000000000000.5" }, { "input": "9 1000000000000000000 1000000000000000000", "output": "1999999999999999982" }, { "input": "1 2 1000000000000000000", "output": "1333333333333333333.0" }, { "input": "2 5 1000000000000000000", "output": "1428571428571428571.0" }, { "input": "81413279254461199 310548139128293806 1000000000000000000", "output": "1572837149684581517.5" }, { "input": "6 3 417701740543616353", "output": "417701740543616353.0" }, { "input": "17 68 4913", "output": "7854" }, { "input": "68 17 4913", "output": "4913.0" }, { "input": "121 395 621154158314692955", "output": "950991831528308936" }, { "input": "897 443 134730567336441375", "output": "160877739434079591.0" }, { "input": "200 10 979220166595737684", "output": "979220166595737684.0" }, { "input": "740 251 930540301905511549", "output": "938642796161889076.5" }, { "input": "4 232 801899894850800409", "output": "1576616742418522838" }, { "input": "472 499 166288453006087540", "output": "170912333779686266.5" }, { "input": "42 9 1000000000000000000", "output": "1034482758620689654.0" }, { "input": "312 93 1000000000000000000", "output": "1087719298245614020.0" }, { "input": "1000 1000 1000000000000000000", "output": "1000000000000000000.0" }, { "input": "6000 1000 1000000000", "output": "1000000000.0" }, { "input": "9999999999 33333 1000000000", "output": "1000000000.0" }, { "input": "33333 9999999999 1000000000", "output": "1999966667" }, { "input": "25441360464 2658201820 1000000000", "output": "1000000000.0" }, { "input": "20958318104 46685 253251869", "output": "253251869.0" }, { "input": "963276084 698548036 1000000000", "output": "1036723916" }, { "input": "574520976350867177 413897686591532160 1000000000000000000", "output": "1126637198416098571.5" }, { "input": "575556838390916379 15 1000000000000000000", "output": "1000000000000000003.0" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000", "output": "1000000000000000000.0" }, { "input": "1 1000000000000000000 1000000000000000000", "output": "1999999999999999998" }, { "input": "8 1000000000000000000 1000000000000000000", "output": "1999999999999999984" }, { "input": "1 976958144546785462 1000000000000000000", "output": "1999999999999999997" }, { "input": "3 10 1000000000000000000", "output": "1538461538461538461.0" }, { "input": "312200625484460654 543737694709247394 1000000000000000000", "output": "1231537069224786740.0" }, { "input": "2 99 53", "output": "102" }, { "input": "900000000000000000 1 1234", "output": "1234.0" } ]
1,556,336,706
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
print("-ddddddddddddddddddddddddddddddddddddddd1")
Title: Save Energy! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after *k* minutes after turning on. During cooking, Julia goes to the kitchen every *d* minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs *t* minutes to be cooked on the stove, if it is turned on, and 2*t* minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input Specification: The single line contains three integers *k*, *d* and *t* (1<=≤<=*k*,<=*d*,<=*t*<=≤<=1018). Output Specification: Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10<=-<=9. Namely, let's assume that your answer is *x* and the answer of the jury is *y*. The checker program will consider your answer correct if . Demo Input: ['3 2 6\n', '4 2 20\n'] Demo Output: ['6.5\n', '20.0\n'] Note: In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cce5d3f2f46552034d5ae5d487725705429ec7a5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a10fa55d1324328f9ba60c9343ed0ecb0506d678.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, after four minutes the chicken will be cooked for <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6fcc8bd6c2188b260d9d18e7b6c9e3908848df71.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/87a86c8e9632089279245fff912c077126c4e704.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
```python print("-ddddddddddddddddddddddddddddddddddddddd1") ```
0
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }, { "input": "693\n970", "output": "NO" }, { "input": "981\n1", "output": "YES" }, { "input": "352\n276", "output": "YES" }, { "input": "164\n691", "output": "YES" }, { "input": "110036\n43", "output": "YES" }, { "input": "100\n1000", "output": "NO" }, { "input": "1000000000\n1000000000", "output": "YES" }, { "input": "999999999\n999999999", "output": "YES" }, { "input": "6\n4", "output": "NO" }, { "input": "123456\n876543", "output": "YES" }, { "input": "1234567\n9876543", "output": "NO" }, { "input": "1111111\n1119111", "output": "NO" }, { "input": "10502405\n40403403", "output": "YES" }, { "input": "1\n1", "output": "YES" }, { "input": "5\n4", "output": "YES" }, { "input": "1\n6", "output": "YES" }, { "input": "40\n17", "output": "NO" }, { "input": "35\n81", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "2081\n7450", "output": "NO" }, { "input": "84355694\n373629503", "output": "NO" }, { "input": "885992048\n510468672", "output": "NO" }, { "input": "540144752\n647307841", "output": "NO" }, { "input": "341781108\n784147010", "output": "NO" }, { "input": "960440938\n572334653", "output": "NO" }, { "input": "657414510\n768771903", "output": "NO" }, { "input": "501871728\n725074574", "output": "NO" }, { "input": "968\n851", "output": "YES" }, { "input": "943\n939", "output": "YES" }, { "input": "347\n908", "output": "NO" }, { "input": "611\n41", "output": "YES" }, { "input": "737\n289", "output": "NO" }, { "input": "168\n571", "output": "YES" }, { "input": "868\n463", "output": "YES" }, { "input": "815732007\n913882008", "output": "NO" }, { "input": "459039901\n453033850", "output": "NO" }, { "input": "975305404\n484601256", "output": "NO" } ]
1,687,211,088
2,147,483,647
PyPy 3-64
OK
TESTS
43
124
0
a=input() b=input() c=int(a)+int(b) str_c=str(c) if '0' in a: a=a.replace('0','') if '0' in b: b=b.replace('0', '') if '0' in str_c: str_c=str_c.replace('0', '') c=int(str_c) if int(a)+int(b)==c: print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. Input Specification: The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. Output Specification: The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Demo Input: ['101\n102\n', '105\n106\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python a=input() b=input() c=int(a)+int(b) str_c=str(c) if '0' in a: a=a.replace('0','') if '0' in b: b=b.replace('0', '') if '0' in str_c: str_c=str_c.replace('0', '') c=int(str_c) if int(a)+int(b)==c: print("YES") else: print("NO") ```
3.969
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,497,350,366
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
21
77
307,200
# http://codeforces.com/problemset/problem/814/B import sys #sys.stdin = open('input2','r') n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) """empty array""" store = [0]*n """check where not pair""" for i in range(n): if(a[i] == b[i]): """pair""" if(store[a[i]-1] == 1): store[a[i] - 1] = 4 else: store[a[i] - 1] = 2 else: """if a or b contain pair""" if(store[a[i]-1] == 2 ): store[a[i]-1] = 4 if(store[b[i]-1] == 2): store[b[i]-1] = 4 if(store[a[i]-1] == 0 ): store[a[i]-1] = 1 if(store[b[i]-1] == 0): store[b[i]-1] = 1 #print(store) """search for non-pair item""" for i in range(n): if(a[i] != b[i]): if(store[a[i]-1] == 1): store[a[i]-1] = 2 elif(store[b[i]-1] == 1): a[i] = b[i] store[b[i]-1] = 2 elif(store[a[i]-1] == 4 and store[b[i]-1] == 4 ): pos = store.index(0) a[i] = pos+1 store[pos] = 2 #print(store) print(*a,sep=' ')
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 # http://codeforces.com/problemset/problem/814/B import sys #sys.stdin = open('input2','r') n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) """empty array""" store = [0]*n """check where not pair""" for i in range(n): if(a[i] == b[i]): """pair""" if(store[a[i]-1] == 1): store[a[i] - 1] = 4 else: store[a[i] - 1] = 2 else: """if a or b contain pair""" if(store[a[i]-1] == 2 ): store[a[i]-1] = 4 if(store[b[i]-1] == 2): store[b[i]-1] = 4 if(store[a[i]-1] == 0 ): store[a[i]-1] = 1 if(store[b[i]-1] == 0): store[b[i]-1] = 1 #print(store) """search for non-pair item""" for i in range(n): if(a[i] != b[i]): if(store[a[i]-1] == 1): store[a[i]-1] = 2 elif(store[b[i]-1] == 1): a[i] = b[i] store[b[i]-1] = 2 elif(store[a[i]-1] == 4 and store[b[i]-1] == 4 ): pos = store.index(0) a[i] = pos+1 store[pos] = 2 #print(store) print(*a,sep=' ') ```
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,691,940,798
2,147,483,647
Python 3
OK
TESTS
34
92
0
# Read the input colors = list(map(int, input().split())) # Calculate the number of distinct colors distinct_colors = len(set(colors)) # Calculate the minimum number of horseshoes to buy minimum_horseshoes_to_buy = 4 - distinct_colors # Print the result print(minimum_horseshoes_to_buy)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python # Read the input colors = list(map(int, input().split())) # Calculate the number of distinct colors distinct_colors = len(set(colors)) # Calculate the minimum number of horseshoes to buy minimum_horseshoes_to_buy = 4 - distinct_colors # Print the result print(minimum_horseshoes_to_buy) ```
3
957
A
Tritonic Iridescence
PROGRAMMING
1,300
[ "implementation" ]
null
null
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours. Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas. The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).
[ "5\nCY??Y\n", "5\nC?C?Y\n", "5\n?CYC?\n", "5\nC??MM\n", "3\nMMY\n" ]
[ "Yes\n", "Yes\n", "Yes\n", "No\n", "No\n" ]
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY. For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY. For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY. For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example.
500
[ { "input": "5\nCY??Y", "output": "Yes" }, { "input": "5\nC?C?Y", "output": "Yes" }, { "input": "5\n?CYC?", "output": "Yes" }, { "input": "5\nC??MM", "output": "No" }, { "input": "3\nMMY", "output": "No" }, { "input": "15\n??YYYYYY??YYYY?", "output": "No" }, { "input": "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC", "output": "No" }, { "input": "1\nC", "output": "No" }, { "input": "1\n?", "output": "Yes" }, { "input": "2\nMY", "output": "No" }, { "input": "2\n?M", "output": "Yes" }, { "input": "2\nY?", "output": "Yes" }, { "input": "2\n??", "output": "Yes" }, { "input": "3\n??C", "output": "Yes" }, { "input": "3\nM??", "output": "Yes" }, { "input": "3\nYCM", "output": "No" }, { "input": "3\n?C?", "output": "Yes" }, { "input": "3\nMC?", "output": "Yes" }, { "input": "4\nCYCM", "output": "No" }, { "input": "4\nM?CM", "output": "No" }, { "input": "4\n??YM", "output": "Yes" }, { "input": "4\nC???", "output": "Yes" }, { "input": "10\nMCYM?MYM?C", "output": "Yes" }, { "input": "50\nCMCMCYM?MY?C?MC??YM?CY?YM??M?MCMCYCYMCYCMCM?MCM?MC", "output": "Yes" }, { "input": "97\nMCM?YCMYM?YMY?MY?MYCY?CMCMCYC?YMY?MYCMC?M?YCMC?YM?C?MCMCMYMCMY?MCM?YC?YMYMY?MYCYCM?YC?YCY?MYMYMYC", "output": "No" }, { "input": "100\nC?M?M?M?YM??YMYC?MCYMYM??Y??YC?CYC???YM?YM??MYMY?CYCYMYC?YC?C?CYCMY??CMC?YMCMYCYCYMYM?CYM?M?MCMCMY?Y", "output": "Yes" }, { "input": "100\n?YYYYYYYYYYYYYYYYYYYYYYYYYYYYY??YYY?YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?", "output": "No" }, { "input": "100\n????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "Yes" }, { "input": "100\nY?CYMYMYMYCYMY?CMCYMYMC?MYCY?CMCYCYMCM?YCMCYMYCYCY?MYMYCYCYCM?CYMYMY?CY?MYCYCY?M?YMYCY?CMCMCY?CY?M?C", "output": "No" }, { "input": "4\nM??C", "output": "Yes" }, { "input": "6\nY?C??C", "output": "Yes" }, { "input": "5\nC???Y", "output": "Yes" }, { "input": "5\nC??MY", "output": "Yes" }, { "input": "5\nCY??M", "output": "Yes" }, { "input": "4\nC??Y", "output": "Yes" }, { "input": "52\n??????????????????????????????????????????????????YY", "output": "No" }, { "input": "3\nYY?", "output": "No" }, { "input": "5\nCC??Y", "output": "No" }, { "input": "8\nCMC??MCM", "output": "Yes" }, { "input": "7\nM?YCM??", "output": "Yes" }, { "input": "6\n?CC???", "output": "No" }, { "input": "100\n??????????????????????????????????????????????????????????????????????????????????????????????????MM", "output": "No" }, { "input": "4\nC??M", "output": "Yes" }, { "input": "4\n?C?M", "output": "Yes" }, { "input": "6\nMC??MC", "output": "Yes" } ]
1,521,907,130
1,430
Python 3
WRONG_ANSWER
PRETESTS
1
77
7,065,600
n=int(input()) s=input() if ('CC' in s) or ('YY' in s) or ('MM' in s): print('No') else: if 'C?M' in s: print('No') elif 'M?C' in s: print('No') elif 'C?Y' in s: print('No') elif 'Y?C' in s: print('No') elif 'M?Y' in s: print('No') elif 'Y?M' in s: print('No') else: print('Yes')
Title: Tritonic Iridescence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours. Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. Input Specification: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas. The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). Output Specification: If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower). Demo Input: ['5\nCY??Y\n', '5\nC?C?Y\n', '5\n?CYC?\n', '5\nC??MM\n', '3\nMMY\n'] Demo Output: ['Yes\n', 'Yes\n', 'Yes\n', 'No\n', 'No\n'] Note: For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY. For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY. For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY. For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example.
```python n=int(input()) s=input() if ('CC' in s) or ('YY' in s) or ('MM' in s): print('No') else: if 'C?M' in s: print('No') elif 'M?C' in s: print('No') elif 'C?Y' in s: print('No') elif 'Y?C' in s: print('No') elif 'M?Y' in s: print('No') elif 'Y?M' in s: print('No') else: print('Yes') ```
0
0
none
none
none
0
[ "none" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
0
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { "input": "2\n315 845\n-669 -762", "output": "0" }, { "input": "3\n8911 7861\n-6888 7861\n8911 7861", "output": "3" }, { "input": "2\n-1 1000000000\n0 -1", "output": "0" }, { "input": "2\n1000000000 0\n-7 1", "output": "0" }, { "input": "2\n1 4\n2 1", "output": "0" }, { "input": "2\n1 0\n0 2333333", "output": "0" }, { "input": "2\n2 1\n1 2", "output": "0" }, { "input": "2\n1 1000000000\n2 -1000000000", "output": "0" }, { "input": "2\n0 1000000000\n1 -7", "output": "0" }, { "input": "2\n1 0\n0 19990213", "output": "0" } ]
1,621,182,977
2,147,483,647
Python 3
OK
TESTS
71
1,201
41,164,800
import math import random from queue import Queue def main(arr): x_val={} y_val={} same_val={} for i in range(len(arr)): x,y=arr[i] if x not in x_val: x_val[x]=0 if y not in y_val: y_val[y]=0 if (x,y) not in same_val: same_val[(x,y)]=0 y_val[y]+=1 x_val[x]+=1 same_val[(x,y)]+=1 ans=0 for e in arr: x,y=e ans+=x_val[x]+y_val[y]-same_val[(x,y)]-1 x_val[x]-=1 y_val[y]-=1 same_val[(x,y)]-=1 return ans arr=[] n=int(input()) for i in range(n): arr.append(list(map(int,input().split()))) print(main(arr))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. Input Specification: The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide. Output Specification: Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. Demo Input: ['3\n1 1\n7 5\n1 5\n', '6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n'] Demo Output: ['2\n', '11\n'] Note: In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.
```python import math import random from queue import Queue def main(arr): x_val={} y_val={} same_val={} for i in range(len(arr)): x,y=arr[i] if x not in x_val: x_val[x]=0 if y not in y_val: y_val[y]=0 if (x,y) not in same_val: same_val[(x,y)]=0 y_val[y]+=1 x_val[x]+=1 same_val[(x,y)]+=1 ans=0 for e in arr: x,y=e ans+=x_val[x]+y_val[y]-same_val[(x,y)]-1 x_val[x]-=1 y_val[y]-=1 same_val[(x,y)]-=1 return ans arr=[] n=int(input()) for i in range(n): arr.append(list(map(int,input().split()))) print(main(arr)) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,659,287,042
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
# https://codeforces.com/problemset/problem/50/A n = input("Enter number here: ").split() l1 = [int(i) for i in n] area = 1 for i in l1: area = area * i print(area//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python # https://codeforces.com/problemset/problem/50/A n = input("Enter number here: ").split() l1 = [int(i) for i in n] area = 1 for i in l1: area = area * i print(area//2) ```
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,643,228,630
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
cantidad = input() cantidadS = cantidad.split(" ") M = int(cantidadS[0]) N = int(cantidadS[1]) A = M*N if A%2 != 0: if round(A/2) < (A/2): print(round(A/2)) else: pass else: print(A/2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python cantidad = input() cantidadS = cantidad.split(" ") M = int(cantidadS[0]) N = int(cantidadS[1]) A = M*N if A%2 != 0: if round(A/2) < (A/2): print(round(A/2)) else: pass else: print(A/2) ```
0
702
C
Cellular Network
PROGRAMMING
1,500
[ "binary search", "implementation", "two pointers" ]
null
null
You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower. Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*. If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower.
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order. The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=≤<=*b**j*<=≤<=109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order.
Print minimal *r* so that each city will be covered by cellular network.
[ "3 2\n-2 2 4\n-3 0\n", "5 3\n1 5 10 14 17\n4 11 15\n" ]
[ "4\n", "3\n" ]
none
0
[ { "input": "3 2\n-2 2 4\n-3 0", "output": "4" }, { "input": "5 3\n1 5 10 14 17\n4 11 15", "output": "3" }, { "input": "1 1\n-1000000000\n1000000000", "output": "2000000000" }, { "input": "1 1\n1000000000\n-1000000000", "output": "2000000000" }, { "input": "10 10\n1 1 2 2 2 4 4 6 7 9\n0 1 3 3 3 6 7 8 9 10", "output": "1" }, { "input": "10 10\n2 52 280 401 416 499 721 791 841 943\n246 348 447 486 507 566 568 633 953 986", "output": "244" }, { "input": "7 7\n1 2 3 3 4 5 6\n1 1 2 3 4 5 6", "output": "0" }, { "input": "1 3\n-3\n-1 -1 8", "output": "2" }, { "input": "1 2\n8\n-7 5", "output": "3" }, { "input": "2 1\n4 8\n-1", "output": "9" }, { "input": "1 2\n6\n-8 -8", "output": "14" }, { "input": "1 4\n4\n-8 0 1 7", "output": "3" }, { "input": "1 2\n2\n4 7", "output": "2" }, { "input": "2 2\n-5 2\n-7 4", "output": "2" }, { "input": "1 21\n3\n3 10 23 32 34 40 42 49 49 50 50 58 70 71 71 74 76 79 79 80 83", "output": "0" }, { "input": "1 3\n-4\n-8 -1 1", "output": "3" }, { "input": "4 1\n-6 -3 -1 2\n-7", "output": "9" }, { "input": "2 3\n-2 7\n-7 -2 5", "output": "2" }, { "input": "1 1\n-1\n0", "output": "1" }, { "input": "1 3\n0\n-4 0 5", "output": "0" } ]
1,700,295,998
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
def main(): from sys import stdin, stdout pokl= stdin.read().split() nop= int(pokl.pop(0)) mop=int(pokl.pop(0)) ratcat= [int(xop) for xop in pokl[0:nop]] catrat= [int(xop) for xop in pokl[nop:(nop+mop)]] jam,aop= 0, 0 for pot in ratcat: while jam+1 <mop and abs(pot-catrat[jam])>=abs(pot-catrat[jam+1]): jam+= 1 aop= max(aop, abs(pot-catrat[jam])) stdout.write(str(ans) + '\n') if __name__ == '__main__': main()
Title: Cellular Network Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* points on the straight line — the positions (*x*-coordinates) of the cities and *m* points on the same line — the positions (*x*-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than *r* from this tower. Your task is to find minimal *r* that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than *r*. If *r*<==<=0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than *r* from this tower. Input Specification: The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of cities and the number of cellular towers. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates *a**i* are given in non-decreasing order. The third line contains a sequence of *m* integers *b*1,<=*b*2,<=...,<=*b**m* (<=-<=109<=≤<=*b**j*<=≤<=109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates *b**j* are given in non-decreasing order. Output Specification: Print minimal *r* so that each city will be covered by cellular network. Demo Input: ['3 2\n-2 2 4\n-3 0\n', '5 3\n1 5 10 14 17\n4 11 15\n'] Demo Output: ['4\n', '3\n'] Note: none
```python def main(): from sys import stdin, stdout pokl= stdin.read().split() nop= int(pokl.pop(0)) mop=int(pokl.pop(0)) ratcat= [int(xop) for xop in pokl[0:nop]] catrat= [int(xop) for xop in pokl[nop:(nop+mop)]] jam,aop= 0, 0 for pot in ratcat: while jam+1 <mop and abs(pot-catrat[jam])>=abs(pot-catrat[jam+1]): jam+= 1 aop= max(aop, abs(pot-catrat[jam])) stdout.write(str(ans) + '\n') if __name__ == '__main__': main() ```
-1
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,687,073,161
2,147,483,647
Python 3
OK
TESTS
20
31
0
# Read the input q, w, e = map(int, input().split()) # Calculate the number of flagstones needed flagstones_needed = ((q + e - 1) // e) * ((w + e - 1) // e) # Print the number of flagstones needed print(flagstones_needed) ##v
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 # Read the input q, w, e = map(int, input().split()) # Calculate the number of flagstones needed flagstones_needed = ((q + e - 1) // e) * ((w + e - 1) // e) # Print the number of flagstones needed print(flagstones_needed) ##v ```
3.9845
691
A
Fashion in Berland
PROGRAMMING
1,000
[ "implementation" ]
null
null
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1.
In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".
[ "3\n1 0 1\n", "3\n1 0 0\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 0 1", "output": "YES" }, { "input": "3\n1 0 0", "output": "NO" }, { "input": "3\n1 1 0", "output": "YES" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "3\n0 0 1", "output": "NO" }, { "input": "3\n0 0 0", "output": "NO" }, { "input": "3\n0 1 1", "output": "YES" }, { "input": "3\n0 1 0", "output": "NO" }, { "input": "2\n0 1", "output": "YES" }, { "input": "2\n1 0", "output": "YES" }, { "input": "2\n0 0", "output": "NO" }, { "input": "2\n1 1", "output": "NO" }, { "input": "1\n1", "output": "YES" }, { "input": "1\n0", "output": "NO" }, { "input": "10\n1 0 1 1 1 1 1 1 1 1", "output": "YES" }, { "input": "5\n1 1 1 1 0", "output": "YES" }, { "input": "4\n1 0 1 0", "output": "NO" }, { "input": "4\n1 1 0 0", "output": "NO" }, { "input": "10\n0 0 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "123\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "124\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "94\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "64\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "34\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "NO" }, { "input": "5\n1 1 1 1 1", "output": "NO" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "231\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "NO" }, { "input": "10\n1 1 0 1 1 1 0 1 1 1", "output": "NO" } ]
1,678,713,318
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
#1973 A t = int(input()) a, b = input().split() n, m = input().split() a = int(a) b = int(b) n = int(n) m = int(m) k = n // (m + 1) ans = k * ( m * a - m * b - b) + n * b print(ans)
Title: Fashion in Berland Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. Output Specification: In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". Demo Input: ['3\n1 0 1\n', '3\n1 0 0\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python #1973 A t = int(input()) a, b = input().split() n, m = input().split() a = int(a) b = int(b) n = int(n) m = int(m) k = n // (m + 1) ans = k * ( m * a - m * b - b) + n * b print(ans) ```
-1
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,698,309,819
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
12,288,000
n,m = [int(i) for i in input().split()] array = input().split() for _ in range(m): number = int(input()) cut = array[number-1:n] dic = {} for l in cut: dic[l] = 0 result = 0 for i,j in dic.items(): result += 1 print(result)
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n,m = [int(i) for i in input().split()] array = input().split() for _ in range(m): number = int(input()) cut = array[number-1:n] dic = {} for l in cut: dic[l] = 0 result = 0 for i,j in dic.items(): result += 1 print(result) ```
0
645
C
Enduring Exodus
PROGRAMMING
1,600
[ "binary search", "two pointers" ]
null
null
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupied. Farmer John wants to book a set of *k*<=+<=1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms *i* and *j* is defined as |*j*<=-<=*i*|. Help Farmer John protect his cows by calculating this minimum possible distance.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=100<=000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th room is free, and '1' if the *i*-th room is occupied. It is guaranteed that at least *k*<=+<=1 characters of this string are '0', so there exists at least one possible choice of *k*<=+<=1 rooms for Farmer John and his cows to stay in.
Print the minimum possible distance between Farmer John's room and his farthest cow.
[ "7 2\n0100100\n", "5 1\n01010\n", "3 2\n000\n" ]
[ "2\n", "2\n", "1\n" ]
In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
1,500
[ { "input": "7 2\n0100100", "output": "2" }, { "input": "5 1\n01010", "output": "2" }, { "input": "3 2\n000", "output": "1" }, { "input": "10 1\n1101111101", "output": "6" }, { "input": "2 1\n00", "output": "1" }, { "input": "3 1\n010", "output": "2" }, { "input": "8 7\n00000000", "output": "4" }, { "input": "7 6\n0000000", "output": "3" }, { "input": "112 12\n0110101000000010101110010111100101011010011110100111111100011101011111000111101101110100111011110001100110110010", "output": "10" }, { "input": "9 8\n000000000", "output": "4" }, { "input": "9 3\n010001000", "output": "2" }, { "input": "5 3\n00000", "output": "2" }, { "input": "8 7\n00000000", "output": "4" }, { "input": "6 1\n000011", "output": "1" }, { "input": "100 40\n0010010100000100011100010100110001101100110000110010000000001010000111100000100100100101010010001100", "output": "30" }, { "input": "93 79\n000000000000000000011000000000000000000000000000000000000000000000010000000000100000100000000", "output": "42" }, { "input": "31 11\n0000001011011100010000000110001", "output": "7" }, { "input": "47 46\n00000000000000000000000000000000000000000000000", "output": "23" }, { "input": "100 96\n0000000000000010000010000000000000000000000000000000000000000000000000000010000000000000000000000000", "output": "50" }, { "input": "491 89\n01111101111111100000111010110001010001110111000010101111101000100010010111011101110110111101101010111000111000011100011010010010111111000011011010100110001000011100111000001011100010001111101111101000111001100110010100101000001110010100100100100101001100010101001000010000111110011000000100000100101000100101000001001101011011100000110101111110101001001000100110010000010110101011000101011001001011001000110000011111001110101011000000110101000000100110001101111000101001001001100001001110101", "output": "73" }, { "input": "308 17\n01000000100000000000000001000001000010000000000000000001001110000001010001000110000000000000100101000000010000001000000000001100000110000000000000000001000000000000000100000001000010001000000001000000000000000100010000000000000000000000000000000000001000000000001001101100000000000010000000000000000000000000", "output": "9" }, { "input": "8 4\n00111000", "output": "5" }, { "input": "18 2\n010111110111011110", "output": "5" }, { "input": "29 3\n01110011111111111111110110110", "output": "17" } ]
1,604,410,085
2,147,483,647
Python 3
OK
TESTS
87
1,622
3,072,000
n, k = [int(_) for _ in input().split()] a = input() k += 1 # size of n+1 f = [0] * (n+1) f[1]=int(a[0]=='0') for i in range(1,n+1): f[i]=f[i-1]+int(a[i-1]=='0') #sprint(f) def check(dis): for i in range(n): if a[i]=='0': left=max(i-dis,0) right=min(i+dis,n-1) if f[right+1]-f[left]>=k:return True return False l=1 r=n ans=n while l<=r: mid=(l + r)// 2 # print(mid) if check(mid): # print(True) ans=min(ans,mid) r=mid-1 else: # print(False) l=mid+1 print(ans)
Title: Enduring Exodus Time Limit: None seconds Memory Limit: None megabytes Problem Description: In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupied. Farmer John wants to book a set of *k*<=+<=1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms *i* and *j* is defined as |*j*<=-<=*i*|. Help Farmer John protect his cows by calculating this minimum possible distance. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=100<=000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th room is free, and '1' if the *i*-th room is occupied. It is guaranteed that at least *k*<=+<=1 characters of this string are '0', so there exists at least one possible choice of *k*<=+<=1 rooms for Farmer John and his cows to stay in. Output Specification: Print the minimum possible distance between Farmer John's room and his farthest cow. Demo Input: ['7 2\n0100100\n', '5 1\n01010\n', '3 2\n000\n'] Demo Output: ['2\n', '2\n', '1\n'] Note: In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
```python n, k = [int(_) for _ in input().split()] a = input() k += 1 # size of n+1 f = [0] * (n+1) f[1]=int(a[0]=='0') for i in range(1,n+1): f[i]=f[i-1]+int(a[i-1]=='0') #sprint(f) def check(dis): for i in range(n): if a[i]=='0': left=max(i-dis,0) right=min(i+dis,n-1) if f[right+1]-f[left]>=k:return True return False l=1 r=n ans=n while l<=r: mid=(l + r)// 2 # print(mid) if check(mid): # print(True) ans=min(ans,mid) r=mid-1 else: # print(False) l=mid+1 print(ans) ```
3
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,694,588,849
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
m=input() lst=[] for a in m: lst.append(a) if "1" in lst or "2" in lst or "3" in lst or "5" in lst or "6" in lst or "8" in lst or "9" in lst or "0" in lst: print("NO") else: print("YES")
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python m=input() lst=[] for a in m: lst.append(a) if "1" in lst or "2" in lst or "3" in lst or "5" in lst or "6" in lst or "8" in lst or "9" in lst or "0" in lst: print("NO") else: print("YES") ```
0
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { "input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "output": "245" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "3\n607\n684", "output": "5" }, { "input": "4\n0809\n0636", "output": "8" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762280548\n9519431339078678836940020", "output": "72" }, { "input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "output": "305" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762285484\n9519431339078678836940202", "output": "74" }, { "input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "output": "357" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8378525987476228048406972\n9194339078883694020217816", "output": "55" }, { "input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "output": "274" }, { "input": "1\n0\n0", "output": "0" }, { "input": "1\n7\n7", "output": "0" }, { "input": "1\n0\n5", "output": "5" }, { "input": "1\n2\n7", "output": "5" }, { "input": "1\n7\n9", "output": "2" }, { "input": "1\n9\n7", "output": "2" }, { "input": "1\n2\n9", "output": "3" }, { "input": "1\n9\n2", "output": "3" }, { "input": "25\n3164978461316464614169874\n9413979197249127496597357", "output": "66" }, { "input": "4\n9999\n9999", "output": "0" }, { "input": "2\n11\n11", "output": "0" } ]
1,678,859,273
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
t = int(input()) a = list(map(int, input())) b = list(map(int, input())) s = 0 for i in range(t): s += min(abs(a[i]-b[i]), abs((9 - a[i])+b[i]-1)) print(s)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. Output Specification: Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. Demo Input: ['5\n82195\n64723\n'] Demo Output: ['13\n'] Note: In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python t = int(input()) a = list(map(int, input())) b = list(map(int, input())) s = 0 for i in range(t): s += min(abs(a[i]-b[i]), abs((9 - a[i])+b[i]-1)) print(s) ```
0
690
A2
Collective Mindsets (medium)
PROGRAMMING
2,300
[]
null
null
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)? The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the *N*<=-<=1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109).
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
[ "1\n", "3\n", "99\n" ]
[ "0\n", "1\n", "49\n" ]
none
0
[ { "input": "1", "output": "0" }, { "input": "3", "output": "1" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "2" }, { "input": "6", "output": "1" }, { "input": "7", "output": "3" }, { "input": "8", "output": "0" }, { "input": "9", "output": "4" }, { "input": "10", "output": "1" }, { "input": "11", "output": "5" }, { "input": "12", "output": "2" }, { "input": "13", "output": "6" }, { "input": "14", "output": "3" }, { "input": "15", "output": "7" }, { "input": "16", "output": "0" }, { "input": "17", "output": "8" }, { "input": "18", "output": "1" }, { "input": "19", "output": "9" }, { "input": "20", "output": "2" }, { "input": "99", "output": "49" }, { "input": "100", "output": "18" }, { "input": "9999", "output": "4999" }, { "input": "21736", "output": "2676" }, { "input": "873467", "output": "436733" }, { "input": "4124980", "output": "1013914" }, { "input": "536870910", "output": "134217727" }, { "input": "536870912", "output": "0" }, { "input": "876543210", "output": "169836149" }, { "input": "987654321", "output": "493827160" }, { "input": "1000000000", "output": "231564544" } ]
1,480,957,157
2,147,483,647
Python 3
OK
TESTS
31
77
0
n = int(input()) if (n % 2 == 1): print(n // 2) exit(0) i = 1 while (i <= n): i *= 2 i //= 2 n -= i print(n // 2)
Title: Collective Mindsets (medium) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)? The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the *N*<=-<=1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive. Input Specification: The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109). Output Specification: Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive. Demo Input: ['1\n', '3\n', '99\n'] Demo Output: ['0\n', '1\n', '49\n'] Note: none
```python n = int(input()) if (n % 2 == 1): print(n // 2) exit(0) i = 1 while (i <= n): i *= 2 i //= 2 n -= i print(n // 2) ```
3
870
A
Search for Pretty Integers
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list.
Print the smallest pretty integer.
[ "2 3\n4 2\n5 7 6\n", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n" ]
[ "25\n", "1\n" ]
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
500
[ { "input": "2 3\n4 2\n5 7 6", "output": "25" }, { "input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n9\n1", "output": "19" }, { "input": "9 1\n5 4 2 3 6 1 7 9 8\n9", "output": "9" }, { "input": "5 3\n7 2 5 8 6\n3 1 9", "output": "12" }, { "input": "4 5\n5 2 6 4\n8 9 1 3 7", "output": "12" }, { "input": "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "output": "1" }, { "input": "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "output": "1" }, { "input": "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9", "output": "1" }, { "input": "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n8\n9", "output": "89" }, { "input": "1 1\n9\n8", "output": "89" }, { "input": "1 1\n1\n2", "output": "12" }, { "input": "1 1\n2\n1", "output": "12" }, { "input": "1 1\n9\n9", "output": "9" }, { "input": "1 1\n1\n1", "output": "1" }, { "input": "4 5\n3 2 4 5\n1 6 5 9 8", "output": "5" }, { "input": "3 2\n4 5 6\n1 5", "output": "5" }, { "input": "5 4\n1 3 5 6 7\n2 4 3 9", "output": "3" }, { "input": "5 5\n1 3 5 7 9\n2 4 6 8 9", "output": "9" }, { "input": "2 2\n1 8\n2 8", "output": "8" }, { "input": "5 5\n5 6 7 8 9\n1 2 3 4 5", "output": "5" }, { "input": "5 5\n1 2 3 4 5\n1 2 3 4 5", "output": "1" }, { "input": "5 5\n1 2 3 4 5\n2 3 4 5 6", "output": "2" }, { "input": "2 2\n1 5\n2 5", "output": "5" }, { "input": "4 4\n1 3 5 8\n2 4 6 8", "output": "8" }, { "input": "3 3\n1 5 3\n2 5 7", "output": "5" }, { "input": "3 3\n3 6 8\n2 6 9", "output": "6" }, { "input": "2 2\n1 4\n2 4", "output": "4" }, { "input": "5 3\n3 4 5 6 7\n1 5 9", "output": "5" }, { "input": "4 4\n1 2 3 4\n2 5 6 7", "output": "2" }, { "input": "5 5\n1 2 3 4 5\n9 2 1 7 5", "output": "1" }, { "input": "2 2\n1 3\n2 3", "output": "3" }, { "input": "3 3\n3 2 1\n3 2 1", "output": "1" }, { "input": "3 3\n1 3 5\n2 3 6", "output": "3" }, { "input": "3 3\n5 6 7\n5 6 7", "output": "5" }, { "input": "1 2\n5\n2 5", "output": "5" }, { "input": "3 3\n2 4 9\n7 8 9", "output": "9" }, { "input": "3 3\n1 2 4\n3 4 5", "output": "4" }, { "input": "3 2\n1 4 9\n2 4", "output": "4" }, { "input": "3 3\n3 5 6\n1 5 9", "output": "5" }, { "input": "3 2\n1 2 4\n3 4", "output": "4" }, { "input": "2 4\n8 9\n1 2 3 9", "output": "9" }, { "input": "1 2\n9\n8 9", "output": "9" }, { "input": "3 2\n1 2 4\n4 2", "output": "2" }, { "input": "2 3\n4 5\n1 3 5", "output": "5" }, { "input": "3 2\n1 2 3\n2 3", "output": "2" }, { "input": "4 3\n1 3 5 9\n2 8 9", "output": "9" }, { "input": "2 2\n1 9\n9 2", "output": "9" } ]
1,565,715,061
2,147,483,647
Python 3
OK
TESTS
52
124
0
n = [int(i) for i in input().split()] list_n1 = [int(i) for i in input().split()] list_n2 = [int(i) for i in input().split()] list_n1.sort() list_n2.sort() con=0 for i in list_n1: if i in list_n2: print(i) con=1 break if con != 1: if list_n1[0] == list_n2[0]: print(list_n1[0]) elif list_n1[0] > list_n2[0]: print(str(list_n2[0])+str(list_n1[0])) else: print(str(list_n1[0])+str(list_n2[0]))
Title: Search for Pretty Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. Output Specification: Print the smallest pretty integer. Demo Input: ['2 3\n4 2\n5 7 6\n', '8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n'] Demo Output: ['25\n', '1\n'] Note: In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
```python n = [int(i) for i in input().split()] list_n1 = [int(i) for i in input().split()] list_n2 = [int(i) for i in input().split()] list_n1.sort() list_n2.sort() con=0 for i in list_n1: if i in list_n2: print(i) con=1 break if con != 1: if list_n1[0] == list_n2[0]: print(list_n1[0]) elif list_n1[0] > list_n2[0]: print(str(list_n2[0])+str(list_n1[0])) else: print(str(list_n1[0])+str(list_n2[0])) ```
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, { "input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "output": "10" }, { "input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1", "output": "29" }, { "input": "1\n1 1 1", "output": "1" }, { "input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "output": "4" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "16" } ]
1,699,089,645
2,147,483,647
Python 3
OK
TESTS
21
62
0
num = int(input()) ans = 0 for x in range(num): (p,v,t) = input().split() p = int(p) v = int(v) t = int(t) if p+v+t >=2: ans+=1 print(ans)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Specification: Print a single integer — the number of problems the friends will implement on the contest. Demo Input: ['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
```python num = int(input()) ans = 0 for x in range(num): (p,v,t) = input().split() p = int(p) v = int(v) t = int(t) if p+v+t >=2: ans+=1 print(ans) ```
3
30
A
Accounting
PROGRAMMING
1,400
[ "brute force", "math" ]
A. Accounting
2
256
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative.
The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10).
Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
[ "2 18 2\n", "-1 8 3\n", "0 0 10\n", "1 16 5\n" ]
[ "3", "-2", "5", "No solution" ]
none
500
[ { "input": "2 18 2", "output": "3" }, { "input": "-1 8 3", "output": "-2" }, { "input": "0 0 10", "output": "5" }, { "input": "1 16 5", "output": "No solution" }, { "input": "0 1 2", "output": "No solution" }, { "input": "3 0 4", "output": "0" }, { "input": "1 1000 1", "output": "1000" }, { "input": "7 896 7", "output": "2" }, { "input": "4 972 1", "output": "243" }, { "input": "-1 -1 5", "output": "1" }, { "input": "-1 0 4", "output": "0" }, { "input": "-7 0 1", "output": "0" }, { "input": "-5 -5 3", "output": "1" }, { "input": "-5 -5 9", "output": "1" }, { "input": "-5 -5 6", "output": "1" }, { "input": "-4 0 1", "output": "0" }, { "input": "-5 0 3", "output": "0" }, { "input": "-4 4 9", "output": "-1" }, { "input": "10 0 6", "output": "0" }, { "input": "-5 3 4", "output": "No solution" }, { "input": "0 3 6", "output": "No solution" }, { "input": "3 6 10", "output": "No solution" }, { "input": "-3 7 5", "output": "No solution" }, { "input": "-526 526 1", "output": "-1" }, { "input": "-373 373 3", "output": "-1" }, { "input": "-141 0 8", "output": "0" }, { "input": "7 175 1", "output": "25" }, { "input": "-5 -560 1", "output": "112" }, { "input": "-1 -512 10", "output": "No solution" }, { "input": "-3 -768 8", "output": "2" }, { "input": "-3 -768 7", "output": "No solution" }, { "input": "-3 -768 9", "output": "No solution" }, { "input": "-3 -768 4", "output": "4" }, { "input": "4 972 4", "output": "No solution" }, { "input": "4 972 5", "output": "3" }, { "input": "4 972 6", "output": "No solution" }, { "input": "4 972 1", "output": "243" }, { "input": "4 972 2", "output": "No solution" }, { "input": "1 1000 1", "output": "1000" }, { "input": "1 961 2", "output": "31" }, { "input": "1 1000 3", "output": "10" }, { "input": "1 625 4", "output": "5" }, { "input": "4 972 5", "output": "3" }, { "input": "1 729 6", "output": "3" }, { "input": "7 896 7", "output": "2" }, { "input": "3 768 8", "output": "2" }, { "input": "1 512 9", "output": "2" }, { "input": "1 1000 1", "output": "1000" }, { "input": "1 961 2", "output": "31" }, { "input": "1 1000 3", "output": "10" }, { "input": "1 625 4", "output": "5" }, { "input": "4 972 5", "output": "3" }, { "input": "1 729 6", "output": "3" }, { "input": "7 896 7", "output": "2" }, { "input": "3 768 8", "output": "2" }, { "input": "1 512 9", "output": "2" }, { "input": "1 1000 1", "output": "1000" }, { "input": "1 961 2", "output": "31" }, { "input": "1 1000 3", "output": "10" }, { "input": "1 625 4", "output": "5" }, { "input": "4 972 5", "output": "3" }, { "input": "1 729 6", "output": "3" }, { "input": "7 896 7", "output": "2" }, { "input": "3 768 8", "output": "2" }, { "input": "1 512 9", "output": "2" }, { "input": "1 1 5", "output": "1" }, { "input": "1 1 4", "output": "1" }, { "input": "1 -1 1", "output": "-1" } ]
1,544,319,432
2,147,483,647
Python 3
OK
TESTS
68
218
0
a, b, n = [int(x) for x in input().split(" ")] for i in range(-1000,1001): if a * (i ** n) == b: print(i) exit() print("No solution")
Title: Accounting Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. Input Specification: The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). Output Specification: Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. Demo Input: ['2 18 2\n', '-1 8 3\n', '0 0 10\n', '1 16 5\n'] Demo Output: ['3', '-2', '5', 'No solution'] Note: none
```python a, b, n = [int(x) for x in input().split(" ")] for i in range(-1000,1001): if a * (i ** n) == b: print(i) exit() print("No solution") ```
3.9455
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,636,621,645
2,147,483,647
PyPy 3
OK
TESTS
102
77
17,715,200
''' //Abdurasul #include<bits/stdc++.h> using namespace std; /** ################################## ## ___________________ ## ## | | Abdurasul... | ## ## |▓| _ _ | ## ## |▓| |_||_| | ## ## |▓| |_||_| | ## ## |▓| Microsoft | ## ## |▓|_________________| ## ## |/\ <><><><><><><><> \ ## ## \ \ <><><><><><<<>>> \ ## ## \ \ <<><><><><><><>> \ ## ## \ \__________________\ ## ## \|___________________| ## ################################## **/ void seti(){ int n, m; cin >> n >> m; if(n % 2 == 0 && m % 2 == 0 && n % m == 0) cout << "YES"; else if(n % 2 == 1 && m % 2 == 1 && n % m == 0) cout << "YES"; else if(n % m == 0) cout << "YES"; else cout << "NO"; cout << endl; } int main(){ int n = 1; //freopen("a.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n; for(int i = 0; i < n; i++){ seti(); } return 0; } ''' n = input() m = input() s = '' for i in range(len(n)): if n[i] == m[i]: s += '0' else: s += '1' print(s)
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 ''' //Abdurasul #include<bits/stdc++.h> using namespace std; /** ################################## ## ___________________ ## ## | | Abdurasul... | ## ## |▓| _ _ | ## ## |▓| |_||_| | ## ## |▓| |_||_| | ## ## |▓| Microsoft | ## ## |▓|_________________| ## ## |/\ <><><><><><><><> \ ## ## \ \ <><><><><><<<>>> \ ## ## \ \ <<><><><><><><>> \ ## ## \ \__________________\ ## ## \|___________________| ## ################################## **/ void seti(){ int n, m; cin >> n >> m; if(n % 2 == 0 && m % 2 == 0 && n % m == 0) cout << "YES"; else if(n % 2 == 1 && m % 2 == 1 && n % m == 0) cout << "YES"; else if(n % m == 0) cout << "YES"; else cout << "NO"; cout << endl; } int main(){ int n = 1; //freopen("a.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n; for(int i = 0; i < n; i++){ seti(); } return 0; } ''' n = input() m = input() s = '' for i in range(len(n)): if n[i] == m[i]: s += '0' else: s += '1' print(s) ```
3.947753
990
B
Micro-World
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.
The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have.
Print the only integer — minimal possible number of bacteria can remain.
[ "7 1\n101 53 42 102 101 55 54\n", "6 5\n20 15 10 15 20 25\n", "7 1000000\n1 1 1 1 1 1 1\n" ]
[ "3\n", "1\n", "7\n" ]
The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
0
[ { "input": "7 1\n101 53 42 102 101 55 54", "output": "3" }, { "input": "6 5\n20 15 10 15 20 25", "output": "1" }, { "input": "7 1000000\n1 1 1 1 1 1 1", "output": "7" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 4\n8", "output": "1" }, { "input": "10 1\n1 2 3 5 6 8 10 11 9 4", "output": "2" }, { "input": "9 2\n1 6 1 5 5 8 6 8 7", "output": "4" }, { "input": "15 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "15" }, { "input": "2 1000000\n1 1000000", "output": "1" }, { "input": "7 2\n1 5 5 8 9 8 8", "output": "4" }, { "input": "10 1\n2 6 3 4 2 4 4 3 2 1", "output": "4" }, { "input": "4 1\n2 2 1 1", "output": "2" }, { "input": "10 1\n6 3 1 3 6 4 1 3 6 4", "output": "7" }, { "input": "2 1\n1 1", "output": "2" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "8 2\n3 13 9 8 3 13 9 14", "output": "5" }, { "input": "8 1000000\n1 1 5 1000000 1000000 2 2 2", "output": "2" }, { "input": "2 1\n999152 999153", "output": "1" } ]
1,622,624,874
2,147,483,647
PyPy 3
OK
TESTS
36
358
16,281,600
n,k = map(int, input().split()) v = list(map(int, input().split())) v.sort() ans = 0 cnt = 0 ar = [0] * 1000000 for i in range(len(v)): while cnt>0 and v[i] > ar[cnt] and v[i] <= k+ar[cnt] : cnt=cnt-1 cnt = cnt + 1 ar[cnt] = v[i] print(cnt)
Title: Micro-World Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. Input Specification: The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. Output Specification: Print the only integer — minimal possible number of bacteria can remain. Demo Input: ['7 1\n101 53 42 102 101 55 54\n', '6 5\n20 15 10 15 20 25\n', '7 1000000\n1 1 1 1 1 1 1\n'] Demo Output: ['3\n', '1\n', '7\n'] Note: The first example is clarified in the problem statement. In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$. In the third example no bacteria can swallow any other bacteria.
```python n,k = map(int, input().split()) v = list(map(int, input().split())) v.sort() ans = 0 cnt = 0 ar = [0] * 1000000 for i in range(len(v)): while cnt>0 and v[i] > ar[cnt] and v[i] <= k+ar[cnt] : cnt=cnt-1 cnt = cnt + 1 ar[cnt] = v[i] print(cnt) ```
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500" }, { "input": "1\n3", "output": "3 0" }, { "input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646", "output": "6848 6568" }, { "input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727", "output": "9562 9561" }, { "input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12", "output": "315 315" }, { "input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304", "output": "3238 2222" }, { "input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325", "output": "5246 4864" }, { "input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71", "output": "8147 7807" }, { "input": "1\n1", "output": "1 0" } ]
1,673,341,184
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n=int(input()) a=list(map(int,input().split())) a.sort() lst=[] lst1=[] lst=a[0::2] lst1=a[1::2] c=sum(lst) d=sum(lst1) if c>d: print(c,end=" ") print(d) else: print(d,end=" ") print(c)
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. Output Specification: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Demo Input: ['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n'] Demo Output: ['12 5\n', '16 12\n'] Note: In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
```python n=int(input()) a=list(map(int,input().split())) a.sort() lst=[] lst1=[] lst=a[0::2] lst1=a[1::2] c=sum(lst) d=sum(lst1) if c>d: print(c,end=" ") print(d) else: print(d,end=" ") print(c) ```
0
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "input": "49152 0 0 0 0 81920", "output": "No" }, { "input": "1 -1 4 4 2 -3", "output": "No" }, { "input": "-2 -2 1 4 -2 0", "output": "No" }, { "input": "5 0 4 -2 0 1", "output": "No" }, { "input": "-4 -3 2 -1 -3 4", "output": "No" }, { "input": "-3 -3 5 2 3 -1", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 999999999", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 1000000000", "output": "No" }, { "input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564", "output": "No" }, { "input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734", "output": "No" }, { "input": "419578772 -125025887 169314071 89851312 961404059 21419450", "output": "No" }, { "input": "-607353321 -620687860 248029390 477864359 728255275 -264646027", "output": "No" }, { "input": "299948862 -648908808 338174789 841279400 -850322448 350263551", "output": "No" }, { "input": "48517753 416240699 7672672 272460100 -917845051 199790781", "output": "No" }, { "input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665", "output": "No" }, { "input": "-685673792 -488079395 909733355 385950193 -705890324 256550506", "output": "No" }, { "input": "-326038504 547872194 49630307 713863100 303770000 -556852524", "output": "No" }, { "input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303", "output": "No" }, { "input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000", "output": "Yes" }, { "input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000", "output": "Yes" }, { "input": "-999999999 -1000000000 0 0 1000000000 999999999", "output": "Yes" }, { "input": "-1000000000 -999999999 0 0 1000000000 999999999", "output": "No" }, { "input": "-1 -1000000000 0 1000000000 1 -1000000000", "output": "Yes" }, { "input": "0 1000000000 1 0 0 -1000000000", "output": "Yes" }, { "input": "0 1000000000 0 0 0 -1000000000", "output": "No" }, { "input": "0 1 1 2 2 3", "output": "No" }, { "input": "999999999 1000000000 0 0 -1000000000 -999999999", "output": "Yes" }, { "input": "0 0 1 1 2 0", "output": "Yes" }, { "input": "0 0 1 1 2 2", "output": "No" }, { "input": "1 1 2 2 3 3", "output": "No" }, { "input": "0 2 0 3 0 4", "output": "No" }, { "input": "1 1 1 2 1 3", "output": "No" }, { "input": "0 0 3 4 3 9", "output": "Yes" }, { "input": "589824 196608 262144 196608 0 0", "output": "Yes" }, { "input": "0 0 1000000000 1 1000000000 -999999999", "output": "No" }, { "input": "0 0 2 45 0 90", "output": "Yes" }, { "input": "0 0 0 2 0 1", "output": "No" }, { "input": "0 2 4 5 4 0", "output": "Yes" }, { "input": "0 0 2 0 4 0", "output": "No" }, { "input": "1 1 3 3 5 5", "output": "No" }, { "input": "1 1 2 2 3 1", "output": "Yes" } ]
1,504,536,441
741
Python 3
OK
TESTS
46
61
0
def dist(x1,x2,y1,y2): return (x1-x2)**2 + (y1-y2)**2 ax,ay,bx,by,cx,cy = map(int,input().split()) if ((by-ay)*(cx-bx) == (cy-by)*(bx-ax)): print('No') else: if(dist(ax,bx,ay,by) == dist(bx,cx,by,cy)): print('Yes') else: print('No')
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. Input Specification: The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. Output Specification: Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
```python def dist(x1,x2,y1,y2): return (x1-x2)**2 + (y1-y2)**2 ax,ay,bx,by,cx,cy = map(int,input().split()) if ((by-ay)*(cx-bx) == (cy-by)*(bx-ax)): print('No') else: if(dist(ax,bx,ay,by) == dist(bx,cx,by,cy)): print('Yes') else: print('No') ```
3
534
B
Covered Path
PROGRAMMING
1,400
[ "dp", "greedy", "math" ]
null
null
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters.
The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that: - the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*.
Print the maximum possible length of the path segment in meters.
[ "5 6\n4 2\n", "10 10\n10 0\n" ]
[ "26", "100" ]
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
1,000
[ { "input": "5 6\n4 2", "output": "26" }, { "input": "10 10\n10 0", "output": "100" }, { "input": "87 87\n2 10", "output": "174" }, { "input": "1 11\n6 2", "output": "36" }, { "input": "100 10\n10 10", "output": "550" }, { "input": "1 1\n100 10", "output": "24600" }, { "input": "1 1\n5 1", "output": "9" }, { "input": "1 1\n5 2", "output": "13" }, { "input": "100 100\n100 0", "output": "10000" }, { "input": "100 100\n100 10", "output": "34500" }, { "input": "1 100\n100 1", "output": "5050" }, { "input": "1 100\n100 10", "output": "29305" }, { "input": "100 1\n100 1", "output": "5050" }, { "input": "100 1\n100 10", "output": "29305" }, { "input": "1 10\n2 10", "output": "11" }, { "input": "1 1\n2 1", "output": "2" }, { "input": "1 1\n2 10", "output": "2" }, { "input": "1 2\n2 1", "output": "3" }, { "input": "1 2\n2 10", "output": "3" }, { "input": "1 5\n3 2", "output": "9" }, { "input": "2 1\n2 2", "output": "3" }, { "input": "2 1\n2 10", "output": "3" }, { "input": "1 11\n2 10", "output": "12" }, { "input": "11 1\n2 10", "output": "12" }, { "input": "1 1\n3 5", "output": "8" }, { "input": "1 10\n3 5", "output": "17" }, { "input": "1 21\n3 10", "output": "33" }, { "input": "21 1\n3 10", "output": "33" }, { "input": "100 100\n99 1", "output": "12301" }, { "input": "100 100\n100 1", "output": "12450" }, { "input": "99 99\n99 1", "output": "12202" }, { "input": "99 99\n99 10", "output": "33811" }, { "input": "1 100\n99 10", "output": "28764" }, { "input": "13 31\n7 5", "output": "182" }, { "input": "88 78\n8 5", "output": "719" }, { "input": "34 48\n47 4", "output": "4030" }, { "input": "91 29\n78 3", "output": "8806" }, { "input": "90 81\n21 6", "output": "2391" }, { "input": "95 89\n45 3", "output": "5589" }, { "input": "48 54\n84 2", "output": "7724" }, { "input": "72 31\n59 7", "output": "8865" }, { "input": "51 13\n47 3", "output": "2970" }, { "input": "97 91\n82 2", "output": "10984" }, { "input": "71 71\n9 5", "output": "719" }, { "input": "16 49\n40 3", "output": "2350" }, { "input": "22 41\n68 4", "output": "6608" }, { "input": "13 71\n72 6", "output": "10444" }, { "input": "77 78\n46 3", "output": "5083" }, { "input": "36 60\n54 2", "output": "3924" }, { "input": "55 39\n93 2", "output": "8571" }, { "input": "34 7\n48 6", "output": "4266" }, { "input": "80 88\n79 3", "output": "11193" }, { "input": "34 62\n15 4", "output": "866" }, { "input": "81 40\n73 2", "output": "6798" }, { "input": "13 38\n97 6", "output": "16271" }, { "input": "84 87\n45 2", "output": "4814" }, { "input": "42 65\n76 3", "output": "8240" }, { "input": "55 6\n24 4", "output": "1110" }, { "input": "41 16\n43 2", "output": "2029" }, { "input": "99 93\n78 1", "output": "8961" }, { "input": "10 7\n44 2", "output": "1297" }, { "input": "72 54\n91 3", "output": "11781" }, { "input": "48 34\n80 2", "output": "6376" }, { "input": "92 85\n70 1", "output": "7373" } ]
1,575,661,058
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
0
v1,v2=map(int,input().split()) t,d=map(int,input().split()) l=[v1] if(d!=0): for i in range((6//d)-2): l.append(v1+d) l.append(v2+d) l.append(v2) print(sum(l)) else: if (d==0): print(v1*t)
Title: Covered Path Time Limit: None seconds Memory Limit: None megabytes Problem Description: The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass. Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by *d* meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed *d* in absolute value), find the maximum possible length of the path section in meters. Input Specification: The first line contains two integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=≤<=100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively. The second line contains two integers *t* (2<=≤<=*t*<=≤<=100) — the time when the car moves along the segment in seconds, *d* (0<=≤<=*d*<=≤<=10) — the maximum value of the speed change between adjacent seconds. It is guaranteed that there is a way to complete the segment so that: - the speed in the first second equals *v*1, - the speed in the last second equals *v*2, - the absolute value of difference of speeds between any two adjacent seconds doesn't exceed *d*. Output Specification: Print the maximum possible length of the path segment in meters. Demo Input: ['5 6\n4 2\n', '10 10\n10 0\n'] Demo Output: ['26', '100'] Note: In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters. In the second sample, as *d* = 0, the car covers the whole segment at constant speed *v* = 10. In *t* = 10 seconds it covers the distance of 100 meters.
```python v1,v2=map(int,input().split()) t,d=map(int,input().split()) l=[v1] if(d!=0): for i in range((6//d)-2): l.append(v1+d) l.append(v2+d) l.append(v2) print(sum(l)) else: if (d==0): print(v1*t) ```
0
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.
The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { "input": "750 1000 54 103", "output": "Tie" }, { "input": "2000 1250 176 130", "output": "Tie" }, { "input": "1250 1750 145 179", "output": "Tie" }, { "input": "2000 2000 176 179", "output": "Tie" }, { "input": "1500 1500 148 148", "output": "Tie" }, { "input": "2750 1750 134 147", "output": "Misha" }, { "input": "3250 250 175 173", "output": "Misha" }, { "input": "500 500 170 176", "output": "Misha" }, { "input": "250 1000 179 178", "output": "Vasya" }, { "input": "3250 1000 160 138", "output": "Misha" }, { "input": "3000 2000 162 118", "output": "Tie" }, { "input": "1500 1250 180 160", "output": "Tie" }, { "input": "1250 2500 100 176", "output": "Tie" }, { "input": "3500 3500 177 178", "output": "Tie" }, { "input": "3000 3250 16 34", "output": "Tie" }, { "input": "1750 3000 137 49", "output": "Vasya" }, { "input": "500 1500 179 71", "output": "Vasya" }, { "input": "1250 2000 101 180", "output": "Misha" }, { "input": "250 750 180 176", "output": "Vasya" }, { "input": "2250 2250 163 145", "output": "Vasya" }, { "input": "3000 3000 176 78", "output": "Vasya" }, { "input": "250 3500 8 178", "output": "Vasya" }, { "input": "1750 1250 179 180", "output": "Misha" }, { "input": "2750 1750 13 164", "output": "Misha" }, { "input": "1750 2250 178 53", "output": "Vasya" }, { "input": "2500 2750 73 179", "output": "Misha" }, { "input": "1000 3500 178 175", "output": "Vasya" }, { "input": "1000 500 7 162", "output": "Misha" }, { "input": "1000 250 175 48", "output": "Misha" }, { "input": "1750 500 166 177", "output": "Misha" }, { "input": "250 250 0 0", "output": "Tie" }, { "input": "250 3500 0 0", "output": "Vasya" }, { "input": "250 3500 0 180", "output": "Vasya" }, { "input": "3500 3500 180 180", "output": "Tie" }, { "input": "3500 250 0 180", "output": "Misha" } ]
1,658,775,563
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
a,b,c,d = map(int,input().split()) m = max(3*a/10,a-a/250*c) v = max(3*b/10,b-b/250*d) print('Misha' if m >v else 'Vasya' if m<v else 'Tie')
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the contest started and Vasya submitted the problem *d* minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs *p* points *t* minutes after the contest started, you get points. Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth. Input Specification: The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). Output Specification: Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points. Demo Input: ['500 1000 20 30\n', '1000 1000 1 1\n', '1500 1000 176 177\n'] Demo Output: ['Vasya\n', 'Tie\n', 'Misha\n'] Note: none
```python a,b,c,d = map(int,input().split()) m = max(3*a/10,a-a/250*c) v = max(3*b/10,b-b/250*d) print('Misha' if m >v else 'Vasya' if m<v else 'Tie') ```
3
645
C
Enduring Exodus
PROGRAMMING
1,600
[ "binary search", "two pointers" ]
null
null
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupied. Farmer John wants to book a set of *k*<=+<=1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms *i* and *j* is defined as |*j*<=-<=*i*|. Help Farmer John protect his cows by calculating this minimum possible distance.
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=100<=000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th room is free, and '1' if the *i*-th room is occupied. It is guaranteed that at least *k*<=+<=1 characters of this string are '0', so there exists at least one possible choice of *k*<=+<=1 rooms for Farmer John and his cows to stay in.
Print the minimum possible distance between Farmer John's room and his farthest cow.
[ "7 2\n0100100\n", "5 1\n01010\n", "3 2\n000\n" ]
[ "2\n", "2\n", "1\n" ]
In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
1,500
[ { "input": "7 2\n0100100", "output": "2" }, { "input": "5 1\n01010", "output": "2" }, { "input": "3 2\n000", "output": "1" }, { "input": "10 1\n1101111101", "output": "6" }, { "input": "2 1\n00", "output": "1" }, { "input": "3 1\n010", "output": "2" }, { "input": "8 7\n00000000", "output": "4" }, { "input": "7 6\n0000000", "output": "3" }, { "input": "112 12\n0110101000000010101110010111100101011010011110100111111100011101011111000111101101110100111011110001100110110010", "output": "10" }, { "input": "9 8\n000000000", "output": "4" }, { "input": "9 3\n010001000", "output": "2" }, { "input": "5 3\n00000", "output": "2" }, { "input": "8 7\n00000000", "output": "4" }, { "input": "6 1\n000011", "output": "1" }, { "input": "100 40\n0010010100000100011100010100110001101100110000110010000000001010000111100000100100100101010010001100", "output": "30" }, { "input": "93 79\n000000000000000000011000000000000000000000000000000000000000000000010000000000100000100000000", "output": "42" }, { "input": "31 11\n0000001011011100010000000110001", "output": "7" }, { "input": "47 46\n00000000000000000000000000000000000000000000000", "output": "23" }, { "input": "100 96\n0000000000000010000010000000000000000000000000000000000000000000000000000010000000000000000000000000", "output": "50" }, { "input": "491 89\n01111101111111100000111010110001010001110111000010101111101000100010010111011101110110111101101010111000111000011100011010010010111111000011011010100110001000011100111000001011100010001111101111101000111001100110010100101000001110010100100100100101001100010101001000010000111110011000000100000100101000100101000001001101011011100000110101111110101001001000100110010000010110101011000101011001001011001000110000011111001110101011000000110101000000100110001101111000101001001001100001001110101", "output": "73" }, { "input": "308 17\n01000000100000000000000001000001000010000000000000000001001110000001010001000110000000000000100101000000010000001000000000001100000110000000000000000001000000000000000100000001000010001000000001000000000000000100010000000000000000000000000000000000001000000000001001101100000000000010000000000000000000000000", "output": "9" }, { "input": "8 4\n00111000", "output": "5" }, { "input": "18 2\n010111110111011110", "output": "5" }, { "input": "29 3\n01110011111111111111110110110", "output": "17" } ]
1,677,095,667
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
8
62
0
import sys input = sys.stdin.readline n, k = map(int, input().split()) s = input()[:-1] q = [] j = 0 c = 0 k += 1 x = 1 << 30 a = k//2 for i in range(n): if s[i] == '0': c += 1 q.append(i) if c > k: c -= 1 j += 1 if c == k: x = min(x, max(q[j+a]-q[j], q[-1]-q[j+a])) print(x)
Title: Enduring Exodus Time Limit: None seconds Memory Limit: None megabytes Problem Description: In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupied. Farmer John wants to book a set of *k*<=+<=1 currently unoccupied rooms for him and his cows. He wants his cows to stay as safe as possible, so he wishes to minimize the maximum distance from his room to the room of his cow. The distance between rooms *i* and *j* is defined as |*j*<=-<=*i*|. Help Farmer John protect his cows by calculating this minimum possible distance. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=100<=000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th room is free, and '1' if the *i*-th room is occupied. It is guaranteed that at least *k*<=+<=1 characters of this string are '0', so there exists at least one possible choice of *k*<=+<=1 rooms for Farmer John and his cows to stay in. Output Specification: Print the minimum possible distance between Farmer John's room and his farthest cow. Demo Input: ['7 2\n0100100\n', '5 1\n01010\n', '3 2\n000\n'] Demo Output: ['2\n', '2\n', '1\n'] Note: In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 for his single cow. The distance between him and his cow is 2. In the third sample, Farmer John books all three available rooms, taking the middle room for himself so that both cows are next to him. His distance from the farthest cow is 1.
```python import sys input = sys.stdin.readline n, k = map(int, input().split()) s = input()[:-1] q = [] j = 0 c = 0 k += 1 x = 1 << 30 a = k//2 for i in range(n): if s[i] == '0': c += 1 q.append(i) if c > k: c -= 1 j += 1 if c == k: x = min(x, max(q[j+a]-q[j], q[-1]-q[j+a])) print(x) ```
0
544
A
Set of Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.
The first line contains a positive integer *k* (1<=≤<=*k*<=≤<=26) — the number of strings that should be in a beautiful sequence. The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.
If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*. If there are multiple possible answers, print any of them.
[ "1\nabca\n", "2\naaacas\n", "4\nabc\n" ]
[ "YES\nabca\n", "YES\naaa\ncas\n", "NO\n" ]
In the second sample there are two possible answers: {"*aaaca*", "*s*"} and {"*aaa*", "*cas*"}.
500
[ { "input": "1\nabca", "output": "YES\nabca" }, { "input": "2\naaacas", "output": "YES\naaa\ncas" }, { "input": "4\nabc", "output": "NO" }, { "input": "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk", "output": "YES\nn\ndd\nkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk" }, { "input": "26\nbiibfmmfifmffbmmfmbmbmiimbmiffmffibibfbiffibibiiimbffbbfbifmiibffbmbbbfmfibmibfffibfbffmfmimbmmmfmfm", "output": "NO" }, { "input": "3\nkydoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia", "output": "YES\nk\ny\ndoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia" }, { "input": "3\nssussususskkskkskuusksuuussksukkskuksukukusssususuususkkuukssuksskusukkssuksskskuskusussusskskksksus", "output": "YES\nss\nussususs\nkkskkskuusksuuussksukkskuksukukusssususuususkkuukssuksskusukkssuksskskuskusussusskskksksus" }, { "input": "5\naaaaabcdef", "output": "YES\naaaaa\nb\nc\nd\nef" }, { "input": "3\niiiiiiimiriiriwmimtmwrhhxmbmhwgghhgbqhywebrblyhlxjrthoooltehrmdhqhuodjmsjwcgrfnttiitpmqvbhlafwtzyikc", "output": "YES\niiiiiii\nmi\nriiriwmimtmwrhhxmbmhwgghhgbqhywebrblyhlxjrthoooltehrmdhqhuodjmsjwcgrfnttiitpmqvbhlafwtzyikc" }, { "input": "20\ngggggllglgllltgtlglttstsgtttsslhhlssghgagtlsaghhoggtfgsaahtotdodthfltdxggxislnttlanxonhnkddtigppitdh", "output": "NO" }, { "input": "16\nkkkkkkyykkynkknkkonyokdndkyonokdywkwykdkdotknnwzkoywiooinkcyzyntcdnitnppnpziomyzdspomoqmomcyrrospppn", "output": "NO" }, { "input": "15\nwwwgggowgwwhoohwgwghwyohhggywhyyodgwydwgggkhgyydqyggkgkpokgthqghidhworprodtcogqkwgtfiodwdurcctkmrfmh", "output": "YES\nwww\nggg\nowgww\nhoohwgwghw\nyohhggywhyyo\ndgwydwggg\nkhgyyd\nqyggkgk\npokg\nthqgh\nidhwo\nrprodt\ncogqkwgt\nfiodwd\nurcctkmrfmh" }, { "input": "15\nnnnnnntnttttttqqnqqynnqqwwnnnwneenhwtyhhoqeyeqyeuthwtnhtpnphhwetjhouhwnpojvvovoswwjryrwerbwwpbvrwvjj", "output": "YES\nnnnnnn\ntntttttt\nqqnqq\nynnqq\nwwnnnwn\neen\nhwtyhh\noqeyeqye\nuthwtnht\npnphhwet\njhouhwnpoj\nvvovo\nswwj\nryrwer\nbwwpbvrwvjj" }, { "input": "15\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv", "output": "NO" }, { "input": "1\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai", "output": "YES\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai" }, { "input": "26\nvvvnnsnnnpsnnswwspncvshtncwphaphmwnwkhvvhuvctvnehemowkmtzissswjaxuuvphzrmfzihamdqmmyhhijbitlipgltyy", "output": "YES\nvvv\nnn\nsnnn\npsnns\nwwspn\ncvs\nh\ntncwph\naph\nmwnw\nkhvvh\nuvctvn\nehem\nowkmt\nz\nisssw\nja\nxuuvphz\nrm\nfziham\nd\nqmm\nyhhij\nbit\nlip\ngltyy" }, { "input": "26\njexzsbwaih", "output": "NO" }, { "input": "1\nk", "output": "YES\nk" }, { "input": "1\nzz", "output": "YES\nzz" }, { "input": "3\nziw", "output": "YES\nz\ni\nw" }, { "input": "26\ntjmbyqwuahlixegopkzrfndcsv", "output": "YES\nt\nj\nm\nb\ny\nq\nw\nu\na\nh\nl\ni\nx\ne\ng\no\np\nk\nz\nr\nf\nn\nd\nc\ns\nv" }, { "input": "25\nvobekscyadzqwnjxruplifmthg", "output": "YES\nv\no\nb\ne\nk\ns\nc\ny\na\nd\nz\nq\nw\nn\nj\nx\nr\nu\np\nl\ni\nf\nm\nt\nhg" }, { "input": "26\nlllplzkkzflzflffzznnnnfgflqlttlmtnkzlztskngyymitqagattkdllyutzimsrskpapcmuupjdopxqlnhqcscwvdtxbflefy", "output": "YES\nlll\npl\nz\nkkz\nflzflffzz\nnnnnf\ngfl\nql\nttl\nmtnkzlzt\nskng\nyym\nitq\nagattk\ndlly\nutzims\nrskpap\ncmuup\njd\nop\nxqln\nhqcsc\nw\nvdtx\nbfl\nefy" }, { "input": "25\nkkrrkrkrkrsrskpskbrppdsdbgbkrbllkbswdwcchgskmkhwiidicczlscsodtjglxbmeotzxnmbjmoqgkquglaoxgcykxvbhdi", "output": "YES\nkk\nrrkrkrkr\nsrsk\npsk\nbrpp\ndsdb\ngbkrb\nllkbs\nwdw\ncc\nhgsk\nmkhw\niidicc\nzlscs\nod\nt\njgl\nxbm\neotzx\nnmbjmo\nqgkq\nugl\naoxgc\nykx\nvbhdi" }, { "input": "25\nuuuuuccpucubccbupxubcbpujiliwbpqbpyiweuywaxwqasbsllwehceruytjvphytraawgbjmerfeymoayujqranlvkpkiypadr", "output": "YES\nuuuuu\ncc\npucu\nbccbup\nxubcbpu\nj\ni\nli\nwbp\nqbp\nyiw\neuyw\naxwqa\nsbsllwe\nhce\nruy\ntj\nvphytraaw\ngbj\nmer\nfeym\noayujqra\nnlv\nkpkiypa\ndr" }, { "input": "26\nxxjxodrogovufvohrodliretxxyjqnrbzmicorptkjafiwmsbwml", "output": "YES\nxx\njx\no\nd\nro\ngo\nv\nu\nfvo\nhrod\nl\nir\ne\ntxx\nyj\nq\nnr\nb\nz\nmi\ncor\npt\nkj\nafi\nwm\nsbwml" }, { "input": "26\npjhsxjbvkqntwmsdnrguecaofylzti", "output": "YES\np\nj\nh\ns\nxj\nb\nv\nk\nq\nn\nt\nw\nms\ndn\nr\ng\nu\ne\nc\na\no\nf\ny\nl\nzt\ni" }, { "input": "25\nrrrrqqwrlqrwglrlylwhrrwyvrhvzgvqahrhgsvavtggyduayivxzgeicinlnrkapoepbsfyjjrt", "output": "YES\nrrrr\nqq\nwr\nlqrw\nglrl\nylw\nhrrwy\nvrhv\nzgvq\nahrhg\nsvav\ntggy\nd\nuay\niv\nxzg\nei\nci\nnlnr\nka\np\noep\nbs\nfy\njjrt" }, { "input": "26\ncccccccaacwwaxxaacczacnnnqqwnaggzqrwagcnabxnrcvgjqjamqzgdntzanaxvjfwqlvdttuzjoxiwtkqvrydospmpeirhg", "output": "YES\nccccccc\naac\nwwa\nxxaacc\nzac\nnnn\nqqwna\nggzq\nrwagcna\nbxnrc\nvg\njqja\nmqzg\ndn\ntzanaxvj\nfwq\nlvdtt\nuzj\nox\niwt\nkqvr\nydo\ns\npmp\neir\nhg" }, { "input": "4\nsssssssssssssssssssssssssslsslslsllsslssslslssllaaslsaalsasaassllasasalrlrslarlaarlsrsaslasarlr", "output": "YES\nssssssssssssssssssssssssss\nlsslslsllsslssslslssll\naaslsaalsasaassllasasal\nrlrslarlaarlsrsaslasarlr" }, { "input": "26\na", "output": "NO" }, { "input": "26\nab", "output": "NO" }, { "input": "2\nab", "output": "YES\na\nb" } ]
1,583,434,745
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
6
202
2,150,400
import sys import math import bisect def solve(s, k): d = dict() for i in range(len(s)): if s[i] not in d: d[s[i]] = i A = list(d.values()) #print('s: %s, k: %d, A: %s' % (s, k, A)) if len(A) < k: return None B = [] for i in range(len(A)): if len(B) < k: first = A[i] if i == len(A) - 1: last = n else: last = A[i+1] B.append(s[first:last]) if len(B) == k: B[-1] += (s[last:]) return B def main(): k = int(input()) s = input() ans = solve(s, k) if ans: print('YES') for a in ans: print(a) else: print('NO') if __name__ == "__main__": main()
Title: Set of Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *q*. A sequence of *k* strings *s*1,<=*s*2,<=...,<=*s**k* is called beautiful, if the concatenation of these strings is string *q* (formally, *s*1<=+<=*s*2<=+<=...<=+<=*s**k*<==<=*q*) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist. Input Specification: The first line contains a positive integer *k* (1<=≤<=*k*<=≤<=26) — the number of strings that should be in a beautiful sequence. The second line contains string *q*, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive. Output Specification: If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next *k* lines print the beautiful sequence of strings *s*1,<=*s*2,<=...,<=*s**k*. If there are multiple possible answers, print any of them. Demo Input: ['1\nabca\n', '2\naaacas\n', '4\nabc\n'] Demo Output: ['YES\nabca\n', 'YES\naaa\ncas\n', 'NO\n'] Note: In the second sample there are two possible answers: {"*aaaca*", "*s*"} and {"*aaa*", "*cas*"}.
```python import sys import math import bisect def solve(s, k): d = dict() for i in range(len(s)): if s[i] not in d: d[s[i]] = i A = list(d.values()) #print('s: %s, k: %d, A: %s' % (s, k, A)) if len(A) < k: return None B = [] for i in range(len(A)): if len(B) < k: first = A[i] if i == len(A) - 1: last = n else: last = A[i+1] B.append(s[first:last]) if len(B) == k: B[-1] += (s[last:]) return B def main(): k = int(input()) s = input() ans = solve(s, k) if ans: print('YES') for a in ans: print(a) else: print('NO') if __name__ == "__main__": main() ```
-1
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,533,943,812
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
0
s=input() if(s=="1"): print(0) else: s1="" k=0 while(s[k]!="0"): s1+=s[k] k+=1 s1+=s[k+1:] if(k==len(s)-1): print(s[1:]) else: print(s1)
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python s=input() if(s=="1"): print(0) else: s1="" k=0 while(s[k]!="0"): s1+=s[k] k+=1 s1+=s[k+1:] if(k==len(s)-1): print(s[1:]) else: print(s1) ```
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6", "output": "3" }, { "input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32", "output": "6" }, { "input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30", "output": "10" }, { "input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20", "output": "8" }, { "input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49", "output": "1" }, { "input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16", "output": "5" }, { "input": "2\n0 24\n1 0", "output": "1" }, { "input": "1\n0 0", "output": "1" }, { "input": "1\n1 5", "output": "1" }, { "input": "1\n1 1", "output": "1" }, { "input": "3\n0 0\n0 0\n0 0", "output": "3" }, { "input": "1\n5 0", "output": "1" }, { "input": "5\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "5" }, { "input": "1\n10 10", "output": "1" }, { "input": "1\n8 0", "output": "1" }, { "input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "output": "10" }, { "input": "2\n0 0\n0 1", "output": "1" }, { "input": "2\n8 5\n8 5", "output": "2" } ]
1,630,586,662
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n = int(input()) time = [] line = input() while(line != ‘’): final_list.append(list(line.split())) line = input() ans = 1 for i in range(1, n): if (time[i][0] == time[i-1][0]): diff = abs(time[i][1] - time[i-1][1]) if abs(diff) <= 1: ans += 1 elif (time[i][0] - time[i-1][0] == 1) and (time[i-1][1] == 59 and time[i][1] == 0): ans += 1 print(ans)
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period. Output Specification: Print a single integer — the minimum number of cashes, needed to serve all clients next day. Demo Input: ['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so it will be enough one cash.
```python n = int(input()) time = [] line = input() while(line != ‘’): final_list.append(list(line.split())) line = input() ans = 1 for i in range(1, n): if (time[i][0] == time[i-1][0]): diff = abs(time[i][1] - time[i-1][1]) if abs(diff) <= 1: ans += 1 elif (time[i][0] - time[i-1][0] == 1) and (time[i-1][1] == 59 and time[i][1] == 0): ans += 1 print(ans) ```
-1
977
A
Wrong Subtraction
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number.
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number.
[ "512 4\n", "1000000000 9\n" ]
[ "50\n", "1\n" ]
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
0
[ { "input": "512 4", "output": "50" }, { "input": "1000000000 9", "output": "1" }, { "input": "131203 11", "output": "12" }, { "input": "999999999 50", "output": "9999" }, { "input": "999999999 49", "output": "99990" }, { "input": "131203 9", "output": "130" }, { "input": "900000000 16", "output": "1" }, { "input": "909090909 50", "output": "3" }, { "input": "1001 2", "output": "100" }, { "input": "5 2", "output": "3" }, { "input": "2 1", "output": "1" } ]
1,694,578,632
2,147,483,647
Python 3
OK
TESTS
11
46
0
a,b=map(int,input().split()) for x in range(b): if a%10==0: a=a/10 elif a%10!=0: a=a-1 print(int(a))
Title: Wrong Subtraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: - if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions. It is guaranteed that the result will be positive integer number. Input Specification: The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. Output Specification: Print one integer number — the result of the decreasing $n$ by one $k$ times. It is guaranteed that the result will be positive integer number. Demo Input: ['512 4\n', '1000000000 9\n'] Demo Output: ['50\n', '1\n'] Note: The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$.
```python a,b=map(int,input().split()) for x in range(b): if a%10==0: a=a/10 elif a%10!=0: a=a-1 print(int(a)) ```
3