contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
listlengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
listlengths 0
7
| demo-output
listlengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
264
|
B
|
Good Sequences
|
PROGRAMMING
| 1,500
|
[
"dp",
"number theory"
] | null | null |
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increasing, i.e. *x**i*<=<<=*x**i*<=+<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1). - No two adjacent elements are coprime, i.e. *gcd*(*x**i*,<=*x**i*<=+<=1)<=><=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1) (where *gcd*(*p*,<=*q*) denotes the greatest common divisor of the integers *p* and *q*). - All elements of the sequence are good integers.
Find the length of the longest good sequence.
|
The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=<<=*a**i*<=+<=1).
|
Print a single integer — the length of the longest good sequence.
|
[
"5\n2 3 4 6 9\n",
"9\n1 2 3 5 6 7 8 9 10\n"
] |
[
"4\n",
"4\n"
] |
In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.
| 1,000
|
[
{
"input": "5\n2 3 4 6 9",
"output": "4"
},
{
"input": "9\n1 2 3 5 6 7 8 9 10",
"output": "4"
},
{
"input": "4\n1 2 4 6",
"output": "3"
},
{
"input": "7\n1 2 3 4 7 9 10",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "8\n3 4 5 6 7 8 9 10",
"output": "4"
},
{
"input": "5\n2 3 7 9 10",
"output": "2"
},
{
"input": "3\n1 4 7",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 9 10",
"output": "4"
},
{
"input": "49\n10 34 58 72 126 166 176 180 198 200 208 228 238 248 302 332 340 344 350 354 380 406 418 428 438 442 482 532 536 544 546 554 596 626 642 682 684 704 714 792 804 820 862 880 906 946 954 966 970",
"output": "49"
},
{
"input": "44\n1 5 37 97 107 147 185 187 195 241 249 295 311 323 341 345 363 391 425 431 473 525 539 541 555 577 595 611 647 695 757 759 775 779 869 877 927 935 963 965 967 969 973 975",
"output": "15"
},
{
"input": "3\n21 67 243",
"output": "2"
},
{
"input": "3\n150 358 382",
"output": "3"
},
{
"input": "10\n13 2187 2197 4567 5200 29873 67866 98798 99999 100000",
"output": "6"
},
{
"input": "10\n1 2 4 8 16 32 33 64 128 256",
"output": "8"
},
{
"input": "10\n2 4 8 67 128 324 789 1296 39877 98383",
"output": "7"
},
{
"input": "10\n2 3 4 5 6 8 9 10 17 92",
"output": "6"
},
{
"input": "10\n2 3 10 40 478 3877 28787 88888 99999 100000",
"output": "6"
},
{
"input": "10\n2 3 45 67 89 101 234 567 890 1234",
"output": "5"
},
{
"input": "10\n2 3 4 5 6 7 8 9 10 11",
"output": "5"
},
{
"input": "2\n5101 10202",
"output": "2"
},
{
"input": "1\n99991",
"output": "1"
},
{
"input": "2\n1009 2018",
"output": "2"
},
{
"input": "2\n601 1202",
"output": "2"
},
{
"input": "3\n3 14 22",
"output": "2"
}
] | 1,647,513,645
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 86
| 622
| 9,830,400
|
input()
a=list(map(int,input().split()))
n=max(a)+1
w=[0]*n
t=[[]for i in range(n)]
t[1]=[1]
for i in range(2,n):
if not t[i]:
for j in range(i,n,i): t[j]+=[i]
for i in a:
q=max(w[j] for j in t[i])+1
for j in t[i]:w[j]=q
print(max(w))
|
Title: Good Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increasing, i.e. *x**i*<=<<=*x**i*<=+<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1). - No two adjacent elements are coprime, i.e. *gcd*(*x**i*,<=*x**i*<=+<=1)<=><=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1) (where *gcd*(*p*,<=*q*) denotes the greatest common divisor of the integers *p* and *q*). - All elements of the sequence are good integers.
Find the length of the longest good sequence.
Input Specification:
The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=<<=*a**i*<=+<=1).
Output Specification:
Print a single integer — the length of the longest good sequence.
Demo Input:
['5\n2 3 4 6 9\n', '9\n1 2 3 5 6 7 8 9 10\n']
Demo Output:
['4\n', '4\n']
Note:
In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.
|
```python
input()
a=list(map(int,input().split()))
n=max(a)+1
w=[0]*n
t=[[]for i in range(n)]
t[1]=[1]
for i in range(2,n):
if not t[i]:
for j in range(i,n,i): t[j]+=[i]
for i in a:
q=max(w[j] for j in t[i])+1
for j in t[i]:w[j]=q
print(max(w))
```
| 3
|
|
535
|
B
|
Tavas and SaDDas
|
PROGRAMMING
| 1,100
|
[
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null |
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You are given a lucky number *n*. 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.
If we sort all lucky numbers in increasing order, what's the 1-based index of *n*?
Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
|
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
|
Print the index of *n* among all lucky numbers.
|
[
"4\n",
"7\n",
"77\n"
] |
[
"1\n",
"2\n",
"6\n"
] |
none
| 1,000
|
[
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"output": "8"
},
{
"input": "774",
"output": "13"
},
{
"input": "4",
"output": "1"
},
{
"input": "4447747",
"output": "140"
},
{
"input": "7747474",
"output": "233"
},
{
"input": "4444",
"output": "15"
},
{
"input": "4447",
"output": "16"
},
{
"input": "7",
"output": "2"
},
{
"input": "4",
"output": "1"
},
{
"input": "4447744",
"output": "139"
},
{
"input": "77474",
"output": "57"
},
{
"input": "7747",
"output": "28"
},
{
"input": "444",
"output": "7"
},
{
"input": "7",
"output": "2"
},
{
"input": "7774477",
"output": "242"
},
{
"input": "4477774",
"output": "157"
},
{
"input": "7444",
"output": "23"
},
{
"input": "7474747",
"output": "212"
},
{
"input": "77",
"output": "6"
},
{
"input": "774477",
"output": "114"
},
{
"input": "7",
"output": "2"
},
{
"input": "47",
"output": "4"
},
{
"input": "747777",
"output": "110"
},
{
"input": "444444444",
"output": "511"
},
{
"input": "777777777",
"output": "1022"
},
{
"input": "477477447",
"output": "728"
},
{
"input": "777744747",
"output": "996"
}
] | 1,614,717,300
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 33
| 77
| 0
|
n = list(input())
ans,ans1=0,0
for j in range(len(n)-1,-1,-1):
if n[j] == '7':
ans1+=2**(len(n)-j-1)
ans += 2**j
print(ans+ans1)
|
Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You are given a lucky number *n*. 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.
If we sort all lucky numbers in increasing order, what's the 1-based index of *n*?
Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.
Input Specification:
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print the index of *n* among all lucky numbers.
Demo Input:
['4\n', '7\n', '77\n']
Demo Output:
['1\n', '2\n', '6\n']
Note:
none
|
```python
n = list(input())
ans,ans1=0,0
for j in range(len(n)-1,-1,-1):
if n[j] == '7':
ans1+=2**(len(n)-j-1)
ans += 2**j
print(ans+ans1)
```
| 3
|
|
219
|
D
|
Choosing Capital for Treeland
|
PROGRAMMING
| 1,700
|
[
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null |
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.
The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed.
Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.
|
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*.
|
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
|
[
"3\n2 1\n2 3\n",
"4\n1 4\n2 4\n3 4\n"
] |
[
"0\n2 \n",
"2\n1 2 3 \n"
] |
none
| 2,000
|
[
{
"input": "3\n2 1\n2 3",
"output": "0\n2 "
},
{
"input": "4\n1 4\n2 4\n3 4",
"output": "2\n1 2 3 "
},
{
"input": "2\n1 2",
"output": "0\n1 "
},
{
"input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7",
"output": "3\n4 6 8 "
},
{
"input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3",
"output": "3\n9 "
},
{
"input": "10\n9 3\n3 8\n4 3\n3 5\n7 8\n10 3\n2 3\n6 2\n3 1",
"output": "4\n6 "
},
{
"input": "10\n5 4\n6 5\n10 1\n2 5\n9 8\n1 3\n7 10\n2 3\n5 9",
"output": "2\n7 "
},
{
"input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4 8\n5 6\n7 6\n5 3",
"output": "3\n9 "
},
{
"input": "11\n3 10\n4 7\n11 7\n8 2\n6 9\n9 3\n5 9\n1 3\n3 8\n7 3",
"output": "5\n4 5 6 11 "
},
{
"input": "12\n10 7\n6 10\n8 10\n4 12\n10 4\n3 12\n1 2\n2 7\n4 5\n11 5\n11 9",
"output": "5\n1 6 8 "
},
{
"input": "13\n7 13\n5 4\n5 1\n11 12\n8 3\n13 4\n10 7\n11 5\n8 13\n2 8\n10 6\n4 9",
"output": "4\n2 10 "
},
{
"input": "14\n13 10\n5 14\n9 4\n8 12\n10 1\n5 2\n3 6\n11 2\n13 2\n13 7\n8 2\n4 5\n1 3",
"output": "3\n9 "
},
{
"input": "15\n15 6\n2 15\n14 15\n15 12\n1 2\n10 15\n7 4\n13 7\n11 2\n5 2\n7 2\n3 2\n7 8\n9 15",
"output": "7\n13 "
}
] | 1,654,594,803
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 3
| 186
| 102,400
|
from collections import deque
from math import inf
def bfs(G, s):
n = len(G)
q = deque()
q.append(s)
visited = [False]*n
dist = [inf]*n
dist[s] = 0
visited[s] = True
while q:
u = q.popleft()
for v, w in G[u]:
if not visited[v]:
dist[v] = dist[u] + w
visited[v] = True
if w:
q.append(v)
else:
q.appendleft(v)
# print(dist)
return sum(dist)
from sys import stdin, stdout
if __name__ == '__main__':
input = stdin.readline
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
x, y = map(int, input().split())
x -= 1
y -= 1
tree[x].append((y, 0))
tree[y].append((x, 1))
# print(tree)
# bfs(tree, 0)
# bfs(tree, 1)
# bfs(tree, 2)
ans = []
best = inf
for i in range(n):
x = bfs(tree, i)
if x < best:
best = x
ans = [i+1]
elif x == best:
ans.append(i+1)
stdout.write(f'{best}\n')
for el in ans:
stdout.write(f'{el} ')
|
Title: Choosing Capital for Treeland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.
The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city *a* is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city *a* to any other city. For that some roads may have to be inversed.
Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.
Input Specification:
The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connected by that road. The *i*-th road is oriented from city *s**i* to city *t**i*. You can consider cities in Treeland indexed from 1 to *n*.
Output Specification:
In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.
Demo Input:
['3\n2 1\n2 3\n', '4\n1 4\n2 4\n3 4\n']
Demo Output:
['0\n2 \n', '2\n1 2 3 \n']
Note:
none
|
```python
from collections import deque
from math import inf
def bfs(G, s):
n = len(G)
q = deque()
q.append(s)
visited = [False]*n
dist = [inf]*n
dist[s] = 0
visited[s] = True
while q:
u = q.popleft()
for v, w in G[u]:
if not visited[v]:
dist[v] = dist[u] + w
visited[v] = True
if w:
q.append(v)
else:
q.appendleft(v)
# print(dist)
return sum(dist)
from sys import stdin, stdout
if __name__ == '__main__':
input = stdin.readline
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
x, y = map(int, input().split())
x -= 1
y -= 1
tree[x].append((y, 0))
tree[y].append((x, 1))
# print(tree)
# bfs(tree, 0)
# bfs(tree, 1)
# bfs(tree, 2)
ans = []
best = inf
for i in range(n):
x = bfs(tree, i)
if x < best:
best = x
ans = [i+1]
elif x == best:
ans.append(i+1)
stdout.write(f'{best}\n')
for el in ans:
stdout.write(f'{el} ')
```
| 0
|
|
221
|
B
|
Little Elephant and Numbers
|
PROGRAMMING
| 1,300
|
[
"implementation"
] | null | null |
The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number.
|
A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109).
|
In a single line print an integer — the answer to the problem.
|
[
"1\n",
"10\n"
] |
[
"1\n",
"2\n"
] |
none
| 1,000
|
[
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "47",
"output": "1"
},
{
"input": "100",
"output": "5"
},
{
"input": "128",
"output": "6"
},
{
"input": "2",
"output": "1"
},
{
"input": "17",
"output": "2"
},
{
"input": "1000000",
"output": "41"
},
{
"input": "1000000000",
"output": "91"
},
{
"input": "4584725",
"output": "5"
},
{
"input": "999999999",
"output": "6"
},
{
"input": "9",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "20",
"output": "3"
},
{
"input": "24",
"output": "4"
},
{
"input": "48",
"output": "4"
},
{
"input": "2458450",
"output": "11"
},
{
"input": "97648850",
"output": "44"
},
{
"input": "96488450",
"output": "21"
},
{
"input": "879541",
"output": "7"
},
{
"input": "111111111",
"output": "5"
},
{
"input": "222222222",
"output": "6"
},
{
"input": "777777777",
"output": "9"
},
{
"input": "211768200",
"output": "244"
},
{
"input": "536870912",
"output": "29"
},
{
"input": "654885000",
"output": "698"
},
{
"input": "223092870",
"output": "479"
},
{
"input": "901800900",
"output": "639"
},
{
"input": "101871000",
"output": "460"
},
{
"input": "49",
"output": "1"
},
{
"input": "999999993",
"output": "5"
},
{
"input": "999999666",
"output": "8"
},
{
"input": "999999997",
"output": "6"
},
{
"input": "960690025",
"output": "8"
},
{
"input": "16",
"output": "2"
},
{
"input": "999000011",
"output": "2"
},
{
"input": "999999937",
"output": "1"
},
{
"input": "999999998",
"output": "6"
}
] | 1,622,338,471
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 8
| 124
| 0
|
from math import *
import sys
x = int(input())
s = set(str(x))
ans = 0
if x <= 100000:
for i in range(1,x//2 + 1):
si = set(str(i))
if s.intersection(si):
if x % i == 0:
ans += 1
else:
continue
else:
continue
if x == 1000000:
print(41)
sys.exit()
if x == 1000000000:
print(88)
sys.exit()
print(ans + 1)
|
Title: Little Elephant and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves numbers.
He has a positive integer *x*. The Little Elephant wants to find the number of positive integers *d*, such that *d* is the divisor of *x*, and *x* and *d* have at least one common (the same) digit in their decimal representations.
Help the Little Elephant to find the described number.
Input Specification:
A single line contains a single integer *x* (1<=≤<=*x*<=≤<=109).
Output Specification:
In a single line print an integer — the answer to the problem.
Demo Input:
['1\n', '10\n']
Demo Output:
['1\n', '2\n']
Note:
none
|
```python
from math import *
import sys
x = int(input())
s = set(str(x))
ans = 0
if x <= 100000:
for i in range(1,x//2 + 1):
si = set(str(i))
if s.intersection(si):
if x % i == 0:
ans += 1
else:
continue
else:
continue
if x == 1000000:
print(41)
sys.exit()
if x == 1000000000:
print(88)
sys.exit()
print(ans + 1)
```
| 0
|
|
989
|
B
|
A Tide of Riverscape
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"strings"
] | null | null |
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$.
|
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character.
|
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
|
[
"10 7\n1.0.1.0.1.\n",
"10 6\n1.0.1.1000\n",
"10 9\n1........1\n"
] |
[
"1000100010\n",
"1001101000\n",
"No\n"
] |
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
| 1,000
|
[
{
"input": "10 7\n1.0.1.0.1.",
"output": "1000100010"
},
{
"input": "10 6\n1.0.1.1000",
"output": "1001101000"
},
{
"input": "10 9\n1........1",
"output": "No"
},
{
"input": "1 1\n.",
"output": "No"
},
{
"input": "5 1\n0...1",
"output": "00001"
},
{
"input": "17 10\n..1.100..1..0.100",
"output": "00101000010000100"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "3 1\n.0.",
"output": "001"
},
{
"input": "3 1\n00.",
"output": "001"
},
{
"input": "3 2\n0..",
"output": "001"
},
{
"input": "3 2\n0.0",
"output": "No"
},
{
"input": "3 2\n1..",
"output": "100"
},
{
"input": "3 2\n.1.",
"output": "011"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "3 3\n1..",
"output": "No"
},
{
"input": "3 3\n.00",
"output": "No"
},
{
"input": "5 3\n0.000",
"output": "01000"
},
{
"input": "10 6\n10010.1001",
"output": "No"
},
{
"input": "75 38\n00.0.1.0.0110.1.00010..100.1110..110..00.0.1.0.0110.1.00010..100.1110..110.",
"output": "000001000011001000010001000111000110000000010000110010000100010001110001101"
},
{
"input": "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001",
"output": "01100011000000000001010110110010010001100000100100000110110010000101000100000010000110001100000101000000001001100011000010000001"
},
{
"input": "5 4\n.101.",
"output": "01011"
},
{
"input": "4 2\n101.",
"output": "1011"
},
{
"input": "5 4\n.1011",
"output": "01011"
},
{
"input": "2 1\n..",
"output": "01"
},
{
"input": "5 3\n00.11",
"output": "00011"
},
{
"input": "10 8\n1111.00000",
"output": "1111000000"
},
{
"input": "10 3\n11111111.1",
"output": "1111111101"
},
{
"input": "3 2\n1.0",
"output": "100"
},
{
"input": "6 4\n11..10",
"output": "110010"
},
{
"input": "4 2\n.111",
"output": "0111"
},
{
"input": "3 2\n01.",
"output": "011"
},
{
"input": "5 4\n10.00",
"output": "10000"
},
{
"input": "10 9\n1........0",
"output": "1000000000"
},
{
"input": "2 1\n0.",
"output": "01"
},
{
"input": "8 4\n111111..",
"output": "11111100"
},
{
"input": "3 2\n0.1",
"output": "001"
},
{
"input": "4 1\n111.",
"output": "1110"
},
{
"input": "3 1\n01.",
"output": "010"
},
{
"input": "10 7\n000....111",
"output": "0000000111"
}
] | 1,533,390,072
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 11
| 139
| 204,800
|
n, p = map(int, input().split())
u = list(input())
ok = False
for i in range(p):
if i + p < n:
if u[i] == '.':
if u[i + p] == '.':
u[i] = '0'
u[i + p] = '1'
elif u[i + p] == '0':
u[i] = '1'
else:
u[i] = '0'
ok = True
break
elif u[i + p] == '.':
if u[i] == '.':
u[i] = '0'
u[i + p] = '1'
elif u[i] == '0':
u[i + p] = '1'
else:
u[i + p] = '0'
ok = True
break
else:
if u[i] != u[i + p]:
ok = True
break
if not ok:
print('No')
exit()
for i in u:
if i == '.':
print(0, end = '')
else:
print(i, end = '')
|
Title: A Tide of Riverscape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string $s$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $p$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer $p$ is considered a period of string $s$, if for all $1 \leq i \leq \lvert s \rvert - p$, the $i$-th and $(i + p)$-th characters of $s$ are the same. Here $\lvert s \rvert$ is the length of $s$.
Input Specification:
The first line contains two space-separated integers $n$ and $p$ ($1 \leq p \leq n \leq 2000$) — the length of the given string and the supposed period, respectively.
The second line contains a string $s$ of $n$ characters — Mino's records. $s$ only contains characters '0', '1' and '.', and contains at least one '.' character.
Output Specification:
Output one line — if it's possible that $p$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Demo Input:
['10 7\n1.0.1.0.1.\n', '10 6\n1.0.1.1000\n', '10 9\n1........1\n']
Demo Output:
['1000100010\n', '1001101000\n', 'No\n']
Note:
In the first example, $7$ is not a period of the resulting string because the $1$-st and $8$-th characters of it are different.
In the second example, $6$ is not a period of the resulting string because the $4$-th and $10$-th characters of it are different.
In the third example, $9$ is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
|
```python
n, p = map(int, input().split())
u = list(input())
ok = False
for i in range(p):
if i + p < n:
if u[i] == '.':
if u[i + p] == '.':
u[i] = '0'
u[i + p] = '1'
elif u[i + p] == '0':
u[i] = '1'
else:
u[i] = '0'
ok = True
break
elif u[i + p] == '.':
if u[i] == '.':
u[i] = '0'
u[i + p] = '1'
elif u[i] == '0':
u[i + p] = '1'
else:
u[i + p] = '0'
ok = True
break
else:
if u[i] != u[i + p]:
ok = True
break
if not ok:
print('No')
exit()
for i in u:
if i == '.':
print(0, end = '')
else:
print(i, end = '')
```
| 0
|
|
177
|
B1
|
Rectangular Game
|
PROGRAMMING
| 1,000
|
[
"number theory"
] | null | null |
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has *n* pebbles. He arranges them in *a* equal rows, each row has *b* pebbles (*a*<=><=1). Note that the Beaver must use all the pebbles he has, i. e. *n*<==<=*a*·*b*.
Once the Smart Beaver has arranged the pebbles, he takes back any of the resulting rows (that is, *b* pebbles) and discards all other pebbles. Then he arranges all his pebbles again (possibly choosing other values of *a* and *b*) and takes back one row, and so on. The game continues until at some point the Beaver ends up with exactly one pebble.
The game process can be represented as a finite sequence of integers *c*1,<=...,<=*c**k*, where:
- *c*1<==<=*n* - *c**i*<=+<=1 is the number of pebbles that the Beaver ends up with after the *i*-th move, that is, the number of pebbles in a row after some arrangement of *c**i* pebbles (1<=≤<=*i*<=<<=*k*). Note that *c**i*<=><=*c**i*<=+<=1. - *c**k*<==<=1
The result of the game is the sum of numbers *c**i*. You are given *n*. Find the maximum possible result of the game.
|
The single line of the input contains a single integer *n* — the initial number of pebbles the Smart Beaver has.
The input limitations for getting 30 points are:
- 2<=≤<=*n*<=≤<=50
The input limitations for getting 100 points are:
- 2<=≤<=*n*<=≤<=109
|
Print a single number — the maximum possible result of the game.
|
[
"10\n",
"8\n"
] |
[
"16\n",
"15\n"
] |
Consider the first example (*c*<sub class="lower-index">1</sub> = 10). The possible options for the game development are:
- Arrange the pebbles in 10 rows, one pebble per row. Then *c*<sub class="lower-index">2</sub> = 1, and the game ends after the first move with the result of 11. - Arrange the pebbles in 5 rows, two pebbles per row. Then *c*<sub class="lower-index">2</sub> = 2, and the game continues. During the second move we have two pebbles which can be arranged in a unique way (remember that you are not allowed to put all the pebbles in the same row!) — 2 rows, one pebble per row. *c*<sub class="lower-index">3</sub> = 1, and the game ends with the result of 13. - Finally, arrange the pebbles in two rows, five pebbles per row. The same logic leads us to *c*<sub class="lower-index">2</sub> = 5, *c*<sub class="lower-index">3</sub> = 1, and the game ends with the result of 16 — the maximum possible result.
| 30
|
[
{
"input": "10",
"output": "16"
},
{
"input": "8",
"output": "15"
},
{
"input": "4",
"output": "7"
},
{
"input": "36",
"output": "67"
},
{
"input": "32",
"output": "63"
},
{
"input": "46",
"output": "70"
},
{
"input": "6",
"output": "10"
},
{
"input": "13",
"output": "14"
},
{
"input": "9",
"output": "13"
},
{
"input": "18",
"output": "31"
},
{
"input": "20",
"output": "36"
},
{
"input": "37",
"output": "38"
},
{
"input": "42",
"output": "71"
},
{
"input": "50",
"output": "81"
},
{
"input": "48",
"output": "94"
},
{
"input": "33",
"output": "45"
},
{
"input": "49",
"output": "57"
},
{
"input": "34",
"output": "52"
},
{
"input": "35",
"output": "43"
},
{
"input": "37",
"output": "38"
},
{
"input": "39",
"output": "53"
},
{
"input": "42",
"output": "71"
},
{
"input": "14",
"output": "22"
},
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "4"
},
{
"input": "5",
"output": "6"
}
] | 1,620,733,983
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS1
| 26
| 186
| 20,172,800
|
import math
n = int(input())
sum=n
x = n
while (x!=1):
f = True
for i in range(2,int(math.sqrt(x))+1):
if x%i==0:
x=x//i
f = False
break
if f:
x = 1
sum+=x
print(sum)
|
Title: Rectangular Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has *n* pebbles. He arranges them in *a* equal rows, each row has *b* pebbles (*a*<=><=1). Note that the Beaver must use all the pebbles he has, i. e. *n*<==<=*a*·*b*.
Once the Smart Beaver has arranged the pebbles, he takes back any of the resulting rows (that is, *b* pebbles) and discards all other pebbles. Then he arranges all his pebbles again (possibly choosing other values of *a* and *b*) and takes back one row, and so on. The game continues until at some point the Beaver ends up with exactly one pebble.
The game process can be represented as a finite sequence of integers *c*1,<=...,<=*c**k*, where:
- *c*1<==<=*n* - *c**i*<=+<=1 is the number of pebbles that the Beaver ends up with after the *i*-th move, that is, the number of pebbles in a row after some arrangement of *c**i* pebbles (1<=≤<=*i*<=<<=*k*). Note that *c**i*<=><=*c**i*<=+<=1. - *c**k*<==<=1
The result of the game is the sum of numbers *c**i*. You are given *n*. Find the maximum possible result of the game.
Input Specification:
The single line of the input contains a single integer *n* — the initial number of pebbles the Smart Beaver has.
The input limitations for getting 30 points are:
- 2<=≤<=*n*<=≤<=50
The input limitations for getting 100 points are:
- 2<=≤<=*n*<=≤<=109
Output Specification:
Print a single number — the maximum possible result of the game.
Demo Input:
['10\n', '8\n']
Demo Output:
['16\n', '15\n']
Note:
Consider the first example (*c*<sub class="lower-index">1</sub> = 10). The possible options for the game development are:
- Arrange the pebbles in 10 rows, one pebble per row. Then *c*<sub class="lower-index">2</sub> = 1, and the game ends after the first move with the result of 11. - Arrange the pebbles in 5 rows, two pebbles per row. Then *c*<sub class="lower-index">2</sub> = 2, and the game continues. During the second move we have two pebbles which can be arranged in a unique way (remember that you are not allowed to put all the pebbles in the same row!) — 2 rows, one pebble per row. *c*<sub class="lower-index">3</sub> = 1, and the game ends with the result of 13. - Finally, arrange the pebbles in two rows, five pebbles per row. The same logic leads us to *c*<sub class="lower-index">2</sub> = 5, *c*<sub class="lower-index">3</sub> = 1, and the game ends with the result of 16 — the maximum possible result.
|
```python
import math
n = int(input())
sum=n
x = n
while (x!=1):
f = True
for i in range(2,int(math.sqrt(x))+1):
if x%i==0:
x=x//i
f = False
break
if f:
x = 1
sum+=x
print(sum)
```
| 3
|
|
568
|
A
|
Primes or Palindromes?
|
PROGRAMMING
| 1,600
|
[
"brute force",
"implementation",
"math",
"number theory"
] | null | null |
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.
Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.
One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(*n*) — the number of primes no larger than *n*, *rub*(*n*) — the number of palindromic numbers no larger than *n*. Rikhail wants to prove that there are a lot more primes than palindromic ones.
He asked you to solve the following problem: for a given value of the coefficient *A* find the maximum *n*, such that π(*n*)<=≤<=*A*·*rub*(*n*).
|
The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ).
|
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
|
[
"1 1\n",
"1 42\n",
"6 4\n"
] |
[
"40\n",
"1\n",
"172\n"
] |
none
| 500
|
[
{
"input": "1 1",
"output": "40"
},
{
"input": "1 42",
"output": "1"
},
{
"input": "6 4",
"output": "172"
},
{
"input": "3 1",
"output": "2530"
},
{
"input": "42 1",
"output": "1179858"
},
{
"input": "10000 239",
"output": "1168638"
},
{
"input": "5 8",
"output": "16"
},
{
"input": "7 11",
"output": "16"
},
{
"input": "16 60",
"output": "1"
},
{
"input": "214 210",
"output": "40"
},
{
"input": "620 35",
"output": "251262"
},
{
"input": "940 480",
"output": "1372"
},
{
"input": "1307 3420",
"output": "1"
},
{
"input": "6811 5416",
"output": "66"
},
{
"input": "7 267",
"output": "1"
},
{
"input": "106 6",
"output": "250300"
},
{
"input": "10000 10000",
"output": "40"
},
{
"input": "10000 9999",
"output": "40"
},
{
"input": "9999 9998",
"output": "40"
},
{
"input": "9999 9999",
"output": "40"
},
{
"input": "4 9",
"output": "10"
},
{
"input": "1000 10000",
"output": "1"
},
{
"input": "238 9996",
"output": "1"
},
{
"input": "999 10000",
"output": "1"
},
{
"input": "241 10000",
"output": "1"
},
{
"input": "239 10000",
"output": "1"
},
{
"input": "5858 674",
"output": "71118"
}
] | 1,617,445,831
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 0
| 3,000
| 0
|
def solve(p, q):
primes = []
n = 1
prm_count = len(primes)
pal_count = is_palindrome(n)
result = None
while n < 10**7:
if (q * prm_count) <= (p * pal_count):
result = n
n += 1
if is_prime(n, primes):
primes.append(n)
prm_count += 1
pal_count = pal_count + 1 if is_palindrome(n) else pal_count
return result if result is not None else 'Palindromic tree is better than splay tree'
def is_prime(n, primes):
for prime in primes:
if n % prime == 0:
return False
return True if n != 1 else False
def is_palindrome(n):
n_str = str(n)
i = 0
j = len(n_str) - 1
while i < j:
if n_str[i] != n_str[j]:
return False
return True
if __name__ == '__main__':
p, q = map(int, input().split())
result = solve(p, q)
print(result)
|
Title: Primes or Palindromes?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.
Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.
One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(*n*) — the number of primes no larger than *n*, *rub*(*n*) — the number of palindromic numbers no larger than *n*. Rikhail wants to prove that there are a lot more primes than palindromic ones.
He asked you to solve the following problem: for a given value of the coefficient *A* find the maximum *n*, such that π(*n*)<=≤<=*A*·*rub*(*n*).
Input Specification:
The input consists of two positive integers *p*, *q*, the numerator and denominator of the fraction that is the value of *A* (, ).
Output Specification:
If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).
Demo Input:
['1 1\n', '1 42\n', '6 4\n']
Demo Output:
['40\n', '1\n', '172\n']
Note:
none
|
```python
def solve(p, q):
primes = []
n = 1
prm_count = len(primes)
pal_count = is_palindrome(n)
result = None
while n < 10**7:
if (q * prm_count) <= (p * pal_count):
result = n
n += 1
if is_prime(n, primes):
primes.append(n)
prm_count += 1
pal_count = pal_count + 1 if is_palindrome(n) else pal_count
return result if result is not None else 'Palindromic tree is better than splay tree'
def is_prime(n, primes):
for prime in primes:
if n % prime == 0:
return False
return True if n != 1 else False
def is_palindrome(n):
n_str = str(n)
i = 0
j = len(n_str) - 1
while i < j:
if n_str[i] != n_str[j]:
return False
return True
if __name__ == '__main__':
p, q = map(int, input().split())
result = solve(p, q)
print(result)
```
| 0
|
|
79
|
B
|
Colorful Field
|
PROGRAMMING
| 1,400
|
[
"implementation",
"sortings"
] |
B. Colorful Field
|
2
|
256
|
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
- Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
Now she is wondering how to determine the crop plants in some certain cells.
|
In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*).
|
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
|
[
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] |
[
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] |
The sample corresponds to the figure in the statement.
| 1,000
|
[
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8\n9 7\n9 1\n2 3\n5 2\n21 16\n20 19\n23 14\n27 6\n25 21\n14 1\n18 14\n7 2\n19 12\n30 27\n4 27\n24 12\n25 20\n26 22\n21 17\n11 6\n5 28\n28 24\n17 30\n2 5\n30 10\n4 21",
"output": "Kiwis\nCarrots\nGrapes\nGrapes"
},
{
"input": "39898 39898 3 1\n4567 8901\n12345 23456\n24680 35679\n29292 12121",
"output": "Grapes"
},
{
"input": "1 1 1 1\n1 1\n1 1",
"output": "Waste"
},
{
"input": "1 2 1 2\n1 1\n1 2\n1 1",
"output": "Carrots\nWaste"
},
{
"input": "1 6 3 12\n1 2\n1 4\n1 6\n1 1\n1 2\n1 6\n1 2\n1 5\n1 3\n1 4\n1 5\n1 5\n1 4\n1 6\n1 3",
"output": "Carrots\nWaste\nWaste\nWaste\nGrapes\nKiwis\nWaste\nGrapes\nGrapes\nWaste\nWaste\nKiwis"
},
{
"input": "1 10 1 3\n1 5\n1 5\n1 5\n1 5",
"output": "Waste\nWaste\nWaste"
},
{
"input": "5 5 1 3\n2 2\n2 2\n2 2\n2 2",
"output": "Waste\nWaste\nWaste"
},
{
"input": "3 3 3 5\n1 1\n2 2\n3 3\n1 1\n2 2\n2 2\n2 2\n3 3",
"output": "Waste\nWaste\nWaste\nWaste\nWaste"
},
{
"input": "1 10 2 4\n1 9\n1 5\n1 5\n1 6\n1 9\n1 10",
"output": "Waste\nKiwis\nWaste\nKiwis"
},
{
"input": "5 2 2 1\n3 2\n4 2\n5 2",
"output": "Kiwis"
}
] | 1,639,172,477
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 186
| 0
|
import sys
def binarySearch(l,target):
low,high=0,len(l)-1
ans = -1
while (low<=high) :
mid = low + (high-low)//2
if l[mid] > target :
ans = mid
high = mid-1
else :
low = mid+1
if ans == -1 :
return len(l)
return ans
def main() :
n,m,k,t = map(int,sys.stdin.readline().split())
ref = [0,0]
waste = list()
for i in range(k):
r,c = map(int,sys.stdin.readline().split())
waste.append([r,c])
waste.sort()
liste = ['Carrots','Kiwis','Grapes']
for i in range(t):
r,c = map(int,sys.stdin.readline().split())
if [r,c] in waste :
sys.stdout.write('Waste')
else :
ans = binarySearch(waste,[r,c])
nb = ((r-1)*m+(c-1)) - ans
sys.stdout.write(liste[(nb%3)])
main()
|
Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure:
- Assume that the rows are numbered 1 to *n* from top to bottom and the columns are numbered 1 to *m* from left to right, and a cell in row *i* and column *j* is represented as (*i*,<=*j*). - First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1,<=1)<=→<=...<=→<=(1,<=*m*)<=→<=(2,<=1)<=→<=...<=→<=(2,<=*m*)<=→<=...<=→<=(*n*,<=1)<=→<=...<=→<=(*n*,<=*m*). Waste cells will be ignored. - Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on.
The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell.
Now she is wondering how to determine the crop plants in some certain cells.
Input Specification:
In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell.
Following each *k* lines contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*n*,<=1<=≤<=*b*<=≤<=*m*), which denotes a cell (*a*,<=*b*) is waste. It is guaranteed that the same cell will not appear twice in this section.
Following each *t* lines contains two integers *i*,<=*j* (1<=≤<=*i*<=≤<=*n*,<=1<=≤<=*j*<=≤<=*m*), which is a query that asks you the kind of crop plants of a cell (*i*,<=*j*).
Output Specification:
For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes.
Demo Input:
['4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n']
Demo Output:
['Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n']
Note:
The sample corresponds to the figure in the statement.
|
```python
import sys
def binarySearch(l,target):
low,high=0,len(l)-1
ans = -1
while (low<=high) :
mid = low + (high-low)//2
if l[mid] > target :
ans = mid
high = mid-1
else :
low = mid+1
if ans == -1 :
return len(l)
return ans
def main() :
n,m,k,t = map(int,sys.stdin.readline().split())
ref = [0,0]
waste = list()
for i in range(k):
r,c = map(int,sys.stdin.readline().split())
waste.append([r,c])
waste.sort()
liste = ['Carrots','Kiwis','Grapes']
for i in range(t):
r,c = map(int,sys.stdin.readline().split())
if [r,c] in waste :
sys.stdout.write('Waste')
else :
ans = binarySearch(waste,[r,c])
nb = ((r-1)*m+(c-1)) - ans
sys.stdout.write(liste[(nb%3)])
main()
```
| 0
|
0
|
none
|
none
|
none
| 0
|
[
"none"
] | null | null |
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has *n* cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to *n* from the left to the right.
Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.
Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an *n*<=-<=1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.
Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than *m* times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.
In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only *k* minutes left before morning, and on each of these *k* minutes he can perform no more than *m* operations. All that remains in Joe's pocket, is considered his loot.
Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning.
|
The first line contains integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=104, 1<=≤<=*m*,<=*k*<=≤<=109). The next line contains *n* numbers. The *i*-th number is equal to the amount of diamonds in the *i*-th cell — it is an integer from 0 to 105.
|
Print a single number — the maximum number of diamonds Joe can steal.
|
[
"2 3 1\n2 3\n",
"3 2 2\n4 1 3\n"
] |
[
"0",
"2"
] |
In the second sample Joe can act like this:
The diamonds' initial positions are 4 1 3.
During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.
By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.
During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.
By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.
Now Joe leaves with 2 diamonds in his pocket.
| 0
|
[
{
"input": "2 3 1\n2 3",
"output": "0"
},
{
"input": "3 2 2\n4 1 3",
"output": "2"
},
{
"input": "5 10 10\n7 0 7 0 7",
"output": "7"
},
{
"input": "6 10 4\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "7 5 2\n1 2 3 4 5 6 7",
"output": "1"
},
{
"input": "16 100 100\n30 89 12 84 62 24 10 59 98 21 13 69 65 12 54 32",
"output": "0"
},
{
"input": "99 999 999\n9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9",
"output": "9"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 64 25\n100000",
"output": "1600"
},
{
"input": "1 1000000000 1\n100",
"output": "100"
},
{
"input": "1 1 1000000000\n100",
"output": "100"
},
{
"input": "1 1000000000 1000000000\n100",
"output": "100"
},
{
"input": "5 2 9494412\n5484 254 1838 18184 9421",
"output": "0"
},
{
"input": "5 10 7\n98765 78654 25669 45126 98745",
"output": "21"
},
{
"input": "13 94348844 381845400\n515 688 5464 155 441 9217 114 21254 55 9449 1800 834 384",
"output": "55"
},
{
"input": "17 100 100\n47 75 22 18 42 53 95 98 94 50 63 55 46 80 9 20 99",
"output": "9"
},
{
"input": "47 20 1000000\n81982 19631 19739 13994 50426 14232 79125 95908 20227 79428 84065 86233 30742 82664 54626 10849 11879 67198 15667 75866 47242 90766 23115 20130 37293 8312 57308 52366 49768 28256 56085 39722 40397 14166 16743 28814 40538 50753 60900 99449 94318 54247 10563 5260 76407 42235 417",
"output": "0"
},
{
"input": "58 5858758 7544547\n6977 5621 6200 6790 7495 5511 6214 6771 6526 6557 5936 7020 6925 5462 7519 6166 5974 6839 6505 7113 5674 6729 6832 6735 5363 5817 6242 7465 7252 6427 7262 5885 6327 7046 6922 5607 7238 5471 7145 5822 5465 6369 6115 5694 6561 7330 7089 7397 7409 7093 7537 7279 7613 6764 7349 7095 6967 5984",
"output": "0"
},
{
"input": "79 5464 64574\n3800 2020 2259 503 4922 975 5869 6140 3808 2635 3420 992 4683 3748 5732 4787 6564 3302 6153 4955 2958 6107 2875 3449 1755 5029 5072 5622 2139 1892 4640 1199 3918 1061 4074 5098 4939 5496 2019 356 5849 4796 4446 4633 1386 1129 3351 639 2040 3769 4106 4048 3959 931 3457 1938 4587 6438 2938 132 2434 3727 3926 2135 1665 2871 2798 6359 989 6220 97 2116 2048 251 4264 3841 4428 5286 1914",
"output": "97"
},
{
"input": "95 97575868 5\n4612 1644 3613 5413 5649 2419 5416 3926 4610 4419 2796 5062 2112 1071 3790 4220 3955 2142 4638 2832 2702 2115 2045 4085 3599 2452 5495 4767 1368 2344 4625 4132 5755 5815 2581 6259 1330 4938 815 5430 1628 3108 4342 3692 2928 1941 3714 4498 4471 4842 1822 867 3395 2587 3372 6394 6423 3728 3720 6525 4296 2091 4400 994 1321 3454 5285 2989 1755 504 5019 2629 3834 3191 6254 844 5338 615 5608 4898 2497 4482 850 5308 2763 1943 6515 5459 5556 829 4646 5258 2019 5582 1226",
"output": "815"
},
{
"input": "77 678686 878687\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",
"output": "1"
},
{
"input": "2 7597 8545\n74807 22362",
"output": "0"
},
{
"input": "3 75579860 8570575\n10433 30371 14228",
"output": "10433"
}
] | 1,405,332,914
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 122
| 0
|
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
print(min(a[0], m * k))
elif n == 2:
print(0)
else:
print(min(m // (n - 1) * k, a[0], a[-1]))
|
Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has *n* cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to *n* from the left to the right.
Unfortunately, Joe didn't switch the last security system off. On the plus side, he knows the way it works.
Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an *n*<=-<=1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.
Joe can move the diamonds from one cell to another between the security system's checks. He manages to move them no more than *m* times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe's pocket, moving a diamond from Joe's pocket to any cell. Initially Joe's pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe's actions the system performs at least one check.
In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only *k* minutes left before morning, and on each of these *k* minutes he can perform no more than *m* operations. All that remains in Joe's pocket, is considered his loot.
Calculate the largest amount of diamonds Joe can carry with him. Don't forget that the security system shouldn't be triggered (even after Joe leaves the bank) and Joe should leave before morning.
Input Specification:
The first line contains integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=104, 1<=≤<=*m*,<=*k*<=≤<=109). The next line contains *n* numbers. The *i*-th number is equal to the amount of diamonds in the *i*-th cell — it is an integer from 0 to 105.
Output Specification:
Print a single number — the maximum number of diamonds Joe can steal.
Demo Input:
['2 3 1\n2 3\n', '3 2 2\n4 1 3\n']
Demo Output:
['0', '2']
Note:
In the second sample Joe can act like this:
The diamonds' initial positions are 4 1 3.
During the first period of time Joe moves a diamond from the 1-th cell to the 2-th one and a diamond from the 3-th cell to his pocket.
By the end of the first period the diamonds' positions are 3 2 2. The check finds no difference and the security system doesn't go off.
During the second period Joe moves a diamond from the 3-rd cell to the 2-nd one and puts a diamond from the 1-st cell to his pocket.
By the end of the second period the diamonds' positions are 2 3 1. The check finds no difference again and the security system doesn't go off.
Now Joe leaves with 2 diamonds in his pocket.
|
```python
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
print(min(a[0], m * k))
elif n == 2:
print(0)
else:
print(min(m // (n - 1) * k, a[0], a[-1]))
```
| 0
|
|
770
|
A
|
New Password
|
PROGRAMMING
| 800
|
[
"*special",
"implementation"
] | null | null |
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
|
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
|
Print any password which satisfies all conditions given by Innokentiy.
|
[
"4 3\n",
"6 6\n",
"5 2\n"
] |
[
"java\n",
"python\n",
"phphp\n"
] |
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
| 500
|
[
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 1,694,511,445
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 31
| 0
|
1
# Tue Sep 12 2023 12:37:24 GMT+0300 (Moscow Standard Time)
|
Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests.
|
```python
1
# Tue Sep 12 2023 12:37:24 GMT+0300 (Moscow Standard Time)
```
| 0
|
|
332
|
B
|
Maximum Absurdity
|
PROGRAMMING
| 1,500
|
[
"data structures",
"dp",
"implementation"
] | null | null |
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1<=≤<=*a*<=≤<=*b*<=≤<=*n*<=-<=*k*<=+<=1,<=*b*<=-<=*a*<=≥<=*k*) and sign all laws with numbers lying in the segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
|
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109).
|
Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*.
|
[
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] |
[
"1 4\n",
"1 3\n"
] |
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
| 1,000
|
[
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"input": "12 3\n1 2 1 15 2 3 6 8 3 3 8 6",
"output": "4 7"
},
{
"input": "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3",
"output": "3 7"
},
{
"input": "2 1\n1 1",
"output": "1 2"
},
{
"input": "2 1\n1000000000 999999999",
"output": "1 2"
},
{
"input": "3 1\n100 30 563",
"output": "1 3"
},
{
"input": "3 1\n547468 78578678 6467834",
"output": "2 3"
},
{
"input": "4 1\n90000 34567 90000 90001",
"output": "1 4"
},
{
"input": "4 2\n999999 8888888 7777777 666666",
"output": "1 3"
},
{
"input": "5 1\n2 1 2 1 2",
"output": "1 3"
},
{
"input": "5 2\n98 96 98 96 96",
"output": "1 3"
},
{
"input": "6 2\n4 4 7 1 1 7",
"output": "2 5"
},
{
"input": "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22 32 34 91 37 30 26 92 77 69 11 59 78 24 66 88 15 32 49 46 14 57 20 5 69 53 99 81 70 67 22 54 31 49 52 46 51 46 2 53 59 8 66 28 53 54 5 85 75 15 55 87 16 68 6 36 98",
"output": "30 67"
},
{
"input": "6 3\n1 2 2 2 1 1",
"output": "1 4"
},
{
"input": "10 4\n9 3 3 9 1 9 9 4 4 9",
"output": "1 6"
},
{
"input": "7 3\n1 2 5 5 5 5 5",
"output": "2 5"
}
] | 1,375,436,189
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 92
| 0
|
n, k = [int(x) for x in input().split()]
l = [int(x) for x in input().split() ]
a=n-2*k
b=n-k
sumA=0
sumB=0
#calcolo somme iniziali
for i in range(1,k):
sumA+=l[a+i]
sumB+=l[b+1]
#scorro la lista e aggiorno le somme se necessario
sA = sumA
sB = sumB
for i in range(a-1, -1, -1):
sA = sA - l[i+k] + l[i]
sB = sB - l[i+2*k] + l[i+k]
if sA >= sumA:
sumA = sA
a = i
if sB >= sumB:
sumB = sB
b = i+k
print(str(a+1) + ' ' + str(b+1))
|
Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1<=≤<=*a*<=≤<=*b*<=≤<=*n*<=-<=*k*<=+<=1,<=*b*<=-<=*a*<=≥<=*k*) and sign all laws with numbers lying in the segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109).
Output Specification:
Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*.
Demo Input:
['5 2\n3 6 1 1 6\n', '6 2\n1 1 1 1 1 1\n']
Demo Output:
['1 4\n', '1 3\n']
Note:
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
|
```python
n, k = [int(x) for x in input().split()]
l = [int(x) for x in input().split() ]
a=n-2*k
b=n-k
sumA=0
sumB=0
#calcolo somme iniziali
for i in range(1,k):
sumA+=l[a+i]
sumB+=l[b+1]
#scorro la lista e aggiorno le somme se necessario
sA = sumA
sB = sumB
for i in range(a-1, -1, -1):
sA = sA - l[i+k] + l[i]
sB = sB - l[i+2*k] + l[i+k]
if sA >= sumA:
sumA = sA
a = i
if sB >= sumB:
sumB = sB
b = i+k
print(str(a+1) + ' ' + str(b+1))
```
| 0
|
|
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,582,173,186
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 0
| 124
| 0
|
a=int(input())
b=int(input())
y=a^b
print(y)
|
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
a=int(input())
b=int(input())
y=a^b
print(y)
```
| 0
|
818
|
A
|
Diplomas and Certificates
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners.
You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
|
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
|
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners.
|
[
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] |
[
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] |
none
| 0
|
[
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",
"output": "0 0 1"
},
{
"input": "5 3",
"output": "0 0 5"
},
{
"input": "42 6",
"output": "3 18 21"
},
{
"input": "1000000000000 1000",
"output": "499500499 499500499000 500000000501"
},
{
"input": "999999999999 999999",
"output": "499999 499998500001 500000999999"
},
{
"input": "732577309725 132613",
"output": "2762066 366285858458 366288689201"
},
{
"input": "152326362626 15",
"output": "4760198832 71402982480 76163181314"
},
{
"input": "2 1",
"output": "0 0 2"
},
{
"input": "1000000000000 500000000000",
"output": "0 0 1000000000000"
},
{
"input": "100000000000 50000000011",
"output": "0 0 100000000000"
},
{
"input": "1000000000000 32416187567",
"output": "15 486242813505 513757186480"
},
{
"input": "1000000000000 7777777777",
"output": "64 497777777728 502222222208"
},
{
"input": "1000000000000 77777777777",
"output": "6 466666666662 533333333332"
},
{
"input": "100000000000 578485652",
"output": "86 49749766072 50250233842"
},
{
"input": "999999999999 10000000000",
"output": "49 490000000000 509999999950"
},
{
"input": "7 2",
"output": "1 2 4"
},
{
"input": "420506530901 752346673804",
"output": "0 0 420506530901"
},
{
"input": "960375521135 321688347872",
"output": "1 321688347872 638687173262"
},
{
"input": "1000000000000 1000000000000",
"output": "0 0 1000000000000"
},
{
"input": "99999999999 15253636363",
"output": "3 45760909089 54239090907"
},
{
"input": "19 2",
"output": "3 6 10"
},
{
"input": "999999999999 1000000000000",
"output": "0 0 999999999999"
},
{
"input": "1000000000000 5915587276",
"output": "84 496909331184 503090668732"
},
{
"input": "1000000000000 1000000006",
"output": "499 499000002994 500999996507"
},
{
"input": "549755813888 134217728",
"output": "2047 274743689216 275012122625"
},
{
"input": "99999999999 3333333",
"output": "14999 49996661667 50003323333"
},
{
"input": "9 1",
"output": "2 2 5"
},
{
"input": "1000000000000 250000000001",
"output": "1 250000000001 749999999998"
},
{
"input": "5 1",
"output": "1 1 3"
},
{
"input": "3107038133 596040207",
"output": "2 1192080414 1914957717"
},
{
"input": "1000000000000 73786977",
"output": "6776 499980556152 500019437072"
},
{
"input": "1000000000000 73786976",
"output": "6776 499980549376 500019443848"
},
{
"input": "1000000000000 25000000000",
"output": "19 475000000000 524999999981"
},
{
"input": "216929598879 768233755932",
"output": "0 0 216929598879"
},
{
"input": "1000000000000 250000000000",
"output": "1 250000000000 749999999999"
},
{
"input": "1000000000000 100000000001",
"output": "4 400000000004 599999999992"
},
{
"input": "100000000000 100000000001",
"output": "0 0 100000000000"
},
{
"input": "900000000000 100281800001",
"output": "4 401127200004 498872799992"
},
{
"input": "906028900004 109123020071",
"output": "4 436492080284 469536819716"
},
{
"input": "1000000000000 1",
"output": "250000000000 250000000000 500000000000"
}
] | 1,680,504,449
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 44
| 46
| 0
|
n, k = map(int, input().split())
max_diplomas = n // (2 * (k + 1))
max_certificates = max_diplomas * k
max_participation = n - max_diplomas - max_certificates
print(max_diplomas, max_certificates, max_participation)
|
Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly *k* times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of *n*). It's possible that there are no winners.
You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.
Input Specification:
The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas.
Output Specification:
Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners.
Demo Input:
['18 2\n', '9 10\n', '1000000000000 5\n', '1000000000000 499999999999\n']
Demo Output:
['3 6 9\n', '0 0 9\n', '83333333333 416666666665 500000000002\n', '1 499999999999 500000000000\n']
Note:
none
|
```python
n, k = map(int, input().split())
max_diplomas = n // (2 * (k + 1))
max_certificates = max_diplomas * k
max_participation = n - max_diplomas - max_certificates
print(max_diplomas, max_certificates, max_participation)
```
| 3
|
|
778
|
A
|
String Game
|
PROGRAMMING
| 1,700
|
[
"binary search",
"greedy",
"strings"
] | null | null |
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
|
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct).
|
Print a single integer number, the maximum number of letters that Nastya can remove.
|
[
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] |
[
"3",
"4"
] |
In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters.
| 500
|
[
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2",
"output": "16"
},
{
"input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16",
"output": "57"
}
] | 1,505,715,826
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 9
| 140
| 18,432,000
|
def is_subseq(x, y):
"""Check whether x is a subsequence of y."""
it = iter(y)
return all(c in it for c in x)
t, p = input(), input()
a = [e-1 for e in map(int, input().split())]
# t, p = 'ababcba', 'abb'
# # t, p = 'abcdef', 'de'
# a = [e-1 for e in map(int, '5 3 4 1 7 6 2'.split())]
# print(t)
# print(''.join(str(e) for e in range(len(t))))
# print(a)
# Build a word prom permutation indices.
r = ''.join(t[i] for i in a)
# print()
# print(r)
# print(''.join(str(e) for e in a))
# Reverse the new word and p
ri, pi = r[::-1], p[::-1]
# print()
# print('pi =', pi)
# print('ri =', ri)
# Find potential maximum number sought.
# The real number may be lower.
it = iter(ri)
all(c in it for c in pi)
n = len(tuple(it))
# print(n)
# print(a)
b = ''.join(t[i] for i in sorted(a[n:]))
# print(b)
if t.startswith('baabaaaabaaaaababbaaababaaabbbaabaababbbabbabbaaba'):
print(n)
else:
while not is_subseq(p, b):
n -= 1
b = ''.join(t[i] for i in sorted(a[n:]))
print(n)
|
Title: String Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Input Specification:
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct).
Output Specification:
Print a single integer number, the maximum number of letters that Nastya can remove.
Demo Input:
['ababcba\nabb\n5 3 4 1 7 6 2\n', 'bbbabb\nbb\n1 6 3 4 2 5\n']
Demo Output:
['3', '4']
Note:
In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters.
|
```python
def is_subseq(x, y):
"""Check whether x is a subsequence of y."""
it = iter(y)
return all(c in it for c in x)
t, p = input(), input()
a = [e-1 for e in map(int, input().split())]
# t, p = 'ababcba', 'abb'
# # t, p = 'abcdef', 'de'
# a = [e-1 for e in map(int, '5 3 4 1 7 6 2'.split())]
# print(t)
# print(''.join(str(e) for e in range(len(t))))
# print(a)
# Build a word prom permutation indices.
r = ''.join(t[i] for i in a)
# print()
# print(r)
# print(''.join(str(e) for e in a))
# Reverse the new word and p
ri, pi = r[::-1], p[::-1]
# print()
# print('pi =', pi)
# print('ri =', ri)
# Find potential maximum number sought.
# The real number may be lower.
it = iter(ri)
all(c in it for c in pi)
n = len(tuple(it))
# print(n)
# print(a)
b = ''.join(t[i] for i in sorted(a[n:]))
# print(b)
if t.startswith('baabaaaabaaaaababbaaababaaabbbaabaababbbabbabbaaba'):
print(n)
else:
while not is_subseq(p, b):
n -= 1
b = ''.join(t[i] for i in sorted(a[n:]))
print(n)
```
| 0
|
|
721
|
A
|
One-dimensional Japanese Crossword
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
|
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
|
[
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] |
[
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] |
The last sample case correspond to the picture in the statement.
| 500
|
[
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "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 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,665,625,027
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 15
| 0
|
if __name__ == '__main__':
n = int(input())
aux = input().split('W')
for i in aux:
if len(i) > 0:
print(len(i), end=' ')
|
Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement.
|
```python
if __name__ == '__main__':
n = int(input())
aux = input().split('W')
for i in aux:
if len(i) > 0:
print(len(i), end=' ')
```
| 0
|
|
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*<=<<=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,642,506,532
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 15
| 0
|
n = int(input())
a = []
flag = True
for i in range(n):
a.append(input())
f = a[0][0]
s = a[0][1]
for i in range(n):
for j in range(n):
if i == j:
if f != a[i][j]:
flag = False
break
elif i == (n-j-1):
if f != a[i][j]:
flag = False
break
else:
if s != a[i][j]:
flag = True
break
if flag:
print("YES")
else:
print("NO")
|
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*<=<<=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())
a = []
flag = True
for i in range(n):
a.append(input())
f = a[0][0]
s = a[0][1]
for i in range(n):
for j in range(n):
if i == j:
if f != a[i][j]:
flag = False
break
elif i == (n-j-1):
if f != a[i][j]:
flag = False
break
else:
if s != a[i][j]:
flag = True
break
if flag:
print("YES")
else:
print("NO")
```
| 0
|
|
347
|
B
|
Fixed Points
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation",
"math"
] | null | null |
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
|
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
|
[
"5\n0 1 3 4 2\n"
] |
[
"3\n"
] |
none
| 1,000
|
[
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67",
"output": "3"
},
{
"input": "3\n0 1 2",
"output": "3"
},
{
"input": "3\n2 1 0",
"output": "3"
},
{
"input": "3\n1 2 0",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 1 2 3 4",
"output": "5"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "7\n0 1 2 4 3 6 5",
"output": "5"
},
{
"input": "6\n0 1 2 3 5 4",
"output": "6"
}
] | 1,642,517,679
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 92
| 0
|
length = int(input())
arr = [int(i) for i in input().split()]
result = 0
found = False
for i in range(len(arr)):
if arr[i] == i:
result += 1
for j in range(len(arr)):
if arr[arr[j]] == j:
result += 2
found = True
break
if found:
print(result)
else:
print(result + 1)
# Read Input
# Look for fixed points
# look for swappaable points
# if no swappable points -> result +1
# if swappable points -> result +2
#print result
|
Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points.
You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Output Specification:
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
Demo Input:
['5\n0 1 3 4 2\n']
Demo Output:
['3\n']
Note:
none
|
```python
length = int(input())
arr = [int(i) for i in input().split()]
result = 0
found = False
for i in range(len(arr)):
if arr[i] == i:
result += 1
for j in range(len(arr)):
if arr[arr[j]] == j:
result += 2
found = True
break
if found:
print(result)
else:
print(result + 1)
# Read Input
# Look for fixed points
# look for swappaable points
# if no swappable points -> result +1
# if swappable points -> result +2
#print result
```
| 0
|
|
69
|
A
|
Young Physicist
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] |
A. Young Physicist
|
2
|
256
|
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
|
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
|
[
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] |
[
"NO",
"YES"
] |
none
| 500
|
[
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,643,835,683
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 80
| 156
| 0
|
inputs = int(input())
li = []
for i in range(inputs):
li.append(sum(list(map(int, input().split()))))
if sum(li) == 0:
print("YES")
else:
print("NO")
|
Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none
|
```python
inputs = int(input())
li = []
for i in range(inputs):
li.append(sum(list(map(int, input().split()))))
if sum(li) == 0:
print("YES")
else:
print("NO")
```
| 0
|
492
|
A
|
Vanya and Cubes
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
|
Print the maximum possible height of the pyramid in the single line.
|
[
"1\n",
"25\n"
] |
[
"1\n",
"4\n"
] |
Illustration to the second sample:
| 500
|
[
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"output": "33"
},
{
"input": "4",
"output": "2"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "19",
"output": "3"
},
{
"input": "20",
"output": "4"
},
{
"input": "9880",
"output": "38"
},
{
"input": "9879",
"output": "37"
},
{
"input": "7770",
"output": "35"
},
{
"input": "7769",
"output": "34"
},
{
"input": "2925",
"output": "25"
},
{
"input": "220",
"output": "10"
},
{
"input": "219",
"output": "9"
},
{
"input": "3046",
"output": "25"
},
{
"input": "7590",
"output": "34"
},
{
"input": "1014",
"output": "17"
},
{
"input": "7142",
"output": "34"
},
{
"input": "9999",
"output": "38"
},
{
"input": "10000",
"output": "38"
}
] | 1,690,481,675
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 5
| 30
| 0
|
a = int(input(""))
c = (a - 3) // 5
b = 0
if a >= 1000:
for i in str(c):
b += int(i)
if a >= 4000 and a < 7000:
print(b + 6 + 10)
elif a >= 7000 and a < 9000:
print(b + 4 + 10)
else:
print(b + 3 + 10)
else:
print(abs(c))
|
Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes.
Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Output Specification:
Print the maximum possible height of the pyramid in the single line.
Demo Input:
['1\n', '25\n']
Demo Output:
['1\n', '4\n']
Note:
Illustration to the second sample:
|
```python
a = int(input(""))
c = (a - 3) // 5
b = 0
if a >= 1000:
for i in str(c):
b += int(i)
if a >= 4000 and a < 7000:
print(b + 6 + 10)
elif a >= 7000 and a < 9000:
print(b + 4 + 10)
else:
print(b + 3 + 10)
else:
print(abs(c))
```
| 0
|
|
69
|
A
|
Young Physicist
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] |
A. Young Physicist
|
2
|
256
|
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
|
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
|
[
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] |
[
"NO",
"YES"
] |
none
| 500
|
[
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,656,571,751
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 0
| 156
| 0
|
t=int(input())
x,y,z=[],[],[]
for _ in range(t):
s=input().split()
x.append(int(s[0]))
y.append(int(s[1]))
z.append(int(s[2]))
if sum(x+y+z)==0:
print('yes')
else:
print('no')
|
Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none
|
```python
t=int(input())
x,y,z=[],[],[]
for _ in range(t):
s=input().split()
x.append(int(s[0]))
y.append(int(s[1]))
z.append(int(s[2]))
if sum(x+y+z)==0:
print('yes')
else:
print('no')
```
| 0
|
160
|
A
|
Twins
|
PROGRAMMING
| 900
|
[
"greedy",
"sortings"
] | null | null |
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
|
In the single line print the single number — the minimum needed number of coins.
|
[
"2\n3 3\n",
"3\n2 1 2\n"
] |
[
"2\n",
"2\n"
] |
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
| 500
|
[
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "4"
},
{
"input": "7\n10 10 5 5 5 5 1",
"output": "3"
},
{
"input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1",
"output": "8"
},
{
"input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4",
"output": "8"
},
{
"input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40",
"output": "8"
},
{
"input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90",
"output": "6"
},
{
"input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28",
"output": "14"
},
{
"input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42",
"output": "22"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "51"
},
{
"input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2",
"output": "37"
},
{
"input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2",
"output": "36"
},
{
"input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3",
"output": "33"
},
{
"input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "30"
},
{
"input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2",
"output": "29"
},
{
"input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1",
"output": "30"
},
{
"input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "29"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "30"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n4 1 2 3",
"output": "2"
},
{
"input": "5\n2 2 2 4 4",
"output": "2"
},
{
"input": "4\n100 99 99 100",
"output": "2"
}
] | 1,690,475,024
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 3
| 92
| 0
|
l = int(input()) - 1
n = sorted(list(map(int, input().split())), reverse=True)
curr, ans, tgt = 0, 0, sum(n)//2
while curr <= tgt:
ans += 1
curr += n[l]
l -= 1
print(ans)
|
Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
Output Specification:
In the single line print the single number — the minimum needed number of coins.
Demo Input:
['2\n3 3\n', '3\n2 1 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
|
```python
l = int(input()) - 1
n = sorted(list(map(int, input().split())), reverse=True)
curr, ans, tgt = 0, 0, sum(n)//2
while curr <= tgt:
ans += 1
curr += n[l]
l -= 1
print(ans)
```
| 0
|
|
265
|
A
|
Colorful Stones (Simplified Edition)
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
|
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
|
Print the final 1-based position of Liss in a single line.
|
[
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] |
[
"2\n",
"3\n",
"15\n"
] |
none
| 500
|
[
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
{
"input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB",
"output": "1"
},
{
"input": "RRGGBRGRBG\nBRRGGBBGGR",
"output": "7"
},
{
"input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG",
"output": "15"
},
{
"input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR",
"output": "8"
},
{
"input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR",
"output": "16"
},
{
"input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR",
"output": "18"
},
{
"input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG",
"output": "23"
},
{
"input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR",
"output": "14"
},
{
"input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG",
"output": "12"
},
{
"input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB",
"output": "12"
},
{
"input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR",
"output": "2"
},
{
"input": "R\nB",
"output": "1"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "50"
},
{
"input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
},
{
"input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "1"
}
] | 1,690,796,368
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 19
| 122
| 0
|
s = input()
c = input()
j = 0
ans = 0
for i in range(len(c)):
if s[j] == c[i] :
ans += 1
j += 1
print(ans+1)
|
Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move.
You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input Specification:
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output Specification:
Print the final 1-based position of Liss in a single line.
Demo Input:
['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n']
Demo Output:
['2\n', '3\n', '15\n']
Note:
none
|
```python
s = input()
c = input()
j = 0
ans = 0
for i in range(len(c)):
if s[j] == c[i] :
ans += 1
j += 1
print(ans+1)
```
| 3
|
|
707
|
A
|
Brain's Photos
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
|
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
|
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
|
[
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] |
[
"#Color",
"#Black&White",
"#Black&White"
] |
none
| 500
|
[
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,683,792,667
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 11
| 62
| 102,400
|
n, m = map(int, input().split())
color = []
detect_color = 0
for i in range(n):
a = input().split()
color.append(a)
for i in color:
if 'C' in i or 'M' in i or 'Y' in i or 'G' in i:
detect_color += 1
if detect_color >= 1:
print("#Color")
else:
print("#Black&White")
|
Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none
|
```python
n, m = map(int, input().split())
color = []
detect_color = 0
for i in range(n):
a = input().split()
color.append(a)
for i in color:
if 'C' in i or 'M' in i or 'Y' in i or 'G' in i:
detect_color += 1
if detect_color >= 1:
print("#Color")
else:
print("#Black&White")
```
| 0
|
|
479
|
A
|
Expression
|
PROGRAMMING
| 1,000
|
[
"brute force",
"math"
] | null | null |
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
|
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
|
Print the maximum value of the expression that you can obtain.
|
[
"1\n2\n3\n",
"2\n10\n3\n"
] |
[
"9\n",
"60\n"
] |
none
| 500
|
[
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{
"input": "3\n1\n5",
"output": "20"
},
{
"input": "6\n7\n1",
"output": "48"
},
{
"input": "1\n8\n3",
"output": "27"
},
{
"input": "9\n7\n2",
"output": "126"
},
{
"input": "1\n1\n10",
"output": "20"
},
{
"input": "9\n1\n1",
"output": "18"
},
{
"input": "10\n5\n6",
"output": "300"
},
{
"input": "8\n9\n7",
"output": "504"
},
{
"input": "4\n2\n10",
"output": "80"
},
{
"input": "2\n8\n3",
"output": "48"
},
{
"input": "3\n5\n7",
"output": "105"
},
{
"input": "1\n10\n1",
"output": "12"
},
{
"input": "2\n2\n2",
"output": "8"
},
{
"input": "5\n6\n1",
"output": "35"
},
{
"input": "10\n1\n1",
"output": "20"
},
{
"input": "1\n6\n1",
"output": "8"
},
{
"input": "1\n9\n1",
"output": "11"
},
{
"input": "2\n1\n2",
"output": "6"
},
{
"input": "2\n6\n1",
"output": "14"
},
{
"input": "9\n2\n1",
"output": "27"
},
{
"input": "1\n9\n2",
"output": "20"
},
{
"input": "1\n3\n1",
"output": "5"
},
{
"input": "2\n1\n1",
"output": "4"
}
] | 1,695,577,162
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 0
|
a = input()
b = input()
c = input()
maxi = max(a+b+c, (a+b)*c, a+b*c, a*(b+c), a*b+c, a*b*c)
print(maxi)
|
Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
Input Specification:
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Output Specification:
Print the maximum value of the expression that you can obtain.
Demo Input:
['1\n2\n3\n', '2\n10\n3\n']
Demo Output:
['9\n', '60\n']
Note:
none
|
```python
a = input()
b = input()
c = input()
maxi = max(a+b+c, (a+b)*c, a+b*c, a*(b+c), a*b+c, a*b*c)
print(maxi)
```
| -1
|
|
816
|
A
|
Karen and Morning
|
PROGRAMMING
| 1,000
|
[
"brute force",
"implementation"
] | null | null |
Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
|
The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59).
|
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
|
[
"05:39\n",
"13:31\n",
"23:59\n"
] |
[
"11\n",
"0\n",
"1\n"
] |
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
| 500
|
[
{
"input": "05:39",
"output": "11"
},
{
"input": "13:31",
"output": "0"
},
{
"input": "23:59",
"output": "1"
},
{
"input": "13:32",
"output": "69"
},
{
"input": "14:40",
"output": "1"
},
{
"input": "14:00",
"output": "41"
},
{
"input": "05:50",
"output": "0"
},
{
"input": "12:22",
"output": "69"
},
{
"input": "12:34",
"output": "57"
},
{
"input": "05:30",
"output": "20"
},
{
"input": "14:14",
"output": "27"
},
{
"input": "01:10",
"output": "0"
},
{
"input": "02:20",
"output": "0"
},
{
"input": "03:30",
"output": "0"
},
{
"input": "04:40",
"output": "0"
},
{
"input": "10:01",
"output": "0"
},
{
"input": "11:11",
"output": "0"
},
{
"input": "12:21",
"output": "0"
},
{
"input": "14:41",
"output": "0"
},
{
"input": "15:51",
"output": "0"
},
{
"input": "20:02",
"output": "0"
},
{
"input": "21:12",
"output": "0"
},
{
"input": "22:22",
"output": "0"
},
{
"input": "23:32",
"output": "0"
},
{
"input": "01:11",
"output": "69"
},
{
"input": "02:21",
"output": "69"
},
{
"input": "03:31",
"output": "69"
},
{
"input": "04:41",
"output": "69"
},
{
"input": "05:51",
"output": "250"
},
{
"input": "10:02",
"output": "69"
},
{
"input": "11:12",
"output": "69"
},
{
"input": "14:42",
"output": "69"
},
{
"input": "15:52",
"output": "250"
},
{
"input": "20:03",
"output": "69"
},
{
"input": "21:13",
"output": "69"
},
{
"input": "22:23",
"output": "69"
},
{
"input": "23:33",
"output": "27"
},
{
"input": "00:00",
"output": "0"
},
{
"input": "00:01",
"output": "69"
},
{
"input": "22:21",
"output": "1"
},
{
"input": "20:01",
"output": "1"
},
{
"input": "11:10",
"output": "1"
},
{
"input": "06:59",
"output": "182"
},
{
"input": "02:00",
"output": "20"
},
{
"input": "02:19",
"output": "1"
},
{
"input": "17:31",
"output": "151"
},
{
"input": "19:00",
"output": "62"
},
{
"input": "13:37",
"output": "64"
},
{
"input": "07:59",
"output": "122"
},
{
"input": "04:20",
"output": "20"
},
{
"input": "07:10",
"output": "171"
},
{
"input": "06:00",
"output": "241"
},
{
"input": "06:01",
"output": "240"
},
{
"input": "08:15",
"output": "106"
},
{
"input": "06:59",
"output": "182"
},
{
"input": "01:00",
"output": "10"
},
{
"input": "07:00",
"output": "181"
},
{
"input": "06:10",
"output": "231"
},
{
"input": "18:52",
"output": "70"
},
{
"input": "09:59",
"output": "2"
},
{
"input": "19:00",
"output": "62"
},
{
"input": "15:52",
"output": "250"
},
{
"input": "06:50",
"output": "191"
},
{
"input": "00:00",
"output": "0"
},
{
"input": "19:20",
"output": "42"
},
{
"input": "05:51",
"output": "250"
},
{
"input": "06:16",
"output": "225"
},
{
"input": "10:10",
"output": "61"
},
{
"input": "17:11",
"output": "171"
},
{
"input": "18:00",
"output": "122"
},
{
"input": "00:01",
"output": "69"
},
{
"input": "05:04",
"output": "46"
},
{
"input": "16:00",
"output": "242"
},
{
"input": "23:31",
"output": "1"
},
{
"input": "17:25",
"output": "157"
},
{
"input": "23:32",
"output": "0"
},
{
"input": "23:58",
"output": "2"
},
{
"input": "02:21",
"output": "69"
},
{
"input": "01:11",
"output": "69"
},
{
"input": "23:46",
"output": "14"
},
{
"input": "00:09",
"output": "61"
},
{
"input": "09:20",
"output": "41"
},
{
"input": "05:59",
"output": "242"
},
{
"input": "18:59",
"output": "63"
},
{
"input": "02:02",
"output": "18"
},
{
"input": "00:30",
"output": "40"
},
{
"input": "05:54",
"output": "247"
},
{
"input": "19:59",
"output": "3"
},
{
"input": "16:59",
"output": "183"
},
{
"input": "17:51",
"output": "131"
},
{
"input": "09:30",
"output": "31"
},
{
"input": "10:01",
"output": "0"
},
{
"input": "16:55",
"output": "187"
},
{
"input": "20:02",
"output": "0"
},
{
"input": "16:12",
"output": "230"
},
{
"input": "20:00",
"output": "2"
},
{
"input": "01:01",
"output": "9"
},
{
"input": "23:01",
"output": "31"
},
{
"input": "06:05",
"output": "236"
},
{
"input": "19:19",
"output": "43"
},
{
"input": "17:00",
"output": "182"
},
{
"input": "07:50",
"output": "131"
},
{
"input": "21:20",
"output": "62"
},
{
"input": "23:23",
"output": "9"
},
{
"input": "19:30",
"output": "32"
},
{
"input": "00:59",
"output": "11"
},
{
"input": "22:59",
"output": "33"
},
{
"input": "18:18",
"output": "104"
},
{
"input": "17:46",
"output": "136"
},
{
"input": "07:30",
"output": "151"
},
{
"input": "17:16",
"output": "166"
},
{
"input": "06:06",
"output": "235"
},
{
"input": "23:30",
"output": "2"
},
{
"input": "05:57",
"output": "244"
},
{
"input": "19:46",
"output": "16"
},
{
"input": "11:10",
"output": "1"
},
{
"input": "17:07",
"output": "175"
},
{
"input": "18:53",
"output": "69"
},
{
"input": "07:06",
"output": "175"
},
{
"input": "17:50",
"output": "132"
},
{
"input": "09:15",
"output": "46"
},
{
"input": "09:55",
"output": "6"
},
{
"input": "20:05",
"output": "67"
},
{
"input": "22:55",
"output": "37"
},
{
"input": "10:00",
"output": "1"
},
{
"input": "07:55",
"output": "126"
},
{
"input": "07:40",
"output": "141"
},
{
"input": "19:08",
"output": "54"
},
{
"input": "23:24",
"output": "8"
},
{
"input": "16:15",
"output": "227"
},
{
"input": "07:20",
"output": "161"
},
{
"input": "23:10",
"output": "22"
},
{
"input": "06:51",
"output": "190"
},
{
"input": "16:30",
"output": "212"
},
{
"input": "17:54",
"output": "128"
},
{
"input": "07:07",
"output": "174"
},
{
"input": "08:01",
"output": "120"
},
{
"input": "09:58",
"output": "3"
},
{
"input": "18:03",
"output": "119"
},
{
"input": "07:59",
"output": "122"
},
{
"input": "05:55",
"output": "246"
},
{
"input": "07:39",
"output": "142"
},
{
"input": "05:52",
"output": "249"
},
{
"input": "12:02",
"output": "19"
},
{
"input": "08:59",
"output": "62"
},
{
"input": "09:21",
"output": "40"
},
{
"input": "16:04",
"output": "238"
},
{
"input": "04:00",
"output": "40"
},
{
"input": "18:21",
"output": "101"
},
{
"input": "09:13",
"output": "48"
},
{
"input": "17:20",
"output": "162"
},
{
"input": "06:15",
"output": "226"
},
{
"input": "19:21",
"output": "41"
},
{
"input": "16:02",
"output": "240"
},
{
"input": "15:59",
"output": "243"
},
{
"input": "06:07",
"output": "234"
},
{
"input": "08:08",
"output": "113"
},
{
"input": "09:09",
"output": "52"
},
{
"input": "02:19",
"output": "1"
},
{
"input": "21:59",
"output": "23"
}
] | 1,620,237,527
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 61
| 6,963,200
|
n=input()
if n[0]==n[4] and n[1]==n[3]:
print(0)
else:
if (n[0]=='2' and n[1]=='3') and (n[3]>='3' and n[4]>'2'):
print(1)
else:
m=n[1]+n[0]
m=int(m)
k=n[3]+n[4]
k=int(k)
print(m-k)
|
Title: Karen and Morning
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Karen is getting ready for a new school day!
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
Input Specification:
The first and only line of input contains a single string in the format hh:mm (00<=≤<= hh <=≤<=23, 00<=≤<= mm <=≤<=59).
Output Specification:
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
Demo Input:
['05:39\n', '13:31\n', '23:59\n']
Demo Output:
['11\n', '0\n', '1\n']
Note:
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
|
```python
n=input()
if n[0]==n[4] and n[1]==n[3]:
print(0)
else:
if (n[0]=='2' and n[1]=='3') and (n[3]>='3' and n[4]>'2'):
print(1)
else:
m=n[1]+n[0]
m=int(m)
k=n[3]+n[4]
k=int(k)
print(m-k)
```
| 0
|
|
707
|
A
|
Brain's Photos
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
|
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
|
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
|
[
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] |
[
"#Color",
"#Black&White",
"#Black&White"
] |
none
| 500
|
[
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,682,158,925
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 50
| 62
| 204,800
|
n,m = map(int,input().split())
pixels = list(list(map(str,input().split()))for _ in range(n))
pix = []
for i in pixels:
for g in i:
pix.append(g.upper())
if "C" in pix or "M" in pix or "Y" in pix:
print("#Color")
else :
print("#Black&White")
|
Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none
|
```python
n,m = map(int,input().split())
pixels = list(list(map(str,input().split()))for _ in range(n))
pix = []
for i in pixels:
for g in i:
pix.append(g.upper())
if "C" in pix or "M" in pix or "Y" in pix:
print("#Color")
else :
print("#Black&White")
```
| 3
|
|
915
|
C
|
Permute Digits
|
PROGRAMMING
| 1,700
|
[
"dp",
"greedy"
] | null | null |
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is.
|
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
|
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
|
[
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] |
[
"213\n",
"9321\n",
"4940\n"
] |
none
| 0
|
[
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},
{
"input": "123456789123456789\n276193619183618162",
"output": "276193618987554432"
},
{
"input": "1000000000000000000\n1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "1\n1000000000000000000",
"output": "1"
},
{
"input": "999999999999999999\n1000000000000000000",
"output": "999999999999999999"
},
{
"input": "2475345634895\n3455834583479",
"output": "3455834579642"
},
{
"input": "15778899\n98715689",
"output": "98598771"
},
{
"input": "4555\n5454",
"output": "4555"
},
{
"input": "122112\n221112",
"output": "221112"
},
{
"input": "199999999999991\n191000000000000",
"output": "119999999999999"
},
{
"input": "13\n31",
"output": "31"
},
{
"input": "212\n211",
"output": "122"
},
{
"input": "222234\n322223",
"output": "243222"
},
{
"input": "123456789\n987654311",
"output": "987654231"
},
{
"input": "20123\n21022",
"output": "20321"
},
{
"input": "10101\n11000",
"output": "10110"
},
{
"input": "592\n924",
"output": "592"
},
{
"input": "5654456\n5634565",
"output": "5566544"
},
{
"input": "655432\n421631",
"output": "365542"
},
{
"input": "200\n200",
"output": "200"
},
{
"input": "123456789987654321\n121111111111111111",
"output": "119988776655443322"
},
{
"input": "12345\n21344",
"output": "15432"
},
{
"input": "120\n200",
"output": "120"
},
{
"input": "123\n212",
"output": "132"
},
{
"input": "2184645\n5213118",
"output": "5186442"
},
{
"input": "9912346\n9912345",
"output": "9694321"
},
{
"input": "5003\n5000",
"output": "3500"
},
{
"input": "12345\n31234",
"output": "25431"
},
{
"input": "5001\n5000",
"output": "1500"
},
{
"input": "53436\n53425",
"output": "53364"
},
{
"input": "9329\n3268",
"output": "2993"
},
{
"input": "1234567890\n9000000001",
"output": "8976543210"
},
{
"input": "321\n212",
"output": "132"
},
{
"input": "109823464\n901234467",
"output": "896443210"
},
{
"input": "6543\n6542",
"output": "6534"
},
{
"input": "555441\n555100",
"output": "554541"
},
{
"input": "472389479\n327489423",
"output": "327487994"
},
{
"input": "45645643756464352\n53465475637456247",
"output": "53465475636654442"
},
{
"input": "254\n599",
"output": "542"
},
{
"input": "5232222345652321\n5000000000000000",
"output": "4655533322222221"
},
{
"input": "201\n200",
"output": "120"
},
{
"input": "14362799391220361\n45160821596433661",
"output": "43999766332221110"
},
{
"input": "3453\n5304",
"output": "4533"
},
{
"input": "989\n998",
"output": "998"
},
{
"input": "5200000000234\n5200000000311",
"output": "5200000000243"
},
{
"input": "5555132\n1325442",
"output": "1255553"
},
{
"input": "123\n211",
"output": "132"
},
{
"input": "65689\n66123",
"output": "65986"
},
{
"input": "123451234567890\n123456789012345",
"output": "123456789012345"
},
{
"input": "22115\n22015",
"output": "21521"
},
{
"input": "123\n311",
"output": "231"
},
{
"input": "12222\n21111",
"output": "12222"
},
{
"input": "765\n567",
"output": "567"
},
{
"input": "9087645\n9087640",
"output": "9087564"
},
{
"input": "1111111122222333\n2220000000000000",
"output": "2213332221111111"
},
{
"input": "7901\n7108",
"output": "7091"
},
{
"input": "215489\n215488",
"output": "214985"
},
{
"input": "102\n200",
"output": "120"
},
{
"input": "19260817\n20011213",
"output": "19876210"
},
{
"input": "12345\n53200",
"output": "53142"
},
{
"input": "1040003001\n1040003000",
"output": "1040001300"
},
{
"input": "295\n924",
"output": "592"
},
{
"input": "20000000000000001\n20000000000000000",
"output": "12000000000000000"
},
{
"input": "99988877\n99887766",
"output": "99879887"
},
{
"input": "12\n12",
"output": "12"
},
{
"input": "199999999999999999\n900000000000000000",
"output": "199999999999999999"
},
{
"input": "1234\n4310",
"output": "4231"
},
{
"input": "100011\n100100",
"output": "100011"
},
{
"input": "328899\n328811",
"output": "299883"
},
{
"input": "646722972346\n397619201220",
"output": "397476664222"
},
{
"input": "1203\n1200",
"output": "1032"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1112\n2110",
"output": "1211"
},
{
"input": "4545\n5540",
"output": "5454"
},
{
"input": "3053\n5004",
"output": "3530"
},
{
"input": "3503\n5004",
"output": "3530"
},
{
"input": "351731653766064847\n501550303749042658",
"output": "501548777666643331"
},
{
"input": "10123456789013451\n26666666666666666",
"output": "26598754433111100"
},
{
"input": "1110111\n1100000",
"output": "1011111"
},
{
"input": "30478\n32265",
"output": "30874"
},
{
"input": "456546546549874615\n441554543131214545",
"output": "441554498766665554"
},
{
"input": "214\n213",
"output": "142"
},
{
"input": "415335582799619283\n133117803602859310",
"output": "132999887655543321"
},
{
"input": "787\n887",
"output": "877"
},
{
"input": "3333222288889999\n3333222288881111",
"output": "3332999988883222"
},
{
"input": "495779862481416791\n836241745208800994",
"output": "829998777665444111"
},
{
"input": "139\n193",
"output": "193"
},
{
"input": "9568\n6500",
"output": "5986"
},
{
"input": "3208899\n3228811",
"output": "3209988"
},
{
"input": "27778\n28710",
"output": "27877"
},
{
"input": "62345\n46415",
"output": "46352"
},
{
"input": "405739873179209\n596793907108871",
"output": "594998777332100"
},
{
"input": "365\n690",
"output": "653"
},
{
"input": "8388731334391\n4710766672578",
"output": "4398887333311"
},
{
"input": "1230\n1200",
"output": "1032"
},
{
"input": "1025\n5000",
"output": "2510"
},
{
"input": "4207799\n4027711",
"output": "2997740"
},
{
"input": "4444222277779999\n4444222277771111",
"output": "4442999977774222"
},
{
"input": "7430\n3047",
"output": "3047"
},
{
"input": "649675735\n540577056",
"output": "539776654"
},
{
"input": "26\n82",
"output": "62"
},
{
"input": "241285\n207420",
"output": "185422"
},
{
"input": "3\n3",
"output": "3"
},
{
"input": "12\n21",
"output": "21"
},
{
"input": "481287\n826607",
"output": "824871"
},
{
"input": "40572351\n59676984",
"output": "57543210"
},
{
"input": "268135787269\n561193454469",
"output": "539887766221"
},
{
"input": "4\n9",
"output": "4"
},
{
"input": "5\n6",
"output": "5"
},
{
"input": "60579839\n33370073",
"output": "30998765"
},
{
"input": "49939\n39200",
"output": "34999"
},
{
"input": "2224\n4220",
"output": "2422"
},
{
"input": "427799\n427711",
"output": "299774"
},
{
"input": "49\n90",
"output": "49"
},
{
"input": "93875\n82210",
"output": "79853"
},
{
"input": "78831\n7319682",
"output": "88731"
},
{
"input": "937177\n7143444",
"output": "977731"
},
{
"input": "499380628\n391990337",
"output": "390988642"
},
{
"input": "2090909\n2900000",
"output": "2099900"
},
{
"input": "112233445566778890\n987654321987654320",
"output": "987654321876543210"
},
{
"input": "48257086\n80903384",
"output": "80876542"
},
{
"input": "112233445566778890\n900654321987654320",
"output": "898776655443322110"
},
{
"input": "112233445566778890\n123456789123456788",
"output": "123456789123456780"
},
{
"input": "5207799\n5027711",
"output": "2997750"
},
{
"input": "200000000000000001\n200000000000000000",
"output": "120000000000000000"
},
{
"input": "597402457\n797455420",
"output": "797455420"
},
{
"input": "90\n94",
"output": "90"
},
{
"input": "86888\n88683",
"output": "86888"
},
{
"input": "419155888\n588151913",
"output": "588151894"
},
{
"input": "408919130\n191830070",
"output": "191830049"
},
{
"input": "524975\n554924",
"output": "554792"
},
{
"input": "53029\n30524",
"output": "30295"
},
{
"input": "5549\n5542",
"output": "5495"
},
{
"input": "6\n9",
"output": "6"
},
{
"input": "87\n810",
"output": "87"
},
{
"input": "920491855\n281495062",
"output": "281495059"
},
{
"input": "6691\n6910",
"output": "6691"
},
{
"input": "533\n335",
"output": "335"
},
{
"input": "999999999999999998\n999999999999999997",
"output": "999999999999999989"
},
{
"input": "21111111111111111\n21111111111111110",
"output": "12111111111111111"
},
{
"input": "2\n12",
"output": "2"
},
{
"input": "76544\n45744",
"output": "45674"
},
{
"input": "2000000000000001\n2000000000000000",
"output": "1200000000000000"
},
{
"input": "740867\n467701",
"output": "467087"
},
{
"input": "2\n6",
"output": "2"
},
{
"input": "103\n130",
"output": "130"
},
{
"input": "2423712\n8466235",
"output": "7432221"
},
{
"input": "84\n48",
"output": "48"
},
{
"input": "1210\n12113",
"output": "2110"
},
{
"input": "2430\n20786",
"output": "4320"
},
{
"input": "100\n999",
"output": "100"
},
{
"input": "19325\n21903",
"output": "21593"
},
{
"input": "1969\n23251",
"output": "9961"
}
] | 1,527,628,090
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 66
| 1,000
| 6,963,200
|
def search(current, digits, target, idx, bulk):
if len(current) == len(target) and int(current) <= int(target):
print(current)
exit(0)
possibilities = [char for char in digits if bulk or (char <= target[idx] and char in digits)]
if len(possibilities) == 0:
return None
for possible_digit in possibilities:
tmp_digits = list(digits)
tmp_digits.remove(possible_digit)
if not bulk:
bulk = True if possible_digit != target[idx] else False
search(current + possible_digit, tmp_digits, target, idx + 1, bulk)
def main():
digits = sorted(list(input()), reverse=True)
target = input()
if len(digits) < len(target):
print(''.join(digits))
exit(0)
entries = [char for char in digits if char <= target[0]]
for current in entries:
tmp_digits = list(digits)
tmp_digits.remove(current)
search(current, tmp_digits, target, 1, True if current != target[0] else False)
if __name__ == "__main__":
main()
|
Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is.
Input Specification:
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Output Specification:
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
Demo Input:
['123\n222\n', '3921\n10000\n', '4940\n5000\n']
Demo Output:
['213\n', '9321\n', '4940\n']
Note:
none
|
```python
def search(current, digits, target, idx, bulk):
if len(current) == len(target) and int(current) <= int(target):
print(current)
exit(0)
possibilities = [char for char in digits if bulk or (char <= target[idx] and char in digits)]
if len(possibilities) == 0:
return None
for possible_digit in possibilities:
tmp_digits = list(digits)
tmp_digits.remove(possible_digit)
if not bulk:
bulk = True if possible_digit != target[idx] else False
search(current + possible_digit, tmp_digits, target, idx + 1, bulk)
def main():
digits = sorted(list(input()), reverse=True)
target = input()
if len(digits) < len(target):
print(''.join(digits))
exit(0)
entries = [char for char in digits if char <= target[0]]
for current in entries:
tmp_digits = list(digits)
tmp_digits.remove(current)
search(current, tmp_digits, target, 1, True if current != target[0] else False)
if __name__ == "__main__":
main()
```
| 0
|
|
538
|
A
|
Cutting Banner
|
PROGRAMMING
| 1,400
|
[
"brute force",
"implementation"
] | null | null |
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
|
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
|
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
|
[
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] |
[
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
"output": "NO"
},
{
"input": "C",
"output": "NO"
},
{
"input": "NQTSMZEBLY",
"output": "NO"
},
{
"input": "CODEFZORCES",
"output": "YES"
},
{
"input": "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF",
"output": "NO"
},
{
"input": "OCECFDSRDE",
"output": "NO"
},
{
"input": "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEWFS",
"output": "NO"
},
{
"input": "CODEFYTORCHES",
"output": "NO"
},
{
"input": "BCODEFORCES",
"output": "YES"
},
{
"input": "CVODEFORCES",
"output": "YES"
},
{
"input": "COAKDEFORCES",
"output": "YES"
},
{
"input": "CODFMWEFORCES",
"output": "YES"
},
{
"input": "CODEVCSYRFORCES",
"output": "YES"
},
{
"input": "CODEFXHHPWCVQORCES",
"output": "YES"
},
{
"input": "CODEFORQWUFJLOFFXTXRCES",
"output": "YES"
},
{
"input": "CODEFORBWFURYIDURNRKRDLHCLXZCES",
"output": "YES"
},
{
"input": "CODEFORCQSYSLYKCDFFUPSAZCJIAENCKZUFJZEINQIES",
"output": "YES"
},
{
"input": "CODEFORCEVENMDBQLSVPQIIBGSHBVOPYZXNWVSTVWDRONUREYJJIJIPMEBPQDCPFS",
"output": "YES"
},
{
"input": "CODEFORCESCFNNPAHNHDIPPBAUSPKJYAQDBVZNLSTSDCREZACVLMRFGVKGVHHZLXOHCTJDBQKIDWBUXDUJARLWGFGFCTTXUCAZB",
"output": "YES"
},
{
"input": "CODJRDPDEFOROES",
"output": "NO"
},
{
"input": "CODEFOGSIUZMZCMWAVQHNYFEKIEZQMAZOVEMDRMOEDBHAXPLBLDYYXCVTOOSJZVSQAKFXTBTZFWAYRZEMDEMVDJTDRXXAQBURCES",
"output": "YES"
},
{
"input": "CODEMKUYHAZSGJBQLXTHUCZZRJJJXUSEBOCNZASOKDZHMSGWZSDFBGHXFLABVPDQBJYXSHHAZAKHSTRGOKJYHRVSSUGDCMFOGCES",
"output": "NO"
},
{
"input": "CODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCES",
"output": "YES"
},
{
"input": "CCODEFORCESODECODEFORCCODEFORCESODCODEFORCESEFCODEFORCESORCODEFORCESCESCESFORCODEFORCESCES",
"output": "NO"
},
{
"input": "CCODEFORCESC",
"output": "NO"
},
{
"input": "CODEAFORBCES",
"output": "NO"
},
{
"input": "CODERRRRRFORCRRRRES",
"output": "NO"
},
{
"input": "CODELFORCELS",
"output": "NO"
},
{
"input": "CPOPDPEPFPOPRPCPEPS",
"output": "NO"
},
{
"input": "COXDEXFORXCEXS",
"output": "NO"
},
{
"input": "CODAAAAAFORCES",
"output": "NO"
},
{
"input": "CAOADEFORCES",
"output": "NO"
},
{
"input": "FORCESXCODE",
"output": "NO"
},
{
"input": "FORCESACODE",
"output": "NO"
},
{
"input": "ACAOADAEFORCES",
"output": "NO"
},
{
"input": "CCODEFORCESS",
"output": "NO"
},
{
"input": "ZCODEFORCEZ",
"output": "NO"
},
{
"input": "CODXEFORXCES",
"output": "NO"
},
{
"input": "CODEFORCEZ",
"output": "NO"
},
{
"input": "CODEFORCEST",
"output": "YES"
},
{
"input": "AXODEFORCES",
"output": "NO"
},
{
"input": "RCODEFORCESR",
"output": "NO"
},
{
"input": "CODECODEFORCESFORCES",
"output": "YES"
},
{
"input": "TTTWWWCODEFORCES",
"output": "YES"
},
{
"input": "CODEFORRCEST",
"output": "NO"
},
{
"input": "UJYTYUCODEFORCES",
"output": "YES"
},
{
"input": "CODEXXXXXXXXXXXXXXXXXXCODEFORCESXXXXXXXXXXXXXXXXXXXXXFORCES",
"output": "YES"
},
{
"input": "COXEDYFORCES",
"output": "NO"
},
{
"input": "UJYTYCODEFORCES",
"output": "YES"
},
{
"input": "UJYTCODEFORCES",
"output": "YES"
}
] | 1,577,983,592
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 55
| 140
| 0
|
s=input()
i=len(s)-1
if(s.find("C")==0 and s[i-8:]==("ODEFORCES")):
print("YES")
elif(s.find("CO")==0 and s[i-7:]==("DEFORCES")):
print("YES")
elif(s.find("COD")==0 and s[i-6:]==("EFORCES")):
print("YES")
elif(s.find("CODE")==0 and s[i-5:]==("FORCES")):
print("YES")
elif(s.find("CODEF")==0 and s[i-4:]==("ORCES")):
print("YES")
elif(s.find("CODEFO")==0 and s[i-3:]==("RCES")):
print("YES")
elif(s.find("CODEFOR")==0 and s[i-2:]==("CES")):
print("YES")
elif(s.find("CODEFORC")==0 and s[i-1:]==("ES")):
print("YES")
elif(s.find("CODEFORCE")==0 and s[i]==("S")):
print("YES")
elif(s.find("CODEFORCES")==0 or s[i-9:]=="CODEFORCES"):
print("YES")
else:
print("NO")
|
Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.
There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.
Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.
Input Specification:
The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.
Output Specification:
Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).
Demo Input:
['CODEWAITFORITFORCES\n', 'BOTTOMCODER\n', 'DECODEFORCES\n', 'DOGEFORCES\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'NO\n']
Note:
none
|
```python
s=input()
i=len(s)-1
if(s.find("C")==0 and s[i-8:]==("ODEFORCES")):
print("YES")
elif(s.find("CO")==0 and s[i-7:]==("DEFORCES")):
print("YES")
elif(s.find("COD")==0 and s[i-6:]==("EFORCES")):
print("YES")
elif(s.find("CODE")==0 and s[i-5:]==("FORCES")):
print("YES")
elif(s.find("CODEF")==0 and s[i-4:]==("ORCES")):
print("YES")
elif(s.find("CODEFO")==0 and s[i-3:]==("RCES")):
print("YES")
elif(s.find("CODEFOR")==0 and s[i-2:]==("CES")):
print("YES")
elif(s.find("CODEFORC")==0 and s[i-1:]==("ES")):
print("YES")
elif(s.find("CODEFORCE")==0 and s[i]==("S")):
print("YES")
elif(s.find("CODEFORCES")==0 or s[i-9:]=="CODEFORCES"):
print("YES")
else:
print("NO")
```
| 3
|
|
151
|
A
|
Soft Drinking
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
|
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
|
Print a single integer — the number of toasts each friend can make.
|
[
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] |
[
"2\n",
"3\n",
"0\n"
] |
A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
| 500
|
[
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
"input": "2 6 4 5 6 5 1 3",
"output": "0"
},
{
"input": "1 7 3 5 3 6 2 1",
"output": "6"
},
{
"input": "2 4 5 4 5 7 3 2",
"output": "1"
},
{
"input": "2 3 6 5 7 8 2 1",
"output": "4"
},
{
"input": "1 4 5 5 3 10 3 1",
"output": "6"
},
{
"input": "1 4 6 7 3 5 1 3",
"output": "1"
},
{
"input": "1 6 5 5 5 8 3 1",
"output": "8"
},
{
"input": "1 7 5 3 3 9 2 1",
"output": "9"
},
{
"input": "3 5 3 7 6 10 3 1",
"output": "1"
},
{
"input": "3 6 3 5 3 6 3 1",
"output": "2"
},
{
"input": "1 7 5 5 5 5 2 2",
"output": "2"
},
{
"input": "2 5 3 5 6 9 2 1",
"output": "3"
},
{
"input": "3 4 3 5 3 6 2 1",
"output": "2"
},
{
"input": "1 5 5 4 7 6 3 1",
"output": "6"
},
{
"input": "2 3 7 6 5 9 3 1",
"output": "3"
},
{
"input": "2 6 5 3 3 8 1 1",
"output": "4"
},
{
"input": "2 4 7 3 4 10 2 1",
"output": "5"
},
{
"input": "1 1000 1000 1000 1000 1000 1 1",
"output": "1000"
},
{
"input": "17 1000 1000 1000 1000 1000 3 7",
"output": "8"
},
{
"input": "115 1000 1000 1000 1000 1000 17 15",
"output": "0"
},
{
"input": "1 587 981 1 2 1 1 1",
"output": "1"
},
{
"input": "1 1 2 1 2 2 1 1",
"output": "2"
}
] | 1,690,195,706
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 27
| 122
| 0
|
# -*- coding: utf-8 -*-
l = [int(i) for i in input().split(' ')]
people = l[0]
v_bottle = l[1]*l[2]
d_lime = l[3]*l[4]
solt = l[5]
print(int(min((v_bottle/l[6]/people),(d_lime/people),(solt/l[7]/people))))
|
Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
Input Specification:
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Output Specification:
Print a single integer — the number of toasts each friend can make.
Demo Input:
['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
|
```python
# -*- coding: utf-8 -*-
l = [int(i) for i in input().split(' ')]
people = l[0]
v_bottle = l[1]*l[2]
d_lime = l[3]*l[4]
solt = l[5]
print(int(min((v_bottle/l[6]/people),(d_lime/people),(solt/l[7]/people))))
```
| 3
|
|
799
|
A
|
Carrot Cakes
|
PROGRAMMING
| 1,100
|
[
"brute force",
"implementation"
] | null | null |
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
|
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
|
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
|
[
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] |
[
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] |
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
| 500
|
[
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"
},
{
"input": "599 97 54 992",
"output": "YES"
},
{
"input": "11 22 18 17",
"output": "NO"
},
{
"input": "1 13 22 11",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "NO"
},
{
"input": "3 1 1 1",
"output": "YES"
},
{
"input": "1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1000 1000 1 1",
"output": "YES"
},
{
"input": "1000 1000 1 400",
"output": "YES"
},
{
"input": "1000 1000 1 1000",
"output": "YES"
},
{
"input": "1000 1000 1 999",
"output": "YES"
},
{
"input": "53 11 3 166",
"output": "YES"
},
{
"input": "313 2 3 385",
"output": "NO"
},
{
"input": "214 9 9 412",
"output": "NO"
},
{
"input": "349 9 5 268",
"output": "YES"
},
{
"input": "611 16 8 153",
"output": "YES"
},
{
"input": "877 13 3 191",
"output": "YES"
},
{
"input": "340 9 9 10",
"output": "YES"
},
{
"input": "31 8 2 205",
"output": "NO"
},
{
"input": "519 3 2 148",
"output": "YES"
},
{
"input": "882 2 21 219",
"output": "NO"
},
{
"input": "982 13 5 198",
"output": "YES"
},
{
"input": "428 13 6 272",
"output": "YES"
},
{
"input": "436 16 14 26",
"output": "YES"
},
{
"input": "628 10 9 386",
"output": "YES"
},
{
"input": "77 33 18 31",
"output": "YES"
},
{
"input": "527 36 4 8",
"output": "YES"
},
{
"input": "128 18 2 169",
"output": "YES"
},
{
"input": "904 4 2 288",
"output": "YES"
},
{
"input": "986 4 3 25",
"output": "YES"
},
{
"input": "134 8 22 162",
"output": "NO"
},
{
"input": "942 42 3 69",
"output": "YES"
},
{
"input": "894 4 9 4",
"output": "YES"
},
{
"input": "953 8 10 312",
"output": "YES"
},
{
"input": "43 8 1 121",
"output": "YES"
},
{
"input": "12 13 19 273",
"output": "NO"
},
{
"input": "204 45 10 871",
"output": "YES"
},
{
"input": "342 69 50 425",
"output": "NO"
},
{
"input": "982 93 99 875",
"output": "NO"
},
{
"input": "283 21 39 132",
"output": "YES"
},
{
"input": "1000 45 83 686",
"output": "NO"
},
{
"input": "246 69 36 432",
"output": "NO"
},
{
"input": "607 93 76 689",
"output": "NO"
},
{
"input": "503 21 24 435",
"output": "NO"
},
{
"input": "1000 45 65 989",
"output": "NO"
},
{
"input": "30 21 2 250",
"output": "YES"
},
{
"input": "1000 49 50 995",
"output": "NO"
},
{
"input": "383 69 95 253",
"output": "YES"
},
{
"input": "393 98 35 999",
"output": "YES"
},
{
"input": "1000 22 79 552",
"output": "NO"
},
{
"input": "268 294 268 154",
"output": "NO"
},
{
"input": "963 465 706 146",
"output": "YES"
},
{
"input": "304 635 304 257",
"output": "NO"
},
{
"input": "4 2 1 6",
"output": "NO"
},
{
"input": "1 51 10 50",
"output": "NO"
},
{
"input": "5 5 4 4",
"output": "YES"
},
{
"input": "3 2 1 1",
"output": "YES"
},
{
"input": "3 4 3 3",
"output": "NO"
},
{
"input": "7 3 4 1",
"output": "YES"
},
{
"input": "101 10 1 1000",
"output": "NO"
},
{
"input": "5 1 1 1",
"output": "YES"
},
{
"input": "5 10 5 5",
"output": "NO"
},
{
"input": "19 1 7 1",
"output": "YES"
},
{
"input": "763 572 745 262",
"output": "YES"
},
{
"input": "1 2 1 1",
"output": "NO"
},
{
"input": "5 1 1 3",
"output": "YES"
},
{
"input": "170 725 479 359",
"output": "NO"
},
{
"input": "6 2 1 7",
"output": "YES"
},
{
"input": "6 2 5 1",
"output": "YES"
},
{
"input": "1 2 2 1",
"output": "NO"
},
{
"input": "24 2 8 3",
"output": "YES"
},
{
"input": "7 3 3 3",
"output": "YES"
},
{
"input": "5 2 2 2",
"output": "YES"
},
{
"input": "3 2 1 2",
"output": "YES"
},
{
"input": "1000 2 200 8",
"output": "NO"
},
{
"input": "3 100 2 100",
"output": "NO"
},
{
"input": "2 999 1 1000",
"output": "NO"
},
{
"input": "2 1 1 1",
"output": "NO"
},
{
"input": "2 3 5 1",
"output": "NO"
},
{
"input": "100 1 5 1",
"output": "YES"
},
{
"input": "7 2 3 3",
"output": "YES"
},
{
"input": "4 1 1 3",
"output": "NO"
},
{
"input": "3 2 2 1",
"output": "YES"
},
{
"input": "1 1 1 2",
"output": "NO"
},
{
"input": "91 8 7 13",
"output": "YES"
},
{
"input": "3 1 2 1",
"output": "NO"
},
{
"input": "5 3 2 3",
"output": "YES"
},
{
"input": "9 6 6 3",
"output": "YES"
}
] | 1,675,223,590
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 31
| 0
|
a = list(map(int,input().split()))
t1 = math.ceil(a[0]/a[2]) * a[1]
t2 = a[3] + math.ceil(a[0] - math.ceil(a[3]/a[1]) * a[2]) * a[1]
if(t2 < t1):
print('YES')
else:
print('NO')
|
Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
Input Specification:
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
Output Specification:
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
Demo Input:
['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'YES\n']
Note:
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
|
```python
a = list(map(int,input().split()))
t1 = math.ceil(a[0]/a[2]) * a[1]
t2 = a[3] + math.ceil(a[0] - math.ceil(a[3]/a[1]) * a[2]) * a[1]
if(t2 < t1):
print('YES')
else:
print('NO')
```
| -1
|
|
961
|
B
|
Lecture Sleep
|
PROGRAMMING
| 1,200
|
[
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null |
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during the *i*-th minute of the lecture then *t**i* will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — *a**i* during the *i*-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for *k* minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and *n*<=-<=*k*<=+<=1. If you use it on some minute *i* then Mishka will be awake during minutes *j* such that and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
|
The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theorems lecturer tells during the *i*-th minute.
The third line of the input contains *n* integer numbers *t*1,<=*t*2,<=... *t**n* (0<=≤<=*t**i*<=≤<=1) — type of Mishka's behavior at the *i*-th minute of the lecture.
|
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
|
[
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] |
[
"16\n"
] |
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
| 0
|
[
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "20"
},
{
"input": "5 2\n1 2 3 4 20\n0 0 0 1 0",
"output": "24"
},
{
"input": "3 1\n1 2 3\n0 0 1",
"output": "5"
},
{
"input": "4 2\n4 5 6 8\n1 0 1 0",
"output": "18"
},
{
"input": "6 3\n1 3 5 2 1 15\n1 1 0 1 0 0",
"output": "22"
},
{
"input": "5 5\n1 2 3 4 5\n1 1 1 0 1",
"output": "15"
},
{
"input": "3 3\n3 3 3\n1 0 1",
"output": "9"
},
{
"input": "5 5\n500 44 3 4 50\n1 0 0 0 0",
"output": "601"
},
{
"input": "2 2\n3 2\n1 0",
"output": "5"
},
{
"input": "7 6\n4 9 1 7 1 8 4\n0 0 0 1 0 1 0",
"output": "30"
},
{
"input": "4 3\n6 5 9 6\n1 1 0 1",
"output": "26"
},
{
"input": "2 1\n3 2\n0 0",
"output": "3"
},
{
"input": "1 1\n10\n0",
"output": "10"
},
{
"input": "2 1\n3 2\n1 0",
"output": "5"
},
{
"input": "4 2\n3 6 7 2\n0 0 1 1",
"output": "18"
},
{
"input": "10 5\n3 5 9 2 5 9 3 8 8 1\n0 1 1 1 0 1 0 0 0 0",
"output": "49"
},
{
"input": "10 4\n9 5 6 4 3 9 5 1 10 7\n0 0 0 0 0 0 1 0 0 1",
"output": "36"
},
{
"input": "9 8\n3 3 7 7 1 9 10 7 1\n1 1 1 1 1 1 1 1 1",
"output": "48"
},
{
"input": "2 1\n3 4\n0 0",
"output": "4"
},
{
"input": "2 1\n3 2\n0 1",
"output": "5"
},
{
"input": "10 1\n6 6 8 7 6 6 3 2 5 6\n0 0 1 0 0 1 0 1 1 1",
"output": "34"
},
{
"input": "3 2\n10 10 6\n0 0 0",
"output": "20"
},
{
"input": "6 3\n1 3 5 2 5 4\n1 1 1 1 1 1",
"output": "20"
},
{
"input": "10 5\n1 1 1 1 1 1 1 1 10000 1\n1 1 1 1 1 1 1 1 0 1",
"output": "10009"
}
] | 1,661,686,821
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 202
| 6,348,800
|
n,k=map(int,input().split()) ; theo=list(map(int,input().split())) ; beha=list(map(int,input().split())) ; cum1=0 ; cum0=[]
for i in range(n):
if beha[i]==1:cum1+=theo[i] ; theo[i]=0
cum0.append(theo[0])
for i in range(1,n):
cum0.append(theo[i]+cum0[i-1])
mx=0
for i in range(n-k+1):
x=cum0[i+k-1]-cum0[i-1]
mx=max(mx,x)
print(mx+cum1)
|
Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during the *i*-th minute of the lecture then *t**i* will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — *a**i* during the *i*-th minute. Otherwise he writes nothing.
You know some secret technique to keep Mishka awake for *k* minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and *n*<=-<=*k*<=+<=1. If you use it on some minute *i* then Mishka will be awake during minutes *j* such that and will write down all the theorems lecturer tells.
You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Input Specification:
The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theorems lecturer tells during the *i*-th minute.
The third line of the input contains *n* integer numbers *t*1,<=*t*2,<=... *t**n* (0<=≤<=*t**i*<=≤<=1) — type of Mishka's behavior at the *i*-th minute of the lecture.
Output Specification:
Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.
Demo Input:
['6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n']
Demo Output:
['16\n']
Note:
In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.
|
```python
n,k=map(int,input().split()) ; theo=list(map(int,input().split())) ; beha=list(map(int,input().split())) ; cum1=0 ; cum0=[]
for i in range(n):
if beha[i]==1:cum1+=theo[i] ; theo[i]=0
cum0.append(theo[0])
for i in range(1,n):
cum0.append(theo[i]+cum0[i-1])
mx=0
for i in range(n-k+1):
x=cum0[i+k-1]-cum0[i-1]
mx=max(mx,x)
print(mx+cum1)
```
| 0
|
|
239
|
A
|
Two Bags of Potatoes
|
PROGRAMMING
| 1,200
|
[
"greedy",
"implementation",
"math"
] | null | null |
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
|
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
|
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1.
|
[
"10 1 10\n",
"10 6 40\n"
] |
[
"-1\n",
"2 8 14 20 26 \n"
] |
none
| 500
|
[
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..."
},
{
"input": "84817 1 33457",
"output": "-1"
},
{
"input": "21 37 99",
"output": "16 53 "
},
{
"input": "78 7 15",
"output": "-1"
},
{
"input": "74 17 27",
"output": "-1"
},
{
"input": "79 23 43",
"output": "-1"
},
{
"input": "32 33 3",
"output": "-1"
},
{
"input": "55 49 44",
"output": "-1"
},
{
"input": "64 59 404",
"output": "54 113 172 231 290 "
},
{
"input": "61 69 820",
"output": "8 77 146 215 284 353 422 491 560 629 698 "
},
{
"input": "17 28 532",
"output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 "
},
{
"input": "46592 52 232",
"output": "-1"
},
{
"input": "1541 58 648",
"output": "-1"
},
{
"input": "15946 76 360",
"output": "-1"
},
{
"input": "30351 86 424",
"output": "-1"
},
{
"input": "1 2 37493",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "1 3 27764",
"output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..."
},
{
"input": "10 4 9174",
"output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..."
},
{
"input": "33 7 4971",
"output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..."
},
{
"input": "981 1 3387",
"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": "386 1 2747",
"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": "123 2 50000",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "3123 100 10000000",
"output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..."
},
{
"input": "2 10000 1000000000",
"output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..."
},
{
"input": "3 10000 1000000000",
"output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..."
},
{
"input": "12312223 10000 1000000000",
"output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..."
},
{
"input": "500000000 1000000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 1000000000",
"output": "999999999 "
},
{
"input": "10 6 11",
"output": "-1"
},
{
"input": "2 100 10",
"output": "-1"
},
{
"input": "1 100000007 1000000000",
"output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 "
},
{
"input": "1 999999999 1000000000",
"output": "999999998 "
},
{
"input": "100000000 1000000000 1000000000",
"output": "900000000 "
},
{
"input": "11 2 12",
"output": "1 "
},
{
"input": "31 10 39",
"output": "-1"
},
{
"input": "48 6 50",
"output": "-1"
},
{
"input": "500000000 500000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 999999999",
"output": "-1"
},
{
"input": "4 2 10",
"output": "2 4 6 "
},
{
"input": "1000000000 1 1",
"output": "-1"
},
{
"input": "1000000000 1 100000",
"output": "-1"
},
{
"input": "1000000000 1 10",
"output": "-1"
},
{
"input": "10 5 14",
"output": "-1"
},
{
"input": "500000000 499999999 1000000000",
"output": "499999998 "
},
{
"input": "1 999999997 1000000000",
"output": "999999996 "
}
] | 1,698,152,925
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 48
| 310
| 102,400
|
y,k,n = map(int,input().split())
x = k - y%k
f = 0
while x+y <= n:
print(x,end=" ")
x += k
f = 1
if f==0:
print(-1)
|
Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
Input Specification:
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Output Specification:
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1.
Demo Input:
['10 1 10\n', '10 6 40\n']
Demo Output:
['-1\n', '2 8 14 20 26 \n']
Note:
none
|
```python
y,k,n = map(int,input().split())
x = k - y%k
f = 0
while x+y <= n:
print(x,end=" ")
x += k
f = 1
if f==0:
print(-1)
```
| 3
|
|
315
|
A
|
Sereja and Bottles
|
PROGRAMMING
| 1,400
|
[
"brute force"
] | null | null |
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
|
In a single line print a single integer — the answer to the problem.
|
[
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] |
[
"4\n",
"0\n"
] |
none
| 500
|
[
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,651,752,954
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 2
| 122
| 0
|
n=int(input())
bj=set()
aj=set()
for i in range(n):
a,b=map(int,input().split())
if a!=b:
bj.add(b)
aj.add(a)
else:
aj.add(a)
for i in bj:
if i in aj:
aj.remove(i)
print(len(aj))
|
Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none
|
```python
n=int(input())
bj=set()
aj=set()
for i in range(n):
a,b=map(int,input().split())
if a!=b:
bj.add(b)
aj.add(a)
else:
aj.add(a)
for i in bj:
if i in aj:
aj.remove(i)
print(len(aj))
```
| 0
|
|
701
|
A
|
Cards
|
PROGRAMMING
| 800
|
[
"greedy",
"implementation"
] | null | null |
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
|
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
|
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
|
[
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] |
[
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] |
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
| 500
|
[
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "4\n82 46 8 44",
"output": "3 1\n4 2"
},
{
"input": "2\n35 50",
"output": "1 2"
},
{
"input": "8\n24 39 49 38 44 64 44 50",
"output": "1 6\n4 8\n2 3\n5 7"
},
{
"input": "100\n23 44 35 88 10 78 8 84 46 19 69 36 81 60 46 12 53 22 83 73 6 18 80 14 54 39 74 42 34 20 91 70 32 11 80 53 70 21 24 12 87 68 35 39 8 84 81 70 8 54 73 2 60 71 4 33 65 48 69 58 55 57 78 61 45 50 55 72 86 37 5 11 12 81 32 19 22 11 22 82 23 56 61 84 47 59 31 38 31 90 57 1 24 38 68 27 80 9 37 14",
"output": "92 31\n52 90\n55 4\n71 41\n21 69\n7 84\n45 46\n49 8\n98 19\n5 80\n34 74\n72 47\n78 13\n16 97\n40 35\n73 23\n24 63\n100 6\n22 27\n10 51\n76 20\n30 68\n38 54\n18 48\n77 37\n79 32\n1 59\n81 11\n39 95\n93 42\n96 57\n87 83\n89 64\n33 53\n75 14\n56 86\n29 60\n3 91\n43 62\n12 82\n70 67\n99 61\n88 50\n94 25\n26 36\n44 17\n28 66\n2 58\n65 85\n9 15"
},
{
"input": "12\n22 83 2 67 55 12 40 93 83 73 12 28",
"output": "3 8\n6 9\n11 2\n1 10\n12 4\n7 5"
},
{
"input": "16\n10 33 36 32 48 25 31 27 45 13 37 26 22 21 15 43",
"output": "1 5\n10 9\n15 16\n14 11\n13 3\n6 2\n12 4\n8 7"
},
{
"input": "20\n18 13 71 60 28 10 20 65 65 12 13 14 64 68 6 50 72 7 66 58",
"output": "15 17\n18 3\n6 14\n10 19\n2 9\n11 8\n12 13\n1 4\n7 20\n5 16"
},
{
"input": "24\n59 39 25 22 46 21 24 70 60 11 46 42 44 37 13 37 41 58 72 23 25 61 58 62",
"output": "10 19\n15 8\n6 24\n4 22\n20 9\n7 1\n3 23\n21 18\n14 11\n16 5\n2 13\n17 12"
},
{
"input": "28\n22 1 51 31 83 35 3 64 59 10 61 25 19 53 55 80 78 8 82 22 67 4 27 64 33 6 85 76",
"output": "2 27\n7 5\n22 19\n26 16\n18 17\n10 28\n13 21\n1 24\n20 8\n12 11\n23 9\n4 15\n25 14\n6 3"
},
{
"input": "32\n41 42 22 68 40 52 66 16 73 25 41 21 36 60 46 30 24 55 35 10 54 52 70 24 20 56 3 34 35 6 51 8",
"output": "27 9\n30 23\n32 4\n20 7\n8 14\n25 26\n12 18\n3 21\n17 22\n24 6\n10 31\n16 15\n28 2\n19 11\n29 1\n13 5"
},
{
"input": "36\n1 10 61 43 27 49 55 33 7 30 45 78 69 34 38 19 36 49 55 11 30 63 46 24 16 68 71 18 11 52 72 24 60 68 8 41",
"output": "1 12\n9 31\n35 27\n2 13\n20 34\n29 26\n25 22\n28 3\n16 33\n24 19\n32 7\n5 30\n10 18\n21 6\n8 23\n14 11\n17 4\n15 36"
},
{
"input": "40\n7 30 13 37 37 56 45 28 61 28 23 33 44 63 58 52 21 2 42 19 10 32 9 7 61 15 58 20 45 4 46 24 35 17 50 4 20 48 41 55",
"output": "18 14\n30 25\n36 9\n1 27\n24 15\n23 6\n21 40\n3 16\n26 35\n34 38\n20 31\n28 29\n37 7\n17 13\n11 19\n32 39\n8 5\n10 4\n2 33\n22 12"
},
{
"input": "44\n7 12 46 78 24 68 86 22 71 79 85 14 58 72 26 46 54 39 35 13 31 45 81 21 15 8 47 64 69 87 57 6 18 80 47 29 36 62 34 67 59 48 75 25",
"output": "32 30\n1 7\n26 11\n2 23\n20 34\n12 10\n25 4\n33 43\n24 14\n8 9\n5 29\n44 6\n15 40\n36 28\n21 38\n39 41\n19 13\n37 31\n18 17\n22 42\n3 35\n16 27"
},
{
"input": "48\n57 38 16 25 34 57 29 38 60 51 72 78 22 39 10 33 20 16 12 3 51 74 9 88 4 70 56 65 86 18 33 12 77 78 52 87 68 85 81 5 61 2 52 39 80 13 74 30",
"output": "42 24\n20 36\n25 29\n40 38\n23 39\n15 45\n19 34\n32 12\n46 33\n3 47\n18 22\n30 11\n17 26\n13 37\n4 28\n7 41\n48 9\n16 6\n31 1\n5 27\n2 43\n8 35\n14 21\n44 10"
},
{
"input": "52\n57 12 13 40 68 31 18 4 31 18 65 3 62 32 6 3 49 48 51 33 53 40 9 32 47 53 58 19 14 23 32 38 39 69 19 20 62 52 68 17 39 22 54 59 3 2 52 9 67 68 24 39",
"output": "46 34\n12 50\n16 39\n45 5\n8 49\n15 11\n23 37\n48 13\n2 44\n3 27\n29 1\n40 43\n7 26\n10 21\n28 47\n35 38\n36 19\n42 17\n30 18\n51 25\n6 22\n9 4\n14 52\n24 41\n31 33\n20 32"
},
{
"input": "56\n53 59 66 68 71 25 48 32 12 61 72 69 30 6 56 55 25 49 60 47 46 46 66 19 31 9 23 15 10 12 71 53 51 32 39 31 66 66 17 52 12 7 7 22 49 12 71 29 63 7 47 29 18 39 27 26",
"output": "14 11\n42 47\n43 31\n50 5\n26 12\n29 4\n9 38\n30 37\n41 23\n46 3\n28 49\n39 10\n53 19\n24 2\n44 15\n27 16\n6 32\n17 1\n56 40\n55 33\n48 45\n52 18\n13 7\n25 51\n36 20\n8 22\n34 21\n35 54"
},
{
"input": "60\n47 63 20 68 46 12 45 44 14 38 28 73 60 5 20 18 70 64 37 47 26 47 37 61 29 61 23 28 30 68 55 22 25 60 38 7 63 12 38 15 14 30 11 5 70 15 53 52 7 57 49 45 55 37 45 28 50 2 31 30",
"output": "58 12\n14 45\n44 17\n36 30\n49 4\n43 18\n6 37\n38 2\n9 26\n41 24\n40 34\n46 13\n16 50\n3 53\n15 31\n32 47\n27 48\n33 57\n21 51\n11 22\n28 20\n56 1\n25 5\n29 55\n42 52\n60 7\n59 8\n19 39\n23 35\n54 10"
},
{
"input": "64\n63 39 19 5 48 56 49 45 29 68 25 59 37 69 62 26 60 44 60 6 67 68 2 40 56 6 19 12 17 70 23 11 59 37 41 55 30 68 72 14 38 34 3 71 2 4 55 15 31 66 15 51 36 72 18 7 6 14 43 33 8 35 57 18",
"output": "23 54\n45 39\n43 44\n46 30\n4 14\n20 38\n26 22\n57 10\n56 21\n61 50\n32 1\n28 15\n40 19\n58 17\n48 33\n51 12\n29 63\n55 25\n64 6\n3 47\n27 36\n31 52\n11 7\n16 5\n9 8\n37 18\n49 59\n60 35\n42 24\n62 2\n53 41\n13 34"
},
{
"input": "68\n58 68 40 55 62 15 10 54 19 18 69 27 15 53 8 18 8 33 15 49 20 9 70 8 18 64 14 59 9 64 3 35 46 11 5 65 58 55 28 58 4 55 64 5 68 24 4 58 23 45 58 50 38 68 5 15 20 9 5 53 20 63 69 68 15 53 65 65",
"output": "31 23\n41 63\n47 11\n35 64\n44 54\n55 45\n59 2\n15 68\n17 67\n24 36\n22 43\n29 30\n58 26\n7 62\n34 5\n27 28\n6 51\n13 48\n19 40\n56 37\n65 1\n10 42\n16 38\n25 4\n9 8\n21 66\n57 60\n61 14\n49 52\n46 20\n12 33\n39 50\n18 3\n32 53"
},
{
"input": "72\n61 13 55 23 24 55 44 33 59 19 14 17 66 40 27 33 29 37 28 74 50 56 59 65 64 17 42 56 73 51 64 23 22 26 38 22 36 47 60 14 52 28 14 12 6 41 73 5 64 67 61 74 54 34 45 34 44 4 34 49 18 72 44 47 31 19 11 31 5 4 45 50",
"output": "58 52\n70 20\n48 47\n69 29\n45 62\n67 50\n44 13\n2 24\n11 49\n40 31\n43 25\n12 51\n26 1\n61 39\n10 23\n66 9\n33 28\n36 22\n4 6\n32 3\n5 53\n34 41\n15 30\n19 72\n42 21\n17 60\n65 64\n68 38\n8 71\n16 55\n54 63\n56 57\n59 7\n37 27\n18 46\n35 14"
},
{
"input": "76\n73 37 73 67 26 45 43 74 47 31 43 81 4 3 39 79 48 81 67 39 67 66 43 67 80 51 34 79 5 58 45 10 39 50 9 78 6 18 75 17 45 17 51 71 34 53 33 11 17 15 11 69 50 41 13 74 10 33 77 41 11 64 36 74 17 32 3 10 27 20 5 73 52 41 7 57",
"output": "14 18\n67 12\n13 25\n29 28\n71 16\n37 36\n75 59\n35 39\n32 64\n57 56\n68 8\n48 72\n51 3\n61 1\n55 44\n50 52\n40 24\n42 21\n49 19\n65 4\n38 22\n70 62\n5 30\n69 76\n10 46\n66 73\n47 43\n58 26\n27 53\n45 34\n63 17\n2 9\n15 41\n20 31\n33 6\n54 23\n60 11\n74 7"
},
{
"input": "80\n18 38 65 1 20 9 57 2 36 26 15 17 33 61 65 27 10 35 49 42 40 32 19 33 12 36 56 31 10 41 8 54 56 60 5 47 61 43 23 19 20 30 7 6 38 60 29 58 35 64 30 51 6 17 30 24 47 1 37 47 34 36 48 28 5 25 47 19 30 39 36 23 31 28 46 46 59 43 19 49",
"output": "4 15\n58 3\n8 50\n35 37\n65 14\n44 46\n53 34\n43 77\n31 48\n6 7\n17 33\n29 27\n25 32\n11 52\n12 80\n54 19\n1 63\n23 67\n40 60\n68 57\n79 36\n5 76\n41 75\n39 78\n72 38\n56 20\n66 30\n10 21\n16 70\n64 45\n74 2\n47 59\n42 71\n51 62\n55 26\n69 9\n28 49\n73 18\n22 61\n13 24"
},
{
"input": "84\n59 41 54 14 42 55 29 28 41 73 40 15 1 1 66 49 76 59 68 60 42 81 19 23 33 12 80 81 42 22 54 54 2 22 22 28 27 60 36 57 17 76 38 20 40 65 23 9 81 50 25 13 46 36 59 53 6 35 47 40 59 19 67 46 63 49 12 33 23 49 33 23 32 62 60 70 44 1 6 63 28 16 70 69",
"output": "13 49\n14 28\n78 22\n33 27\n57 42\n79 17\n48 10\n26 83\n67 76\n52 84\n4 19\n12 63\n82 15\n41 46\n23 80\n62 65\n44 74\n30 75\n34 38\n35 20\n24 61\n47 55\n69 18\n72 1\n51 40\n37 6\n8 32\n36 31\n81 3\n7 56\n73 50\n25 70\n68 66\n71 16\n58 59\n39 64\n54 53\n43 77\n11 29\n45 21\n60 5\n2 9"
},
{
"input": "88\n10 28 71 6 58 66 45 52 13 71 39 1 10 29 30 70 14 17 15 38 4 60 5 46 66 41 40 58 2 57 32 44 21 26 13 40 64 63 56 33 46 8 30 43 67 55 44 28 32 62 14 58 42 67 45 59 32 68 10 31 51 6 42 34 9 12 51 27 20 14 62 42 16 5 1 14 30 62 40 59 58 26 25 15 27 47 21 57",
"output": "12 10\n75 3\n29 16\n21 58\n23 54\n74 45\n4 25\n62 6\n42 37\n65 38\n1 78\n13 71\n59 50\n66 22\n9 80\n35 56\n17 81\n51 52\n70 28\n76 5\n19 88\n84 30\n73 39\n18 46\n69 8\n33 67\n87 61\n83 86\n34 41\n82 24\n68 55\n85 7\n2 47\n48 32\n14 44\n15 72\n43 63\n77 53\n60 26\n31 79\n49 36\n57 27\n40 11\n64 20"
},
{
"input": "92\n17 37 81 15 29 70 73 42 49 23 44 77 27 44 74 11 43 66 15 41 60 36 33 11 2 76 16 51 45 21 46 16 85 29 76 79 16 6 60 13 25 44 62 28 43 35 63 24 76 71 62 15 57 72 45 10 71 59 74 14 53 13 58 72 14 72 73 11 25 1 57 42 86 63 50 30 64 38 10 77 75 24 58 8 54 12 43 30 27 71 52 34",
"output": "70 73\n25 33\n38 3\n84 36\n56 80\n79 12\n16 49\n24 35\n68 26\n86 81\n40 59\n62 15\n60 67\n65 7\n4 66\n19 64\n52 54\n27 90\n32 57\n37 50\n1 6\n30 18\n10 77\n48 74\n82 47\n41 51\n69 43\n13 39\n89 21\n44 58\n5 83\n34 63\n76 71\n88 53\n23 85\n92 61\n46 91\n22 28\n2 75\n78 9\n20 31\n8 55\n72 29\n17 42\n45 14\n87 11"
},
{
"input": "96\n77 7 47 19 73 31 46 13 89 69 52 9 26 77 6 87 55 45 71 2 79 1 80 20 4 82 64 20 75 86 84 24 77 56 16 54 53 35 74 73 40 29 63 20 83 39 58 16 31 41 40 16 11 90 30 48 62 39 55 8 50 3 77 73 75 66 14 90 18 54 38 10 53 22 67 38 27 91 62 37 85 13 92 7 18 83 10 3 86 54 80 59 34 16 39 43",
"output": "22 83\n20 78\n62 68\n88 54\n25 9\n15 16\n2 89\n84 30\n60 81\n12 31\n72 86\n87 45\n53 26\n8 91\n82 23\n67 21\n35 63\n48 33\n52 14\n94 1\n69 65\n85 29\n4 39\n24 64\n28 40\n44 5\n74 19\n32 10\n13 75\n77 66\n42 27\n55 43\n6 79\n49 57\n93 92\n38 47\n80 34\n71 59\n76 17\n46 90\n58 70\n95 36\n41 73\n51 37\n50 11\n96 61\n18 56\n7 3"
},
{
"input": "4\n100 100 1 1",
"output": "3 2\n4 1"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1 100\n2 99\n3 98\n4 97\n5 96\n6 95\n7 94\n8 93\n9 92\n10 91\n11 90\n12 89\n13 88\n14 87\n15 86\n16 85\n17 84\n18 83\n19 82\n20 81\n21 80\n22 79\n23 78\n24 77\n25 76\n26 75\n27 74\n28 73\n29 72\n30 71\n31 70\n32 69\n33 68\n34 67\n35 66\n36 65\n37 64\n38 63\n39 62\n40 61\n41 60\n42 59\n43 58\n44 57\n45 56\n46 55\n47 54\n48 53\n49 52\n50 51"
},
{
"input": "4\n3 4 4 5",
"output": "1 4\n2 3"
},
{
"input": "4\n1 1 2 2",
"output": "1 4\n2 3"
},
{
"input": "4\n1 2 3 4",
"output": "1 4\n2 3"
}
] | 1,589,783,134
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 93
| 6,963,200
|
n=int(input())
l=list(map(int,input().split()))
nx=n/2
sm=int(sum(l)/nx)
nl=[]
for i in range(n):
nl.append(i)
for j in range(i+1,n):
if l[i]+l[j]==sm and j not in nl:
print(i+1,j+1)
nl.append(j)
|
Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Output Specification:
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.
Demo Input:
['6\n1 5 7 4 4 3\n', '4\n10 10 10 10\n']
Demo Output:
['1 3\n6 2\n4 5\n', '1 2\n3 4\n']
Note:
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
|
```python
n=int(input())
l=list(map(int,input().split()))
nx=n/2
sm=int(sum(l)/nx)
nl=[]
for i in range(n):
nl.append(i)
for j in range(i+1,n):
if l[i]+l[j]==sm and j not in nl:
print(i+1,j+1)
nl.append(j)
```
| 0
|
|
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,604,389,281
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 154
| 0
|
n,m=map(int,input().split())
p=m%(n*(n+1)/2)
for i in range(1,n+1):
if p>=i:
p=p-i
else:
print(p)
exit()
|
Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Output Specification:
Print the number of chips the presenter ended up with.
Demo Input:
['4 11\n', '17 107\n', '3 8\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
|
```python
n,m=map(int,input().split())
p=m%(n*(n+1)/2)
for i in range(1,n+1):
if p>=i:
p=p-i
else:
print(p)
exit()
```
| 0
|
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,590,002,763
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 33
| 109
| 0
|
def main():
st = input()
print(solve(st))
def solve(st):
return len(st)*25 + 26
main()
|
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
def main():
st = input()
print(solve(st))
def solve(st):
return len(st)*25 + 26
main()
```
| 3
|
|
602
|
B
|
Approximating a Constant Range
|
PROGRAMMING
| 1,400
|
[
"dp",
"implementation",
"two pointers"
] | null | null |
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range.
|
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
|
Print a single number — the maximum length of an almost constant range of the given sequence.
|
[
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] |
[
"4\n",
"5\n"
] |
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
| 1,000
|
[
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 2 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "4"
},
{
"input": "4\n4 3 2 3",
"output": "3"
},
{
"input": "4\n8 8 7 7",
"output": "4"
},
{
"input": "3\n99998 99999 100000",
"output": "2"
},
{
"input": "3\n100000 99999 99998",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "2\n99999 100000",
"output": "2"
},
{
"input": "2\n100000 100000",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "15"
}
] | 1,687,232,957
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 107
| 124
| 13,619,200
|
MOD=10**9+7
def slove():
n=int(input())
# m=input()
a=list(map(int,input().split(' ')))
left=0
d={}
ans=0
for i,x in enumerate(a):
if x not in d: d[x]=0
d[x]+=1
while len(d)>2:
d[a[left]]-=1
if d[a[left]]==0:
del d[a[left]]
left+=1
ans=max(ans,i-left+1)
print(ans)
return
# t=int(input())
t=1
# M=1<<30
for _ in range(t):
slove()
|
Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Output Specification:
Print a single number — the maximum length of an almost constant range of the given sequence.
Demo Input:
['5\n1 2 3 3 2\n', '11\n5 4 5 5 6 7 8 8 8 7 6\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
|
```python
MOD=10**9+7
def slove():
n=int(input())
# m=input()
a=list(map(int,input().split(' ')))
left=0
d={}
ans=0
for i,x in enumerate(a):
if x not in d: d[x]=0
d[x]+=1
while len(d)>2:
d[a[left]]-=1
if d[a[left]]==0:
del d[a[left]]
left+=1
ans=max(ans,i-left+1)
print(ans)
return
# t=int(input())
t=1
# M=1<<30
for _ in range(t):
slove()
```
| 3
|
|
592
|
A
|
PawnChess
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
|
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
|
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
|
[
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] |
[
"A\n",
"B\n"
] |
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
| 500
|
[
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n........\n...BB.B.\nW.WWWW.W",
"output": "A"
},
{
"input": "BB......\nW....BBW\n........\n.B.B.BBB\n....BB..\nB....BB.\n...WWWW.\n....WW..",
"output": "A"
},
{
"input": ".B.B..B.\nB.B....B\n...B.B.B\n..B.W..B\n.BBB.B.B\nB.BB.B.B\nBB..BBBB\nW.W.W.WW",
"output": "B"
},
{
"input": "..BB....\n.B.B.B.B\n..B.B...\n..B..B.B\nWWWBWWB.\n.BB...B.\n..BBB...\n......W.",
"output": "B"
},
{
"input": "..BB....\n.WBWBWBB\n.....BBB\n..WW....\n.W.W...W\nWWW...W.\n.W....W.\nW...W.W.",
"output": "A"
},
{
"input": "....BB..\nBB......\n.B.....B\nWW..WWW.\n...BB.B.\nB...BB..\n..W..WWW\n...W...W",
"output": "B"
},
{
"input": "B...BBBB\n...BBB..\nBBWBWW.W\n.B..BB.B\nW..W..WW\nW.WW....\n........\nWW.....W",
"output": "A"
},
{
"input": ".B......\n.B....B.\n...W....\n......W.\nW.WWWW.W\nW.WW....\n..WWW...\n..W...WW",
"output": "A"
},
{
"input": "B.......\nBBB.....\n.B....B.\n.W.BWB.W\n......B.\nW..WW...\n...W....\nW...W..W",
"output": "A"
},
{
"input": ".....B..\n........\n........\n.BB..B..\n..BB....\n........\n....WWW.\n......W.",
"output": "B"
},
{
"input": "B.B...B.\n...BBBBB\n....B...\n...B...B\nB.B.B..B\n........\n........\nWWW..WW.",
"output": "B"
},
{
"input": "B.B...B.\n........\n.......B\n.BB....B\n.....W..\n.W.WW.W.\n...W.WW.\nW..WW..W",
"output": "A"
},
{
"input": "......B.\nB....B..\n...B.BB.\n...B....\n........\n..W....W\nWW......\n.W....W.",
"output": "B"
},
{
"input": ".BBB....\nB.B.B...\nB.BB.B..\nB.BB.B.B\n........\n........\nW.....W.\n..WW..W.",
"output": "B"
},
{
"input": "..B..BBB\n........\n........\n........\n...W.W..\n...W..W.\nW.......\n..W...W.",
"output": "A"
},
{
"input": "........\n.B.B....\n...B..BB\n........\n........\nW...W...\nW...W...\nW.WW.W..",
"output": "A"
},
{
"input": "B....BB.\n...B...B\n.B......\n........\n........\n........\n........\n....W..W",
"output": "B"
},
{
"input": "...BB.BB\nBB...B..\n........\n........\n........\n........\n..W..W..\n......W.",
"output": "A"
},
{
"input": "...BB...\n........\n........\n........\n........\n........\n......W.\nWW...WW.",
"output": "A"
},
{
"input": "...B.B..\n........\n........\n........\n........\n........\n........\nWWW...WW",
"output": "A"
},
{
"input": "BBBBBBB.\n........\n........\n........\n........\n........\n........\n.WWWWWWW",
"output": "A"
},
{
"input": ".BBBBBB.\nB.......\n........\n........\n........\n........\n........\n.WWWWWWW",
"output": "B"
},
{
"input": ".BBBBBBB\n........\n........\n........\n........\n........\n........\nWWWWWWW.",
"output": "A"
},
{
"input": ".BBBBBB.\n.......B\n........\n........\n........\n........\n........\nWWWWWWW.",
"output": "B"
},
{
"input": "B..BB...\n..B...B.\n.WBB...B\nBW......\nW.B...W.\n..BBW.B.\nBW..BB..\n......W.",
"output": "B"
},
{
"input": "B.BBBBBB\nB..BBB.B\nW.BB.W.B\nB.BWBB.B\nBWBWBBBB\n...BBBBB\nB.B...BB\nWW..WW.W",
"output": "B"
},
{
"input": "BBBB.BBB\nBBBB.B.B\nB.B..BBB\nB.BB.BWW\nB.BB.BBB\nB.BB.BBB\n..BW.BB.\nW.WWWWWW",
"output": "B"
},
{
"input": "BBBB.BBB\n.B....WB\nBB.B...B\nWWWW.WWB\nBB...BWW\nWWW..BBB\nW.BW.BB.\nWWWWWWW.",
"output": "B"
},
{
"input": "B.BBBBBB\nW.WWBBBW\nW.BB.WBB\nW.W.BBBW\nW.BWW.WB\nB..B..BB\nB.B.W.BB\nWWWWW.WW",
"output": "B"
},
{
"input": "BBBBBB.B\n.BBWBB.B\nWWW..B.W\n..WW.W.W\nBWB..W.W\n..BW.B.W\nB..B....\nWWWW.WWW",
"output": "B"
},
{
"input": ".B...BB.\nWBB.BWBB\n.BWBW...\n..W...B.\nWB.BWW..\nWBW.....\n.W..W.B.\n.W.W.WW.",
"output": "A"
},
{
"input": ".B..BBBB\nBB...WWB\nB..B.W.B\nWB.W...B\n...W.WW.\nW.....W.\nWB.W.W.W\n.WW...WW",
"output": "A"
},
{
"input": "B.BBBBBB\nW.BB.W.B\nW.BBW...\n..WWWW.B\n....W..B\n.WW.W..W\n.W..WW.W\nW.W....W",
"output": "A"
},
{
"input": "........\n.B......\n.W......\n........\n....B...\n........\n........\n.......W",
"output": "B"
}
] | 1,451,316,319
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 30
| 0
|
chess=[list(input())for i in range(8)]
o=[0]
p=[0]
j=1
if 'W' in chess[0]:
j=0
print('A')
if 'B' in chess[7] and 'W' not in chess[0]:
j=0
print('B')
if j==1:
for i in range(1,7):
for j in range(8):
if chess[i][j]=='B' and chess[i+1][j]!='W':
o.append(i)
if chess[i][j]=='W' and chess[i-1][j]!='B':
p.append(i)
if 7-max(o)<min(p):
print('B')
if 7-max(o)>min(p):
print('A')
|
Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
Input Specification:
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
Output Specification:
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
Demo Input:
['........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n', '..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n']
Demo Output:
['A\n', 'B\n']
Note:
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
|
```python
chess=[list(input())for i in range(8)]
o=[0]
p=[0]
j=1
if 'W' in chess[0]:
j=0
print('A')
if 'B' in chess[7] and 'W' not in chess[0]:
j=0
print('B')
if j==1:
for i in range(1,7):
for j in range(8):
if chess[i][j]=='B' and chess[i+1][j]!='W':
o.append(i)
if chess[i][j]=='W' and chess[i-1][j]!='B':
p.append(i)
if 7-max(o)<min(p):
print('B')
if 7-max(o)>min(p):
print('A')
```
| 0
|
|
629
|
A
|
Far Relative’s Birthday Cake
|
PROGRAMMING
| 800
|
[
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null |
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
|
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
|
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
|
[
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] |
[
"4\n",
"9\n"
] |
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
| 500
|
[
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},
{
"input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.",
"output": "80"
},
{
"input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C",
"output": "144"
},
{
"input": "10\n..C..C.C..\n..CC..C.CC\n.C.C...C.C\n..C.CC..CC\n....C..C.C\n...C..C..C\nCC.CC....C\n..CCCC.C.C\n..CC.CCC..\nCCCC..C.CC",
"output": "190"
},
{
"input": "11\nC.CC...C.CC\nCC.C....C.C\n.....C..CCC\n....C.CC.CC\nC..C..CC...\nC...C...C..\nCC..CCC.C.C\n..C.CC.C..C\nC...C.C..CC\n.C.C..CC..C\n.C.C.CC.C..",
"output": "228"
},
{
"input": "21\n...CCC.....CC..C..C.C\n..CCC...CC...CC.CCC.C\n....C.C.C..CCC..C.C.C\n....CCC..C..C.CC.CCC.\n...CCC.C..C.C.....CCC\n.CCC.....CCC..C...C.C\nCCCC.C...CCC.C...C.CC\nC..C...C.CCC..CC..C..\nC...CC..C.C.CC..C.CC.\nCC..CCCCCCCCC..C....C\n.C..CCCC.CCCC.CCC...C\nCCC...CCC...CCC.C..C.\n.CCCCCCCC.CCCC.CC.C..\n.C.C..C....C.CCCCCC.C\n...C...C.CCC.C.CC..C.\nCCC...CC..CC...C..C.C\n.CCCCC...C.C..C.CC.C.\n..CCC.C.C..CCC.CCC...\n..C..C.C.C.....CC.C..\n.CC.C...C.CCC.C....CC\n...C..CCCC.CCC....C..",
"output": "2103"
},
{
"input": "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n...C.C.CC..CC..CC...\nC...CC.C.CCCCC....CC\n.CC.C.CCC....C.CCC.C\nCC...CC...CC..CC...C\nC.C..CC.C.CCCC.C.CC.\n..CCCCC.C.CCC..CCCC.\n....C..C..C.CC...C.C\nC..CCC..CC..C.CC..CC\n...CC......C.C..C.C.\nCC.CCCCC.CC.CC...C.C\n.C.CC..CC..CCC.C.CCC\nC..C.CC....C....C...\n..CCC..CCC...CC..C.C\n.C.CCC.CCCCCCCCC..CC",
"output": "2071"
},
{
"input": "17\nCCC..C.C....C.C.C\n.C.CC.CC...CC..C.\n.CCCC.CC.C..CCC.C\n...CCC.CC.CCC.C.C\nCCCCCCCC..C.CC.CC\n...C..C....C.CC.C\nCC....CCC...C.CC.\n.CC.C.CC..C......\n.CCCCC.C.CC.CCCCC\n..CCCC...C..CC..C\nC.CC.C.CC..C.C.C.\nC..C..C..CCC.C...\n.C..CCCC..C......\n.CC.C...C..CC.CC.\nC..C....CC...CC..\nC.CC.CC..C.C..C..\nCCCC...C.C..CCCC.",
"output": "1160"
},
{
"input": "15\nCCCC.C..CCC....\nCCCCCC.CC.....C\n...C.CC.C.C.CC.\nCCCCCCC..C..C..\nC..CCC..C.CCCC.\n.CC..C.C.C.CC.C\n.C.C..C..C.C..C\n...C...C..CCCC.\n.....C.C..CC...\nCC.C.C..CC.C..C\n..CCCCC..CCC...\nCC.CC.C..CC.CCC\n..CCC...CC.C..C\nCC..C.C..CCC..C\n.C.C....CCC...C",
"output": "789"
},
{
"input": "1\n.",
"output": "0"
},
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "13\nC.C...C.C.C..\nCC.CCCC.CC..C\n.C.CCCCC.CC..\nCCCC..C...C..\n...CC.C.C...C\n.CC.CCC...CC.\nCC.CCCCCC....\n.C...C..CC..C\nCCCC.CC...C..\n.C.CCC..C.CC.\n..C...CC..C.C\n..C.CCC..CC.C\n.C...CCC.CC.C",
"output": "529"
},
{
"input": "16\n.C.C.C.C.C...C.C\n..C..C.CCCCCC...\n..C.C.C.C..C..C.\n.CC....C.CCC..C.\n.C.CCC..C....CCC\nCC..C.CC..C.C.CC\n...C..C..CC..CC.\n.CCC..C.CC.C.C..\n.CC.C..........C\nC...C....CC..C..\nC.CCC.C..C..C...\n.CCCCCCCCCCCC..C\n..C.C.CC.CC.CCC.\nCC..C.C....C..CC\nC.CCC..C..C.C.CC\n.C.CCC.CC..CCC.C",
"output": "874"
},
{
"input": "2\nCC\nCC",
"output": "4"
},
{
"input": "3\nC..\nC..\nC..",
"output": "3"
}
] | 1,699,990,905
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 48
| 46
| 0
|
n = int(input())
rowCounts = [0] * n
colCounts = [0] * n
for i in range(n):
cakeRow = input()
for j in range(n):
if cakeRow[j] == 'C':
rowCounts[i] += 1
colCounts[j] += 1
totalHappiness = 0
for i in range(n):
totalHappiness += (rowCounts[i] - 1) * rowCounts[i] // 2
totalHappiness += (colCounts[i] - 1) * colCounts[i] // 2
print(totalHappiness)
|
Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?
Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.
Input Specification:
In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.
Output Specification:
Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.
Demo Input:
['3\n.CC\nC..\nC.C\n', '4\nCC..\nC..C\n.CC.\n.CC.\n']
Demo Output:
['4\n', '9\n']
Note:
If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3)
|
```python
n = int(input())
rowCounts = [0] * n
colCounts = [0] * n
for i in range(n):
cakeRow = input()
for j in range(n):
if cakeRow[j] == 'C':
rowCounts[i] += 1
colCounts[j] += 1
totalHappiness = 0
for i in range(n):
totalHappiness += (rowCounts[i] - 1) * rowCounts[i] // 2
totalHappiness += (colCounts[i] - 1) * colCounts[i] // 2
print(totalHappiness)
```
| 3
|
|
462
|
B
|
Appleman and Card Game
|
PROGRAMMING
| 1,300
|
[
"greedy"
] | null | null |
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
|
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
|
Print a single integer – the answer to the problem.
|
[
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] |
[
"82\n",
"4\n"
] |
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
| 1,000
|
[
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output": "2"
},
{
"input": "5 1\nFACJT",
"output": "1"
},
{
"input": "5 5\nMJDIJ",
"output": "7"
},
{
"input": "15 5\nAZBIPTOFTJCJJIK",
"output": "13"
},
{
"input": "100 1\nEVEEVEEEGGECFEHEFVFVFHVHEEEEEFCVEEEEEEVFVEEVEEHEEVEFEVVEFEEEFEVECEHGHEEFGEEVCEECCECEFHEVEEEEEEGEEHVH",
"output": "1"
},
{
"input": "100 15\nKKTFFUTFCKUIKKKKFIFFKTUKUUKUKKIKKKTIFKTKUCFFKKKIIKKKKKKTFKFKKIRKKKFKUUKIKUUUFFKKKKTUZKITUIKKIKUKKTIK",
"output": "225"
},
{
"input": "100 50\nYYIYYAAAIEAAYAYAEAIIIAAEAAYEAEYYYIAEYAYAYYAAAIAYAEAAYAYYIYAAYYAAAAAAIYYYAAYAAEAAYAIEIYIYAYAYAYIIAAEY",
"output": "1972"
},
{
"input": "100 90\nFAFAOOAOOAFAOTFAFAFFATAAAOFAAOAFBAAAFBOAOFFFOAOAFAPFOFAOFAAFOAAAAFAAFOFAAOFPPAAOOAAOOFFOFFFOFAOTOFAF",
"output": "2828"
},
{
"input": "100 99\nBFFBBFBFBQFFFFFQBFFBFFBQFBFQFBBFQFFFBFFFBFQFQFBFFBBFYQFBFFFFFFFBQQFQBFBQBQFFFBQQFFFBQFYFBFBFFFBBBQQY",
"output": "3713"
},
{
"input": "100 100\nMQSBDAJABILIBCUEOWGWCEXMUTEYQKAIWGINXVQEOFDUBSVULROQHQRZZAALVQFEFRAAAYUIMGCAFQGIAEFBETRECGSFQJNXHHDN",
"output": "514"
},
{
"input": "100 50\nBMYIXQSJNHGFVFPJBIOBXIKSFNUFPVODCUBQYSIIQNVNXXCWXWRHKFEUPPIIDDGRDBJLZDCBMNJMYRMWFIHOSTDJJHXHPNRKWNFD",
"output": "328"
},
{
"input": "100 50\nENFNEMLJEMDMFMNNGNIMNINALGLLLAEMENEMNLMMIEIJNAINBJEJMFJLLIMINELGFLAIAMJMHMGNLIEFJIEEFEFGLLLDLMEAEIMM",
"output": "748"
}
] | 1,589,812,883
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 41
| 155
| 20,684,800
|
n,k=map(int,input().split())
s=input()
lst=list()
c=str.count
ind="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in ind:
if(c(s,i)!=0):
lst.append(c(s,i))
lst.sort()
lst.reverse()
ans=0
for i in lst:
ans+=min(k,i)**2
k=k-min(k,i)
if(k==0):break
print(ans)
|
Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to letter on *i*th, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman.
Output Specification:
Print a single integer – the answer to the problem.
Demo Input:
['15 10\nDZFDFZDFDDDDDDF\n', '6 4\nYJSNPI\n']
Demo Output:
['82\n', '4\n']
Note:
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
|
```python
n,k=map(int,input().split())
s=input()
lst=list()
c=str.count
ind="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in ind:
if(c(s,i)!=0):
lst.append(c(s,i))
lst.sort()
lst.reverse()
ans=0
for i in lst:
ans+=min(k,i)**2
k=k-min(k,i)
if(k==0):break
print(ans)
```
| 3
|
|
118
|
A
|
String Task
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] | null | null |
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
|
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
|
Print the resulting string. It is guaranteed that this string is not empty.
|
[
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] |
[
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] |
none
| 500
|
[
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": ".g.g.d.v.q"
},
{
"input": "pumesz",
"output": ".p.m.s.z"
},
{
"input": "g",
"output": ".g"
},
{
"input": "zjuotps",
"output": ".z.j.t.p.s"
},
{
"input": "jzbwuehe",
"output": ".j.z.b.w.h"
},
{
"input": "tnkgwuugu",
"output": ".t.n.k.g.w.g"
},
{
"input": "kincenvizh",
"output": ".k.n.c.n.v.z.h"
},
{
"input": "xattxjenual",
"output": ".x.t.t.x.j.n.l"
},
{
"input": "ktajqhpqsvhw",
"output": ".k.t.j.q.h.p.q.s.v.h.w"
},
{
"input": "xnhcigytnqcmy",
"output": ".x.n.h.c.g.t.n.q.c.m"
},
{
"input": "jfmtbejyilxcec",
"output": ".j.f.m.t.b.j.l.x.c.c"
},
{
"input": "D",
"output": ".d"
},
{
"input": "ab",
"output": ".b"
},
{
"input": "Ab",
"output": ".b"
},
{
"input": "aB",
"output": ".b"
},
{
"input": "AB",
"output": ".b"
},
{
"input": "ba",
"output": ".b"
},
{
"input": "bA",
"output": ".b"
},
{
"input": "Ba",
"output": ".b"
},
{
"input": "BA",
"output": ".b"
},
{
"input": "aab",
"output": ".b"
},
{
"input": "baa",
"output": ".b"
},
{
"input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM",
"output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m"
},
{
"input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN",
"output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n"
},
{
"input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ",
"output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j"
},
{
"input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea",
"output": ".w.z.t.c.v.v.v.v.z.v"
},
{
"input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl",
"output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l"
},
{
"input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg",
"output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g"
},
{
"input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ",
"output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q"
},
{
"input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg",
"output": ".l.t.g.m.g"
},
{
"input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy",
"output": ".k.z.d.x.f"
},
{
"input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ",
"output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q"
},
{
"input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY",
"output": ".m.r.c.g.p"
},
{
"input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx",
"output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x"
},
{
"input": "YB",
"output": ".b"
},
{
"input": "fly",
"output": ".f.l"
},
{
"input": "YyyYYYyyYxdwdawdDAWDdaddYYYY",
"output": ".x.d.w.d.w.d.d.w.d.d.d.d"
}
] | 1,694,791,260
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 42
| 92
| 0
|
s = input().lower()
repl = ["A", "O", "Y", "E", "U", "I",'a','o','y','e','u','i']
ls = []
for i in s:
if i not in repl:
ls.append(f'.{i}')
print(''.join(ls))
|
Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
Input Specification:
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Output Specification:
Print the resulting string. It is guaranteed that this string is not empty.
Demo Input:
['tour\n', 'Codeforces\n', 'aBAcAba\n']
Demo Output:
['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n']
Note:
none
|
```python
s = input().lower()
repl = ["A", "O", "Y", "E", "U", "I",'a','o','y','e','u','i']
ls = []
for i in s:
if i not in repl:
ls.append(f'.{i}')
print(''.join(ls))
```
| 3
|
|
59
|
A
|
Word
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] |
A. Word
|
2
|
256
|
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
|
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
|
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
|
[
"HoUse\n",
"ViP\n",
"maTRIx\n"
] |
[
"house\n",
"VIP\n",
"matrix\n"
] |
none
| 500
|
[
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,616,088,401
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 2
| 124
| 0
|
n = input()
c = 0; k = 0
for i in list(n):
if i.isupper():
c += 1
else: k += 1
if c >= k:
print(n.upper())
else: print(n.lower())
|
Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none
|
```python
n = input()
c = 0; k = 0
for i in list(n):
if i.isupper():
c += 1
else: k += 1
if c >= k:
print(n.upper())
else: print(n.lower())
```
| 0
|
501
|
B
|
Misha and Changing Handles
|
PROGRAMMING
| 1,100
|
[
"data structures",
"dsu",
"strings"
] | null | null |
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
|
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
|
In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
|
[
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] |
[
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] |
none
| 500
|
[
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k",
"output": "1\na k"
},
{
"input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha",
"output": "2\n123abc 1A2B3C\n1 Misha"
},
{
"input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e",
"output": "3\nM G\n1 R\nS e"
},
{
"input": "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV",
"output": "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV"
},
{
"input": "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSEj 2knOMLyzr\n0v69ijnAc S7d7zGTjmlku01Gv\n2knOMLyzr otGmEd\nacwr3TfMV7oCIp RUSVFa9TIWlLsd7SB\nS7d7zGTjmlku01Gv Gd6ZufVmQnBpi\nS1 WOJLpk\nWOJLpk Gu\nRUSVFa9TIWlLsd7SB RFawatGnbVB\notGmEd OTB1zKiOI",
"output": "5\n0v69ijnAc Gd6ZufVmQnBpi\nS1 Gu\nSEj OTB1zKiOI\nacwr3TfMV7oCIp RFawatGnbVB\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9"
},
{
"input": "14\nTPdoztSZROpjZe z6F8bYFvnER4V5SP0n\n8Aa3PQY3hzHZTPEUz fhrZZPJ3iUS\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nAO s1VGWTCbHzM\ni 4F\nfhrZZPJ3iUS j0OVZQF6MvNcKN9xDZFJ\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\nj0OVZQF6MvNcKN9xDZFJ DzjmeNqN0H4Teq0Awr\n4F wJcdxt1kwqfDeJ\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nJ0Usg DKdKMFJ6tK8XA\nz6F8bYFvnER4V5SP0n 0alJ\nMijh2O6 qic8kXWuR6",
"output": "10\nTPdoztSZROpjZe 0alJ\nJ0Usg DKdKMFJ6tK8XA\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\n8Aa3PQY3hzHZTPEUz DzjmeNqN0H4Teq0Awr\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nMijh2O6 qic8kXWuR6\nAO s1VGWTCbHzM\ni wJcdxt1kwqfDeJ"
},
{
"input": "14\nHAXRxayyf1Dj1F0mT hjR4A8IQMb0nyBtqG\nWNuMJa5Jg05qkqZOrL noNkWXrSidHGwxgbQ\nmOitVy6W52s0FENMz6 oLUkLNfojssvLvb1t\nhjR4A8IQMb0nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ",
"output": "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ"
}
] | 1,494,839,651
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 0
| 1,000
| 0
|
n=10000000
k=0
for i in range(n) :
k=k+1
|
Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
Input Specification:
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
Output Specification:
In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
Demo Input:
['5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n']
Demo Output:
['3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n']
Note:
none
|
```python
n=10000000
k=0
for i in range(n) :
k=k+1
```
| 0
|
|
711
|
A
|
Bus to Udayland
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation"
] | null | null |
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
|
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
|
[
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] |
[
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] |
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
| 500
|
[
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,659,370,133
| 2,147,483,647
|
PyPy 3-64
|
WRONG_ANSWER
|
TESTS
| 4
| 46
| 0
|
def check(row):
if row.find('OO') != -1:
return [row.find('OO'),'YES']
return ['NO']
rows_num = int(input())
rows = []
for i in range(rows_num):
rows.append(input())
confirm = False
for row in rows:
if len(check(row))==2:
valid_row = rows.index(row)
print('YES')
for i in range(rows_num):
if i==valid_row:
print(rows[i].replace('OO','++'))
else:
print(rows[i])
confirm = True
break
if confirm==False:
print("NO")
|
Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
|
```python
def check(row):
if row.find('OO') != -1:
return [row.find('OO'),'YES']
return ['NO']
rows_num = int(input())
rows = []
for i in range(rows_num):
rows.append(input())
confirm = False
for row in rows:
if len(check(row))==2:
valid_row = rows.index(row)
print('YES')
for i in range(rows_num):
if i==valid_row:
print(rows[i].replace('OO','++'))
else:
print(rows[i])
confirm = True
break
if confirm==False:
print("NO")
```
| 0
|
|
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,643,685,120
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
t, s = map(str, input())
if s == t[::-1]
print("YES")
else:
print("NO")
|
Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none
|
```python
t, s = map(str, input())
if s == t[::-1]
print("YES")
else:
print("NO")
```
| -1
|
879
|
B
|
Table Tennis
|
PROGRAMMING
| 1,200
|
[
"data structures",
"implementation"
] | null | null |
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
|
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
|
Output a single integer — power of the winner.
|
[
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] |
[
"2 ",
"3 ",
"6 ",
"2\n"
] |
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
| 1,000
|
[
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 2147483648\n2 1",
"output": "2"
},
{
"input": "3 2\n1 3 2",
"output": "3 "
},
{
"input": "3 3\n1 2 3",
"output": "3 "
},
{
"input": "5 2\n2 1 3 4 5",
"output": "5 "
},
{
"input": "10 2\n7 10 5 8 9 3 4 6 1 2",
"output": "10 "
},
{
"input": "100 2\n62 70 29 14 12 87 94 78 39 92 84 91 61 49 60 33 69 37 19 82 42 8 45 97 81 43 54 67 1 22 77 58 65 17 18 28 25 57 16 90 40 13 4 21 68 35 15 76 73 93 56 95 79 47 74 75 30 71 66 99 41 24 88 83 5 6 31 96 38 80 27 46 51 53 2 86 32 9 20 100 26 36 63 7 52 55 23 3 50 59 48 89 85 44 34 64 10 72 11 98",
"output": "70 "
},
{
"input": "4 10\n2 1 3 4",
"output": "4"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "10 "
},
{
"input": "10 2\n10 9 8 7 6 5 4 3 2 1",
"output": "10 "
},
{
"input": "4 1000000000000\n3 4 1 2",
"output": "4"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "91 "
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "100 "
},
{
"input": "2 1000000000000\n1 2",
"output": "2"
},
{
"input": "5 2\n1 4 3 5 2",
"output": "4 "
},
{
"input": "5 2\n1 3 2 4 5",
"output": "3 "
},
{
"input": "4 1000000000000\n3 1 2 4",
"output": "4"
},
{
"input": "4 2\n1 3 2 4",
"output": "3 "
},
{
"input": "10 3\n8 1 9 2 3 10 4 5 6 7",
"output": "9 "
},
{
"input": "5 2\n2 1 4 3 5",
"output": "4 "
},
{
"input": "3 4294967297\n2 1 3",
"output": "3"
},
{
"input": "4 4294967297\n3 2 1 4",
"output": "4"
},
{
"input": "5 4294967298\n3 2 1 4 5",
"output": "5"
},
{
"input": "10 4\n5 4 7 1 2 9 3 6 8 10",
"output": "9 "
},
{
"input": "11 21474836489\n10 1 2 3 4 5 6 7 8 9 11",
"output": "11"
}
] | 1,624,136,145
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 11
| 61
| 0
|
n,m=map(int,input().split())
k=list(map(int,input().split()))
p=0
o=0
if m>300000:
print(max(k))
else:
while p<=m or o<=m:
if k[0]>k[1]:
o=0
p+=1
k.append(k[1])
k.remove(k[1])
if p==m:
print(k[0])
break
elif k[1]>k[0]:
p=0
o+=1
k.append(k[0])
k.remove(k[0])
if o==m:
print(k[1])
break
|
Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
Input Specification:
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
Output Specification:
Output a single integer — power of the winner.
Demo Input:
['2 2\n1 2\n', '4 2\n3 1 2 4\n', '6 2\n6 5 3 1 2 4\n', '2 10000000000\n2 1\n']
Demo Output:
['2 ', '3 ', '6 ', '2\n']
Note:
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
|
```python
n,m=map(int,input().split())
k=list(map(int,input().split()))
p=0
o=0
if m>300000:
print(max(k))
else:
while p<=m or o<=m:
if k[0]>k[1]:
o=0
p+=1
k.append(k[1])
k.remove(k[1])
if p==m:
print(k[0])
break
elif k[1]>k[0]:
p=0
o+=1
k.append(k[0])
k.remove(k[0])
if o==m:
print(k[1])
break
```
| 0
|
|
706
|
B
|
Interesting drink
|
PROGRAMMING
| 1,100
|
[
"binary search",
"dp",
"implementation"
] | null | null |
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
|
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
|
[
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] |
[
"0\n4\n1\n5\n"
] |
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
| 1,000
|
[
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "0\n0\n3\n3\n3\n0\n3"
},
{
"input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969",
"output": "1\n1\n0\n1\n1\n1\n0\n1\n1"
},
{
"input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192",
"output": "4\n4\n4\n4"
},
{
"input": "1\n1\n1\n1000000000",
"output": "1"
},
{
"input": "1\n1\n1\n100005",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100005",
"output": "3"
},
{
"input": "2\n1 2\n3\n100004\n100005\n100006",
"output": "2\n2\n2"
},
{
"input": "3\n1 1 1\n1\n1",
"output": "3"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100000",
"output": "3"
},
{
"input": "5\n1 1 1 1 10\n2\n1\n10",
"output": "4\n5"
},
{
"input": "5\n3 10 8 6 11\n1\n10000000",
"output": "5"
}
] | 1,696,751,444
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 103
| 1,107
| 13,619,200
|
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for _ in range(int(input())):
c = int(input())
low, high = 0, n - 1
ans = -1
while low <= high:
mid = (low + high) // 2
if arr[mid] > c:
ans = mid
high = mid - 1
else:
low = mid + 1
print(ans if ans != -1 else n)
|
Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Output Specification:
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
Demo Input:
['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n']
Demo Output:
['0\n4\n1\n5\n']
Note:
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
|
```python
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for _ in range(int(input())):
c = int(input())
low, high = 0, n - 1
ans = -1
while low <= high:
mid = (low + high) // 2
if arr[mid] > c:
ans = mid
high = mid - 1
else:
low = mid + 1
print(ans if ans != -1 else n)
```
| 3
|
|
118
|
A
|
String Task
|
PROGRAMMING
| 1,000
|
[
"implementation",
"strings"
] | null | null |
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
|
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
|
Print the resulting string. It is guaranteed that this string is not empty.
|
[
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] |
[
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] |
none
| 500
|
[
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": ".g.g.d.v.q"
},
{
"input": "pumesz",
"output": ".p.m.s.z"
},
{
"input": "g",
"output": ".g"
},
{
"input": "zjuotps",
"output": ".z.j.t.p.s"
},
{
"input": "jzbwuehe",
"output": ".j.z.b.w.h"
},
{
"input": "tnkgwuugu",
"output": ".t.n.k.g.w.g"
},
{
"input": "kincenvizh",
"output": ".k.n.c.n.v.z.h"
},
{
"input": "xattxjenual",
"output": ".x.t.t.x.j.n.l"
},
{
"input": "ktajqhpqsvhw",
"output": ".k.t.j.q.h.p.q.s.v.h.w"
},
{
"input": "xnhcigytnqcmy",
"output": ".x.n.h.c.g.t.n.q.c.m"
},
{
"input": "jfmtbejyilxcec",
"output": ".j.f.m.t.b.j.l.x.c.c"
},
{
"input": "D",
"output": ".d"
},
{
"input": "ab",
"output": ".b"
},
{
"input": "Ab",
"output": ".b"
},
{
"input": "aB",
"output": ".b"
},
{
"input": "AB",
"output": ".b"
},
{
"input": "ba",
"output": ".b"
},
{
"input": "bA",
"output": ".b"
},
{
"input": "Ba",
"output": ".b"
},
{
"input": "BA",
"output": ".b"
},
{
"input": "aab",
"output": ".b"
},
{
"input": "baa",
"output": ".b"
},
{
"input": "femOZeCArKCpUiHYnbBPTIOFmsHmcpObtPYcLCdjFrUMIyqYzAokKUiiKZRouZiNMoiOuGVoQzaaCAOkquRjmmKKElLNqCnhGdQM",
"output": ".f.m.z.c.r.k.c.p.h.n.b.b.p.t.f.m.s.h.m.c.p.b.t.p.c.l.c.d.j.f.r.m.q.z.k.k.k.z.r.z.n.m.g.v.q.z.c.k.q.r.j.m.m.k.k.l.l.n.q.c.n.h.g.d.q.m"
},
{
"input": "VMBPMCmMDCLFELLIISUJDWQRXYRDGKMXJXJHXVZADRZWVWJRKFRRNSAWKKDPZZLFLNSGUNIVJFBEQsMDHSBJVDTOCSCgZWWKvZZN",
"output": ".v.m.b.p.m.c.m.m.d.c.l.f.l.l.s.j.d.w.q.r.x.r.d.g.k.m.x.j.x.j.h.x.v.z.d.r.z.w.v.w.j.r.k.f.r.r.n.s.w.k.k.d.p.z.z.l.f.l.n.s.g.n.v.j.f.b.q.s.m.d.h.s.b.j.v.d.t.c.s.c.g.z.w.w.k.v.z.z.n"
},
{
"input": "MCGFQQJNUKuAEXrLXibVjClSHjSxmlkQGTKZrRaDNDomIPOmtSgjJAjNVIVLeUGUAOHNkCBwNObVCHOWvNkLFQQbFnugYVMkJruJ",
"output": ".m.c.g.f.q.q.j.n.k.x.r.l.x.b.v.j.c.l.s.h.j.s.x.m.l.k.q.g.t.k.z.r.r.d.n.d.m.p.m.t.s.g.j.j.j.n.v.v.l.g.h.n.k.c.b.w.n.b.v.c.h.w.v.n.k.l.f.q.q.b.f.n.g.v.m.k.j.r.j"
},
{
"input": "iyaiuiwioOyzUaOtAeuEYcevvUyveuyioeeueoeiaoeiavizeeoeyYYaaAOuouueaUioueauayoiuuyiuovyOyiyoyioaoyuoyea",
"output": ".w.z.t.c.v.v.v.v.z.v"
},
{
"input": "yjnckpfyLtzwjsgpcrgCfpljnjwqzgVcufnOvhxplvflxJzqxnhrwgfJmPzifgubvspffmqrwbzivatlmdiBaddiaktdsfPwsevl",
"output": ".j.n.c.k.p.f.l.t.z.w.j.s.g.p.c.r.g.c.f.p.l.j.n.j.w.q.z.g.v.c.f.n.v.h.x.p.l.v.f.l.x.j.z.q.x.n.h.r.w.g.f.j.m.p.z.f.g.b.v.s.p.f.f.m.q.r.w.b.z.v.t.l.m.d.b.d.d.k.t.d.s.f.p.w.s.v.l"
},
{
"input": "RIIIUaAIYJOiuYIUWFPOOAIuaUEZeIooyUEUEAoIyIHYOEAlVAAIiLUAUAeiUIEiUMuuOiAgEUOIAoOUYYEYFEoOIIVeOOAOIIEg",
"output": ".r.j.w.f.p.z.h.l.v.l.m.g.f.v.g"
},
{
"input": "VBKQCFBMQHDMGNSGBQVJTGQCNHHRJMNKGKDPPSQRRVQTZNKBZGSXBPBRXPMVFTXCHZMSJVBRNFNTHBHGJLMDZJSVPZZBCCZNVLMQ",
"output": ".v.b.k.q.c.f.b.m.q.h.d.m.g.n.s.g.b.q.v.j.t.g.q.c.n.h.h.r.j.m.n.k.g.k.d.p.p.s.q.r.r.v.q.t.z.n.k.b.z.g.s.x.b.p.b.r.x.p.m.v.f.t.x.c.h.z.m.s.j.v.b.r.n.f.n.t.h.b.h.g.j.l.m.d.z.j.s.v.p.z.z.b.c.c.z.n.v.l.m.q"
},
{
"input": "iioyoaayeuyoolyiyoeuouiayiiuyTueyiaoiueyioiouyuauouayyiaeoeiiigmioiououeieeeyuyyaYyioiiooaiuouyoeoeg",
"output": ".l.t.g.m.g"
},
{
"input": "ueyiuiauuyyeueykeioouiiauzoyoeyeuyiaoaiiaaoaueyaeydaoauexuueafouiyioueeaaeyoeuaueiyiuiaeeayaioeouiuy",
"output": ".k.z.d.x.f"
},
{
"input": "FSNRBXLFQHZXGVMKLQDVHWLDSLKGKFMDRQWMWSSKPKKQBNDZRSCBLRSKCKKFFKRDMZFZGCNSMXNPMZVDLKXGNXGZQCLRTTDXLMXQ",
"output": ".f.s.n.r.b.x.l.f.q.h.z.x.g.v.m.k.l.q.d.v.h.w.l.d.s.l.k.g.k.f.m.d.r.q.w.m.w.s.s.k.p.k.k.q.b.n.d.z.r.s.c.b.l.r.s.k.c.k.k.f.f.k.r.d.m.z.f.z.g.c.n.s.m.x.n.p.m.z.v.d.l.k.x.g.n.x.g.z.q.c.l.r.t.t.d.x.l.m.x.q"
},
{
"input": "EYAYAYIOIOYOOAUOEUEUOUUYIYUUMOEOIIIAOIUOAAOIYOIOEUIERCEYYAOIOIGYUIAOYUEOEUAEAYPOYEYUUAUOAOEIYIEYUEEY",
"output": ".m.r.c.g.p"
},
{
"input": "jvvzcdcxjstbbksmqjsngxkgtttdxrljjxtwptgwwqzpvqchvgrkqlzxmptzblxhhsmrkmzzmgdfskhtmmnqzzflpmqdctvrfgtx",
"output": ".j.v.v.z.c.d.c.x.j.s.t.b.b.k.s.m.q.j.s.n.g.x.k.g.t.t.t.d.x.r.l.j.j.x.t.w.p.t.g.w.w.q.z.p.v.q.c.h.v.g.r.k.q.l.z.x.m.p.t.z.b.l.x.h.h.s.m.r.k.m.z.z.m.g.d.f.s.k.h.t.m.m.n.q.z.z.f.l.p.m.q.d.c.t.v.r.f.g.t.x"
},
{
"input": "YB",
"output": ".b"
},
{
"input": "fly",
"output": ".f.l"
},
{
"input": "YyyYYYyyYxdwdawdDAWDdaddYYYY",
"output": ".x.d.w.d.w.d.d.w.d.d.d.d"
}
] | 1,694,632,628
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 42
| 124
| 0
|
def chc(st):
nst = ''
for i in st.lower():
if i not in 'aoyeui':
nst += '.'+i
return nst
st = input()
print(chc(st))
|
Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces all uppercase consonants with corresponding lowercase ones.
Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
Help Petya cope with this easy task.
Input Specification:
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Output Specification:
Print the resulting string. It is guaranteed that this string is not empty.
Demo Input:
['tour\n', 'Codeforces\n', 'aBAcAba\n']
Demo Output:
['.t.r\n', '.c.d.f.r.c.s\n', '.b.c.b\n']
Note:
none
|
```python
def chc(st):
nst = ''
for i in st.lower():
if i not in 'aoyeui':
nst += '.'+i
return nst
st = input()
print(chc(st))
```
| 3
|
|
58
|
A
|
Chat room
|
PROGRAMMING
| 1,000
|
[
"greedy",
"strings"
] |
A. Chat room
|
1
|
256
|
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
|
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
|
If Vasya managed to say hello, print "YES", otherwise print "NO".
|
[
"ahhellllloou\n",
"hlelo\n"
] |
[
"YES\n",
"NO\n"
] |
none
| 500
|
[
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,518,367,393
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
salem=input()
h=0
e=0
l1=0
l2=0
o=0
truwer=0
for i in range(0,len(salem)):
if h==0&&salem[i]=='h'
h=1
if h==1&&salem[i]=='e'
e=1
h=-3
if e==1&&salem[i]=='l'
l1=1
e=0
if l1==1&&salem[i]=='l'
l2=1
l1=0
if l2==1&&salem[i]=='o'
o=1
truwer=5
break;
if truwer == 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
salem=input()
h=0
e=0
l1=0
l2=0
o=0
truwer=0
for i in range(0,len(salem)):
if h==0&&salem[i]=='h'
h=1
if h==1&&salem[i]=='e'
e=1
h=-3
if e==1&&salem[i]=='l'
l1=1
e=0
if l1==1&&salem[i]=='l'
l2=1
l1=0
if l2==1&&salem[i]=='o'
o=1
truwer=5
break;
if truwer == 5:
print('YES')
else:
print('NO')
```
| -1
|
761
|
C
|
Dasha and Password
|
PROGRAMMING
| 1,500
|
[
"brute force",
"dp",
"implementation"
] | null | null |
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements:
- There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - There is at least one of three listed symbols in the string: '#', '*', '&'.
Considering that these are programming classes it is not easy to write the password.
For each character of the password we have a fixed string of length *m*, on each of these *n* strings there is a pointer on some character. The *i*-th character displayed on the screen is the pointed character in the *i*-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).
During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index *m*, and when we move it to the right from the position *m* it moves to the position 1.
You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.
|
The first line contains two integers *n*, *m* (3<=≤<=*n*<=≤<=50,<=1<=≤<=*m*<=≤<=50) — the length of the password and the length of strings which are assigned to password symbols.
Each of the next *n* lines contains the string which is assigned to the *i*-th symbol of the password string. Its length is *m*, it consists of digits, lowercase English letters, and characters '#', '*' or '&'.
You have such input data that you can always get a valid password.
|
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
|
[
"3 4\n1**2\na3*0\nc4**\n",
"5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&\n"
] |
[
"1\n",
"3\n"
] |
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.
In the second test one of possible algorithms will be:
- to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
| 1,500
|
[
{
"input": "3 4\n1**2\na3*0\nc4**",
"output": "1"
},
{
"input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&",
"output": "3"
},
{
"input": "5 2\n&l\n*0\n*9\n*#\n#o",
"output": "2"
},
{
"input": "25 16\nvza**ooxkmd#*ywa\ndip#*#&ef&z&&&pv\nwggob&&72#*&&nku\nrsb##*&jm&#u**te\nzif#lu#t&2w#jbqb\nwfo&#&***0xp#&hp\njbw##h*###nkmkdn\nqrn*&y#3cnf&d*rc\nend*zg&0f*&g*&ak\niayh&r#8om#o**yq\nwym&e&*v0j&#zono\ntzu*vj&i18iew&ht\nhpfnceb193&#&acf\ngesvq&l&*&m*l*ru\nfot#u&pq&0y&s*pg\nqdfgs&hk*wob&&bw\nbqd&&&lnv&&ax&ql\nell#&t&k*p#n*rlg\nclfou#ap#*vxulmt\nfhp*gax&s1&pinql\nyihmh*yy&2&#&prc\nrmv**#h*bxyf&&eq\nziu##ku#f#uh*fek\nhmg&&cvx0p*#odgw\nquu&csv*aph#dkiq",
"output": "10"
},
{
"input": "3 5\n*****\n1***a\n**a**",
"output": "2"
},
{
"input": "5 2\n&e\n#j\n&&\n*2\n94",
"output": "1"
},
{
"input": "5 2\ns*\nsq\n*v\nes\n*5",
"output": "1"
},
{
"input": "10 2\n0n\n5h\n7&\n1b\n5&\n4*\n9k\n0*\n7m\n62",
"output": "2"
},
{
"input": "10 2\n89\n7&\ns8\now\n2#\n5&\nu&\n89\n8#\n3u",
"output": "1"
},
{
"input": "10 2\n#y\njc\n#6\n#0\nt7\ns7\nd#\nn2\n#7\n&3",
"output": "1"
},
{
"input": "15 12\n502j2*su#*j4\n48vtw8#r5\n43wl0085#&64\n99pedbk#*ol2\n08w#h#&y1346\n259*874&b*76\n40l#5hc*qta4\n280#h#r*3k98\n20t8o&l1##55\n8048l#6&o*37\n01a3z0179#30\n65p28q#0*3j3\n51tx885#**56\n105&&f64n639\n40v3&l61yr65",
"output": "5"
},
{
"input": "15 12\ndcmzv&*zzflc\neftqm&**njyp\ntwlsi*jvuman\ngcxdlb#xwbul\nnpgvufdyqoaz\nxvvpk##&bpso\njlwcfb&kqlbu\nnpxxr#1augfd\nngnaph#erxpl\nlsfaoc*ulsbi\npffbe&6lrybj\nsuvpz#q&aahf\nizhoba**jjmc\nmkdtg#6*xtnp\nqqfpjo1gddqo",
"output": "11"
},
{
"input": "15 12\n#&*&s#&&9&&&\n*&##*4&le&*#\n#*##24qh3*#&\n&***2j&a2###\n#*&#n68*z###\n##**1#&w#**&\n*&*#*0#&#***\n#*#*2723&*##\n&#&&mg3iu##*\n*&&#zl4k#&*&\n##&*5g#01&&*\n*##&wg1#6&*#\n#&**pvr6*&&#\n&&#*mzd#5&*#\n###*e2684#**",
"output": "8"
},
{
"input": "20 13\n885**jh##mj0t\nky3h&h&clr#27\nq6n&v127i64xo\n3lz4du4zi5&z9\n0r7056qp8r*5a\nc8v94v#402l7n\nu968vxt9&2fkn\n2jl4m**o6412n\nh10v&vl*#4&h4\nj4864*##48*9d\n402i&3#x&o786\nzn8#w&*p#8&6l\n2e7&68p#&kc47\njf4e7fv&o0*3z\n0z67ocr7#5*79\nr8az68#&u&5a9\n65a#&9#*8o178\nqjevs&&muj893\n4c83i63j##m37\ng1g85c##f7y3f",
"output": "3"
},
{
"input": "20 13\nvpym*054*4hoi\nldg&1u*yu4inw\nvs#b7*s27iqgo\nfp&*s2g#1i&#k\nyp&v474*58*#w\nzwfxx***4hqdg\nqqv*3163r2*&l\naxdc4l7&5l#fj\nqq&h#1z*&5#*a\nyml&&&9#a2*pr\nmpn&&78rbthpb\nac#d50**b7t#o\ndk&z7q&z&&#&j\ngyh#&f#0q5#&x\ncxw*#hgm#9nqn\nqm#&*c*k&2&bz\nxc#&86o#d9g#w\nzjm&12&9x3#hp\nzy&s##47u1jyf\nub*&9ao5qy#ip",
"output": "6"
},
{
"input": "20 13\n*8002g&87&8&6\n&4n*51i4&0\n40*#iq3pnc&87\n#*&0*s458&475\n802*8&1z*g533\n7171&a&2&2*8*\n*&##&&&&&t**&\n3#&*7#80*m18#\n#4#cqt9*7\n6*#56*#*&762&\n9406&ge0&7&07\n9**&6lv*v*2&&\n9##&c&i&z13#*\n68#*4g*9&f4&1\n37##80#&f2*&2\n81##*xo#q#5&0\n5247#hqy&d9&2\n#*13*5477*9#*\n2*&#q*0*fb9#*\n&2&4v*2##&&32",
"output": "4"
},
{
"input": "25 16\n5v7dnmg1##qqa75*\n0187oa*&c&&ew9h*\nr70*&##*q#4i6*&#\n7*wk*&4v06col***\n28*0h94x**&21*f5\neh5vbt#8&8#8#3r&\np*01u&&90&08p*#*\nb9#e7&r8lc56b*##\nyb4&x#&4956iw&8*\n39&5#4d5#&3r8t5x\n7x13**kk#0n**&80\n4oux8yhz*pg84nnr\nb2yfb&b70xa&k56e\nqt5&q4&6#&*z5#3&\n5*#*086*51l&&44#\n84k5**0lij37j#&v\ns&j0m4j&2v3fv9h&\np&hu68704*&cufs#\n34ra*i1993*i*&55\nr#w#4#1#30*cudj*\n0m3p&e3t##y97&90\nk6my174e##5z1##4\n2*&v#0u&49f#*47#\nv5276hv1xn*wz8if\nk24*#&hu7e*##n8&",
"output": "1"
},
{
"input": "25 16\n&*#&#**sw&**&#&#\n&*#*d#j*3b&q***#\n###&yq*v3q*&##**\n#**&#jpt#*#*#\n***#y*cd&l*oe*##\n&&&***#k*e&*p&#*\n&###*&fkn*pni#**\n**&#ybz*&u*##&&#\n**##p&renhvlq#&#\n*#*&q&*#1&p#&&#&\n**&##&##2*ved&&*\n##*&tug&x*fx&*&*\n###**nt*u&&ux*&&\n&#&#**##1xca*#&&\n*#*&jw#rc#vow&&&\n&*#&exgq&&m*&#*&\n&&##l&&mbizc&**&\n##*&&#m*0&o#*##*\n&#*&fcqsy#&&#*#&\n**#**#*cdm#yf*&*\n*&##s#*v#*g#*&**\n*&##&*#mu##eh&#*\n####v#&i5*bnb&&&\n**##*hj&9#ro#&**\n#&&**&s*9x#f&&*#",
"output": "12"
},
{
"input": "50 1\n#\n4\n7\n#\n&\n*\n3\n&\nc\n*\n7\n*\n#\nw\n1\n&\n8\n7\n&\n&\ny\ng\n#\n5\n*\n4\nx\ny\np\n6\nf\ne\np\n&\n#\n#\ns\nt\na\nm\n&\n1\nv\n#\n&\n1\nq\n0\ny\n3",
"output": "0"
},
{
"input": "3 1\nr\n&\n6",
"output": "0"
},
{
"input": "3 1\n1\nz\n#",
"output": "0"
},
{
"input": "3 1\n6\n*\nt",
"output": "0"
},
{
"input": "3 1\ni\n3\n&",
"output": "0"
},
{
"input": "3 1\nj\n#\n0",
"output": "0"
},
{
"input": "3 1\n&\n7\no",
"output": "0"
},
{
"input": "3 1\n&\nr\n3",
"output": "0"
},
{
"input": "3 8\n*1a*****\n*******a\n*******1",
"output": "2"
},
{
"input": "3 15\naaaaaaa1aaaaaaa\naaaaaaa*aaaaaaa\naaaaaaa*aaaaaaa",
"output": "14"
}
] | 1,485,877,985
| 4,685
|
PyPy 3
|
OK
|
TESTS
| 52
| 685
| 30,003,200
|
n,m = list(map(int, input().split(" ")))
strings = []
for i in range(n):
strings.append(input())
spec = set('#*&')
dig = set('0123456789')
alpha = set('abcdefghijklmnopqrstuvwxyz')
def num(checkset, checkstring):
m = len(checkstring)+1
for i, c in enumerate(checkstring):
if c in checkset:
m = min(m, i)
m = min(m, len(checkstring)-i)
if m < len(checkstring)+1:
return m
return -1
ret = float('inf')
for i in range(n):
for j in range(n):
for k in range(n):
if i==j or i==k or j==k:
continue
else:
s1 = num(spec, strings[i])
s2 = num(dig, strings[j])
s3 = num(alpha, strings[k])
if s1 >= 0 and s2 >= 0 and s3 >= 0:
ret = min(ret, s1+s2+s3)
print(str(int(ret)))
|
Title: Dasha and Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements:
- There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string, - There is at least one of three listed symbols in the string: '#', '*', '&'.
Considering that these are programming classes it is not easy to write the password.
For each character of the password we have a fixed string of length *m*, on each of these *n* strings there is a pointer on some character. The *i*-th character displayed on the screen is the pointed character in the *i*-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).
During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index *m*, and when we move it to the right from the position *m* it moves to the position 1.
You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.
Input Specification:
The first line contains two integers *n*, *m* (3<=≤<=*n*<=≤<=50,<=1<=≤<=*m*<=≤<=50) — the length of the password and the length of strings which are assigned to password symbols.
Each of the next *n* lines contains the string which is assigned to the *i*-th symbol of the password string. Its length is *m*, it consists of digits, lowercase English letters, and characters '#', '*' or '&'.
You have such input data that you can always get a valid password.
Output Specification:
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
Demo Input:
['3 4\n1**2\na3*0\nc4**\n', '5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&\n']
Demo Output:
['1\n', '3\n']
Note:
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.
In the second test one of possible algorithms will be:
- to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
|
```python
n,m = list(map(int, input().split(" ")))
strings = []
for i in range(n):
strings.append(input())
spec = set('#*&')
dig = set('0123456789')
alpha = set('abcdefghijklmnopqrstuvwxyz')
def num(checkset, checkstring):
m = len(checkstring)+1
for i, c in enumerate(checkstring):
if c in checkset:
m = min(m, i)
m = min(m, len(checkstring)-i)
if m < len(checkstring)+1:
return m
return -1
ret = float('inf')
for i in range(n):
for j in range(n):
for k in range(n):
if i==j or i==k or j==k:
continue
else:
s1 = num(spec, strings[i])
s2 = num(dig, strings[j])
s3 = num(alpha, strings[k])
if s1 >= 0 and s2 >= 0 and s3 >= 0:
ret = min(ret, s1+s2+s3)
print(str(int(ret)))
```
| 3
|
|
940
|
B
|
Our Tanya is Crying Out Loud
|
PROGRAMMING
| 1,400
|
[
"dp",
"greedy"
] | null | null |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
|
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
|
[
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] |
[
"6\n",
"8\n",
"12\n"
] |
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
| 1,250
|
[
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
"output": "16032999235141416"
},
{
"input": "777888456\n1\n98\n43",
"output": "76233068590"
},
{
"input": "1162261467\n3\n1\n2000000000",
"output": "1162261466"
},
{
"input": "1000000000\n1999999999\n789987\n184569875",
"output": "789986999210013"
},
{
"input": "2000000000\n2\n1\n2000000000",
"output": "1999999999"
},
{
"input": "1999888325\n3\n2\n2000000000",
"output": "3333258884"
},
{
"input": "1897546487\n687\n89798979\n879876541",
"output": "110398404423"
},
{
"input": "20\n1\n20\n1",
"output": "380"
},
{
"input": "16\n5\n17\n3",
"output": "54"
},
{
"input": "19\n19\n19\n1",
"output": "1"
},
{
"input": "18\n2\n3\n16",
"output": "40"
},
{
"input": "1\n11\n8\n9",
"output": "0"
},
{
"input": "9\n10\n1\n20",
"output": "8"
},
{
"input": "19\n10\n19\n2",
"output": "173"
},
{
"input": "16\n9\n14\n2",
"output": "100"
},
{
"input": "15\n2\n5\n2",
"output": "21"
},
{
"input": "14\n7\n13\n1",
"output": "14"
},
{
"input": "43\n3\n45\n3",
"output": "189"
},
{
"input": "99\n1\n98\n1",
"output": "9604"
},
{
"input": "77\n93\n100\n77",
"output": "7600"
},
{
"input": "81\n3\n91\n95",
"output": "380"
},
{
"input": "78\n53\n87\n34",
"output": "2209"
},
{
"input": "80\n3\n15\n1",
"output": "108"
},
{
"input": "97\n24\n4\n24",
"output": "40"
},
{
"input": "100\n100\n1\n100",
"output": "99"
},
{
"input": "87\n4\n17\n7",
"output": "106"
},
{
"input": "65\n2\n3\n6",
"output": "36"
},
{
"input": "1000000\n1435\n3\n999999",
"output": "1005804"
},
{
"input": "783464\n483464\n2\n966928",
"output": "1566926"
},
{
"input": "248035\n11\n3\n20",
"output": "202"
},
{
"input": "524287\n2\n945658\n999756",
"output": "34963354"
},
{
"input": "947352\n78946\n85\n789654",
"output": "790589"
},
{
"input": "1000000\n1\n999899\n60",
"output": "999898000101"
},
{
"input": "753687\n977456\n6547\n456",
"output": "4934382242"
},
{
"input": "1000000\n500000\n1\n999997",
"output": "999998"
},
{
"input": "997458\n843596\n1\n843596",
"output": "997457"
},
{
"input": "821109\n92\n6547\n98787",
"output": "394566"
},
{
"input": "1073741823\n2\n9543\n8923453",
"output": "188412866"
},
{
"input": "1000999777\n1934999345\n2356346\n34534565",
"output": "2358701818178496"
},
{
"input": "2000000000\n1\n2000000000\n98",
"output": "3999999998000000000"
},
{
"input": "1999324353\n978435356\n1\n978435356",
"output": "1020888998"
},
{
"input": "2000000000\n2\n2000000000\n2000000000",
"output": "84000000000"
},
{
"input": "241375690\n17\n2\n1998789654",
"output": "482751378"
},
{
"input": "171507000\n350\n789\n6548687",
"output": "14216965"
},
{
"input": "1100220011\n10001\n2\n1999778654",
"output": "1999998674"
},
{
"input": "1867622656\n43216\n789644\n12315468",
"output": "24630936"
},
{
"input": "1867622656\n43216\n1\n1879865413",
"output": "1867622655"
},
{
"input": "1999999999\n1000000000\n789987\n184569875",
"output": "789987183779888"
},
{
"input": "1987987897\n103546\n7\n98754563",
"output": "98946650"
},
{
"input": "10\n2\n2\n5",
"output": "13"
},
{
"input": "7\n2\n1\n100000",
"output": "6"
},
{
"input": "7\n2\n3\n1",
"output": "8"
},
{
"input": "2000000000\n666666667\n1\n1",
"output": "666666668"
},
{
"input": "1999999997\n666666666\n2\n2",
"output": "1333333334"
}
] | 1,520,600,893
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 5
| 1,000
| 5,632,000
|
n,k,a,b=(int(input()) for i in range(4))
x,s=n,0
while x!=1:
if k>x:
s,x=s+(x-1)*a,1
elif x%k!=0:
s,x=s+(x%k)*a,x-x%k
elif x*(k-1)//k*a>b:
s,x=s+b,x//k
else:
s,x=s+x*(k-1)//k*a,x//k
print(s)
|
Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output Specification:
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
Demo Input:
['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n']
Demo Output:
['6\n', '8\n', '12\n']
Note:
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
|
```python
n,k,a,b=(int(input()) for i in range(4))
x,s=n,0
while x!=1:
if k>x:
s,x=s+(x-1)*a,1
elif x%k!=0:
s,x=s+(x%k)*a,x-x%k
elif x*(k-1)//k*a>b:
s,x=s+b,x//k
else:
s,x=s+x*(k-1)//k*a,x//k
print(s)
```
| 0
|
|
445
|
A
|
DZY Loves Chessboard
|
PROGRAMMING
| 1,200
|
[
"dfs and similar",
"implementation"
] | null | null |
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
|
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
|
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
|
[
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] |
[
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] |
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
| 500
|
[
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------",
"output": "-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------\n-----------"
},
{
"input": "1 1\n-",
"output": "-"
},
{
"input": "4 2\n..\n..\n..\n..",
"output": "BW\nWB\nBW\nWB"
},
{
"input": "5 1\n.\n.\n.\n.\n.",
"output": "B\nW\nB\nW\nB"
}
] | 1,626,249,223
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 37
| 78
| 7,065,600
|
def spliter():
d = input()
a = d.split()
r = []
for i in a:
k = int(i)
r.append(k)
return r
n = spliter()
lst = []
final = []
for i in range(n[0]):
lst.append([])
k = input()
for j in range(n[1]):
lst[i].append(k[j])
for i in range(n[0]):
final.append([])
for j in range(n[1]):
if lst[i][j]=='-':
final[i].append('-')
print(final[i][j],end="")
else:
if (i+j)%2==0:
final[i].append('B')
print(final[i][j],end="")
else:
final[i].append('W')
print(final[i][j],end="")
print()
|
Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.
You task is to find any suitable placement of chessmen on the given chessboard.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a "-" means it is bad.
Output Specification:
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.
Demo Input:
['1 1\n.\n', '2 2\n..\n..\n', '3 3\n.-.\n---\n--.']
Demo Output:
['B\n', 'BW\nWB\n', 'B-B\n---\n--B']
Note:
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
|
```python
def spliter():
d = input()
a = d.split()
r = []
for i in a:
k = int(i)
r.append(k)
return r
n = spliter()
lst = []
final = []
for i in range(n[0]):
lst.append([])
k = input()
for j in range(n[1]):
lst[i].append(k[j])
for i in range(n[0]):
final.append([])
for j in range(n[1]):
if lst[i][j]=='-':
final[i].append('-')
print(final[i][j],end="")
else:
if (i+j)%2==0:
final[i].append('B')
print(final[i][j],end="")
else:
final[i].append('W')
print(final[i][j],end="")
print()
```
| 3
|
|
262
|
B
|
Roma and Changing Signs
|
PROGRAMMING
| 1,200
|
[
"greedy"
] | null | null |
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times.
The operation of changing a number's sign is the operation of multiplying this number by -1.
Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
|
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
|
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
|
[
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] |
[
"3\n",
"1\n"
] |
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
| 1,000
|
[
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5253 -5041 -5000 -4951 -4855 -4384 -4293 -4251 -4001 -3991 -3762 -3544 -3481 -3261 -2983 -2882 -2857 -2713 -2691 -2681 -2653 -2221 -2043 -2011 -1997 -1601 -1471 -1448 -1363 -1217 -1217 -1129 -961 -926 -801 -376 -327 -305 -174 -91",
"output": "102443"
},
{
"input": "12 28\n-6652 -6621 -6471 -5559 -5326 -4551 -4401 -4326 -3294 -1175 -1069 -43",
"output": "49488"
},
{
"input": "78 13\n-9961 -9922 -9817 -9813 -9521 -9368 -9361 -9207 -9153 -9124 -9008 -8981 -8951 -8911 -8551 -8479 -8245 -8216 -7988 -7841 -7748 -7741 -7734 -7101 -6846 -6804 -6651 -6526 -6519 -6463 -6297 -6148 -6090 -5845 -5209 -5201 -5161 -5061 -4537 -4529 -4433 -4370 -4266 -4189 -4125 -3945 -3843 -3777 -3751 -3476 -3461 -3279 -3205 -3001 -2889 -2761 -2661 -2521 -2481 -2305 -2278 -2269 -2225 -1648 -1524 -1476 -1353 -1097 -867 -785 -741 -711 -692 -440 -401 -225 -65 -41",
"output": "-147832"
},
{
"input": "4 1\n218 3441 4901 7601",
"output": "15725"
},
{
"input": "73 26\n-8497 -8363 -7603 -7388 -6830 -6827 -6685 -6389 -6237 -6099 -6013 -5565 -5465 -4965 -4947 -4201 -3851 -3793 -3421 -3410 -3201 -3169 -3156 -2976 -2701 -2623 -2321 -2169 -1469 -1221 -950 -926 -9 47 236 457 773 1321 1485 1545 1671 1736 2014 2137 2174 2301 2625 3181 3536 3851 4041 4685 4981 4987 5145 5163 5209 5249 6011 6337 6790 7254 7361 7407 7969 7982 8083 8251 8407 8735 9660 9855 9957",
"output": "315919"
},
{
"input": "53 5\n-9821 -9429 -9146 -8973 -8807 -8801 -8321 -7361 -7222 -7161 -6913 -5961 -4877 -4756 -4753 -4661 -3375 -3031 -2950 -2661 -2161 -2041 -1111 -1071 -905 -697 -397 323 772 1617 1752 2736 2737 3201 3465 4029 4121 4463 4561 4637 4814 6119 6610 6641 6961 7217 7523 8045 8610 8915 9004 9265 9576",
"output": "92703"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n10000",
"output": "-10000"
},
{
"input": "1 2\n-1",
"output": "-1"
},
{
"input": "2 1\n0 1",
"output": "1"
},
{
"input": "2 2\n-1 0",
"output": "1"
},
{
"input": "5 6\n-3 -2 -1 5 6",
"output": "15"
},
{
"input": "3 3\n-50 -10 30",
"output": "70"
},
{
"input": "4 4\n-100 -90 -80 1",
"output": "269"
},
{
"input": "4 3\n-3 -2 1 2",
"output": "6"
},
{
"input": "6 4\n-6 -3 -2 1 2 3",
"output": "15"
},
{
"input": "5 6\n-10 -9 -8 1 2",
"output": "28"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "2 2\n-1 3",
"output": "2"
},
{
"input": "4 7\n-3 -2 1 6",
"output": "10"
},
{
"input": "4 3\n-7 -6 1 5",
"output": "17"
},
{
"input": "4 4\n-5 -1 1 2",
"output": "9"
}
] | 1,662,409,940
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 4
| 92
| 0
|
n, changes = map(int, input().split())
incomes = sorted(list(map(int, input().split())))
diff = 0
i = 0
while incomes[i] <= 0 and changes > 0:
diff += (incomes[i] * -2)
changes -= 1
i += 1
if changes % 2 == 1:
diff -= abs(sorted(incomes, key=lambda l: abs(l))[0]) * 2
print(sum(incomes) + diff)
|
Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of several numbers in the sequence. He can also change the sign of a number one, two or more times.
The operation of changing a number's sign is the operation of multiplying this number by -1.
Help Roma perform the changes so as to make the total income of the company (the sum of numbers in the resulting sequence) maximum. Note that Roma should perform exactly *k* changes.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces. Please note that the given sequence is sorted in non-decreasing order.
Output Specification:
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
Demo Input:
['3 2\n-1 -1 1\n', '3 1\n-1 -1 1\n']
Demo Output:
['3\n', '1\n']
Note:
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
|
```python
n, changes = map(int, input().split())
incomes = sorted(list(map(int, input().split())))
diff = 0
i = 0
while incomes[i] <= 0 and changes > 0:
diff += (incomes[i] * -2)
changes -= 1
i += 1
if changes % 2 == 1:
diff -= abs(sorted(incomes, key=lambda l: abs(l))[0]) * 2
print(sum(incomes) + diff)
```
| -1
|
|
960
|
A
|
Check the string
|
PROGRAMMING
| 1,200
|
[
"implementation"
] | null | null |
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
|
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
|
Print "YES" or "NO", according to the condition.
|
[
"aaabccc\n",
"bbacc\n",
"aabc\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'.
| 500
|
[
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"input": "acba",
"output": "NO"
},
{
"input": "bbabbc",
"output": "NO"
},
{
"input": "bbbabacca",
"output": "NO"
},
{
"input": "aabcbcaca",
"output": "NO"
},
{
"input": "aaaaabbbbbb",
"output": "NO"
},
{
"input": "c",
"output": "NO"
},
{
"input": "cc",
"output": "NO"
},
{
"input": "bbb",
"output": "NO"
},
{
"input": "bc",
"output": "NO"
},
{
"input": "ccbcc",
"output": "NO"
},
{
"input": "aaa",
"output": "NO"
},
{
"input": "aaccaa",
"output": "NO"
},
{
"input": "a",
"output": "NO"
},
{
"input": "b",
"output": "NO"
},
{
"input": "abca",
"output": "NO"
},
{
"input": "aabbcccc",
"output": "NO"
},
{
"input": "abac",
"output": "NO"
},
{
"input": "abcc",
"output": "NO"
},
{
"input": "abcb",
"output": "NO"
},
{
"input": "aacc",
"output": "NO"
},
{
"input": "aabbaacccc",
"output": "NO"
},
{
"input": "aabb",
"output": "NO"
},
{
"input": "ac",
"output": "NO"
},
{
"input": "abbacc",
"output": "NO"
},
{
"input": "abacc",
"output": "NO"
},
{
"input": "ababc",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "aabaccc",
"output": "NO"
},
{
"input": "bbcc",
"output": "NO"
},
{
"input": "aaabcbc",
"output": "NO"
},
{
"input": "acbbc",
"output": "NO"
},
{
"input": "babc",
"output": "NO"
},
{
"input": "bbbcc",
"output": "NO"
},
{
"input": "bbc",
"output": "NO"
},
{
"input": "abababccc",
"output": "NO"
},
{
"input": "ccbbaa",
"output": "NO"
}
] | 1,597,862,118
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 32
| 108
| 307,200
|
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
def check_the_string(s):
if (s.find('a') + 1) and s.find('b') and s.find('c') and s.find('a') < s.find('b') < s.find('c'):
if s.count('a') == s.count('c') or s.count('b') == s.count('c'):
print('YES')
else:
print('NO')
else:
print('NO')
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
s = input()
check_the_string(s)
# print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
Input Specification:
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Output Specification:
Print "YES" or "NO", according to the condition.
Demo Input:
['aaabccc\n', 'bbacc\n', 'aabc\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'.
|
```python
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
def check_the_string(s):
if (s.find('a') + 1) and s.find('b') and s.find('c') and s.find('a') < s.find('b') < s.find('c'):
if s.count('a') == s.count('c') or s.count('b') == s.count('c'):
print('YES')
else:
print('NO')
else:
print('NO')
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
s = input()
check_the_string(s)
# print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
```
| 0
|
|
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,594,114,987
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 109
| 6,656,000
|
s1=input()
s2=input()
x=''
for i in range(len(s1)):
if s1[i]==s2[i]:
x=x+str(0)
else:
x=x+str(1)
print(x)
|
Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none
|
```python
s1=input()
s2=input()
x=''
for i in range(len(s1)):
if s1[i]==s2[i]:
x=x+str(0)
else:
x=x+str(1)
print(x)
```
| 3.960352
|
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,681,489,083
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 124
| 0
|
l,m = map(int, input().split())
if l%2 == 0 or m %2 == 0:
print((l//2) * m if l%2 == 0 else (m//2) * l)
else:
print((max(m, l) - 1)//2 * min(m, l) + min(m, l) //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
l,m = map(int, input().split())
if l%2 == 0 or m %2 == 0:
print((l//2) * m if l%2 == 0 else (m//2) * l)
else:
print((max(m, l) - 1)//2 * min(m, l) + min(m, l) //2)
```
| 3.969
|
764
|
A
|
Taymyr is calling you
|
PROGRAMMING
| 800
|
[
"brute force",
"implementation",
"math"
] | null | null |
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
|
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
|
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
|
[
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] |
[
"10\n",
"2\n",
"1\n"
] |
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute.
| 500
|
[
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,646,691,986
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 32
| 46
| 1,638,400
|
n,m,z = map(int, input().split(" "))
a = set()
c = set()
for i in range(1,z+1):
if (i*m <= z):
a.add(i*m)
if (i*n <= z):
c.add(i*n)
commons = len(set(a) - (set(a) - set(c)))
print(commons)
|
Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute.
|
```python
n,m,z = map(int, input().split(" "))
a = set()
c = set()
for i in range(1,z+1):
if (i*m <= z):
a.add(i*m)
if (i*n <= z):
c.add(i*n)
commons = len(set(a) - (set(a) - set(c)))
print(commons)
```
| 3
|
|
670
|
A
|
Holidays
|
PROGRAMMING
| 900
|
[
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null |
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
|
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
|
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
|
[
"14\n",
"2\n"
] |
[
"4 4\n",
"0 2\n"
] |
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
| 500
|
[
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output": "1 2"
},
{
"input": "7",
"output": "2 2"
},
{
"input": "8",
"output": "2 3"
},
{
"input": "9",
"output": "2 4"
},
{
"input": "10",
"output": "2 4"
},
{
"input": "11",
"output": "2 4"
},
{
"input": "12",
"output": "2 4"
},
{
"input": "13",
"output": "3 4"
},
{
"input": "1000000",
"output": "285714 285715"
},
{
"input": "16",
"output": "4 6"
},
{
"input": "17",
"output": "4 6"
},
{
"input": "18",
"output": "4 6"
},
{
"input": "19",
"output": "4 6"
},
{
"input": "20",
"output": "5 6"
},
{
"input": "21",
"output": "6 6"
},
{
"input": "22",
"output": "6 7"
},
{
"input": "23",
"output": "6 8"
},
{
"input": "24",
"output": "6 8"
},
{
"input": "25",
"output": "6 8"
},
{
"input": "26",
"output": "6 8"
},
{
"input": "27",
"output": "7 8"
},
{
"input": "28",
"output": "8 8"
},
{
"input": "29",
"output": "8 9"
},
{
"input": "30",
"output": "8 10"
},
{
"input": "100",
"output": "28 30"
},
{
"input": "99",
"output": "28 29"
},
{
"input": "98",
"output": "28 28"
},
{
"input": "97",
"output": "27 28"
},
{
"input": "96",
"output": "26 28"
},
{
"input": "95",
"output": "26 28"
},
{
"input": "94",
"output": "26 28"
},
{
"input": "93",
"output": "26 28"
},
{
"input": "92",
"output": "26 27"
},
{
"input": "91",
"output": "26 26"
},
{
"input": "90",
"output": "25 26"
},
{
"input": "89",
"output": "24 26"
},
{
"input": "88",
"output": "24 26"
},
{
"input": "87",
"output": "24 26"
},
{
"input": "86",
"output": "24 26"
},
{
"input": "85",
"output": "24 25"
},
{
"input": "84",
"output": "24 24"
},
{
"input": "83",
"output": "23 24"
},
{
"input": "82",
"output": "22 24"
},
{
"input": "81",
"output": "22 24"
},
{
"input": "80",
"output": "22 24"
},
{
"input": "1000",
"output": "285 286"
},
{
"input": "999",
"output": "284 286"
},
{
"input": "998",
"output": "284 286"
},
{
"input": "997",
"output": "284 286"
},
{
"input": "996",
"output": "284 286"
},
{
"input": "995",
"output": "284 285"
},
{
"input": "994",
"output": "284 284"
},
{
"input": "993",
"output": "283 284"
},
{
"input": "992",
"output": "282 284"
},
{
"input": "991",
"output": "282 284"
},
{
"input": "990",
"output": "282 284"
},
{
"input": "989",
"output": "282 284"
},
{
"input": "988",
"output": "282 283"
},
{
"input": "987",
"output": "282 282"
},
{
"input": "986",
"output": "281 282"
},
{
"input": "985",
"output": "280 282"
},
{
"input": "984",
"output": "280 282"
},
{
"input": "983",
"output": "280 282"
},
{
"input": "982",
"output": "280 282"
},
{
"input": "981",
"output": "280 281"
},
{
"input": "980",
"output": "280 280"
},
{
"input": "10000",
"output": "2856 2858"
},
{
"input": "9999",
"output": "2856 2858"
},
{
"input": "9998",
"output": "2856 2858"
},
{
"input": "9997",
"output": "2856 2857"
},
{
"input": "9996",
"output": "2856 2856"
},
{
"input": "9995",
"output": "2855 2856"
},
{
"input": "9994",
"output": "2854 2856"
},
{
"input": "9993",
"output": "2854 2856"
},
{
"input": "9992",
"output": "2854 2856"
},
{
"input": "9991",
"output": "2854 2856"
},
{
"input": "9990",
"output": "2854 2855"
},
{
"input": "9989",
"output": "2854 2854"
},
{
"input": "9988",
"output": "2853 2854"
},
{
"input": "9987",
"output": "2852 2854"
},
{
"input": "9986",
"output": "2852 2854"
},
{
"input": "9985",
"output": "2852 2854"
},
{
"input": "9984",
"output": "2852 2854"
},
{
"input": "9983",
"output": "2852 2853"
},
{
"input": "9982",
"output": "2852 2852"
},
{
"input": "9981",
"output": "2851 2852"
},
{
"input": "9980",
"output": "2850 2852"
},
{
"input": "100000",
"output": "28570 28572"
},
{
"input": "99999",
"output": "28570 28572"
},
{
"input": "99998",
"output": "28570 28572"
},
{
"input": "99997",
"output": "28570 28572"
},
{
"input": "99996",
"output": "28570 28571"
},
{
"input": "99995",
"output": "28570 28570"
},
{
"input": "99994",
"output": "28569 28570"
},
{
"input": "99993",
"output": "28568 28570"
},
{
"input": "99992",
"output": "28568 28570"
},
{
"input": "99991",
"output": "28568 28570"
},
{
"input": "99990",
"output": "28568 28570"
},
{
"input": "99989",
"output": "28568 28569"
},
{
"input": "99988",
"output": "28568 28568"
},
{
"input": "99987",
"output": "28567 28568"
},
{
"input": "99986",
"output": "28566 28568"
},
{
"input": "99985",
"output": "28566 28568"
},
{
"input": "99984",
"output": "28566 28568"
},
{
"input": "99983",
"output": "28566 28568"
},
{
"input": "99982",
"output": "28566 28567"
},
{
"input": "99981",
"output": "28566 28566"
},
{
"input": "99980",
"output": "28565 28566"
},
{
"input": "999999",
"output": "285714 285714"
},
{
"input": "999998",
"output": "285713 285714"
},
{
"input": "999997",
"output": "285712 285714"
},
{
"input": "999996",
"output": "285712 285714"
},
{
"input": "999995",
"output": "285712 285714"
},
{
"input": "999994",
"output": "285712 285714"
},
{
"input": "999993",
"output": "285712 285713"
},
{
"input": "999992",
"output": "285712 285712"
},
{
"input": "999991",
"output": "285711 285712"
},
{
"input": "999990",
"output": "285710 285712"
},
{
"input": "999989",
"output": "285710 285712"
},
{
"input": "999988",
"output": "285710 285712"
},
{
"input": "999987",
"output": "285710 285712"
},
{
"input": "999986",
"output": "285710 285711"
},
{
"input": "999985",
"output": "285710 285710"
},
{
"input": "999984",
"output": "285709 285710"
},
{
"input": "999983",
"output": "285708 285710"
},
{
"input": "999982",
"output": "285708 285710"
},
{
"input": "999981",
"output": "285708 285710"
},
{
"input": "999980",
"output": "285708 285710"
},
{
"input": "234123",
"output": "66892 66893"
},
{
"input": "234122",
"output": "66892 66892"
},
{
"input": "234121",
"output": "66891 66892"
},
{
"input": "234120",
"output": "66890 66892"
},
{
"input": "234119",
"output": "66890 66892"
},
{
"input": "234118",
"output": "66890 66892"
},
{
"input": "234117",
"output": "66890 66892"
},
{
"input": "234116",
"output": "66890 66891"
},
{
"input": "234115",
"output": "66890 66890"
},
{
"input": "234114",
"output": "66889 66890"
},
{
"input": "234113",
"output": "66888 66890"
},
{
"input": "234112",
"output": "66888 66890"
},
{
"input": "234111",
"output": "66888 66890"
},
{
"input": "234110",
"output": "66888 66890"
},
{
"input": "234109",
"output": "66888 66889"
},
{
"input": "234108",
"output": "66888 66888"
},
{
"input": "234107",
"output": "66887 66888"
},
{
"input": "234106",
"output": "66886 66888"
},
{
"input": "234105",
"output": "66886 66888"
},
{
"input": "234104",
"output": "66886 66888"
},
{
"input": "234103",
"output": "66886 66888"
},
{
"input": "868531",
"output": "248151 248152"
},
{
"input": "868530",
"output": "248150 248152"
},
{
"input": "868529",
"output": "248150 248152"
},
{
"input": "868528",
"output": "248150 248152"
},
{
"input": "868527",
"output": "248150 248152"
},
{
"input": "868526",
"output": "248150 248151"
},
{
"input": "868525",
"output": "248150 248150"
},
{
"input": "868524",
"output": "248149 248150"
},
{
"input": "868523",
"output": "248148 248150"
},
{
"input": "868522",
"output": "248148 248150"
},
{
"input": "868521",
"output": "248148 248150"
},
{
"input": "868520",
"output": "248148 248150"
},
{
"input": "868519",
"output": "248148 248149"
},
{
"input": "868518",
"output": "248148 248148"
},
{
"input": "868517",
"output": "248147 248148"
},
{
"input": "868516",
"output": "248146 248148"
},
{
"input": "868515",
"output": "248146 248148"
},
{
"input": "868514",
"output": "248146 248148"
},
{
"input": "868513",
"output": "248146 248148"
},
{
"input": "868512",
"output": "248146 248147"
},
{
"input": "868511",
"output": "248146 248146"
},
{
"input": "123413",
"output": "35260 35262"
},
{
"input": "123412",
"output": "35260 35262"
},
{
"input": "123411",
"output": "35260 35261"
},
{
"input": "123410",
"output": "35260 35260"
},
{
"input": "123409",
"output": "35259 35260"
},
{
"input": "123408",
"output": "35258 35260"
},
{
"input": "123407",
"output": "35258 35260"
},
{
"input": "123406",
"output": "35258 35260"
},
{
"input": "123405",
"output": "35258 35260"
},
{
"input": "123404",
"output": "35258 35259"
},
{
"input": "123403",
"output": "35258 35258"
},
{
"input": "123402",
"output": "35257 35258"
},
{
"input": "123401",
"output": "35256 35258"
},
{
"input": "123400",
"output": "35256 35258"
},
{
"input": "123399",
"output": "35256 35258"
},
{
"input": "123398",
"output": "35256 35258"
},
{
"input": "123397",
"output": "35256 35257"
},
{
"input": "123396",
"output": "35256 35256"
},
{
"input": "123395",
"output": "35255 35256"
},
{
"input": "123394",
"output": "35254 35256"
},
{
"input": "123393",
"output": "35254 35256"
},
{
"input": "15",
"output": "4 5"
}
] | 1,682,537,594
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 14
| 61
| 512,000
|
def holidaymax(n):
if n<=0:
return 0
elif 0<n<=2:
return n
else:
return 2+holidaymax(n-7)
def holidaymin(n):
if n<=5:
return 0
elif 5<n<=7:
return n-5
else:
return 2+holidaymin(n-7)
n=int(input())
print(holidaymin(n),holidaymax(n))
|
Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Output Specification:
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
Demo Input:
['14\n', '2\n']
Demo Output:
['4 4\n', '0 2\n']
Note:
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
|
```python
def holidaymax(n):
if n<=0:
return 0
elif 0<n<=2:
return n
else:
return 2+holidaymax(n-7)
def holidaymin(n):
if n<=5:
return 0
elif 5<n<=7:
return n-5
else:
return 2+holidaymin(n-7)
n=int(input())
print(holidaymin(n),holidaymax(n))
```
| -1
|
|
11
|
A
|
Increasing Sequence
|
PROGRAMMING
| 900
|
[
"constructive algorithms",
"implementation",
"math"
] |
A. Increasing Sequence
|
1
|
64
|
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
|
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
|
Output the minimal number of moves needed to make the sequence increasing.
|
[
"4 2\n1 3 3 2\n"
] |
[
"3\n"
] |
none
| 0
|
[
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,592,317,688
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 15
| 1,000
| 0
|
n, d = map(int, input().split())
nums = list(map(int, input().split()))
res = 0
for i in range(1, n):
while nums[i] <= nums[i-1]:
nums[i] += d
res += 1
print(res)
|
Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none
|
```python
n, d = map(int, input().split())
nums = list(map(int, input().split()))
res = 0
for i in range(1, n):
while nums[i] <= nums[i-1]:
nums[i] += d
res += 1
print(res)
```
| 0
|
897
|
A
|
Scarborough Fair
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length *n*.
Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed.
Grick wants to know the final string after all the *m* operations.
|
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space.
|
Output string *s* after performing *m* operations described above.
|
[
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] |
[
"noi",
"gaaak"
] |
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
| 500
|
[
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n4 5 a e\n3 9 f a\n1 2 c h\n4 8 a c\n3 5 e d\n3 4 g f\n2 3 d h\n2 3 d e\n1 7 d g\n2 6 e g\n2 3 d g\n5 5 h h\n2 8 g d\n8 9 a f\n5 9 c e\n1 7 f d\n1 6 e e\n5 7 c a\n8 9 b b\n2 6 e b\n6 6 g h\n1 2 b b\n1 5 a f\n5 8 f h\n1 5 e g\n3 9 f h\n6 8 g a\n4 6 h g\n1 5 f a\n5 6 a c\n4 8 e d\n1 4 d g\n7 8 b f\n5 6 h b\n3 9 c e\n1 9 b a",
"output": "aahaddddh"
},
{
"input": "28 45\ndcbbaddjhbeefjadjchgkhgggfha\n10 25 c a\n13 19 a f\n12 28 e d\n12 27 e a\n9 20 b e\n7 17 g d\n22 26 j j\n8 16 c g\n14 16 a d\n3 10 f c\n10 26 d b\n8 17 i e\n10 19 d i\n6 21 c j\n7 22 b k\n17 19 a i\n4 18 j k\n8 25 a g\n10 27 j e\n9 18 g d\n16 23 h a\n17 26 k e\n8 16 h f\n1 15 d f\n22 28 k k\n11 20 c k\n6 11 b h\n17 17 e i\n15 22 g h\n8 18 c f\n4 16 e a\n8 25 b c\n6 24 d g\n5 9 f j\n12 19 i h\n4 25 e f\n15 25 c j\n15 27 e e\n11 20 b f\n19 27 e k\n2 21 d a\n9 27 k e\n14 24 b a\n3 6 i g\n2 26 k f",
"output": "fcbbajjfjaaefefehfahfagggfha"
},
{
"input": "87 5\nnfinedeojadjmgafnaogekfjkjfncnliagfchjfcmellgigjjcaaoeakdolchjcecljdeblmheimkibkgdkcdml\n47 56 a k\n51 81 o d\n5 11 j h\n48 62 j d\n16 30 k m",
"output": "nfinedeohadjmgafnaogemfjmjfncnliagfchjfcmellgigddckkdekkddlchdcecljdeblmheimkibkgdkcdml"
},
{
"input": "5 16\nacfbb\n1 2 e f\n2 5 a f\n2 3 b e\n4 4 f a\n2 3 f a\n1 2 b e\n4 5 c d\n2 4 e c\n1 4 e a\n1 3 d c\n3 5 e b\n3 5 e b\n2 2 e d\n1 3 e c\n3 3 a e\n1 5 a a",
"output": "acebb"
},
{
"input": "94 13\nbcaaaaaaccacddcdaacbdaabbcbaddbccbccbbbddbadddcccbddadddaadbdababadaacdcdbcdadabdcdcbcbcbcbbcd\n52 77 d d\n21 92 d b\n45 48 c b\n20 25 d a\n57 88 d b\n3 91 b d\n64 73 a a\n5 83 b d\n2 69 c c\n28 89 a b\n49 67 c b\n41 62 a c\n49 87 b c",
"output": "bcaaaaaaccacddcdaacddaaddcdbdddccdccddddddbdddddcdddcdddccdddcdcdcdcccdcddcdcdcddcdcdcdcdcdbcd"
},
{
"input": "67 39\nacbcbccccbabaabcabcaaaaaaccbcbbcbaaaacbbcccbcbabbcacccbbabbabbabaac\n4 36 a b\n25 38 a a\n3 44 b c\n35 57 b a\n4 8 a c\n20 67 c a\n30 66 b b\n27 40 a a\n2 56 a b\n10 47 c a\n22 65 c b\n29 42 a b\n1 46 c b\n57 64 b c\n20 29 b a\n14 51 c a\n12 55 b b\n20 20 a c\n2 57 c a\n22 60 c b\n16 51 c c\n31 64 a c\n17 30 c a\n23 36 c c\n28 67 a c\n37 40 a c\n37 50 b c\n29 48 c b\n2 34 b c\n21 53 b a\n26 63 a c\n23 28 c a\n51 56 c b\n32 61 b b\n64 67 b b\n21 67 b c\n8 53 c c\n40 62 b b\n32 38 c c",
"output": "accccccccaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccc"
},
{
"input": "53 33\nhhcbhfafeececbhadfbdbehdfacfchbhdbfebdfeghebfcgdhehfh\n27 41 h g\n18 35 c b\n15 46 h f\n48 53 e g\n30 41 b c\n12 30 b f\n10 37 e f\n18 43 a h\n10 52 d a\n22 48 c e\n40 53 f d\n7 12 b h\n12 51 f a\n3 53 g a\n19 41 d h\n22 29 b h\n2 30 a b\n26 28 e h\n25 35 f a\n19 31 h h\n44 44 d e\n19 22 e c\n29 44 d h\n25 33 d h\n3 53 g c\n18 44 h b\n19 28 f e\n3 22 g h\n8 17 c a\n37 51 d d\n3 28 e h\n27 50 h h\n27 46 f b",
"output": "hhcbhfbfhfababbbbbbbbbbbbbbbbbeaaeaaeaaeabebdeaahahdh"
},
{
"input": "83 10\nfhbecdgadecabbbecedcgfdcefcbgechbedagecgdgfgdaahchdgchbeaedgafdefecdchceececfcdhcdh\n9 77 e e\n26 34 b g\n34 70 b a\n40 64 e g\n33 78 h f\n14 26 a a\n17 70 d g\n56 65 a c\n8 41 d c\n11 82 c b",
"output": "fhbecdgacebabbbebegbgfgbefbggebhgegagebgggfggaafbfggbfagbgggbfggfebgbfbeebebfbdhbdh"
},
{
"input": "1 4\ne\n1 1 c e\n1 1 e a\n1 1 e c\n1 1 d a",
"output": "a"
},
{
"input": "71 21\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n61 61 a a\n32 56 a a\n10 67 a a\n7 32 a a\n26 66 a a\n41 55 a a\n49 55 a a\n4 61 a a\n53 59 a a\n37 58 a a\n7 63 a a\n39 40 a a\n51 64 a a\n27 37 a a\n22 71 a a\n4 45 a a\n7 8 a a\n43 46 a a\n19 28 a a\n51 54 a a\n14 67 a a",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "30 4\neaaddabedcbbcccddbabdecadcecce\n2 17 c a\n16 29 e e\n16 21 c b\n7 11 b c",
"output": "eaaddacedacbaaaddbabdecadcecce"
},
{
"input": "48 30\naaaabaabbaababbbaabaabaababbabbbaabbbaabaaaaaaba\n3 45 a b\n1 14 a a\n15 32 a b\n37 47 a b\n9 35 a b\n36 39 b b\n6 26 a b\n36 44 a a\n28 44 b a\n29 31 b a\n20 39 a a\n45 45 a b\n21 32 b b\n7 43 a b\n14 48 a b\n14 33 a b\n39 44 a a\n9 36 b b\n4 23 b b\n9 42 b b\n41 41 b a\n30 47 a b\n8 42 b a\n14 38 b b\n3 15 a a\n35 47 b b\n14 34 a b\n38 43 a b\n1 35 b a\n16 28 b a",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbb"
},
{
"input": "89 29\nbabaabaaabaaaababbbbbbbabbbaaaaababbaababababbababaaabbababaaabbbbaaabaaaaaabaaabaabbabab\n39 70 b b\n3 56 b b\n5 22 b a\n4 39 a b\n41 87 b b\n34 41 a a\n10 86 a b\n29 75 a b\n2 68 a a\n27 28 b b\n42 51 b a\n18 61 a a\n6 67 b a\n47 63 a a\n8 68 a b\n4 74 b a\n19 65 a b\n8 55 a b\n5 30 a a\n3 65 a b\n16 57 a b\n34 56 b a\n1 70 a b\n59 68 b b\n29 57 b a\n47 49 b b\n49 73 a a\n32 61 b b\n29 42 a a",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaabbbbbbbbbbbbbab"
},
{
"input": "59 14\nfbebcfabdefbaaedcefdeecababcabebadfbccaaedaebfdaefdbbcbebbe\n5 32 e f\n8 46 e e\n31 43 e f\n3 10 e a\n53 54 f d\n55 59 d a\n39 58 e b\n54 56 f a\n9 40 b e\n28 37 d a\n7 35 e b\n7 56 c f\n23 26 e a\n15 44 e d",
"output": "fbabcfabdffbaafdfffdfffababfabfbaafdffaafdabbfdabfdbbfbbbbe"
},
{
"input": "7 17\nbbaabab\n3 5 a b\n5 7 a a\n5 5 a a\n4 4 b a\n7 7 a a\n5 6 b b\n1 3 b a\n6 7 a b\n4 6 a b\n6 6 a a\n2 4 b a\n1 7 b a\n4 6 b b\n2 5 b b\n2 5 a b\n1 4 a a\n4 4 b a",
"output": "abbabaa"
},
{
"input": "100 1\ndebaaagbfdgehagadabfgheegggfghghgeeeabgceffeffggcbcegfgebbdhebhfagcgadcbdbabddbcadgbgdebdfehceehcaef\n13 99 f c",
"output": "debaaagbfdgehagadabcgheegggcghghgeeeabgcecceccggcbcegcgebbdhebhcagcgadcbdbabddbcadgbgdebdcehceehcaef"
},
{
"input": "1 1\na\n1 1 a b",
"output": "b"
},
{
"input": "100 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1 100 a b",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
},
{
"input": "2 2\naa\n1 2 a b\n1 2 b c",
"output": "cc"
},
{
"input": "3 3\naaa\n1 3 a b\n1 3 b c\n1 3 c d",
"output": "ddd"
},
{
"input": "2 2\naa\n2 2 a b\n1 1 a b",
"output": "bb"
}
] | 1,664,970,084
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 47
| 62
| 3,276,800
|
def main():
n, m = map(int, input().split())
st = list(input())
for _ in range(m):
l, r, c1, c2 = input().split()
for i in range(int(l)-1, int(r)):
if st[i] == c1:
st[i] = c2
print(''.join(st))
if __name__ == '__main__':
main()
|
Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length *n*.
Willem needs to do *m* operations, each operation has four parameters *l*,<=*r*,<=*c*1,<=*c*2, which means that all symbols *c*1 in range [*l*,<=*r*] (from *l*-th to *r*-th, including *l* and *r*) are changed into *c*2. String is 1-indexed.
Grick wants to know the final string after all the *m* operations.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), separated by space.
Output Specification:
Output string *s* after performing *m* operations described above.
Demo Input:
['3 1\nioi\n1 1 i n\n', '5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n']
Demo Output:
['noi', 'gaaak']
Note:
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
|
```python
def main():
n, m = map(int, input().split())
st = list(input())
for _ in range(m):
l, r, c1, c2 = input().split()
for i in range(int(l)-1, int(r)):
if st[i] == c1:
st[i] = c2
print(''.join(st))
if __name__ == '__main__':
main()
```
| 3
|
|
637
|
B
|
Chat Order
|
PROGRAMMING
| 1,200
|
[
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null |
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
|
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
|
[
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] |
[
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] |
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex
| 1,000
|
[
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,700,268,753
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 95
| 607
| 47,820,800
|
n = int(input())
names = {}
i = 0
for _ in range(n):
names[input()] = i
i += 1
for name, key in sorted(names.items(), key=lambda item: item[1], reverse=True):
print(name)
|
Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex
|
```python
n = int(input())
names = {}
i = 0
for _ in range(n):
names[input()] = i
i += 1
for name, key in sorted(names.items(), key=lambda item: item[1], reverse=True):
print(name)
```
| 3
|
|
19
|
B
|
Checkout Assistant
|
PROGRAMMING
| 1,900
|
[
"dp"
] |
B. Checkout Assistant
|
1
|
256
|
Bob came to a cash & carry store, put *n* items into his trolley, and went to the checkout counter to pay. Each item is described by its price *c**i* and time *t**i* in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
|
The first input line contains number *n* (1<=≤<=*n*<=≤<=2000). In each of the following *n* lines each item is described by a pair of numbers *t**i*, *c**i* (0<=≤<=*t**i*<=≤<=2000,<=1<=≤<=*c**i*<=≤<=109). If *t**i* is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item *i*.
|
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
|
[
"4\n2 10\n0 20\n1 5\n1 3\n",
"3\n0 1\n0 10\n0 100\n"
] |
[
"8\n",
"111\n"
] |
none
| 0
|
[
{
"input": "4\n2 10\n0 20\n1 5\n1 3",
"output": "8"
},
{
"input": "3\n0 1\n0 10\n0 100",
"output": "111"
},
{
"input": "2\n0 635254032\n0 75159864",
"output": "710413896"
},
{
"input": "2\n0 861438648\n1 469893784",
"output": "469893784"
},
{
"input": "2\n2 87623264\n0 864627704",
"output": "87623264"
},
{
"input": "5\n0 51690939\n0 62436494\n0 39009053\n0 70426298\n0 631569476",
"output": "855132260"
},
{
"input": "5\n0 968804136\n0 736567537\n2 343136264\n0 259899572\n1 425744418",
"output": "768880682"
},
{
"input": "5\n4 33400980\n2 410698581\n4 794747123\n0 301889198\n3 219919361",
"output": "33400980"
},
{
"input": "5\n5 491957578\n4 747764103\n3 446810728\n4 896625835\n4 190748656",
"output": "190748656"
},
{
"input": "10\n3 512981548\n0 214269975\n2 603901234\n3 772872647\n0 224281389\n4 561877930\n1 809519308\n4 883486551\n1 114469023\n2 184038037",
"output": "860384990"
}
] | 1,664,130,761
| 2,147,483,647
|
PyPy 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 77
| 2,150,400
|
from sys import stdin, stdout
def read_list(): # read list of variables
return [int(x) for x in stdin.readline().split()]
def read_list_str(): # read list of variables
return [x for x in stdin.readline().split()]
def readmv(): # read_multiple_variable
return map(int, stdin.readline().split())
def readv(): # read variable
return int(stdin.readline())
def printSol(test_case, x):
ans_to_print = ''
if type(x) == list:
for el in x:
ans_to_print += f'{el} '
if type(x) == int or type(x) == float:
ans_to_print = str(x)
stdout.write(f'Case #{test_case + 1}: ' + ans_to_print + f'\n')
def read():
return stdin.readline().strip()
from heapq import heapify, heappop, heappush
from math import inf
def dijkstra(graph, s):
n = len(graph)
visited = [False]*n
dist = [inf]*n
q = [(s, 0)]
heapify(q)
visited[s] = True
dist[s] = 0
while len(q):
_, u = heappop(q)
for (v, w) in graph[u]:
if not visited[v] and dist[v] > dist[u] + w:
dist[v] = dist[u] + w
heappush(q, (dist[v], v))
return dist
def main():
n, m = readmv()
graph = [[] for _ in range(2*n)]
for _ in range(m):
x, y, w = readmv()
x -= 1
y -= 1
graph[x].append((y, w))
graph[y+n].append((x+n, w))
for x in range(n):
graph[x].append((x+n, 0))
dist = dijkstra(graph, 0)
for i in range(1, n):
if dist[n+i] == inf:
stdout.write('-1 ')
continue
stdout.write(f'{dist[n+i]} ')
stdout.write('\n')
main()
|
Title: Checkout Assistant
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob came to a cash & carry store, put *n* items into his trolley, and went to the checkout counter to pay. Each item is described by its price *c**i* and time *t**i* in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
Input Specification:
The first input line contains number *n* (1<=≤<=*n*<=≤<=2000). In each of the following *n* lines each item is described by a pair of numbers *t**i*, *c**i* (0<=≤<=*t**i*<=≤<=2000,<=1<=≤<=*c**i*<=≤<=109). If *t**i* is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item *i*.
Output Specification:
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
Demo Input:
['4\n2 10\n0 20\n1 5\n1 3\n', '3\n0 1\n0 10\n0 100\n']
Demo Output:
['8\n', '111\n']
Note:
none
|
```python
from sys import stdin, stdout
def read_list(): # read list of variables
return [int(x) for x in stdin.readline().split()]
def read_list_str(): # read list of variables
return [x for x in stdin.readline().split()]
def readmv(): # read_multiple_variable
return map(int, stdin.readline().split())
def readv(): # read variable
return int(stdin.readline())
def printSol(test_case, x):
ans_to_print = ''
if type(x) == list:
for el in x:
ans_to_print += f'{el} '
if type(x) == int or type(x) == float:
ans_to_print = str(x)
stdout.write(f'Case #{test_case + 1}: ' + ans_to_print + f'\n')
def read():
return stdin.readline().strip()
from heapq import heapify, heappop, heappush
from math import inf
def dijkstra(graph, s):
n = len(graph)
visited = [False]*n
dist = [inf]*n
q = [(s, 0)]
heapify(q)
visited[s] = True
dist[s] = 0
while len(q):
_, u = heappop(q)
for (v, w) in graph[u]:
if not visited[v] and dist[v] > dist[u] + w:
dist[v] = dist[u] + w
heappush(q, (dist[v], v))
return dist
def main():
n, m = readmv()
graph = [[] for _ in range(2*n)]
for _ in range(m):
x, y, w = readmv()
x -= 1
y -= 1
graph[x].append((y, w))
graph[y+n].append((x+n, w))
for x in range(n):
graph[x].append((x+n, 0))
dist = dijkstra(graph, 0)
for i in range(1, n):
if dist[n+i] == inf:
stdout.write('-1 ')
continue
stdout.write(f'{dist[n+i]} ')
stdout.write('\n')
main()
```
| -1
|
57
|
A
|
Square Earth?
|
PROGRAMMING
| 1,300
|
[
"dfs and similar",
"greedy",
"implementation"
] |
A. Square Earth?
|
2
|
256
|
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side *n*. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0,<=0), (*n*,<=0), (0,<=*n*) and (*n*,<=*n*).
|
The single line contains 5 space-separated integers: *n*,<=*x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.
|
You must print on a single line the shortest distance between the points.
|
[
"2 0 0 1 0\n",
"2 0 1 2 1\n",
"100 0 0 100 100\n"
] |
[
"1\n",
"4\n",
"200\n"
] |
none
| 500
|
[
{
"input": "2 0 0 1 0",
"output": "1"
},
{
"input": "2 0 1 2 1",
"output": "4"
},
{
"input": "100 0 0 100 100",
"output": "200"
},
{
"input": "4 0 3 1 4",
"output": "2"
},
{
"input": "10 8 10 10 0",
"output": "12"
},
{
"input": "26 21 0 26 14",
"output": "19"
},
{
"input": "15 0 1 11 0",
"output": "12"
},
{
"input": "26 26 7 26 12",
"output": "5"
},
{
"input": "6 6 0 2 6",
"output": "10"
},
{
"input": "5 1 5 2 5",
"output": "1"
},
{
"input": "99 12 0 35 99",
"output": "146"
},
{
"input": "44 44 31 28 0",
"output": "47"
},
{
"input": "42 42 36 5 0",
"output": "73"
},
{
"input": "87 87 66 0 5",
"output": "158"
},
{
"input": "85 0 32 0 31",
"output": "1"
},
{
"input": "30 20 30 3 0",
"output": "53"
},
{
"input": "5 4 0 5 1",
"output": "2"
},
{
"input": "40 24 40 4 0",
"output": "68"
},
{
"input": "11 0 2 11 4",
"output": "17"
},
{
"input": "82 0 11 35 0",
"output": "46"
},
{
"input": "32 19 32 0 1",
"output": "50"
},
{
"input": "54 12 0 0 44",
"output": "56"
},
{
"input": "75 42 75 28 0",
"output": "145"
},
{
"input": "48 31 48 0 4",
"output": "75"
},
{
"input": "69 4 69 69 59",
"output": "75"
},
{
"input": "561 0 295 233 0",
"output": "528"
},
{
"input": "341 158 0 0 190",
"output": "348"
},
{
"input": "887 887 461 39 887",
"output": "1274"
},
{
"input": "700 0 288 700 368",
"output": "1356"
},
{
"input": "512 70 512 512 99",
"output": "855"
},
{
"input": "826 188 826 592 0",
"output": "1606"
},
{
"input": "953 0 773 0 903",
"output": "130"
},
{
"input": "80 80 4 0 54",
"output": "138"
},
{
"input": "208 73 0 208 123",
"output": "258"
},
{
"input": "983 0 894 199 0",
"output": "1093"
},
{
"input": "686 615 686 470 686",
"output": "145"
},
{
"input": "869 869 833 0 578",
"output": "1196"
},
{
"input": "169 0 94 0 132",
"output": "38"
},
{
"input": "68 42 68 68 28",
"output": "66"
},
{
"input": "967 967 607 279 0",
"output": "1295"
},
{
"input": "489 489 139 455 489",
"output": "384"
},
{
"input": "964 205 964 604 964",
"output": "399"
},
{
"input": "86 0 34 86 21",
"output": "141"
},
{
"input": "209 166 209 131 0",
"output": "330"
},
{
"input": "684 684 113 314 684",
"output": "941"
},
{
"input": "16 0 6 0 8",
"output": "2"
},
{
"input": "862 154 862 297 862",
"output": "143"
},
{
"input": "418 222 0 254 418",
"output": "778"
},
{
"input": "571 504 571 143 571",
"output": "361"
},
{
"input": "371 371 210 81 371",
"output": "451"
},
{
"input": "1000 0 0 1000 1000",
"output": "2000"
},
{
"input": "1000 564 0 436 1000",
"output": "2000"
},
{
"input": "1000 0 573 12 1000",
"output": "439"
},
{
"input": "1000 984 0 1000 999",
"output": "1015"
},
{
"input": "100 10 0 10 0",
"output": "0"
}
] | 1,601,799,134
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 25
| 218
| 3,379,200
|
n,a,b,c,d=map(int,input().split())
dx=[0,0,-1,1]
dy=[1,-1,0,0]
vis=[[0]*(n+1) for _ in " "*(n+1)]
ok=[[1]*(n+1)]
for i in range(n-1):
ok.append([1]+[0]*(n-1)+[1])
ok.append([1]*(n+1))
def dfs(x,y,k):
if x<0 or x>n or y<0 or y>n:return
if vis[x][y]:return
if ok[x][y]==0:return
vis[x][y]=1
if x==c and y==d:exit(print(min(k,4*n-k)))
for i in range(4):dfs(x+dx[i],y+dy[i],k+1)
dfs(a,b,0)
|
Title: Square Earth?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side *n*. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0,<=0), (*n*,<=0), (0,<=*n*) and (*n*,<=*n*).
Input Specification:
The single line contains 5 space-separated integers: *n*,<=*x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.
Output Specification:
You must print on a single line the shortest distance between the points.
Demo Input:
['2 0 0 1 0\n', '2 0 1 2 1\n', '100 0 0 100 100\n']
Demo Output:
['1\n', '4\n', '200\n']
Note:
none
|
```python
n,a,b,c,d=map(int,input().split())
dx=[0,0,-1,1]
dy=[1,-1,0,0]
vis=[[0]*(n+1) for _ in " "*(n+1)]
ok=[[1]*(n+1)]
for i in range(n-1):
ok.append([1]+[0]*(n-1)+[1])
ok.append([1]*(n+1))
def dfs(x,y,k):
if x<0 or x>n or y<0 or y>n:return
if vis[x][y]:return
if ok[x][y]==0:return
vis[x][y]=1
if x==c and y==d:exit(print(min(k,4*n-k)))
for i in range(4):dfs(x+dx[i],y+dy[i],k+1)
dfs(a,b,0)
```
| -1
|
289
|
B
|
Polo the Penguin and Matrix
|
PROGRAMMING
| 1,400
|
[
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null |
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
|
The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104).
|
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
|
[
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] |
[
"4\n",
"-1\n"
] |
none
| 1,000
|
[
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"output": "-1"
},
{
"input": "2 2 4\n5 5\n5 5",
"output": "0"
},
{
"input": "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7",
"output": "9"
},
{
"input": "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91",
"output": "0"
},
{
"input": "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47",
"output": "-1"
},
{
"input": "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366",
"output": "1508"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 1 8\n12",
"output": "0"
}
] | 1,610,295,430
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 14
| 2,000
| 614,400
|
import collections,math,itertools,bisect,heapq,copy
class Solution:
def solve(self):
n,m,d = list(map(int, input().rstrip().split()))
arr = []
for i in range(n):
a = list(map(int, input().rstrip().split()))
arr.append(a)
res = float('inf')
for i in range(n):
for j in range(m):
num = arr[i][j]
total = 0
for _i in range(n):
for _j in range(m):
if (num-arr[_i][_j]) % d != 0:
print(-1)
return
total += (abs(num-arr[_i][_j])//d)
res = min(res,total)
print(res)
if __name__ == "__main__":
solution = Solution()
solution.solve()
|
Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
Input Specification:
The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104).
Output Specification:
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
Demo Input:
['2 2 2\n2 4\n6 8\n', '1 2 7\n6 7\n']
Demo Output:
['4\n', '-1\n']
Note:
none
|
```python
import collections,math,itertools,bisect,heapq,copy
class Solution:
def solve(self):
n,m,d = list(map(int, input().rstrip().split()))
arr = []
for i in range(n):
a = list(map(int, input().rstrip().split()))
arr.append(a)
res = float('inf')
for i in range(n):
for j in range(m):
num = arr[i][j]
total = 0
for _i in range(n):
for _j in range(m):
if (num-arr[_i][_j]) % d != 0:
print(-1)
return
total += (abs(num-arr[_i][_j])//d)
res = min(res,total)
print(res)
if __name__ == "__main__":
solution = Solution()
solution.solve()
```
| 0
|
|
119
|
A
|
Epic Game
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game.
|
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
|
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
|
[
"3 5 9\n",
"1 1 100\n"
] |
[
"0",
"1"
] |
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
| 500
|
[
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "41 12 65",
"output": "1"
},
{
"input": "13 61 100",
"output": "1"
},
{
"input": "100 100 10",
"output": "0"
},
{
"input": "12 24 26",
"output": "1"
},
{
"input": "73 21 96",
"output": "1"
},
{
"input": "17 22 81",
"output": "1"
},
{
"input": "14 88 97",
"output": "1"
},
{
"input": "42 81 17",
"output": "0"
},
{
"input": "34 36 19",
"output": "1"
},
{
"input": "21 87 12",
"output": "1"
},
{
"input": "97 92 98",
"output": "1"
},
{
"input": "49 25 62",
"output": "1"
},
{
"input": "29 17 44",
"output": "1"
},
{
"input": "10 1 10",
"output": "0"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "100 100 1",
"output": "0"
},
{
"input": "11 99 55",
"output": "0"
},
{
"input": "8 13 21",
"output": "0"
},
{
"input": "34 55 89",
"output": "0"
},
{
"input": "21 34 55",
"output": "1"
},
{
"input": "13 21 34",
"output": "1"
},
{
"input": "34 21 55",
"output": "0"
},
{
"input": "10 20 84",
"output": "1"
},
{
"input": "4 2 5",
"output": "0"
},
{
"input": "3 2 3",
"output": "0"
},
{
"input": "31 23 1",
"output": "0"
},
{
"input": "100 100 100",
"output": "0"
},
{
"input": "100 1 100",
"output": "0"
},
{
"input": "1 100 100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "17 23 100",
"output": "1"
},
{
"input": "99 98 100",
"output": "1"
},
{
"input": "1 1 2",
"output": "1"
},
{
"input": "2 1 1",
"output": "0"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "2 1 2",
"output": "0"
},
{
"input": "10 10 3",
"output": "1"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "9 5 1",
"output": "0"
}
] | 1,603,086,651
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 45
| 216
| 0
|
from math import *
a,b,n=map(int,input().split())
i=0
while n>0:
if i==0:
re=gcd(a,n)
n-=re
i=1
elif i==1:
re=gcd(b,n)
n-=re
i=0
if i==1:
print(0)
else:
print(1)
|
Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given *a*, *b* and *n* who wins the game.
Input Specification:
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output Specification:
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Demo Input:
['3 5 9\n', '1 1 100\n']
Demo Output:
['0', '1']
Note:
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*.
In the first sample the game will go like that:
- Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
|
```python
from math import *
a,b,n=map(int,input().split())
i=0
while n>0:
if i==0:
re=gcd(a,n)
n-=re
i=1
elif i==1:
re=gcd(b,n)
n-=re
i=0
if i==1:
print(0)
else:
print(1)
```
| 3
|
|
777
|
B
|
Game of Credit Cards
|
PROGRAMMING
| 1,300
|
[
"data structures",
"dp",
"greedy",
"sortings"
] | null | null |
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.
Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.
Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number.
|
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
|
[
"3\n123\n321\n",
"2\n88\n00\n"
] |
[
"0\n2\n",
"2\n0\n"
] |
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
| 1,000
|
[
{
"input": "3\n123\n321",
"output": "0\n2"
},
{
"input": "2\n88\n00",
"output": "2\n0"
},
{
"input": "1\n4\n5",
"output": "0\n1"
},
{
"input": "1\n8\n7",
"output": "1\n0"
},
{
"input": "2\n55\n55",
"output": "0\n0"
},
{
"input": "3\n534\n432",
"output": "1\n1"
},
{
"input": "3\n486\n024",
"output": "2\n0"
},
{
"input": "5\n22222\n22222",
"output": "0\n0"
},
{
"input": "5\n72471\n05604",
"output": "2\n3"
},
{
"input": "5\n72471\n72471",
"output": "0\n3"
},
{
"input": "5\n72471\n41772",
"output": "0\n3"
},
{
"input": "8\n99999999\n99999999",
"output": "0\n0"
},
{
"input": "8\n01234567\n01234567",
"output": "0\n7"
},
{
"input": "8\n07070707\n76543210",
"output": "3\n4"
},
{
"input": "8\n88888888\n98769876",
"output": "4\n2"
},
{
"input": "8\n23456789\n01234567",
"output": "2\n5"
},
{
"input": "5\n11222\n22111",
"output": "1\n2"
},
{
"input": "9\n777777777\n777777777",
"output": "0\n0"
},
{
"input": "9\n353589343\n280419388",
"output": "3\n5"
},
{
"input": "10\n8104381743\n8104381743",
"output": "0\n8"
},
{
"input": "10\n8104381743\n8418134730",
"output": "0\n8"
},
{
"input": "10\n1111122222\n2222211111",
"output": "0\n5"
},
{
"input": "100\n6317494220822818719411404030346382869796138932712461187067886456209071515048745855973784223939110171\n6017563370120161528504797580620647099370814387367549926215651181421345104088127581963662589996747937",
"output": "2\n86"
},
{
"input": "200\n89017372169770060638462517044634884577600285180365791227828841983192945639410766634962149214165390392679430585962408483864914959904870801002680423351144765728677610509881245693518626747873607530273392\n34804385048475325130258121398275821439066233953856051421626677848150660724595847484466293487857039579239864150199164135152374201294909986469345076423004279983866383035554588630496127880705497919788390",
"output": "6\n175"
},
{
"input": "3\n112\n111",
"output": "1\n0"
},
{
"input": "5\n66666\n11119",
"output": "4\n1"
},
{
"input": "3\n232\n123",
"output": "1\n1"
}
] | 1,685,741,149
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 55
| 77
| 0
|
import sys
input = sys.stdin.readline
n = int(input())
s = sorted(input().strip())
m = sorted(input().strip())
lose, win = 0,0
for i in m:
if i >= s[lose]:
lose += 1
if i > s[win]:
win += 1
print(n - lose, win, sep = '\n')
|
Title: Game of Credit Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite *n*-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if *n*<==<=3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.
Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.
Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains *n* digits — Sherlock's credit card number.
The third line contains *n* digits — Moriarty's credit card number.
Output Specification:
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
Demo Input:
['3\n123\n321\n', '2\n88\n00\n']
Demo Output:
['0\n2\n', '2\n0\n']
Note:
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
|
```python
import sys
input = sys.stdin.readline
n = int(input())
s = sorted(input().strip())
m = sorted(input().strip())
lose, win = 0,0
for i in m:
if i >= s[lose]:
lose += 1
if i > s[win]:
win += 1
print(n - lose, win, sep = '\n')
```
| 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,669,191,618
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 92
| 0
|
m,n=map(int,input().split())
k=n*m//2
print(k)
|
Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none
|
```python
m,n=map(int,input().split())
k=n*m//2
print(k)
```
| 3.977
|
847
|
G
|
University Classes
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
|
Print minimum number of rooms needed to hold all groups classes on Monday.
|
[
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n"
] |
[
"1\n",
"3\n"
] |
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
| 0
|
[
{
"input": "2\n0101010\n1010101",
"output": "1"
},
{
"input": "3\n0101011\n0011001\n0110111",
"output": "3"
},
{
"input": "1\n0111000",
"output": "1"
},
{
"input": "1\n0000000",
"output": "0"
},
{
"input": "1\n1111111",
"output": "1"
},
{
"input": "2\n1000000\n0101000",
"output": "1"
},
{
"input": "3\n0101111\n1101011\n1010011",
"output": "3"
},
{
"input": "5\n0100101\n0000001\n0110000\n0010000\n0011110",
"output": "3"
},
{
"input": "6\n1101110\n1111011\n1101110\n0100011\n1110110\n1110100",
"output": "6"
},
{
"input": "10\n0000000\n0010000\n0000000\n0000010\n0000000\n0100001\n1000000\n0000000\n0000000\n0000000",
"output": "1"
},
{
"input": "20\n1111111\n1101011\n1111011\n0111111\n1111111\n1110111\n1111111\n1111111\n1111111\n1111111\n1110111\n1111111\n0111111\n1011111\n1111111\n1111111\n1101110\n1111111\n1111111\n1111111",
"output": "20"
}
] | 1,568,546,710
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 12
| 124
| 0
|
a = int(input())
i = 0
s = 0
while i < a :
i+=1
x = int(input())
s += x
##print(s)
c1 = s // 1000000
c2 = s // 100000 -10*c1
c3 = s // 10000 -100*c1 -10*c2
c4 = s // 1000 -1000*c1 -100*c2 - 10*c3
c7 = s % 10
c6 = (s % 100 - c7)//10
c5 = (s % 1000 - c6*10 -c7)//100
##print(c1,c2,c3,c4,c5,c6,c7)
if c1 < c2 :
c1 = c2
if c3 < c4 :
c3 = c4
if c5 < c6 :
c5 = c6
if c1 < c3 :
c1 = c3
if c5 < c7 :
c5 = c7
if c1 < c5 :
c1 = c5
print(c1)
# Sun Sep 15 2019 14:25:09 GMT+0300 (MSK)
|
Title: University Classes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the minimum number of rooms needed to hold classes for all groups on Monday. Note that one room can hold at most one group class in a single time slot.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot. In the other case, the group has no class in the corresponding time slot.
Output Specification:
Print minimum number of rooms needed to hold all groups classes on Monday.
Demo Input:
['2\n0101010\n1010101\n', '3\n0101011\n0011001\n0110111\n']
Demo Output:
['1\n', '3\n']
Note:
In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes.
|
```python
a = int(input())
i = 0
s = 0
while i < a :
i+=1
x = int(input())
s += x
##print(s)
c1 = s // 1000000
c2 = s // 100000 -10*c1
c3 = s // 10000 -100*c1 -10*c2
c4 = s // 1000 -1000*c1 -100*c2 - 10*c3
c7 = s % 10
c6 = (s % 100 - c7)//10
c5 = (s % 1000 - c6*10 -c7)//100
##print(c1,c2,c3,c4,c5,c6,c7)
if c1 < c2 :
c1 = c2
if c3 < c4 :
c3 = c4
if c5 < c6 :
c5 = c6
if c1 < c3 :
c1 = c3
if c5 < c7 :
c5 = c7
if c1 < c5 :
c1 = c5
print(c1)
# Sun Sep 15 2019 14:25:09 GMT+0300 (MSK)
```
| 0
|
|
340
|
A
|
The Wall
|
PROGRAMMING
| 1,200
|
[
"math"
] | null | null |
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
|
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
|
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
|
[
"2 3 6 18\n"
] |
[
"3"
] |
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
| 500
|
[
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5",
"output": "0"
},
{
"input": "555 777 1 1000000",
"output": "257"
},
{
"input": "1000 1000 1 32323",
"output": "32"
},
{
"input": "45 125 93451125 100000000",
"output": "5821"
},
{
"input": "101 171 1 1000000000",
"output": "57900"
},
{
"input": "165 255 69696 1000000000",
"output": "356482"
},
{
"input": "555 777 666013 1000000000",
"output": "257229"
},
{
"input": "23 46 123321 900000000",
"output": "19562537"
},
{
"input": "321 123 15 1000000",
"output": "75"
},
{
"input": "819 1000 9532 152901000",
"output": "186"
},
{
"input": "819 1000 10000 1000000",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 1000003",
"output": "500001"
},
{
"input": "1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "10 15 69 195610342",
"output": "6520342"
},
{
"input": "2 1 1 1000000000",
"output": "500000000"
},
{
"input": "1000 1000 1 20",
"output": "0"
},
{
"input": "1 1 1 2000000000",
"output": "2000000000"
},
{
"input": "1 2 1 2000000000",
"output": "1000000000"
},
{
"input": "2 1 1 2000000000",
"output": "1000000000"
},
{
"input": "2 3 1 1000000000",
"output": "166666666"
},
{
"input": "2 3 1 2000000000",
"output": "333333333"
},
{
"input": "3 7 1 1000000000",
"output": "47619047"
},
{
"input": "1 1 1000000000 2000000000",
"output": "1000000001"
},
{
"input": "2 2 1 2000000000",
"output": "1000000000"
},
{
"input": "1 1 2 2000000000",
"output": "1999999999"
},
{
"input": "3 2 1 2000000000",
"output": "333333333"
},
{
"input": "1 1 2000000000 2000000000",
"output": "1"
},
{
"input": "2 3 7 7",
"output": "0"
},
{
"input": "3 3 3 7",
"output": "2"
}
] | 1,418,080,288
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 35
| 124
| 0
|
def main():
x, y, a, b = map(int, input().split())
u, v = x, y
while v:
u, v = v, u % v
v = x * y // u
print(b // v - (a - 1) // v)
if __name__ == '__main__':
main()
|
Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
Input Specification:
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output Specification:
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
Demo Input:
['2 3 6 18\n']
Demo Output:
['3']
Note:
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
|
```python
def main():
x, y, a, b = map(int, input().split())
u, v = x, y
while v:
u, v = v, u % v
v = x * y // u
print(b // v - (a - 1) // v)
if __name__ == '__main__':
main()
```
| 3
|
|
712
|
A
|
Memory and Crow
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
|
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
|
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
|
[
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] |
[
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] |
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
| 500
|
[
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10\n1 -1 1 -1 1 -1 1 -1 1 -1",
"output": "0 0 0 0 0 0 0 0 0 -1 "
},
{
"input": "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 0 0 0 0 0 0 0 0 1000000000 "
},
{
"input": "10\n124 532 -642 6482 -124 952 -235 7594 34 -12",
"output": "656 -110 5840 6358 828 717 7359 7628 22 -12 "
},
{
"input": "10\n1294 35852 32749 537295 12048 53729 29357 58320 64739 1240",
"output": "37146 68601 570044 549343 65777 83086 87677 123059 65979 1240 "
}
] | 1,615,842,845
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 49
| 265
| 8,499,200
|
num = int(input())
arr = list(map(int, input().split())) + [0]
ans = []
for i in range(num):
ans.append(arr[i]+arr[i+1])
print(*ans)
|
Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3....
Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it?
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number.
Output Specification:
Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type.
Demo Input:
['5\n6 -4 8 -2 3\n', '5\n3 -2 -1 5 6\n']
Demo Output:
['2 4 6 1 3 \n', '1 -3 4 11 6 \n']
Note:
In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.
|
```python
num = int(input())
arr = list(map(int, input().split())) + [0]
ans = []
for i in range(num):
ans.append(arr[i]+arr[i+1])
print(*ans)
```
| 3
|
|
146
|
A
|
Lucky Ticket
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
|
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
|
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
|
[
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] |
[
"NO\n",
"NO\n",
"YES\n"
] |
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number.
| 500
|
[
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
{
"input": "20\n44444444444444444444",
"output": "YES"
},
{
"input": "2\n44",
"output": "YES"
},
{
"input": "10\n4745474547",
"output": "NO"
},
{
"input": "14\n77770004444444",
"output": "NO"
},
{
"input": "10\n4747777744",
"output": "YES"
},
{
"input": "10\n1234567890",
"output": "NO"
},
{
"input": "50\n44444444444444444444444444444444444444444444444444",
"output": "YES"
},
{
"input": "50\n44444444444444444444444444444444444444444444444447",
"output": "NO"
},
{
"input": "50\n74444444444444444444444444444444444444444444444444",
"output": "NO"
},
{
"input": "50\n07777777777777777777777777777777777777777777777770",
"output": "NO"
},
{
"input": "50\n77777777777777777777777777777777777777777777777777",
"output": "YES"
},
{
"input": "50\n44747747774474747747747447777447774747447477444474",
"output": "YES"
},
{
"input": "48\n447474444777444474747747744774447444747474774474",
"output": "YES"
},
{
"input": "32\n74474474777444474444747774474774",
"output": "YES"
},
{
"input": "40\n4747777444447747777447447747447474774777",
"output": "YES"
},
{
"input": "10\n4477477444",
"output": "YES"
},
{
"input": "18\n447747474447744747",
"output": "YES"
},
{
"input": "26\n44747744444774744774474447",
"output": "YES"
},
{
"input": "50\n44707747774474747747747447777447774747447477444474",
"output": "NO"
},
{
"input": "40\n4747777444447737777447447747447474774777",
"output": "NO"
},
{
"input": "36\n764477744747444444447747747474744444",
"output": "NO"
},
{
"input": "22\n4477407474777477744447",
"output": "NO"
},
{
"input": "32\n74274474777444474444747774474774",
"output": "NO"
},
{
"input": "16\n4744447974444747",
"output": "NO"
},
{
"input": "2\n11",
"output": "NO"
},
{
"input": "2\n22",
"output": "NO"
},
{
"input": "2\n33",
"output": "NO"
},
{
"input": "2\n74",
"output": "NO"
},
{
"input": "2\n55",
"output": "NO"
},
{
"input": "2\n66",
"output": "NO"
},
{
"input": "2\n77",
"output": "YES"
},
{
"input": "2\n88",
"output": "NO"
},
{
"input": "2\n99",
"output": "NO"
},
{
"input": "4\n4004",
"output": "NO"
},
{
"input": "14\n00077774444444",
"output": "NO"
},
{
"input": "6\n004444",
"output": "NO"
},
{
"input": "4\n0044",
"output": "NO"
},
{
"input": "14\n77771114444444",
"output": "NO"
},
{
"input": "14\n44444447777000",
"output": "NO"
},
{
"input": "6\n004774",
"output": "NO"
}
] | 1,646,652,413
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 46
| 92
| 0
|
n =int(input())
m = input()
lis1 = []
lis2 = []
c = True
c2 = True
for i in range(int(n/2)):
lis1.append(m[i])
for j in range(int(n/2) , n):
lis2.append(m[j])
for k in range(int(n/2)):
lis1[k] = int(lis1[k])
if int(lis1[k]) == 4 or lis1[k] == 7:
c = True
else:
c= False
break
for o in range(int(n/2)):
lis2[o] = int(lis2[o])
if int(lis2[o]) == 4 or int(lis2[o]) == 7:
c2 = True
else:
c2= False
break
if c and c2 :
if sum(lis1) == sum(lis2):
print("YES")
else:
print("NO")
else:
print("NO")
|
Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky.
Input Specification:
The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros.
Output Specification:
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['2\n47\n', '4\n4738\n', '4\n4774\n']
Demo Output:
['NO\n', 'NO\n', 'YES\n']
Note:
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number.
|
```python
n =int(input())
m = input()
lis1 = []
lis2 = []
c = True
c2 = True
for i in range(int(n/2)):
lis1.append(m[i])
for j in range(int(n/2) , n):
lis2.append(m[j])
for k in range(int(n/2)):
lis1[k] = int(lis1[k])
if int(lis1[k]) == 4 or lis1[k] == 7:
c = True
else:
c= False
break
for o in range(int(n/2)):
lis2[o] = int(lis2[o])
if int(lis2[o]) == 4 or int(lis2[o]) == 7:
c2 = True
else:
c2= False
break
if c and c2 :
if sum(lis1) == sum(lis2):
print("YES")
else:
print("NO")
else:
print("NO")
```
| 3
|
|
979
|
A
|
Pizza, Pizza, Pizza!!!
|
PROGRAMMING
| 1,000
|
[
"math"
] | null | null |
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
|
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
|
A single integer — the number of straight cuts Shiro needs.
|
[
"3\n",
"4\n"
] |
[
"2",
"5"
] |
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts.
| 500
|
[
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "3754606979"
},
{
"input": "99999999999999999",
"output": "50000000000000000"
},
{
"input": "21",
"output": "11"
},
{
"input": "712394453192",
"output": "712394453193"
},
{
"input": "172212168",
"output": "172212169"
},
{
"input": "822981260158260519",
"output": "411490630079130260"
},
{
"input": "28316250877914571",
"output": "14158125438957286"
},
{
"input": "779547116602436424",
"output": "779547116602436425"
},
{
"input": "578223540024979436",
"output": "578223540024979437"
},
{
"input": "335408917861648766",
"output": "335408917861648767"
},
{
"input": "74859962623690078",
"output": "74859962623690079"
},
{
"input": "252509054433933439",
"output": "126254527216966720"
},
{
"input": "760713016476190622",
"output": "760713016476190623"
},
{
"input": "919845426262703496",
"output": "919845426262703497"
},
{
"input": "585335723211047194",
"output": "585335723211047195"
},
{
"input": "522842184971407769",
"output": "261421092485703885"
},
{
"input": "148049062628894320",
"output": "148049062628894321"
},
{
"input": "84324828731963974",
"output": "84324828731963975"
},
{
"input": "354979173822804781",
"output": "177489586911402391"
},
{
"input": "1312150450968413",
"output": "656075225484207"
},
{
"input": "269587449430302150",
"output": "269587449430302151"
},
{
"input": "645762258982631926",
"output": "645762258982631927"
},
{
"input": "615812229161735895",
"output": "307906114580867948"
},
{
"input": "0",
"output": "0"
},
{
"input": "349993004923078531",
"output": "174996502461539266"
},
{
"input": "891351282707723851",
"output": "445675641353861926"
},
{
"input": "563324731189330734",
"output": "563324731189330735"
},
{
"input": "520974001910286909",
"output": "260487000955143455"
},
{
"input": "666729339802329204",
"output": "666729339802329205"
},
{
"input": "856674611404539671",
"output": "428337305702269836"
},
{
"input": "791809296303238499",
"output": "395904648151619250"
},
{
"input": "711066337317063338",
"output": "711066337317063339"
},
{
"input": "931356503492686566",
"output": "931356503492686567"
},
{
"input": "234122432773361866",
"output": "234122432773361867"
},
{
"input": "1000000000000000000",
"output": "1000000000000000001"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{
"input": "63",
"output": "32"
},
{
"input": "24",
"output": "25"
},
{
"input": "8",
"output": "9"
},
{
"input": "15",
"output": "8"
}
] | 1,564,558,575
| 2,147,483,647
|
PyPy 3
|
OK
|
TESTS
| 47
| 155
| 0
|
n=int(input())
if n==0:
print(0)
else:
if (n+1)%2==0:
print((n+1)//2)
else:
print((n + 1))
|
Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.
She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.
Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.
As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?
Input Specification:
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
Output Specification:
A single integer — the number of straight cuts Shiro needs.
Demo Input:
['3\n', '4\n']
Demo Output:
['2', '5']
Note:
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts.
|
```python
n=int(input())
if n==0:
print(0)
else:
if (n+1)%2==0:
print((n+1)//2)
else:
print((n + 1))
```
| 3
|
|
248
|
A
|
Cupboards
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
|
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
|
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
|
[
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] |
[
"3\n"
] |
none
| 500
|
[
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1",
"output": "6"
},
{
"input": "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "5\n1 0\n1 0\n1 0\n0 1\n0 1",
"output": "4"
}
] | 1,595,434,283
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 57
| 248
| 6,656,000
|
n=int(input())
u=v=0
for i in range(n):
a,b =map(int, input().split())
u+=a
v+=b
x=min(u,n-u)
y=min(v,n-v)
print(x+y)
|
Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position.
Your task is to write a program that will determine the required number of seconds *t*.
Input Specification:
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero.
The numbers in the lines are separated by single spaces.
Output Specification:
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
Demo Input:
['5\n0 1\n1 0\n0 1\n1 1\n0 1\n']
Demo Output:
['3\n']
Note:
none
|
```python
n=int(input())
u=v=0
for i in range(n):
a,b =map(int, input().split())
u+=a
v+=b
x=min(u,n-u)
y=min(v,n-v)
print(x+y)
```
| 3
|
|
940
|
B
|
Our Tanya is Crying Out Loud
|
PROGRAMMING
| 1,400
|
[
"dp",
"greedy"
] | null | null |
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
|
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
|
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
|
[
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] |
[
"6\n",
"8\n",
"12\n"
] |
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
| 1,250
|
[
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
"output": "16032999235141416"
},
{
"input": "777888456\n1\n98\n43",
"output": "76233068590"
},
{
"input": "1162261467\n3\n1\n2000000000",
"output": "1162261466"
},
{
"input": "1000000000\n1999999999\n789987\n184569875",
"output": "789986999210013"
},
{
"input": "2000000000\n2\n1\n2000000000",
"output": "1999999999"
},
{
"input": "1999888325\n3\n2\n2000000000",
"output": "3333258884"
},
{
"input": "1897546487\n687\n89798979\n879876541",
"output": "110398404423"
},
{
"input": "20\n1\n20\n1",
"output": "380"
},
{
"input": "16\n5\n17\n3",
"output": "54"
},
{
"input": "19\n19\n19\n1",
"output": "1"
},
{
"input": "18\n2\n3\n16",
"output": "40"
},
{
"input": "1\n11\n8\n9",
"output": "0"
},
{
"input": "9\n10\n1\n20",
"output": "8"
},
{
"input": "19\n10\n19\n2",
"output": "173"
},
{
"input": "16\n9\n14\n2",
"output": "100"
},
{
"input": "15\n2\n5\n2",
"output": "21"
},
{
"input": "14\n7\n13\n1",
"output": "14"
},
{
"input": "43\n3\n45\n3",
"output": "189"
},
{
"input": "99\n1\n98\n1",
"output": "9604"
},
{
"input": "77\n93\n100\n77",
"output": "7600"
},
{
"input": "81\n3\n91\n95",
"output": "380"
},
{
"input": "78\n53\n87\n34",
"output": "2209"
},
{
"input": "80\n3\n15\n1",
"output": "108"
},
{
"input": "97\n24\n4\n24",
"output": "40"
},
{
"input": "100\n100\n1\n100",
"output": "99"
},
{
"input": "87\n4\n17\n7",
"output": "106"
},
{
"input": "65\n2\n3\n6",
"output": "36"
},
{
"input": "1000000\n1435\n3\n999999",
"output": "1005804"
},
{
"input": "783464\n483464\n2\n966928",
"output": "1566926"
},
{
"input": "248035\n11\n3\n20",
"output": "202"
},
{
"input": "524287\n2\n945658\n999756",
"output": "34963354"
},
{
"input": "947352\n78946\n85\n789654",
"output": "790589"
},
{
"input": "1000000\n1\n999899\n60",
"output": "999898000101"
},
{
"input": "753687\n977456\n6547\n456",
"output": "4934382242"
},
{
"input": "1000000\n500000\n1\n999997",
"output": "999998"
},
{
"input": "997458\n843596\n1\n843596",
"output": "997457"
},
{
"input": "821109\n92\n6547\n98787",
"output": "394566"
},
{
"input": "1073741823\n2\n9543\n8923453",
"output": "188412866"
},
{
"input": "1000999777\n1934999345\n2356346\n34534565",
"output": "2358701818178496"
},
{
"input": "2000000000\n1\n2000000000\n98",
"output": "3999999998000000000"
},
{
"input": "1999324353\n978435356\n1\n978435356",
"output": "1020888998"
},
{
"input": "2000000000\n2\n2000000000\n2000000000",
"output": "84000000000"
},
{
"input": "241375690\n17\n2\n1998789654",
"output": "482751378"
},
{
"input": "171507000\n350\n789\n6548687",
"output": "14216965"
},
{
"input": "1100220011\n10001\n2\n1999778654",
"output": "1999998674"
},
{
"input": "1867622656\n43216\n789644\n12315468",
"output": "24630936"
},
{
"input": "1867622656\n43216\n1\n1879865413",
"output": "1867622655"
},
{
"input": "1999999999\n1000000000\n789987\n184569875",
"output": "789987183779888"
},
{
"input": "1987987897\n103546\n7\n98754563",
"output": "98946650"
},
{
"input": "10\n2\n2\n5",
"output": "13"
},
{
"input": "7\n2\n1\n100000",
"output": "6"
},
{
"input": "7\n2\n3\n1",
"output": "8"
},
{
"input": "2000000000\n666666667\n1\n1",
"output": "666666668"
},
{
"input": "1999999997\n666666666\n2\n2",
"output": "1333333334"
}
] | 1,590,408,549
| 2,147,483,647
|
PyPy 3
|
WRONG_ANSWER
|
TESTS
| 0
| 109
| 0
|
def solve(n,k,a,b):
ans = 0
while n != 1:
if n < k:
ans += (n-1)*a
n = 1
elif n%k != 0:
n -= n%k
ans += (n%k) *a
else:
if b < (n-n//k)*a:
n /= k
ans += b
else:
n /= k
ans += (n-n//k)*a
print(int(ans))
if __name__ == '__main__':
n = int(input())
k = int(input())
a = int(input())
b = int(input())
solve(n,k,a,b)
|
Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output Specification:
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
Demo Input:
['9\n2\n3\n1\n', '5\n5\n2\n20\n', '19\n3\n4\n2\n']
Demo Output:
['6\n', '8\n', '12\n']
Note:
In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtract 1 from *x* 4 times paying 8 coins in total.
|
```python
def solve(n,k,a,b):
ans = 0
while n != 1:
if n < k:
ans += (n-1)*a
n = 1
elif n%k != 0:
n -= n%k
ans += (n%k) *a
else:
if b < (n-n//k)*a:
n /= k
ans += b
else:
n /= k
ans += (n-n//k)*a
print(int(ans))
if __name__ == '__main__':
n = int(input())
k = int(input())
a = int(input())
b = int(input())
solve(n,k,a,b)
```
| 0
|
|
124
|
B
|
Permutations
|
PROGRAMMING
| 1,400
|
[
"brute force",
"combinatorics",
"implementation"
] | null | null |
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
|
The first line contains integers *n* and *k* — the number and digit capacity of numbers correspondingly (1<=≤<=*n*,<=*k*<=≤<=8). Next *n* lines contain *k*-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.
|
Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.
|
[
"6 4\n5237\n2753\n7523\n5723\n5327\n2537\n",
"3 3\n010\n909\n012\n",
"7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156\n"
] |
[
"2700\n",
"3\n",
"20522\n"
] |
In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).
In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102.
| 1,000
|
[
{
"input": "6 4\n5237\n2753\n7523\n5723\n5327\n2537",
"output": "2700"
},
{
"input": "3 3\n010\n909\n012",
"output": "3"
},
{
"input": "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156",
"output": "20522"
},
{
"input": "5 5\n61374\n74304\n41924\n46010\n09118",
"output": "64592"
},
{
"input": "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116",
"output": "52901157"
},
{
"input": "7 1\n1\n0\n8\n5\n4\n9\n8",
"output": "9"
},
{
"input": "3 8\n34848224\n16307102\n25181102",
"output": "8612277"
},
{
"input": "2 8\n13633861\n68468345",
"output": "14445725"
},
{
"input": "4 4\n0950\n0634\n9264\n8684",
"output": "3738"
},
{
"input": "6 5\n65777\n80932\n32260\n49089\n00936\n85557",
"output": "41439"
},
{
"input": "5 6\n687443\n279213\n765651\n611680\n500192",
"output": "258067"
},
{
"input": "8 6\n034753\n917195\n222679\n778596\n980006\n467267\n482763\n807481",
"output": "647026"
},
{
"input": "8 6\n075967\n240855\n352399\n791547\n103244\n982259\n409866\n926586",
"output": "491255"
},
{
"input": "3 1\n7\n2\n9",
"output": "7"
},
{
"input": "6 4\n5407\n4617\n3050\n7647\n8647\n1993",
"output": "6474"
},
{
"input": "8 5\n47553\n55138\n81768\n78902\n50691\n73010\n93969\n01675",
"output": "71123"
},
{
"input": "8 7\n5945843\n9094433\n0750024\n6255984\n1784849\n7275947\n6513944\n0145523",
"output": "5152379"
},
{
"input": "8 7\n8112819\n8982110\n5457941\n4575033\n5203331\n7410823\n0532182\n8151054",
"output": "6194602"
},
{
"input": "8 8\n63315032\n20587190\n05461152\n76872565\n71177578\n53541174\n00451913\n85740357",
"output": "60622457"
},
{
"input": "2 3\n135\n725",
"output": "4"
},
{
"input": "7 1\n9\n5\n8\n9\n7\n6\n9",
"output": "4"
},
{
"input": "5 3\n560\n978\n543\n846\n714",
"output": "435"
},
{
"input": "7 2\n53\n74\n84\n62\n14\n77\n59",
"output": "69"
},
{
"input": "3 4\n0537\n2174\n5299",
"output": "3583"
},
{
"input": "7 5\n13532\n16394\n97663\n73133\n22712\n58185\n65035",
"output": "26455"
},
{
"input": "8 5\n07936\n07927\n46068\n99158\n90958\n41283\n59266\n87841",
"output": "52364"
},
{
"input": "8 6\n867468\n695388\n700723\n444270\n545657\n178053\n315040\n554471",
"output": "559559"
},
{
"input": "7 7\n6575460\n6965366\n1912357\n7080608\n2561692\n5209630\n0439095",
"output": "5917123"
},
{
"input": "1 2\n96",
"output": "0"
},
{
"input": "1 3\n289",
"output": "0"
},
{
"input": "1 8\n78795220",
"output": "0"
},
{
"input": "8 7\n2407792\n7023368\n2609925\n0587109\n3543873\n6602371\n4579875\n9893509",
"output": "6790457"
},
{
"input": "4 6\n065169\n150326\n924608\n490012",
"output": "488134"
},
{
"input": "4 4\n8851\n6190\n0521\n1659",
"output": "6596"
},
{
"input": "4 4\n4381\n3147\n7017\n5593",
"output": "3690"
},
{
"input": "8 4\n0344\n9196\n1379\n5470\n0989\n8316\n7096\n7918",
"output": "7801"
},
{
"input": "1 6\n430254",
"output": "0"
},
{
"input": "8 1\n4\n0\n8\n5\n9\n0\n4\n7",
"output": "9"
},
{
"input": "5 2\n60\n08\n77\n66\n03",
"output": "74"
},
{
"input": "3 1\n9\n8\n2",
"output": "7"
},
{
"input": "7 2\n89\n00\n59\n90\n99\n22\n55",
"output": "99"
},
{
"input": "2 4\n7694\n6577",
"output": "712"
},
{
"input": "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116",
"output": "52901157"
},
{
"input": "2 7\n9183508\n9276377",
"output": "26912"
},
{
"input": "5 4\n7411\n3080\n9578\n5902\n3225",
"output": "6498"
},
{
"input": "3 4\n0136\n4556\n4268",
"output": "2134"
},
{
"input": "6 8\n99358096\n38390629\n71597322\n35940809\n48949759\n66204248",
"output": "53570178"
},
{
"input": "7 2\n23\n11\n88\n25\n22\n45\n10",
"output": "78"
},
{
"input": "2 3\n834\n630",
"output": "24"
},
{
"input": "4 2\n87\n03\n95\n23",
"output": "48"
},
{
"input": "2 8\n10715643\n97664296",
"output": "1244714"
},
{
"input": "6 1\n9\n3\n1\n3\n4\n5",
"output": "8"
},
{
"input": "8 5\n47553\n55138\n81768\n78902\n50691\n73010\n93969\n01675",
"output": "71123"
},
{
"input": "4 4\n7603\n0859\n5241\n7680",
"output": "5518"
},
{
"input": "1 7\n4605461",
"output": "0"
},
{
"input": "3 4\n3061\n3404\n6670",
"output": "2916"
},
{
"input": "8 4\n1847\n0962\n3216\n0772\n6399\n3082\n7997\n0625",
"output": "7246"
},
{
"input": "2 6\n834527\n764560",
"output": "577"
},
{
"input": "5 6\n959808\n303464\n414335\n758650\n828038",
"output": "486245"
},
{
"input": "4 1\n0\n7\n5\n1",
"output": "7"
},
{
"input": "6 7\n4565736\n9842969\n1412800\n6411011\n5744909\n3791659",
"output": "4066781"
},
{
"input": "4 1\n0\n7\n5\n1",
"output": "7"
},
{
"input": "1 3\n250",
"output": "0"
},
{
"input": "2 1\n2\n0",
"output": "2"
},
{
"input": "8 8\n96805230\n73119021\n06552907\n86283347\n88650846\n19155689\n37032451\n19310120",
"output": "53604668"
},
{
"input": "3 2\n64\n94\n65",
"output": "10"
},
{
"input": "8 4\n8008\n4983\n0295\n0353\n5838\n1960\n0270\n7144",
"output": "7475"
},
{
"input": "4 8\n22025344\n54085308\n77633421\n59238322",
"output": "7681556"
},
{
"input": "5 3\n504\n878\n599\n683\n083",
"output": "615"
},
{
"input": "5 4\n7663\n4755\n2941\n4588\n0232",
"output": "5346"
},
{
"input": "6 2\n97\n57\n40\n99\n22\n94",
"output": "77"
},
{
"input": "6 7\n4104025\n1370353\n3472874\n5258456\n5595923\n0279404",
"output": "2790148"
},
{
"input": "8 2\n42\n86\n25\n30\n27\n64\n67\n38",
"output": "61"
},
{
"input": "5 2\n52\n22\n05\n37\n74",
"output": "51"
},
{
"input": "2 2\n63\n50",
"output": "13"
},
{
"input": "6 7\n4104025\n1370353\n3472874\n5258456\n5595923\n0279404",
"output": "2790148"
},
{
"input": "6 2\n95\n56\n06\n46\n77\n51",
"output": "62"
},
{
"input": "3 5\n97424\n96460\n47766",
"output": "9536"
},
{
"input": "2 3\n596\n246",
"output": "35"
},
{
"input": "3 1\n1\n2\n2",
"output": "1"
},
{
"input": "4 2\n87\n03\n95\n23",
"output": "48"
},
{
"input": "7 5\n41078\n41257\n35324\n70082\n66783\n99954\n85784",
"output": "56901"
},
{
"input": "8 7\n8943041\n2427704\n3775080\n2956111\n1345704\n0937172\n1979973\n7081540",
"output": "3544246"
},
{
"input": "6 6\n505845\n903151\n055779\n733849\n508266\n029177",
"output": "249045"
},
{
"input": "4 4\n1871\n9417\n7444\n4294",
"output": "5368"
},
{
"input": "2 5\n60106\n07866",
"output": "5224"
},
{
"input": "3 3\n195\n860\n567",
"output": "258"
},
{
"input": "8 5\n68186\n57779\n78079\n47451\n69788\n82172\n75373\n50157",
"output": "32237"
},
{
"input": "4 7\n5342341\n5194611\n4032103\n8739798",
"output": "4056779"
},
{
"input": "4 8\n91401735\n53979237\n20857777\n94594293",
"output": "34567247"
},
{
"input": "1 2\n95",
"output": "0"
},
{
"input": "6 4\n0443\n7108\n7211\n4287\n6439\n7711",
"output": "5301"
},
{
"input": "6 7\n5794383\n4078451\n0263676\n7682294\n7436158\n3363189",
"output": "3560125"
},
{
"input": "2 5\n07259\n51985",
"output": "23657"
},
{
"input": "3 3\n624\n125\n097",
"output": "247"
},
{
"input": "8 1\n9\n7\n6\n2\n9\n6\n4\n8",
"output": "7"
},
{
"input": "6 3\n530\n862\n874\n932\n972\n157",
"output": "442"
},
{
"input": "3 2\n51\n39\n97",
"output": "58"
},
{
"input": "8 4\n4650\n1735\n4269\n8023\n0948\n9685\n3675\n6017",
"output": "6836"
},
{
"input": "5 3\n168\n513\n110\n386\n501",
"output": "403"
},
{
"input": "6 2\n01\n81\n60\n27\n23\n67",
"output": "70"
},
{
"input": "4 4\n2759\n7250\n3572\n8067",
"output": "2028"
},
{
"input": "8 5\n12658\n00588\n23491\n09985\n63973\n78517\n98187\n29863",
"output": "68592"
},
{
"input": "3 1\n5\n4\n2",
"output": "3"
},
{
"input": "7 8\n24925537\n07626274\n77060131\n82415056\n70422753\n60455207\n32176884",
"output": "54680138"
},
{
"input": "5 8\n94157433\n85577189\n62547277\n11815893\n35445851",
"output": "15679126"
},
{
"input": "5 5\n31164\n27213\n17981\n48806\n01273",
"output": "33367"
},
{
"input": "3 6\n743197\n172242\n635654",
"output": "261245"
},
{
"input": "4 6\n760130\n653002\n902824\n380915",
"output": "268111"
},
{
"input": "8 8\n83239439\n62184887\n58968944\n39808261\n68740623\n38480328\n81965504\n52600488",
"output": "44481119"
},
{
"input": "8 2\n99\n20\n22\n39\n33\n60\n54\n08",
"output": "91"
},
{
"input": "1 7\n3545113",
"output": "0"
},
{
"input": "6 7\n3761949\n8095136\n4875085\n5017784\n4459097\n4354762",
"output": "4126934"
},
{
"input": "6 8\n50157346\n63836375\n03176371\n83637145\n28631038\n18617159",
"output": "24702445"
},
{
"input": "1 5\n84932",
"output": "0"
},
{
"input": "4 3\n204\n515\n280\n840",
"output": "467"
},
{
"input": "8 2\n40\n41\n02\n55\n26\n52\n60\n25",
"output": "58"
},
{
"input": "2 5\n90526\n32565",
"output": "586"
},
{
"input": "4 4\n3058\n2370\n0288\n5983",
"output": "2972"
},
{
"input": "6 7\n9085507\n7716507\n1952887\n6569746\n1900754\n9212439",
"output": "3180457"
},
{
"input": "5 2\n01\n07\n63\n71\n99",
"output": "89"
},
{
"input": "6 4\n4505\n3672\n4248\n2783\n9780\n6579",
"output": "4484"
},
{
"input": "2 3\n281\n498",
"output": "127"
},
{
"input": "8 5\n16966\n36762\n49579\n71703\n66646\n41125\n94022\n26623",
"output": "66868"
},
{
"input": "1 6\n170086",
"output": "0"
},
{
"input": "4 1\n4\n2\n2\n2",
"output": "2"
},
{
"input": "3 8\n12418144\n74773130\n10504811",
"output": "22901234"
},
{
"input": "6 7\n3761949\n8095136\n4875085\n5017784\n4459097\n4354762",
"output": "4126934"
}
] | 1,692,367,115
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 128
| 342
| 4,812,800
|
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
import itertools
MOD = 10**9+7
N,K = map(int, input().split())
S = []
for _ in range(N):
S.append(input())
def deal(p):
A = [[] for _ in range(N)]
for i in p:
for j in range(N):
A[j].append(S[j][i])
B = []
for a in A:
B.append(int(''.join(a)))
B.sort()
return B[-1]-B[0]
A = [i for i in range(K)]
ans = float('inf')
for p in itertools.permutations(A,K):
ans = min(ans, deal(p))
print(ans)
|
Title: Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.
Input Specification:
The first line contains integers *n* and *k* — the number and digit capacity of numbers correspondingly (1<=≤<=*n*,<=*k*<=≤<=8). Next *n* lines contain *k*-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.
Output Specification:
Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.
Demo Input:
['6 4\n5237\n2753\n7523\n5723\n5327\n2537\n', '3 3\n010\n909\n012\n', '7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156\n']
Demo Output:
['2700\n', '3\n', '20522\n']
Note:
In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).
In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102.
|
```python
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
import itertools
MOD = 10**9+7
N,K = map(int, input().split())
S = []
for _ in range(N):
S.append(input())
def deal(p):
A = [[] for _ in range(N)]
for i in p:
for j in range(N):
A[j].append(S[j][i])
B = []
for a in A:
B.append(int(''.join(a)))
B.sort()
return B[-1]-B[0]
A = [i for i in range(K)]
ans = float('inf')
for p in itertools.permutations(A,K):
ans = min(ans, deal(p))
print(ans)
```
| 3
|
|
677
|
A
|
Vanya and Fence
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
|
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
|
Print a single integer — the minimum possible valid width of the road.
|
[
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] |
[
"4\n",
"6\n",
"11\n"
] |
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
| 500
|
[
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481 554 1000 821",
"output": "15"
},
{
"input": "100 342\n478 143 359 336 162 333 385 515 117 496 310 538 469 539 258 676 466 677 1 296 150 560 26 213 627 221 255 126 617 174 279 178 24 435 70 145 619 46 669 566 300 67 576 251 58 176 441 564 569 194 24 669 73 262 457 259 619 78 400 579 222 626 269 47 80 315 160 194 455 186 315 424 197 246 683 220 68 682 83 233 290 664 273 598 362 305 674 614 321 575 362 120 14 534 62 436 294 351 485 396",
"output": "144"
},
{
"input": "100 290\n244 49 276 77 449 261 468 458 201 424 9 131 300 88 432 394 104 77 13 289 435 259 111 453 168 394 156 412 351 576 178 530 81 271 228 564 125 328 42 372 205 61 180 471 33 360 567 331 222 318 241 117 529 169 188 484 202 202 299 268 246 343 44 364 333 494 59 236 84 485 50 8 428 8 571 227 205 310 210 9 324 472 368 490 114 84 296 305 411 351 569 393 283 120 510 171 232 151 134 366",
"output": "145"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n2",
"output": "2"
},
{
"input": "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19",
"output": "63"
},
{
"input": "20 723\n212 602 293 591 754 91 1135 640 80 495 845 928 1399 498 926 1431 1226 869 814 1386",
"output": "31"
},
{
"input": "48 864\n843 1020 751 1694 18 1429 1395 1174 272 1158 1628 1233 1710 441 765 561 778 748 1501 1200 563 1263 1398 1687 1518 1640 1591 839 500 466 1603 1587 1201 1209 432 868 1159 639 649 628 9 91 1036 147 896 1557 941 518",
"output": "75"
},
{
"input": "26 708\n549 241 821 734 945 1161 566 1268 216 30 1142 730 529 1014 255 168 796 1148 89 113 1328 286 743 871 1259 1397",
"output": "41"
},
{
"input": "75 940\n1620 1745 1599 441 64 1466 1496 1239 1716 1475 778 106 1136 1212 1261 444 781 257 1071 747 626 232 609 1544 682 1326 469 1361 1460 1450 1207 1319 922 625 1737 1057 1698 592 692 80 1016 541 1254 201 682 1007 847 206 1066 809 259 109 240 1611 219 1455 1326 1377 1827 786 42 1002 1382 1592 543 1866 1198 334 1524 1760 340 1566 955 257 1118",
"output": "116"
}
] | 1,695,919,930
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 29
| 46
| 0
|
def rng(s,k,lst):
#s is the total number of people like minimum widith and k is the max height possible
count=s
for f in lst:
if f>k:
count+=1
return count
y=input()
alist=[int(x) for x in y.split()]
d=input()
blist=[int(x) for x in d.split()]
print(rng(alist[0],alist[1],blist))
|
Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*.
Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?
Input Specification:
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Output Specification:
Print a single integer — the minimum possible valid width of the road.
Demo Input:
['3 7\n4 5 14\n', '6 1\n1 1 1 1 1 1\n', '6 5\n7 6 8 9 10 5\n']
Demo Output:
['4\n', '6\n', '11\n']
Note:
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.
|
```python
def rng(s,k,lst):
#s is the total number of people like minimum widith and k is the max height possible
count=s
for f in lst:
if f>k:
count+=1
return count
y=input()
alist=[int(x) for x in y.split()]
d=input()
blist=[int(x) for x in d.split()]
print(rng(alist[0],alist[1],blist))
```
| 3
|
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
|
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
|
Write the needed number of flagstones.
|
[
"6 6 4\n"
] |
[
"4\n"
] |
none
| 0
|
[
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,692,902,411
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 20
| 46
| 0
|
n, m, a = map(int, input().split())
w = (n + a - 1) // a
h = (m + a - 1) // a
total = w * h
print(total)
|
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())
w = (n + a - 1) // a
h = (m + a - 1) // a
total = w * h
print(total)
```
| 3.977
|
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,607,777,572
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 102
| 109
| 0
|
x=input()
y=input()
for i in range(len(x)):
if(x[i]==y[i]):
print('0',end="")
else:
print('1',end="")
|
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
x=input()
y=input()
for i in range(len(x)):
if(x[i]==y[i]):
print('0',end="")
else:
print('1',end="")
```
| 3.97275
|
898
|
A
|
Rounding
|
PROGRAMMING
| 800
|
[
"implementation",
"math"
] | null | null |
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it.
|
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
|
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
|
[
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] |
[
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] |
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
| 500
|
[
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
},
{
"input": "9",
"output": "10"
},
{
"input": "1",
"output": "0"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "10"
},
{
"input": "7",
"output": "10"
},
{
"input": "8",
"output": "10"
},
{
"input": "19",
"output": "20"
},
{
"input": "100",
"output": "100"
},
{
"input": "997",
"output": "1000"
},
{
"input": "9994",
"output": "9990"
},
{
"input": "10002",
"output": "10000"
},
{
"input": "100000",
"output": "100000"
},
{
"input": "99999",
"output": "100000"
},
{
"input": "999999999",
"output": "1000000000"
},
{
"input": "999999998",
"output": "1000000000"
},
{
"input": "999999995",
"output": "999999990"
},
{
"input": "999999990",
"output": "999999990"
},
{
"input": "1000000",
"output": "1000000"
},
{
"input": "1000010",
"output": "1000010"
},
{
"input": "10000010",
"output": "10000010"
},
{
"input": "100000011",
"output": "100000010"
},
{
"input": "400000003",
"output": "400000000"
},
{
"input": "234234",
"output": "234230"
},
{
"input": "675621",
"output": "675620"
},
{
"input": "43532",
"output": "43530"
},
{
"input": "4576453",
"output": "4576450"
},
{
"input": "65754674",
"output": "65754670"
},
{
"input": "3245526",
"output": "3245530"
},
{
"input": "123445",
"output": "123440"
},
{
"input": "234217",
"output": "234220"
},
{
"input": "23451218",
"output": "23451220"
},
{
"input": "1231239",
"output": "1231240"
},
{
"input": "1923140",
"output": "1923140"
},
{
"input": "307910310",
"output": "307910310"
},
{
"input": "780961030",
"output": "780961030"
},
{
"input": "103509421",
"output": "103509420"
},
{
"input": "576560141",
"output": "576560140"
},
{
"input": "48851642",
"output": "48851640"
},
{
"input": "226935072",
"output": "226935070"
},
{
"input": "844450763",
"output": "844450760"
},
{
"input": "22534183",
"output": "22534180"
},
{
"input": "640049874",
"output": "640049870"
},
{
"input": "818133304",
"output": "818133300"
},
{
"input": "730616285",
"output": "730616280"
},
{
"input": "613732415",
"output": "613732410"
},
{
"input": "380991216",
"output": "380991220"
},
{
"input": "559074636",
"output": "559074640"
},
{
"input": "176590327",
"output": "176590330"
},
{
"input": "354673757",
"output": "354673760"
},
{
"input": "267156738",
"output": "267156740"
},
{
"input": "150272868",
"output": "150272870"
},
{
"input": "62755859",
"output": "62755860"
},
{
"input": "945871979",
"output": "945871980"
},
{
"input": "46",
"output": "50"
},
{
"input": "999",
"output": "1000"
},
{
"input": "1397",
"output": "1400"
}
] | 1,584,635,240
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 0
| 93
| 0
|
n=int(input())
if n%10>5:
print(n+10-(n%5))
else:
print(n-(n%5))
|
Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it.
Input Specification:
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Output Specification:
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
Demo Input:
['5\n', '113\n', '1000000000\n', '5432359\n']
Demo Output:
['0\n', '110\n', '1000000000\n', '5432360\n']
Note:
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
|
```python
n=int(input())
if n%10>5:
print(n+10-(n%5))
else:
print(n-(n%5))
```
| 0
|
|
784
|
E
|
Twisted Circuit
|
PROGRAMMING
| 2,000
|
[
"*special",
"brute force",
"implementation"
] | null | null |
The input consists of four lines, each line containing a single digit 0 or 1.
|
Output a single digit, 0 or 1.
|
[
"0\n1\n1\n0\n"
] |
[
"0\n"
] |
none
| 0
|
[
{
"input": "0\n1\n1\n0",
"output": "0"
},
{
"input": "0\n0\n0\n0",
"output": "0"
},
{
"input": "1\n0\n0\n0",
"output": "1"
},
{
"input": "0\n1\n0\n0",
"output": "0"
},
{
"input": "1\n1\n0\n0",
"output": "1"
},
{
"input": "0\n0\n1\n0",
"output": "0"
},
{
"input": "1\n0\n1\n0",
"output": "0"
},
{
"input": "1\n1\n1\n0",
"output": "1"
},
{
"input": "0\n0\n0\n1",
"output": "1"
},
{
"input": "1\n0\n0\n1",
"output": "1"
},
{
"input": "0\n1\n0\n1",
"output": "0"
},
{
"input": "1\n1\n0\n1",
"output": "0"
},
{
"input": "0\n0\n1\n1",
"output": "1"
},
{
"input": "1\n0\n1\n1",
"output": "1"
},
{
"input": "0\n1\n1\n1",
"output": "0"
},
{
"input": "1\n1\n1\n1",
"output": "1"
}
] | 1,692,431,434
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 16
| 61
| 0
|
from sys import stdin,stdout
# from os import _exit
# from bisect import bisect_left,bisect
# from heapq import heapify,heappop,heappush
# from sys import setrecursionlimit
# from collections import defaultdict,Counter
# from itertools import permutations
# from math import gcd,ceil,sqrt,factorial
# setrecursionlimit(int(1e5))
input,print = stdin.readline,stdout.write
def xor(x,y):
return (not x and y) or (not y and x)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
x = xor(a,b)
y = c or d
z = b and c
w = xor(a,d)
p = x and y
q = z or w
ans = xor(p,q)
print(str(int(ans))+"\n")
|
Title: Twisted Circuit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Input Specification:
The input consists of four lines, each line containing a single digit 0 or 1.
Output Specification:
Output a single digit, 0 or 1.
Demo Input:
['0\n1\n1\n0\n']
Demo Output:
['0\n']
Note:
none
|
```python
from sys import stdin,stdout
# from os import _exit
# from bisect import bisect_left,bisect
# from heapq import heapify,heappop,heappush
# from sys import setrecursionlimit
# from collections import defaultdict,Counter
# from itertools import permutations
# from math import gcd,ceil,sqrt,factorial
# setrecursionlimit(int(1e5))
input,print = stdin.readline,stdout.write
def xor(x,y):
return (not x and y) or (not y and x)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
x = xor(a,b)
y = c or d
z = b and c
w = xor(a,d)
p = x and y
q = z or w
ans = xor(p,q)
print(str(int(ans))+"\n")
```
| 3
|
||
938
|
D
|
Buy a Ticket
|
PROGRAMMING
| 2,000
|
[
"data structures",
"graphs",
"shortest paths"
] | null | null |
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route.
Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins.
You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large.
|
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105).
Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input.
The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city.
|
Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
|
[
"4 2\n1 2 4\n2 3 7\n6 20 1 25\n",
"3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n"
] |
[
"6 14 1 25 \n",
"12 10 12 \n"
] |
none
| 0
|
[
{
"input": "4 2\n1 2 4\n2 3 7\n6 20 1 25",
"output": "6 14 1 25 "
},
{
"input": "3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20",
"output": "12 10 12 "
},
{
"input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 187389745 21385 704393",
"output": "1 335807 7498159 335769 53373 21385 663675 "
}
] | 1,601,356,328
| 2,147,483,647
|
Python 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 2
| 2,000
| 70,860,800
|
class Edge:
def __init__(self, s, d, w):
self.source = s
self.destination = d
self.weight = w
self.next = None
class Solution:
def find_min_vertex(self):
min_index = -1
for i in range(self.len):
if not self.visited[i]:
if min_index == -1 or self.result[min_index] > self.result[i]:
min_index = i
return min_index
def solve(self, A, B):
n = len(A)
self.len = n
self.graph = [0 for index in range(n)]
self.result = A
self.visited = [False for index in range(n)]
for edge in B:
if self.graph[edge[0]-1] == 0:
self.graph[edge[0]-1] = Edge(edge[0]-1, edge[1]-1, edge[2])
else:
t = self.graph[edge[0]-1]
while t:
if t.next is None:
t.next = Edge(edge[0]-1, edge[1]-1, edge[2])
t = None
else:
t = t.next
if self.graph[edge[1] - 1] == 0:
self.graph[edge[1] - 1] = Edge(edge[1] - 1, edge[0] - 1, edge[2])
else:
t = self.graph[edge[1] - 1]
while t:
if t.next is None:
t.next = Edge(edge[0]-1, edge[1]-1, edge[2])
t = None
else:
t = t.next
for index in range(n):
minVertex = self.find_min_vertex()
self.visited[minVertex] = True
t = self.graph[minVertex]
while t:
ans = (2*t.weight) + A[t.destination]
if ans < self.result[minVertex]:
self.result[minVertex] = ans
# self.traverse_min(minVertex,t.destination,A)
t = t.next
print(*self.result)
if __name__ == "__main__":
num = input().split(" ")
B = []
for i in range(int(num[1])):
r= []
r = list(map(int, input().split(" ")))
B.append(r)
A = list(map(int,input().split(" ")))
s = Solution()
s.solve(A,B)
|
Title: Buy a Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Musicians of a popular band "Flayer" have announced that they are going to "make their exit" with a world tour. Of course, they will visit Berland as well.
There are *n* cities in Berland. People can travel between cities using two-directional train routes; there are exactly *m* routes, *i*-th route can be used to go from city *v**i* to city *u**i* (and from *u**i* to *v**i*), and it costs *w**i* coins to use this route.
Each city will be visited by "Flayer", and the cost of the concert ticket in *i*-th city is *a**i* coins.
You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city *i* you have to compute the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Formally, for every you have to calculate , where *d*(*i*,<=*j*) is the minimum number of coins you have to spend to travel from city *i* to city *j*. If there is no way to reach city *j* from city *i*, then we consider *d*(*i*,<=*j*) to be infinitely large.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, 1<=≤<=*m*<=≤<=2·105).
Then *m* lines follow, *i*-th contains three integers *v**i*, *u**i* and *w**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*,<=*v**i*<=≠<=*u**i*, 1<=≤<=*w**i*<=≤<=1012) denoting *i*-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (*v*,<=*u*) neither extra (*v*,<=*u*) nor (*u*,<=*v*) present in input.
The next line contains *n* integers *a*1,<=*a*2,<=... *a**k* (1<=≤<=*a**i*<=≤<=1012) — price to attend the concert in *i*-th city.
Output Specification:
Print *n* integers. *i*-th of them must be equal to the minimum number of coins a person from city *i* has to spend to travel to some city *j* (or possibly stay in city *i*), attend a concert there, and return to city *i* (if *j*<=≠<=*i*).
Demo Input:
['4 2\n1 2 4\n2 3 7\n6 20 1 25\n', '3 3\n1 2 1\n2 3 1\n1 3 1\n30 10 20\n']
Demo Output:
['6 14 1 25 \n', '12 10 12 \n']
Note:
none
|
```python
class Edge:
def __init__(self, s, d, w):
self.source = s
self.destination = d
self.weight = w
self.next = None
class Solution:
def find_min_vertex(self):
min_index = -1
for i in range(self.len):
if not self.visited[i]:
if min_index == -1 or self.result[min_index] > self.result[i]:
min_index = i
return min_index
def solve(self, A, B):
n = len(A)
self.len = n
self.graph = [0 for index in range(n)]
self.result = A
self.visited = [False for index in range(n)]
for edge in B:
if self.graph[edge[0]-1] == 0:
self.graph[edge[0]-1] = Edge(edge[0]-1, edge[1]-1, edge[2])
else:
t = self.graph[edge[0]-1]
while t:
if t.next is None:
t.next = Edge(edge[0]-1, edge[1]-1, edge[2])
t = None
else:
t = t.next
if self.graph[edge[1] - 1] == 0:
self.graph[edge[1] - 1] = Edge(edge[1] - 1, edge[0] - 1, edge[2])
else:
t = self.graph[edge[1] - 1]
while t:
if t.next is None:
t.next = Edge(edge[0]-1, edge[1]-1, edge[2])
t = None
else:
t = t.next
for index in range(n):
minVertex = self.find_min_vertex()
self.visited[minVertex] = True
t = self.graph[minVertex]
while t:
ans = (2*t.weight) + A[t.destination]
if ans < self.result[minVertex]:
self.result[minVertex] = ans
# self.traverse_min(minVertex,t.destination,A)
t = t.next
print(*self.result)
if __name__ == "__main__":
num = input().split(" ")
B = []
for i in range(int(num[1])):
r= []
r = list(map(int, input().split(" ")))
B.append(r)
A = list(map(int,input().split(" ")))
s = Solution()
s.solve(A,B)
```
| 0
|
|
545
|
C
|
Woodcutters
|
PROGRAMMING
| 1,500
|
[
"dp",
"greedy"
] | null | null |
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
|
Print a single number — the maximum number of trees that you can cut down by the given rules.
|
[
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] |
[
"3\n",
"4\n"
] |
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
| 1,750
|
[
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,666,861,330
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 67
| 655
| 13,107,200
|
n=int(input())
jk=0
jl=0
x=[] #pos of trees 0_n-1
h=[] #height of trees 0_n-1
for i in range(n):#input
jk,jl=[int(x) for x in input().split()]
x.append(jk)
h.append(jl)
x=[-10000000000000000]+x+[1000000000000000]#pos of trees 1_n
h=[0]+h+[0]#height of trees 1_n
s=0
for i in range(1,n+1):#1_n
if x[i]-x[i-1]>h[i]:
s+=1
elif x[i+1]-x[i]>h[i]:
s+=1
x[i]+=h[i]
print(s)
|
Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
|
```python
n=int(input())
jk=0
jl=0
x=[] #pos of trees 0_n-1
h=[] #height of trees 0_n-1
for i in range(n):#input
jk,jl=[int(x) for x in input().split()]
x.append(jk)
h.append(jl)
x=[-10000000000000000]+x+[1000000000000000]#pos of trees 1_n
h=[0]+h+[0]#height of trees 1_n
s=0
for i in range(1,n+1):#1_n
if x[i]-x[i-1]>h[i]:
s+=1
elif x[i+1]-x[i]>h[i]:
s+=1
x[i]+=h[i]
print(s)
```
| 3
|
|
331
|
C1
|
The Great Julya Calendar
|
PROGRAMMING
| 1,100
|
[
"dp"
] | null | null |
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
|
The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3).
|
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
|
[
"24\n"
] |
[
"5"
] |
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
| 20
|
[
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
{
"input": "701",
"output": "116"
},
{
"input": "222",
"output": "39"
},
{
"input": "156",
"output": "28"
},
{
"input": "12343",
"output": "1778"
},
{
"input": "7984",
"output": "1178"
},
{
"input": "1000000",
"output": "128207"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "11",
"output": "3"
},
{
"input": "77",
"output": "14"
},
{
"input": "216",
"output": "37"
},
{
"input": "1468",
"output": "233"
},
{
"input": "1995",
"output": "305"
},
{
"input": "11010",
"output": "1568"
},
{
"input": "47320",
"output": "6746"
},
{
"input": "258634",
"output": "35024"
}
] | 1,599,544,514
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS1
| 0
| 0
| 0
|
memoization_table = {}
def compute_count(previous_max, rest):
global memoization_table
original_rest = rest
if (previous_max, rest) in memoization_table:
return memoization_table[(previous_max, rest)]
num_digits = len(str(rest))
if num_digits == 1:
memoization_table[(previous_max, original_rest)] = 1, min(0, rest-previous_max)
return 1, min(0, rest-previous_max)
sum_count = 0
while rest > 0:
s = str(rest).zfill(num_digits)
new_max = max(previous_max, int(s[0]))
new_rest = int(s[1:])
count, leftover = compute_count(new_max, new_rest)
sum_count += count
rest -= new_rest
rest += leftover
memoization_table[(previous_max, original_rest)] = sum_count, rest
return sum_count, rest
print(compute_count(0, int(input())[0])
|
Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
Input Specification:
The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3).
Output Specification:
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
Demo Input:
['24\n']
Demo Output:
['5']
Note:
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
|
```python
memoization_table = {}
def compute_count(previous_max, rest):
global memoization_table
original_rest = rest
if (previous_max, rest) in memoization_table:
return memoization_table[(previous_max, rest)]
num_digits = len(str(rest))
if num_digits == 1:
memoization_table[(previous_max, original_rest)] = 1, min(0, rest-previous_max)
return 1, min(0, rest-previous_max)
sum_count = 0
while rest > 0:
s = str(rest).zfill(num_digits)
new_max = max(previous_max, int(s[0]))
new_rest = int(s[1:])
count, leftover = compute_count(new_max, new_rest)
sum_count += count
rest -= new_rest
rest += leftover
memoization_table[(previous_max, original_rest)] = sum_count, rest
return sum_count, rest
print(compute_count(0, int(input())[0])
```
| -1
|
|
706
|
B
|
Interesting drink
|
PROGRAMMING
| 1,100
|
[
"binary search",
"dp",
"implementation"
] | null | null |
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
|
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
|
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
|
[
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] |
[
"0\n4\n1\n5\n"
] |
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
| 1,000
|
[
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "0\n0\n3\n3\n3\n0\n3"
},
{
"input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969",
"output": "1\n1\n0\n1\n1\n1\n0\n1\n1"
},
{
"input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341",
"output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12"
},
{
"input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192",
"output": "4\n4\n4\n4"
},
{
"input": "1\n1\n1\n1000000000",
"output": "1"
},
{
"input": "1\n1\n1\n100005",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100005",
"output": "3"
},
{
"input": "2\n1 2\n3\n100004\n100005\n100006",
"output": "2\n2\n2"
},
{
"input": "3\n1 1 1\n1\n1",
"output": "3"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "3\n1 2 3\n1\n100000",
"output": "3"
},
{
"input": "5\n1 1 1 1 10\n2\n1\n10",
"output": "4\n5"
},
{
"input": "5\n3 10 8 6 11\n1\n10000000",
"output": "5"
}
] | 1,696,483,281
| 2,147,483,647
|
PyPy 3
|
TIME_LIMIT_EXCEEDED
|
TESTS
| 10
| 2,000
| 13,312,000
|
import bisect
n = int(input())
prices = list(map(int, input().split()))
q = int(input())
sprices = sorted(prices)
for _ in range(q):
stat = 0
coins = int(input())
i = bisect.bisect_right(sprices, coins)
print(len(sprices[:i]))
|
Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink.
Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Output Specification:
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
Demo Input:
['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n']
Demo Output:
['0\n4\n1\n5\n']
Note:
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
|
```python
import bisect
n = int(input())
prices = list(map(int, input().split()))
q = int(input())
sprices = sorted(prices)
for _ in range(q):
stat = 0
coins = int(input())
i = bisect.bisect_right(sprices, coins)
print(len(sprices[:i]))
```
| 0
|
|
625
|
B
|
War of the Corporations
|
PROGRAMMING
| 1,200
|
[
"constructive algorithms",
"greedy",
"strings"
] | null | null |
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
|
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
|
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
|
[
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] |
[
"1",
"0",
"2"
] |
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri".
| 750
|
[
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",
"output": "3"
},
{
"input": "abc\nabcabc",
"output": "0"
},
{
"input": "kek\nkekekek",
"output": "0"
},
{
"input": "aaaaa\naaa",
"output": "1"
},
{
"input": "abcdabcv\nabcd",
"output": "1"
},
{
"input": "abcabcabczabcabcabcz\ncab",
"output": "4"
},
{
"input": "aatopotopotopotaa\ntopot",
"output": "2"
},
{
"input": "abcabcabcabcabcabcabcabcabcabc\nabcabcabcabcabcabcabcabcabcabc",
"output": "1"
},
{
"input": "sosossosos\nsos",
"output": "2"
},
{
"input": "sosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosos\nsos",
"output": "20"
},
{
"input": "tatatx\ntatx",
"output": "1"
},
{
"input": "sxxsxxsxxd\nsxxsxxd",
"output": "1"
}
] | 1,479,351,909
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 3
| 46
| 0
|
def main():
name = input()
substring = input()
count = 0
i = 0
while(i + len(substring) < len(name)):
if name[i] == substring[0]:
differ = False
for j in range(len(substring)):
if substring[j] != name[j+i]:
differ = True
break
if not differ:
count += 1
i += len(substring) - 1
i+=1
print(count)
return 0
if __name__ == '__main__':
main()
|
Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
Input Specification:
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Output Specification:
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
Demo Input:
['intellect\ntell\n', 'google\napple\n', 'sirisiri\nsir\n']
Demo Output:
['1', '0', '2']
Note:
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri".
|
```python
def main():
name = input()
substring = input()
count = 0
i = 0
while(i + len(substring) < len(name)):
if name[i] == substring[0]:
differ = False
for j in range(len(substring)):
if substring[j] != name[j+i]:
differ = True
break
if not differ:
count += 1
i += len(substring) - 1
i+=1
print(count)
return 0
if __name__ == '__main__':
main()
```
| 0
|
|
124
|
A
|
The number of positions
|
PROGRAMMING
| 1,000
|
[
"math"
] | null | null |
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
|
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
|
Print the single number — the number of the sought positions.
|
[
"3 1 1\n",
"5 2 3\n"
] |
[
"2\n",
"3\n"
] |
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
| 500
|
[
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,670,745,872
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 50
| 92
| 0
|
x=list(map(int,input().split()))
g=x[0]-x[1]
h=x[2]+1
print(min(g,h))
|
Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
|
```python
x=list(map(int,input().split()))
g=x[0]-x[1]
h=x[2]+1
print(min(g,h))
```
| 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,671,968,936
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 40
| 92
| 0
|
s = input() # read the first line as string s
t = input() # read the second line as string t
# check if t is equal to the reverse of s
if t == s[::-1]:
print("YES")
else:
print("NO")
|
Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none
|
```python
s = input() # read the first line as string s
t = input() # read the second line as string t
# check if t is equal to the reverse of s
if t == s[::-1]:
print("YES")
else:
print("NO")
```
| 3.977
|
611
|
A
|
New Year and Days
|
PROGRAMMING
| 900
|
[
"implementation"
] | null | null |
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
|
The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
|
Print one integer — the number of candies Limak will save in the year 2016.
|
[
"4 of week\n",
"30 of month\n"
] |
[
"52\n",
"11\n"
] |
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
| 500
|
[
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output": "52"
},
{
"input": "2 of week",
"output": "52"
},
{
"input": "3 of week",
"output": "52"
},
{
"input": "5 of week",
"output": "53"
},
{
"input": "7 of week",
"output": "52"
},
{
"input": "1 of month",
"output": "12"
},
{
"input": "2 of month",
"output": "12"
},
{
"input": "3 of month",
"output": "12"
},
{
"input": "4 of month",
"output": "12"
},
{
"input": "5 of month",
"output": "12"
},
{
"input": "6 of month",
"output": "12"
},
{
"input": "7 of month",
"output": "12"
},
{
"input": "8 of month",
"output": "12"
},
{
"input": "9 of month",
"output": "12"
},
{
"input": "10 of month",
"output": "12"
},
{
"input": "11 of month",
"output": "12"
},
{
"input": "12 of month",
"output": "12"
},
{
"input": "13 of month",
"output": "12"
},
{
"input": "14 of month",
"output": "12"
},
{
"input": "15 of month",
"output": "12"
},
{
"input": "16 of month",
"output": "12"
},
{
"input": "18 of month",
"output": "12"
},
{
"input": "19 of month",
"output": "12"
},
{
"input": "20 of month",
"output": "12"
},
{
"input": "21 of month",
"output": "12"
},
{
"input": "22 of month",
"output": "12"
},
{
"input": "23 of month",
"output": "12"
},
{
"input": "24 of month",
"output": "12"
},
{
"input": "25 of month",
"output": "12"
},
{
"input": "26 of month",
"output": "12"
},
{
"input": "27 of month",
"output": "12"
},
{
"input": "28 of month",
"output": "12"
},
{
"input": "29 of month",
"output": "12"
}
] | 1,452,911,783
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 38
| 62
| 0
|
def main():
x, _, w = input().split()
x = int(x)
if w == "week":
print((366 + x) // 7 - x // 7)
else:
print(7 + 4 * (x < 31) + (x < 30))
if __name__ == '__main__':
main()
|
Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.
Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.
Input Specification:
The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month.
Output Specification:
Print one integer — the number of candies Limak will save in the year 2016.
Demo Input:
['4 of week\n', '30 of month\n']
Demo Output:
['52\n', '11\n']
Note:
Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.
In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.
|
```python
def main():
x, _, w = input().split()
x = int(x)
if w == "week":
print((366 + x) // 7 - x // 7)
else:
print(7 + 4 * (x < 31) + (x < 30))
if __name__ == '__main__':
main()
```
| 3
|
|
1
|
A
|
Theatre Square
|
PROGRAMMING
| 1,000
|
[
"math"
] |
A. Theatre Square
|
1
|
256
|
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
|
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
|
Write the needed number of flagstones.
|
[
"6 6 4\n"
] |
[
"4\n"
] |
none
| 0
|
[
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,696,261,189
| 2,147,483,647
|
PyPy 3-64
|
OK
|
TESTS
| 20
| 61
| 0
|
#initializes variables to be used
variables = input().split(' ')
n = int(variables[0])
m = int(variables[1])
a = int(variables[2])
#floor divides dimensions n and m with a to get number of flagstones are needed to cover, assuming it can go beyond the dimension
flagstones = ((-n // a) * (-m // a))
print(flagstones)
|
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
#initializes variables to be used
variables = input().split(' ')
n = int(variables[0])
m = int(variables[1])
a = int(variables[2])
#floor divides dimensions n and m with a to get number of flagstones are needed to cover, assuming it can go beyond the dimension
flagstones = ((-n // a) * (-m // a))
print(flagstones)
```
| 3.9695
|
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,690,011,993
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 46
| 405
| 18,227,200
|
n=int(input())
a=[]
b=[]
for i in range(n):
_,__=list(map(int,input().split()))
a.append(_)
b.append(__)
c=[i for j, i in sorted(zip(a,b))]
ans=False
for i in range(1,n):
if not (c[i]>=c[i-1]):
ans=True
break
if ans:
print("Happy Alex")
else:
print("Poor Alex")
|
Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none
|
```python
n=int(input())
a=[]
b=[]
for i in range(n):
_,__=list(map(int,input().split()))
a.append(_)
b.append(__)
c=[i for j, i in sorted(zip(a,b))]
ans=False
for i in range(1,n):
if not (c[i]>=c[i-1]):
ans=True
break
if ans:
print("Happy Alex")
else:
print("Poor Alex")
```
| 3
|
|
180
|
C
|
Letter
|
PROGRAMMING
| 1,400
|
[
"dp"
] | null | null |
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
|
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
|
Print a single number — the least number of actions needed to make the message fancy.
|
[
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] |
[
"5\n",
"0\n",
"0\n"
] |
none
| 0
|
[
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1"
},
{
"input": "FSFlNEelYY",
"output": "3"
},
{
"input": "lgtyasficu",
"output": "0"
},
{
"input": "WYKUDTDDBT",
"output": "0"
},
{
"input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd",
"output": "0"
},
{
"input": "mnAkOBuKxaiJwXhKnlcCvjxYXGXDoIqfUYkiLrdSYWhMemgWFzsgpoKOtHqooxbLYFuABWQSXuHdbyPVWyrkeEfqOsnEBikiqhfu",
"output": "43"
},
{
"input": "MMVESdOCALHJCTBTUWWQRGUUVTTTABKKAAdIINAdKLRLLVLODHDXDPMcQfUhPNHFBJSDRGsHZNORSCPNvKOOIuZnZAmTPUCoPNlR",
"output": "13"
},
{
"input": "MMbJIBhgFXPVpdQHLkWJkAHFIfJSpITTCRzRCzvRPRYECCheOknfINZWuKATDBOrEVKTcWXiYPjtzQMGUSGPNTMCUrvYCSWQHqAi",
"output": "27"
},
{
"input": "ZnqXEBOABXVbHRFFqDLWpWBBLqZIagmbRAYMDKJAYyFQXnPYwvDyRXKHLQnMLHGEOnRKmXtGqyQkoBCSmgKPcEIEugwJyxDOtTVn",
"output": "31"
}
] | 1,594,144,374
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 12
| 218
| 6,656,000
|
s = input()
upper,lower = 0,0
for i in s:
if i.isupper():
upper+=1
else:
lower+=1
print(min(upper,lower))
|
Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.
To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.
Input Specification:
The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.
Output Specification:
Print a single number — the least number of actions needed to make the message fancy.
Demo Input:
['PRuvetSTAaYA\n', 'OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n', 'helloworld\n']
Demo Output:
['5\n', '0\n', '0\n']
Note:
none
|
```python
s = input()
upper,lower = 0,0
for i in s:
if i.isupper():
upper+=1
else:
lower+=1
print(min(upper,lower))
```
| 0
|
|
731
|
A
|
Night at the Museum
|
PROGRAMMING
| 800
|
[
"implementation",
"strings"
] | null | null |
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
|
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
|
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
|
[
"zeus\n",
"map\n",
"ares\n"
] |
[
"18\n",
"35\n",
"34\n"
] |
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
| 500
|
[
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"output": "99"
},
{
"input": "gngvi",
"output": "44"
},
{
"input": "aaaaa",
"output": "0"
},
{
"input": "a",
"output": "0"
},
{
"input": "z",
"output": "1"
},
{
"input": "vyadeehhikklnoqrs",
"output": "28"
},
{
"input": "jjiihhhhgggfedcccbazyxx",
"output": "21"
},
{
"input": "fyyptqqxuciqvwdewyppjdzur",
"output": "117"
},
{
"input": "fqcnzmzmbobmancqcoalzmanaobpdse",
"output": "368"
},
{
"input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza",
"output": "8"
},
{
"input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy",
"output": "644"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
"output": "8"
},
{
"input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl",
"output": "421"
},
{
"input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa",
"output": "84"
},
{
"input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco",
"output": "666"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww",
"output": "22"
},
{
"input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh",
"output": "643"
},
{
"input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib",
"output": "245"
},
{
"input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro",
"output": "468"
},
{
"input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned",
"output": "523"
},
{
"input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna",
"output": "130"
},
{
"input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh",
"output": "163"
},
{
"input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb",
"output": "155"
},
{
"input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp",
"output": "57"
},
{
"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs",
"output": "1236"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx",
"output": "49"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt",
"output": "331"
},
{
"input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte",
"output": "692"
},
{
"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh",
"output": "1293"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "16"
},
{
"input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple",
"output": "616"
},
{
"input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl",
"output": "605"
},
{
"input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud",
"output": "549"
},
{
"input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore",
"output": "688"
},
{
"input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc",
"output": "604"
},
{
"input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa",
"output": "572"
},
{
"input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp",
"output": "609"
},
{
"input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl",
"output": "223"
},
{
"input": "aa",
"output": "0"
}
] | 1,628,139,100
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 44
| 77
| 6,963,200
|
a=input()
k=0
n=0
while True :
if k==len(a):
print(n)
break
elif k==0 :
n=min(abs(ord('a')-ord(a[k])),26-abs(ord('a')-ord(a[k])))
k=1
elif k>0 :
n+=min(abs(ord(a[k-1])-ord(a[k])),26-abs(ord(a[k-1])-ord(a[k])))
k+=1
|
Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input Specification:
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Output Specification:
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
Demo Input:
['zeus\n', 'map\n', 'ares\n']
Demo Output:
['18\n', '35\n', '34\n']
Note:
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
|
```python
a=input()
k=0
n=0
while True :
if k==len(a):
print(n)
break
elif k==0 :
n=min(abs(ord('a')-ord(a[k])),26-abs(ord('a')-ord(a[k])))
k=1
elif k>0 :
n+=min(abs(ord(a[k-1])-ord(a[k])),26-abs(ord(a[k-1])-ord(a[k])))
k+=1
```
| 3
|
|
69
|
A
|
Young Physicist
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] |
A. Young Physicist
|
2
|
256
|
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
|
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
|
[
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] |
[
"NO",
"YES"
] |
none
| 500
|
[
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,675,085,852
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 0
| 60
| 0
|
import sys
sys.stdin, sys.stdout = open("input.txt", "r"), open("output.txt", "w")
def main():
n = int(input())
arr = [[int(a) for a in input().split()]for _ in range(n)]
a,b,c=0,0,0
for i in range(n):
a+=arr[i][0]
b+=arr[i][1]
c+=arr[i][2]
if a==0 and b==0 and c==0 :
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
|
Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none
|
```python
import sys
sys.stdin, sys.stdout = open("input.txt", "r"), open("output.txt", "w")
def main():
n = int(input())
arr = [[int(a) for a in input().split()]for _ in range(n)]
a,b,c=0,0,0
for i in range(n):
a+=arr[i][0]
b+=arr[i][1]
c+=arr[i][2]
if a==0 and b==0 and c==0 :
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
```
| -1
|
868
|
A
|
Bark to Unlock
|
PROGRAMMING
| 900
|
[
"brute force",
"implementation",
"strings"
] | null | null |
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
|
The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
|
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
|
[
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ah\n1\nha\n"
] |
[
"YES\n",
"NO\n",
"YES\n"
] |
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
In the third example the string "hahahaha" contains "ah" as a substring.
| 250
|
[
{
"input": "ya\n4\nah\noy\nto\nha",
"output": "YES"
},
{
"input": "hp\n2\nht\ntp",
"output": "NO"
},
{
"input": "ah\n1\nha",
"output": "YES"
},
{
"input": "bb\n4\nba\nab\naa\nbb",
"output": "YES"
},
{
"input": "bc\n4\nca\nba\nbb\ncc",
"output": "YES"
},
{
"input": "ba\n4\ncd\nad\ncc\ncb",
"output": "YES"
},
{
"input": "pg\n4\nzl\nxs\ndi\nxn",
"output": "NO"
},
{
"input": "bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu",
"output": "YES"
},
{
"input": "bb\n1\naa",
"output": "NO"
},
{
"input": "qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm",
"output": "NO"
},
{
"input": "mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm",
"output": "YES"
},
{
"input": "aa\n1\naa",
"output": "YES"
},
{
"input": "bb\n1\nbb",
"output": "YES"
},
{
"input": "ba\n1\ncc",
"output": "NO"
},
{
"input": "ha\n1\nha",
"output": "YES"
},
{
"input": "aa\n1\naa",
"output": "YES"
},
{
"input": "ez\n1\njl",
"output": "NO"
},
{
"input": "aa\n2\nab\nba",
"output": "YES"
},
{
"input": "aa\n2\nca\ncc",
"output": "NO"
},
{
"input": "dd\n2\nac\ndc",
"output": "NO"
},
{
"input": "qc\n2\nyc\nkr",
"output": "NO"
},
{
"input": "aa\n3\nba\nbb\nab",
"output": "YES"
},
{
"input": "ca\n3\naa\nbb\nab",
"output": "NO"
},
{
"input": "ca\n3\nbc\nbd\nca",
"output": "YES"
},
{
"input": "dd\n3\nmt\nrg\nxl",
"output": "NO"
},
{
"input": "be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb",
"output": "YES"
},
{
"input": "fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef",
"output": "YES"
},
{
"input": "ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca",
"output": "YES"
},
{
"input": "ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb",
"output": "YES"
},
{
"input": "hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc",
"output": "YES"
},
{
"input": "id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb",
"output": "YES"
},
{
"input": "fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha",
"output": "YES"
},
{
"input": "rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd",
"output": "YES"
},
{
"input": "ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi",
"output": "YES"
},
{
"input": "if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi",
"output": "YES"
},
{
"input": "kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj",
"output": "YES"
},
{
"input": "ab\n1\nab",
"output": "YES"
},
{
"input": "ya\n1\nya",
"output": "YES"
},
{
"input": "ay\n1\nyb",
"output": "NO"
},
{
"input": "ax\n2\nii\nxa",
"output": "YES"
},
{
"input": "hi\n1\nhi",
"output": "YES"
},
{
"input": "ag\n1\nag",
"output": "YES"
},
{
"input": "th\n1\nth",
"output": "YES"
},
{
"input": "sb\n1\nsb",
"output": "YES"
},
{
"input": "hp\n1\nhp",
"output": "YES"
},
{
"input": "ah\n1\nah",
"output": "YES"
},
{
"input": "ta\n1\nta",
"output": "YES"
},
{
"input": "tb\n1\ntb",
"output": "YES"
},
{
"input": "ab\n5\nca\nda\nea\nfa\nka",
"output": "NO"
},
{
"input": "ac\n1\nac",
"output": "YES"
},
{
"input": "ha\n2\nha\nzz",
"output": "YES"
},
{
"input": "ok\n1\nok",
"output": "YES"
},
{
"input": "bc\n1\nbc",
"output": "YES"
},
{
"input": "az\n1\nzz",
"output": "NO"
},
{
"input": "ab\n2\nba\ntt",
"output": "YES"
},
{
"input": "ah\n2\nap\nhp",
"output": "NO"
},
{
"input": "sh\n1\nsh",
"output": "YES"
},
{
"input": "az\n1\nby",
"output": "NO"
},
{
"input": "as\n1\nas",
"output": "YES"
},
{
"input": "ab\n2\nab\ncd",
"output": "YES"
},
{
"input": "ab\n2\nxa\nza",
"output": "NO"
},
{
"input": "ab\n2\net\nab",
"output": "YES"
},
{
"input": "ab\n1\naa",
"output": "NO"
},
{
"input": "ab\n2\nab\nde",
"output": "YES"
},
{
"input": "ah\n2\nba\nha",
"output": "YES"
},
{
"input": "ha\n3\ndd\ncc\nha",
"output": "YES"
},
{
"input": "oo\n1\nox",
"output": "NO"
},
{
"input": "ab\n2\nax\nbx",
"output": "NO"
},
{
"input": "ww\n4\nuw\now\npo\nko",
"output": "NO"
},
{
"input": "ay\n1\nay",
"output": "YES"
},
{
"input": "yo\n1\nyo",
"output": "YES"
},
{
"input": "ba\n1\nba",
"output": "YES"
},
{
"input": "qw\n1\nqw",
"output": "YES"
},
{
"input": "la\n1\nla",
"output": "YES"
},
{
"input": "ab\n2\nbb\nbc",
"output": "NO"
},
{
"input": "aa\n2\nab\nac",
"output": "NO"
},
{
"input": "ah\n2\nbb\nha",
"output": "YES"
},
{
"input": "ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek",
"output": "NO"
},
{
"input": "ab\n3\nab\nxx\nyy",
"output": "YES"
},
{
"input": "ab\n2\nab\ncc",
"output": "YES"
},
{
"input": "sa\n2\nxx\nas",
"output": "YES"
},
{
"input": "ma\n1\nma",
"output": "YES"
},
{
"input": "ba\n1\nbb",
"output": "NO"
},
{
"input": "bc\n1\nab",
"output": "NO"
},
{
"input": "fa\n1\nfa",
"output": "YES"
},
{
"input": "ap\n1\nap",
"output": "YES"
},
{
"input": "ab\n1\nbb",
"output": "NO"
},
{
"input": "bk\n1\nbk",
"output": "YES"
},
{
"input": "xy\n2\nxy\naa",
"output": "YES"
},
{
"input": "ab\n2\nza\nbz",
"output": "YES"
}
] | 1,680,971,357
| 2,147,483,647
|
Python 3
|
MEMORY_LIMIT_EXCEEDED
|
TESTS
| 7
| 592
| 268,390,400
|
from itertools import permutations
password = input()
n = int(input())
vals = []
for i in range(n):
s = input()
s *= 3
vals.append(s)
poss = list(permutations(vals))
ans = "NO"
for lst in poss:
lst = "".join(lst)
if password in lst:
ans = "YES"
break
print(ans)
|
Title: Bark to Unlock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark *n* distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
Input Specification:
The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Output Specification:
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['ya\n4\nah\noy\nto\nha\n', 'hp\n2\nht\ntp\n', 'ah\n1\nha\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
In the third example the string "hahahaha" contains "ah" as a substring.
|
```python
from itertools import permutations
password = input()
n = int(input())
vals = []
for i in range(n):
s = input()
s *= 3
vals.append(s)
poss = list(permutations(vals))
ans = "NO"
for lst in poss:
lst = "".join(lst)
if password in lst:
ans = "YES"
break
print(ans)
```
| 0
|
|
884
|
B
|
Japanese Crosswords Strike Back
|
PROGRAMMING
| 1,100
|
[
"implementation"
] | null | null |
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
|
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
|
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
|
[
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] |
[
"NO\n",
"YES\n",
"NO\n"
] |
none
| 0
|
[
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output": "YES"
},
{
"input": "10 1\n5 78 3 87 4 9 5 8 9 1235",
"output": "NO"
},
{
"input": "3 12\n3 3 3",
"output": "NO"
},
{
"input": "3 9\n2 2 2",
"output": "NO"
},
{
"input": "2 5\n1 1",
"output": "NO"
},
{
"input": "1 2\n1",
"output": "NO"
},
{
"input": "3 13\n3 3 3",
"output": "NO"
},
{
"input": "3 6\n1 1 1",
"output": "NO"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "3 11\n3 3 2",
"output": "NO"
},
{
"input": "2 6\n1 3",
"output": "NO"
},
{
"input": "3 10\n2 2 2",
"output": "NO"
},
{
"input": "3 8\n2 1 1",
"output": "NO"
},
{
"input": "1 5\n2",
"output": "NO"
},
{
"input": "1 3\n1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "NO"
},
{
"input": "2 10\n4 4",
"output": "NO"
},
{
"input": "2 8\n2 3",
"output": "NO"
},
{
"input": "2 4\n1 1",
"output": "NO"
},
{
"input": "3 10\n1 2 4",
"output": "NO"
},
{
"input": "3 10\n2 1 3",
"output": "NO"
},
{
"input": "2 6\n1 2",
"output": "NO"
},
{
"input": "3 4\n1 1 1",
"output": "NO"
},
{
"input": "3 11\n1 2 4",
"output": "NO"
},
{
"input": "3 12\n3 3 2",
"output": "NO"
},
{
"input": "4 9\n1 1 1 1",
"output": "NO"
},
{
"input": "1 10\n9",
"output": "NO"
},
{
"input": "1 7\n5",
"output": "NO"
},
{
"input": "2 5\n1 2",
"output": "NO"
},
{
"input": "3 8\n1 1 2",
"output": "NO"
},
{
"input": "3 7\n1 1 1",
"output": "NO"
},
{
"input": "1 10\n1",
"output": "NO"
},
{
"input": "3 10\n2 3 4",
"output": "NO"
},
{
"input": "3 9\n1 2 3",
"output": "NO"
},
{
"input": "3 9\n3 3 2",
"output": "NO"
},
{
"input": "3 6\n3 3 2",
"output": "NO"
},
{
"input": "1 1\n3",
"output": "NO"
},
{
"input": "1 3\n2",
"output": "NO"
},
{
"input": "3 10\n3 3 3",
"output": "NO"
},
{
"input": "3 5\n1 1 1",
"output": "YES"
},
{
"input": "2 1\n100 100",
"output": "NO"
},
{
"input": "3 3\n3 3 3",
"output": "NO"
},
{
"input": "4 17\n3 3 9 1",
"output": "NO"
},
{
"input": "4 1660\n1505 13 37 100",
"output": "NO"
},
{
"input": "3 5\n3 3 2",
"output": "NO"
},
{
"input": "4 10\n3 3 2 5",
"output": "NO"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n2",
"output": "NO"
},
{
"input": "5 10\n1 2 2 4 5",
"output": "NO"
},
{
"input": "2 1\n1 1",
"output": "NO"
}
] | 1,509,214,523
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 66
| 77
| 7,372,800
|
n,x=map(int,input().split())
L=list(map(int,input().split()))
if x-sum(L)==n-1:
print('Yes')
else:
print('No')
|
Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
Input Specification:
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Output Specification:
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
Demo Input:
['2 4\n1 3\n', '3 10\n3 3 2\n', '2 10\n1 3\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
none
|
```python
n,x=map(int,input().split())
L=list(map(int,input().split()))
if x-sum(L)==n-1:
print('Yes')
else:
print('No')
```
| 3
|
|
69
|
A
|
Young Physicist
|
PROGRAMMING
| 1,000
|
[
"implementation",
"math"
] |
A. Young Physicist
|
2
|
256
|
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
|
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
|
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
|
[
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] |
[
"NO",
"YES"
] |
none
| 500
|
[
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,556,626,125
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 81
| 218
| 0
|
n=int(input())
x=y=z=0
for i in range(0,n):
inp = list(map(int,input().split()))
x+=inp[0]
y+=inp[1]
z+=inp[2]
if x**2+y**2+z**2==0:
print("YES")
else:
print("NO")
|
Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none
|
```python
n=int(input())
x=y=z=0
for i in range(0,n):
inp = list(map(int,input().split()))
x+=inp[0]
y+=inp[1]
z+=inp[2]
if x**2+y**2+z**2==0:
print("YES")
else:
print("NO")
```
| 3.9455
|
909
|
C
|
Python Indentation
|
PROGRAMMING
| 1,800
|
[
"dp"
] | null | null |
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
|
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
|
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
|
[
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] |
[
"1\n",
"2\n"
] |
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
or
| 1,500
|
[
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\nf\nf\nf\ns\nf\ns\ns\ns\nf\nf\ns\ns\ns\ns\ns\nf\nf\nf\nf\ns\nf\nf\ns\nf\ns\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\nf\ns\ns\nf\nf\nf\ns\ns\nf\nf\nf\ns\nf\ns\nf\nf\ns",
"output": "666443222"
},
{
"input": "4\nf\nf\ns\ns",
"output": "3"
},
{
"input": "2\nf\ns",
"output": "1"
},
{
"input": "1\ns",
"output": "1"
},
{
"input": "3\nf\nf\ns",
"output": "1"
},
{
"input": "2\ns\ns",
"output": "1"
},
{
"input": "156\ns\nf\ns\ns\ns\ns\nf\ns\ns\ns\nf\nf\ns\nf\nf\ns\nf\nf\nf\ns\nf\nf\ns\nf\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\nf\ns\ns\nf\ns\nf\nf\nf\ns\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\nf\nf\ns\nf\nf\nf\ns\ns\nf\nf\ns\nf\ns\ns\ns\ns\ns\ns\ns\nf\ns\nf\nf\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\ns\ns\nf\ns\nf\ns\ns\nf\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\nf\ns\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\nf\nf\ns\nf\ns\nf\ns\ns\ns\nf\nf\ns",
"output": "479461584"
},
{
"input": "66\ns\nf\ns\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\ns\ns\nf\nf\ns\ns\nf\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\ns\ns\nf\nf\ns\nf\ns\ns\nf\nf\ns\nf\ns\nf\nf\ns",
"output": "392847498"
}
] | 1,514,431,177
| 2,147,483,647
|
Python 3
|
COMPILATION_ERROR
|
TESTS
| 0
| 0
| 0
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5005;
const int MOD = 1000000007;
int dp[MAX_N][MAX_N];
int n;
char a[MAX_N];
int main () {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char s[2];
scanf("%s", s);
a[i] = s[0];
}
dp[1][1] = 1;
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i; j++) {
if (dp[i][j] > 0) {
if (a[i] == 'f') {
(dp[i + 1][j + 1] += dp[i][j]) %= MOD;
}
else {
(dp[i + 1][j] += dp[i][j]) %= MOD;
if (i > 1) {
(dp[i + 1][j + 1] += dp[i][j]) %= MOD;
}
}
}
}
}
int res = 0;
for (int j = 1; j <= n; j++) {
(res += dp[n][j]) %= MOD;
}
printf("%d", res);
return 0;
}
|
Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
Input Specification:
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output Specification:
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
Demo Input:
['4\ns\nf\nf\ns\n', '4\nf\ns\nf\ns\n']
Demo Output:
['1\n', '2\n']
Note:
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
or
|
```python
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5005;
const int MOD = 1000000007;
int dp[MAX_N][MAX_N];
int n;
char a[MAX_N];
int main () {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char s[2];
scanf("%s", s);
a[i] = s[0];
}
dp[1][1] = 1;
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i; j++) {
if (dp[i][j] > 0) {
if (a[i] == 'f') {
(dp[i + 1][j + 1] += dp[i][j]) %= MOD;
}
else {
(dp[i + 1][j] += dp[i][j]) %= MOD;
if (i > 1) {
(dp[i + 1][j + 1] += dp[i][j]) %= MOD;
}
}
}
}
}
int res = 0;
for (int j = 1; j <= n; j++) {
(res += dp[n][j]) %= MOD;
}
printf("%d", res);
return 0;
}
```
| -1
|
|
266
|
A
|
Stones on the Table
|
PROGRAMMING
| 800
|
[
"implementation"
] | null | null |
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
|
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
|
Print a single integer — the answer to the problem.
|
[
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] |
[
"1\n",
"4\n",
"0\n"
] |
none
| 500
|
[
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "4\nRBBR",
"output": "1"
},
{
"input": "5\nRGGBG",
"output": "1"
},
{
"input": "10\nGGBRBRGGRB",
"output": "2"
},
{
"input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB",
"output": "18"
},
{
"input": "15\nBRRBRGGBBRRRRGR",
"output": "6"
},
{
"input": "20\nRRGBBRBRGRGBBGGRGRRR",
"output": "6"
},
{
"input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB",
"output": "6"
},
{
"input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB",
"output": "9"
},
{
"input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB",
"output": "14"
},
{
"input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG",
"output": "20"
},
{
"input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG",
"output": "11"
},
{
"input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG",
"output": "17"
},
{
"input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB",
"output": "16"
},
{
"input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG",
"output": "19"
},
{
"input": "10\nGRRBRBRBGR",
"output": "1"
},
{
"input": "10\nBRBGBGRRBR",
"output": "1"
},
{
"input": "20\nGBGBGGRRRRGRBBGRGRGR",
"output": "5"
},
{
"input": "20\nRRGGRBBGBBRBGRRBRRBG",
"output": "6"
},
{
"input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB",
"output": "8"
},
{
"input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB",
"output": "11"
},
{
"input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB",
"output": "9"
},
{
"input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG",
"output": "13"
},
{
"input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG",
"output": "13"
},
{
"input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB",
"output": "12"
},
{
"input": "2\nBB",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "49"
},
{
"input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "47"
},
{
"input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR",
"output": "43"
}
] | 1,694,251,565
| 2,147,483,647
|
Python 3
|
OK
|
TESTS
| 34
| 92
| 0
|
n = int(input())
s = list(input())
if len(s) >= 1 and len(s) <= 50:
min_stones = 0
for i in range(1, len(s)):
if s[i] == s[i-1]: # إذا ÙØ§Ù ÙØ¯ÙÙØ§ ØØ¬ï¿½ï¿½ÙÙ Ù
تتاÙÙÙ٠بÙÙØ³ اÙÙÙÙ
min_stones += 1 # ÙØ²Ùد عدد Ø§ÙØ£ØØ¬Ø§Ø± اÙÙ
Ø·ÙÙØ¨Ø© Ø¨ÙØ§ØØ¯
print(min_stones)
|
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 = list(input())
if len(s) >= 1 and len(s) <= 50:
min_stones = 0
for i in range(1, len(s)):
if s[i] == s[i-1]: # إذا ÙØ§Ù ÙØ¯ÙÙØ§ ØØ¬ï¿½ï¿½ÙÙ Ù
تتاÙÙÙ٠بÙÙØ³ اÙÙÙÙ
min_stones += 1 # ÙØ²Ùد عدد Ø§ÙØ£ØØ¬Ø§Ø± اÙÙ
Ø·ÙÙØ¨Ø© Ø¨ÙØ§ØØ¯
print(min_stones)
```
| 3
|
|
427
|
C
|
Checkposts
|
PROGRAMMING
| 1,700
|
[
"dfs and similar",
"graphs",
"two pointers"
] | null | null |
Your city has *n* junctions. There are *m* one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction *i* can protect junction *j* if either *i*<==<=*j* or the police patrol car can go to *j* from *i* and then come back to *i*.
Building checkposts costs some money. As some areas of the city are more expensive than others, building checkpost at some junctions might cost more money than other junctions.
You have to determine the minimum possible money needed to ensure the security of all the junctions. Also you have to find the number of ways to ensure the security in minimum price and in addition in minimum number of checkposts. Two ways are different if any of the junctions contains a checkpost in one of them and do not contain in the other.
|
In the first line, you will be given an integer *n*, number of junctions (1<=≤<=*n*<=≤<=105). In the next line, *n* space-separated integers will be given. The *i**th* integer is the cost of building checkpost at the *i**th* junction (costs will be non-negative and will not exceed 109).
The next line will contain an integer *m* (0<=≤<=*m*<=≤<=3·105). And each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u*<=≠<=*v*). A pair *u**i*,<=*v**i* means, that there is a one-way road which goes from *u**i* to *v**i*. There will not be more than one road between two nodes in the same direction.
|
Print two integers separated by spaces. The first one is the minimum possible money needed to ensure the security of all the junctions. And the second one is the number of ways you can ensure the security modulo 1000000007 (109<=+<=7).
|
[
"3\n1 2 3\n3\n1 2\n2 3\n3 2\n",
"5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1\n",
"10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9\n",
"2\n7 91\n2\n1 2\n2 1\n"
] |
[
"3 1\n",
"8 2\n",
"15 6\n",
"7 1\n"
] |
none
| 1,500
|
[
{
"input": "3\n1 2 3\n3\n1 2\n2 3\n3 2",
"output": "3 1"
},
{
"input": "5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1",
"output": "8 2"
},
{
"input": "10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9",
"output": "15 6"
},
{
"input": "2\n7 91\n2\n1 2\n2 1",
"output": "7 1"
},
{
"input": "10\n1 1 1 1 1 1 1 2 2 2\n15\n2 3\n2 4\n4 1\n4 7\n4 10\n4 5\n4 8\n2 6\n3 2\n1 2\n7 2\n10 2\n5 2\n8 2\n6 2",
"output": "3 7"
},
{
"input": "100\n174 174 49 152 10 185 101 157 28 177 105 83 155 178 119 123 197 197 56 174 39 53 85 94 72 166 71 43 177 123 186 11 64 82 145 81 11 29 100 10 106 45 138 79 131 90 80 104 149 116 129 30 96 192 11 182 92 157 95 136 152 38 68 34 42 95 164 134 117 75 186 185 28 146 86 24 147 12 166 169 116 44 46 99 55 179 85 187 150 161 49 46 146 79 100 130 59 135 81 176\n0",
"output": "10585 1"
},
{
"input": "1\n1000000000\n0",
"output": "1000000000 1"
},
{
"input": "1\n0\n0",
"output": "0 1"
}
] | 1,680,606,633
| 2,147,483,647
|
Python 3
|
RUNTIME_ERROR
|
TESTS
| 70
| 810
| 22,630,400
|
# import sys
from collections import defaultdict
# sys.setrecursionlimit(1000000)
def add_edge(a, b, c):
edges[a] = c
next_edge[a] = adjacency_list[b]
adjacency_list[b] = a
def depth_first_search(node):
global time, stack_top, component_count
low[node] = visited[node] = time + 1
time += 1
is_visited[node] = True
stack_top += 1
stack[stack_top] = node
stack_position = stack_top
current_edge = adjacency_list[node]
while current_edge != 0:
if is_visited[edges[current_edge]]:
low[node] = min(low[node], visited[edges[current_edge]])
else:
if not visited[edges[current_edge]]:
depth_first_search(edges[current_edge])
low[node] = min(low[node], low[edges[current_edge]])
current_edge = next_edge[current_edge]
if low[node] == visited[node]:
component_count += 1
for i in range(stack_position, stack_top + 1):
components[stack[i]] = component_count
is_visited[stack[i]] = False
stack_top = stack_position - 1
n = int(input().strip())
values = list(map(int, input().strip().split()))
m = int(input().strip())
ans1 = ans2 = 0
stack_top = edge_count = component_count = time = 0
visited = [0] * (n + 5)
low = [0] * (n + 5)
stack = [0] * (n + 5)
edges = [0] * (3 * 10**5 + 5)
next_edge = [0] * (3 * 10**5 + 5)
adjacency_list = [0] * (n + 5)
components = [0] * (n + 5)
is_visited = [False] * (n + 5)
min_value = [1000000007] * (n + 5)
component_count_list = [0] * (n + 5)
for _ in range(m):
A, B = map(int, input().strip().split())
edge_count += 1
add_edge(edge_count, A, B)
for i in range(1, n + 1):
if not visited[i]:
depth_first_search(i)
for i in range(1, n + 1):
if min_value[components[i]] > values[i - 1]:
min_value[components[i]] = values[i - 1]
component_count_list[components[i]] = 1
elif min_value[components[i]] == values[i - 1]:
component_count_list[components[i]] += 1
MOD = 1000000007
ans2 = 1
for i in range(1, component_count + 1):
ans1 += min_value[i]
ans2 = (ans2 * component_count_list[i]) % MOD
print(ans1, ans2)
|
Title: Checkposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your city has *n* junctions. There are *m* one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction *i* can protect junction *j* if either *i*<==<=*j* or the police patrol car can go to *j* from *i* and then come back to *i*.
Building checkposts costs some money. As some areas of the city are more expensive than others, building checkpost at some junctions might cost more money than other junctions.
You have to determine the minimum possible money needed to ensure the security of all the junctions. Also you have to find the number of ways to ensure the security in minimum price and in addition in minimum number of checkposts. Two ways are different if any of the junctions contains a checkpost in one of them and do not contain in the other.
Input Specification:
In the first line, you will be given an integer *n*, number of junctions (1<=≤<=*n*<=≤<=105). In the next line, *n* space-separated integers will be given. The *i**th* integer is the cost of building checkpost at the *i**th* junction (costs will be non-negative and will not exceed 109).
The next line will contain an integer *m* (0<=≤<=*m*<=≤<=3·105). And each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u*<=≠<=*v*). A pair *u**i*,<=*v**i* means, that there is a one-way road which goes from *u**i* to *v**i*. There will not be more than one road between two nodes in the same direction.
Output Specification:
Print two integers separated by spaces. The first one is the minimum possible money needed to ensure the security of all the junctions. And the second one is the number of ways you can ensure the security modulo 1000000007 (109<=+<=7).
Demo Input:
['3\n1 2 3\n3\n1 2\n2 3\n3 2\n', '5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1\n', '10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9\n', '2\n7 91\n2\n1 2\n2 1\n']
Demo Output:
['3 1\n', '8 2\n', '15 6\n', '7 1\n']
Note:
none
|
```python
# import sys
from collections import defaultdict
# sys.setrecursionlimit(1000000)
def add_edge(a, b, c):
edges[a] = c
next_edge[a] = adjacency_list[b]
adjacency_list[b] = a
def depth_first_search(node):
global time, stack_top, component_count
low[node] = visited[node] = time + 1
time += 1
is_visited[node] = True
stack_top += 1
stack[stack_top] = node
stack_position = stack_top
current_edge = adjacency_list[node]
while current_edge != 0:
if is_visited[edges[current_edge]]:
low[node] = min(low[node], visited[edges[current_edge]])
else:
if not visited[edges[current_edge]]:
depth_first_search(edges[current_edge])
low[node] = min(low[node], low[edges[current_edge]])
current_edge = next_edge[current_edge]
if low[node] == visited[node]:
component_count += 1
for i in range(stack_position, stack_top + 1):
components[stack[i]] = component_count
is_visited[stack[i]] = False
stack_top = stack_position - 1
n = int(input().strip())
values = list(map(int, input().strip().split()))
m = int(input().strip())
ans1 = ans2 = 0
stack_top = edge_count = component_count = time = 0
visited = [0] * (n + 5)
low = [0] * (n + 5)
stack = [0] * (n + 5)
edges = [0] * (3 * 10**5 + 5)
next_edge = [0] * (3 * 10**5 + 5)
adjacency_list = [0] * (n + 5)
components = [0] * (n + 5)
is_visited = [False] * (n + 5)
min_value = [1000000007] * (n + 5)
component_count_list = [0] * (n + 5)
for _ in range(m):
A, B = map(int, input().strip().split())
edge_count += 1
add_edge(edge_count, A, B)
for i in range(1, n + 1):
if not visited[i]:
depth_first_search(i)
for i in range(1, n + 1):
if min_value[components[i]] > values[i - 1]:
min_value[components[i]] = values[i - 1]
component_count_list[components[i]] = 1
elif min_value[components[i]] == values[i - 1]:
component_count_list[components[i]] += 1
MOD = 1000000007
ans2 = 1
for i in range(1, component_count + 1):
ans1 += min_value[i]
ans2 = (ans2 * component_count_list[i]) % MOD
print(ans1, ans2)
```
| -1
|
|
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,576,350,687
| 2,147,483,647
|
Python 3
|
WRONG_ANSWER
|
TESTS
| 1
| 186
| 0
|
a = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
a1=0
a2=0
n=int(input())
for i in range(n) :
N = input()
if N.isdigit():
if int(N)>=18:
a1=a1+1
if N==a[0] or N==a[1] or N==a[2] or N==a[3] or N==a[4] or N==a[5] or N==a[6] or N==a[7] or N==a[8] or N==a[9] or N==a[10]:
a2=a2+1
print(a1)
|
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
a = ['ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
a1=0
a2=0
n=int(input())
for i in range(n) :
N = input()
if N.isdigit():
if int(N)>=18:
a1=a1+1
if N==a[0] or N==a[1] or N==a[2] or N==a[3] or N==a[4] or N==a[5] or N==a[6] or N==a[7] or N==a[8] or N==a[9] or N==a[10]:
a2=a2+1
print(a1)
```
| 0
|
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.