contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,674,701,445 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 62 | 0 | t=[]
a=[int(x) for x in input().split()]
x=0
for i in range(a[0]):
t=input().split()
x+=t.count('W')+t.count('B')+t.count('G')
if x==a[0]*a[1]:
print("#Black&White")
else:
print("#Color")
| 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
t=[]
a=[int(x) for x in input().split()]
x=0
for i in range(a[0]):
t=input().split()
x+=t.count('W')+t.count('B')+t.count('G')
if x==a[0]*a[1]:
print("#Black&White")
else:
print("#Color")
``` | 3 |
|
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add. | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable. | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
"input": "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n19 16\n17 20\n17 23\n18 22\n18 23\n22 19\n21 20\n23 24",
"output": "215"
},
{
"input": "10 30 1\n4\n1 2\n3 1\n4 1\n1 6\n1 8\n10 1\n2 4\n2 7\n3 4\n3 5\n7 3\n3 9\n10 3\n5 4\n6 4\n7 4\n9 4\n10 4\n6 5\n5 8\n9 5\n10 5\n6 7\n9 6\n10 6\n7 8\n9 7\n10 7\n9 8\n10 8",
"output": "15"
},
{
"input": "10 13 2\n5 10\n2 1\n1 4\n2 3\n2 8\n3 4\n7 3\n4 6\n8 4\n4 9\n6 7\n6 9\n10 6\n7 8",
"output": "23"
},
{
"input": "10 10 3\n2 5 6\n1 3\n4 1\n4 3\n5 3\n3 9\n8 4\n9 4\n5 10\n8 7\n10 8",
"output": "18"
},
{
"input": "10 5 3\n1 5 9\n1 3\n1 8\n2 3\n8 4\n5 7",
"output": "17"
},
{
"input": "6 4 2\n1 4\n1 2\n2 3\n4 5\n5 6",
"output": "2"
},
{
"input": "7 8 2\n1 4\n1 2\n2 3\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7",
"output": "1"
},
{
"input": "5 2 3\n1 3 4\n1 5\n2 4",
"output": "0"
},
{
"input": "5 3 2\n1 2\n2 3\n2 4\n1 5",
"output": "1"
},
{
"input": "9 5 2\n1 5\n1 2\n2 3\n3 4\n5 6\n6 7",
"output": "13"
},
{
"input": "6 4 1\n1\n2 3\n3 4\n4 5\n5 6",
"output": "11"
},
{
"input": "6 4 2\n1 5\n1 2\n2 3\n3 4\n5 6",
"output": "3"
},
{
"input": "7 3 3\n1 5 6\n1 2\n1 3\n6 7",
"output": "4"
},
{
"input": "5 2 2\n1 2\n1 3\n2 4",
"output": "2"
},
{
"input": "11 7 2\n1 4\n1 2\n1 3\n4 5\n4 6\n5 6\n9 10\n1 11",
"output": "24"
},
{
"input": "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10",
"output": "89"
}
] | 1,622,050,150 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 134,656,000 | def main():
n,m,k = map(int,input().split())
ks = [int(x) for x in input().split()]
adj = [[] for _ in range(n+1)]
for _ in range(m):
u,v = map(int,input().split())
adj[u].append(v)
adj[v].append(u)
take = []
def dfs(node,adj,cnt,taken):
leaf = True
for children in adj[node]:
if children not in taken:
leaf = False
taken.add(children)
dfs(children,adj,cnt+1,taken)
if leaf:
take.append(cnt+1)
for gov in ks:
dfs(gov,adj,0,{gov})
take.sort(reverse=True)
take[0] += n-sum(take)
#print(take)
answer = 0
for gov in take:
answer += gov*(gov-1)//2
print(answer-m)
if __name__=="__main__":
import sys, threading
input = sys.stdin.readline
sys.setrecursionlimit(2 ** 32 // 2 - 1)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start()
thread.join()
| Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Input Specification:
The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable.
Output Specification:
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
Demo Input:
['4 1 2\n1 3\n1 2\n', '3 3 1\n2\n1 2\n1 3\n2 3\n']
Demo Output:
['2\n', '0\n']
Note:
For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | ```python
def main():
n,m,k = map(int,input().split())
ks = [int(x) for x in input().split()]
adj = [[] for _ in range(n+1)]
for _ in range(m):
u,v = map(int,input().split())
adj[u].append(v)
adj[v].append(u)
take = []
def dfs(node,adj,cnt,taken):
leaf = True
for children in adj[node]:
if children not in taken:
leaf = False
taken.add(children)
dfs(children,adj,cnt+1,taken)
if leaf:
take.append(cnt+1)
for gov in ks:
dfs(gov,adj,0,{gov})
take.sort(reverse=True)
take[0] += n-sum(take)
#print(take)
answer = 0
for gov in take:
answer += gov*(gov-1)//2
print(answer-m)
if __name__=="__main__":
import sys, threading
input = sys.stdin.readline
sys.setrecursionlimit(2 ** 32 // 2 - 1)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start()
thread.join()
``` | 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,680,913,294 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 46 | 0 | n = input()
rows = []
flag = False
for i in range(int(n)):
row = input()
if not flag and 'OO' in row:
row = row.replace('OO', '++', 1)
flag = True
rows.append(row)
if flag:
print("YES")
for i in range(int(n)):
print(rows[i])
else:
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
n = input()
rows = []
flag = False
for i in range(int(n)):
row = input()
if not flag and 'OO' in row:
row = row.replace('OO', '++', 1)
flag = True
rows.append(row)
if flag:
print("YES")
for i in range(int(n)):
print(rows[i])
else:
print("NO")
``` | 3 |
|
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. | The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd",
"output": "100"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "199"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb",
"output": "99"
},
{
"input": "abcde\nfghij",
"output": "5"
},
{
"input": "abcde\nabcdf",
"output": "5"
},
{
"input": "abcde\nbbcde",
"output": "5"
},
{
"input": "abcde\neabcd",
"output": "5"
},
{
"input": "abcdefgh\nabdcefgh",
"output": "8"
},
{
"input": "mmmmm\nmnmmm",
"output": "5"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa",
"output": "34"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy",
"output": "26"
},
{
"input": "a\nab",
"output": "2"
},
{
"input": "b\nab",
"output": "2"
},
{
"input": "ab\nb",
"output": "2"
},
{
"input": "ab\nc",
"output": "2"
},
{
"input": "aaaaaa\naaaaaa",
"output": "-1"
},
{
"input": "abacaba\nabacaba",
"output": "-1"
},
{
"input": "aabb\nbbaa",
"output": "4"
},
{
"input": "ab\nba",
"output": "2"
},
{
"input": "abcd\nabc",
"output": "4"
},
{
"input": "abaa\nabaa",
"output": "-1"
},
{
"input": "ab\nab",
"output": "-1"
},
{
"input": "ab\nabcd",
"output": "4"
},
{
"input": "abc\nabcd",
"output": "4"
},
{
"input": "mo\nmomo",
"output": "4"
},
{
"input": "koooooooooooooooo\nloooooooooooooooo",
"output": "17"
},
{
"input": "aaa\naa",
"output": "3"
},
{
"input": "abc\nabc",
"output": "-1"
},
{
"input": "abcd\nabcd",
"output": "-1"
},
{
"input": "abc\ncba",
"output": "3"
},
{
"input": "ahc\nahc",
"output": "-1"
},
{
"input": "abc\nbac",
"output": "3"
},
{
"input": "aa\naaa",
"output": "3"
},
{
"input": "aaa\naaa",
"output": "-1"
},
{
"input": "abc\nacb",
"output": "3"
},
{
"input": "abc\nab",
"output": "3"
},
{
"input": "abb\nabb",
"output": "-1"
},
{
"input": "abc\ncab",
"output": "3"
},
{
"input": "aaaaaa\naaaaa",
"output": "6"
},
{
"input": "aa\naab",
"output": "3"
},
{
"input": "len\nlena",
"output": "4"
},
{
"input": "aaaaa\naa",
"output": "5"
},
{
"input": "aaa\naaaa",
"output": "4"
},
{
"input": "bcd\nabcd",
"output": "4"
},
{
"input": "aaabbc\naaaccc",
"output": "6"
},
{
"input": "abcd\nzycd",
"output": "4"
},
{
"input": "baa\nzaa",
"output": "3"
},
{
"input": "asdf\nadfs",
"output": "4"
},
{
"input": "abcdefgh\nabcdefgh",
"output": "-1"
},
{
"input": "aba\naab",
"output": "3"
},
{
"input": "aba\naba",
"output": "-1"
},
{
"input": "abcccc\naccccc",
"output": "6"
},
{
"input": "acb\nabc",
"output": "3"
},
{
"input": "a\naa",
"output": "2"
},
{
"input": "abababab\nab",
"output": "8"
},
{
"input": "ababab\nab",
"output": "6"
}
] | 1,699,714,759 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 73 | 62 | 307,200 | a = input()
b = input()
print(max(len(a), len(b)) if a != b else -1) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input Specification:
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output Specification:
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
Demo Input:
['abcd\ndefgh\n', 'a\na\n']
Demo Output:
['5\n', '-1\n']
Note:
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | ```python
a = input()
b = input()
print(max(len(a), len(b)) if a != b else -1)
``` | 3 |
|
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,682,503,159 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 122 | 0 | def system_of_equations_a():
n,m = map(int, input().split())
a, c = 0, 0
while(a <= int(math.sqrt(n))):
b = n - a*a
if(a + b*b == m):
c += 1
a += 1
print(c)
if __name__ == '__main__':
import math
system_of_equations_a() | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
def system_of_equations_a():
n,m = map(int, input().split())
a, c = 0, 0
while(a <= int(math.sqrt(n))):
b = n - a*a
if(a + b*b == m):
c += 1
a += 1
print(c)
if __name__ == '__main__':
import math
system_of_equations_a()
``` | 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,656,699,041 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n=input()
k=[]
m='hello'
for t in m:
if m["l"]==3:
c=n.find(t,nfind("l")+1)
else:
c=n.find(t)
k.append(c)
g=k[:]
g.sort()
if k==g and g[0] !=0:
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
n=input()
k=[]
m='hello'
for t in m:
if m["l"]==3:
c=n.find(t,nfind("l")+1)
else:
c=n.find(t)
k.append(c)
g=k[:]
g.sort()
if k==g and g[0] !=0:
print('YES')
else:
print("NO")
``` | -1 |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 2 5 3 4",
"output": "chest"
},
{
"input": "8\n7 2 9 10 3 8 10 6",
"output": "chest"
},
{
"input": "9\n5 4 2 3 4 4 5 2 2",
"output": "chest"
},
{
"input": "10\n4 9 8 5 3 8 8 10 4 2",
"output": "biceps"
},
{
"input": "11\n10 9 7 6 1 3 9 7 1 3 5",
"output": "chest"
},
{
"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5",
"output": "chest"
},
{
"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24",
"output": "chest"
},
{
"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7",
"output": "back"
},
{
"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12",
"output": "chest"
},
{
"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8",
"output": "biceps"
},
{
"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19",
"output": "chest"
},
{
"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21",
"output": "back"
},
{
"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24",
"output": "chest"
},
{
"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20",
"output": "chest"
},
{
"input": "1\n10",
"output": "chest"
},
{
"input": "2\n15 3",
"output": "chest"
},
{
"input": "3\n21 11 19",
"output": "chest"
},
{
"input": "4\n19 24 13 15",
"output": "chest"
},
{
"input": "5\n4 24 1 9 19",
"output": "biceps"
},
{
"input": "6\n6 22 24 7 15 24",
"output": "back"
},
{
"input": "7\n10 8 23 23 14 18 14",
"output": "chest"
},
{
"input": "8\n5 16 8 9 17 16 14 7",
"output": "biceps"
},
{
"input": "9\n12 3 10 23 6 4 22 13 12",
"output": "chest"
},
{
"input": "10\n1 9 20 18 20 17 7 24 23 2",
"output": "back"
},
{
"input": "11\n22 25 8 2 18 15 1 13 1 11 4",
"output": "biceps"
},
{
"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14",
"output": "chest"
},
{
"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18",
"output": "back"
},
{
"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22",
"output": "biceps"
},
{
"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6",
"output": "back"
},
{
"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14",
"output": "chest"
},
{
"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10",
"output": "biceps"
},
{
"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17",
"output": "chest"
},
{
"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14",
"output": "back"
},
{
"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6",
"output": "back"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "2\n1 7",
"output": "biceps"
},
{
"input": "3\n18 18 23",
"output": "back"
},
{
"input": "4\n12 15 1 13",
"output": "chest"
},
{
"input": "5\n11 14 25 21 21",
"output": "biceps"
},
{
"input": "6\n11 9 12 11 22 18",
"output": "biceps"
},
{
"input": "7\n11 1 16 20 21 25 20",
"output": "chest"
},
{
"input": "8\n1 2 20 9 3 22 17 4",
"output": "back"
},
{
"input": "9\n19 2 10 19 15 20 3 1 13",
"output": "back"
},
{
"input": "10\n11 2 11 8 21 16 2 3 19 9",
"output": "back"
},
{
"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24",
"output": "chest"
},
{
"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15",
"output": "back"
},
{
"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3",
"output": "biceps"
},
{
"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11",
"output": "biceps"
},
{
"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17",
"output": "back"
},
{
"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17",
"output": "chest"
},
{
"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8",
"output": "chest"
},
{
"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22",
"output": "chest"
},
{
"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24",
"output": "chest"
},
{
"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23",
"output": "biceps"
},
{
"input": "1\n19",
"output": "chest"
},
{
"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22",
"output": "biceps"
}
] | 1,584,802,471 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 248 | 0 | # Дано n упражнений
# Каждое упраженине это A1.. A2.. A3......
# 1. Грудь
# 2. Бицепс
# 3. Спина
n = int(input()) # Кол-во упражнений
tren = list(map(int,input().split()))
grud = 0
bic = 0
spin = 0
upr = 1
for i in tren:
if upr == 1:
grud += i
elif upr == 2:
bic += i
elif upr == 3:
spin += i
upr += 1
if upr > 3:
upr = 1
if bic < grud > spin:
print('chest')
elif grud < bic > spin:
print('biceps')
elif bic < spin > grud:
print('back')
| Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Output Specification:
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Demo Input:
['2\n2 8\n', '3\n5 1 10\n', '7\n3 3 2 7 9 6 8\n']
Demo Output:
['biceps\n', 'back\n', 'chest\n']
Note:
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise. | ```python
# Дано n упражнений
# Каждое упраженине это A1.. A2.. A3......
# 1. Грудь
# 2. Бицепс
# 3. Спина
n = int(input()) # Кол-во упражнений
tren = list(map(int,input().split()))
grud = 0
bic = 0
spin = 0
upr = 1
for i in tren:
if upr == 1:
grud += i
elif upr == 2:
bic += i
elif upr == 3:
spin += i
upr += 1
if upr > 3:
upr = 1
if bic < grud > spin:
print('chest')
elif grud < bic > spin:
print('biceps')
elif bic < spin > grud:
print('back')
``` | 3 |
|
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
The second sample case is described in the statement. | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111",
"output": "321"
},
{
"input": "1110010001000101001011111\n00011011000000100001010000010100110011010001111010",
"output": "316"
}
] | 1,451,131,398 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 342 | 7,270,400 | a,b,cum,total,ans=input(),input(),[0],0,0
for i in range(len(b)):
total+=int(b[i])
cum.append(total)
for i in range(len(a)):
one = cum[len(b)-(len(a)-i)+1]- cum[i]
zero = len(b)-len(a)+1-one
if a[i]=='0':
ans+=one
else:
ans+=zero
# print("i:",i,"one:",one,"zero:",zero,"ans:",ans,"large:",len(b)-(len(a)-i)+1,"cum:",cum[len(b)-(len(a)-i)+1],"small:",i,"cum:",cum[i])
print(ans)
| Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For example, the Hamming distance between string "0011" and string "0110" is |0<=-<=0|<=+<=|0<=-<=1|<=+<=|1<=-<=1|<=+<=|1<=-<=0|<==<=0<=+<=1<=+<=0<=+<=1<==<=2.
Given two binary strings *a* and *b*, find the sum of the Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
Input Specification:
The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only.
Output Specification:
Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
Demo Input:
['01\n00111\n', '0011\n0110\n']
Demo Output:
['3\n', '2\n']
Note:
For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.
The second sample case is described in the statement. | ```python
a,b,cum,total,ans=input(),input(),[0],0,0
for i in range(len(b)):
total+=int(b[i])
cum.append(total)
for i in range(len(a)):
one = cum[len(b)-(len(a)-i)+1]- cum[i]
zero = len(b)-len(a)+1-one
if a[i]=='0':
ans+=one
else:
ans+=zero
# print("i:",i,"one:",one,"zero:",zero,"ans:",ans,"large:",len(b)-(len(a)-i)+1,"cum:",cum[len(b)-(len(a)-i)+1],"small:",i,"cum:",cum[i])
print(ans)
``` | 3 |
|
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,667,307,127 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 343 | 11,264,000 | n = int(input())
d = [ ]
res = 2
for _ in range(n):
x , h = map(int,input().split())
d.append([x,h])
for i in range(1,n):
d[i].append(d[i][0]-d[i-1][0])
for i in range(1,n-1):
if d[i][1] < d[i][2]:
res += 1
elif d[i][1] < d[i+1][2]:
res += 1
d[i+1][2] -= d[i][1]
print(res) | 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())
d = [ ]
res = 2
for _ in range(n):
x , h = map(int,input().split())
d.append([x,h])
for i in range(1,n):
d[i].append(d[i][0]-d[i-1][0])
for i in range(1,n-1):
if d[i][1] < d[i][2]:
res += 1
elif d[i][1] < d[i+1][2]:
res += 1
d[i+1][2] -= d[i][1]
print(res)
``` | 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,698,637,028 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 62 | 1,740,800 | user = str(input())
b = user.split()
c = [int(x) for x in b]
Black = 0
Colored = 0
for x in range(c[0]):
user_put = str(input())
d = user_put.split()
for x in d:
if x == "W" or x == "B" or x == "G":
Black = Black + 1
else:
Colored = Colored + 1
if Black > 0 and Colored > 0:
print("#Color")
elif Black == 0 and Colored > 0:
print("#Color")
elif Black > 0 and Colored == 0:
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
user = str(input())
b = user.split()
c = [int(x) for x in b]
Black = 0
Colored = 0
for x in range(c[0]):
user_put = str(input())
d = user_put.split()
for x in d:
if x == "W" or x == "B" or x == "G":
Black = Black + 1
else:
Colored = Colored + 1
if Black > 0 and Colored > 0:
print("#Color")
elif Black == 0 and Colored > 0:
print("#Color")
elif Black > 0 and Colored == 0:
print("#Black&White")
``` | 3 |
|
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4",
"output": "0\nDDDDRRRR"
},
{
"input": "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4",
"output": "1\nDDRRDRDDRR"
},
{
"input": "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8\n2 7 10 7 5 7 7\n9 2 7 6 4 8 4\n7 2 4 7 4 1 8\n9 5 3 10 1 6 2",
"output": "0\nRRDRRDRDDDDR"
},
{
"input": "8\n1 1 10 1 8 4 8 7\n9 3 3 2 2 6 2 4\n7 4 3 5 10 3 5 1\n8 4 4 10 4 5 9 4\n5 5 5 2 6 7 1 8\n4 10 1 3 2 4 8 3\n8 1 10 2 8 2 2 4\n2 10 6 8 10 2 8 4",
"output": "0\nDRRRRRRRDDDDDD"
},
{
"input": "9\n8 3 3 3 10 3 10 5 6\n2 1 6 1 8 1 9 1 6\n6 1 5 4 2 2 10 4 9\n1 9 1 3 10 6 10 5 5\n1 10 5 4 7 2 5 9 10\n6 6 1 3 1 9 4 9 9\n5 3 7 6 4 6 2 10 2\n9 3 3 10 5 6 7 6 4\n4 9 6 7 4 3 7 6 5",
"output": "1\nDDDDDRDDDRRRRRRR"
},
{
"input": "10\n10 8 6 5 9 8 2 5 3 2\n3 1 8 6 8 10 5 5 7 8\n5 9 7 7 4 9 7 2 5 2\n5 9 9 5 4 2 6 6 8 1\n10 6 9 9 10 5 6 3 5 9\n6 7 10 3 1 4 3 6 7 6\n10 10 4 7 4 4 8 6 7 4\n10 5 8 2 2 7 4 4 1 4\n8 4 6 10 10 6 1 3 3 1\n9 9 7 2 9 5 1 8 6 3",
"output": "1\nDRDDDRRDDDRRDRDRRR"
}
] | 1,688,093,887 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 1,740,800 | def valor(x):
fake = "34567890"
x = str(x)
n = len(x)/2
k = 0
for i in x:
if i in fake:
k += 1
if k == 0 and x.count("1") == n and x.count("2") == n:
return True
else:
return False
def jugada(mov, matriz):
r, c = 0, 0
patron = ""
producto = matriz[0][0]
for i in mov:
if i == "1":
r += 1
patron += "D"
else:
c += 1
patron += "R"
# print("row ",r," col ",c)
producto *= matriz[r][c]
return producto, patron
def count_zero(x):
if x % 10 == 0:
return 1+count_zero(x/10)
else:
return 0
n = int(input())
matriz = []
for i in range(n):
matriz.append(list(map(int, input().split())))
# print(matriz)
n_patron = 2*n-2
minimo, _ = jugada("1"*(n-1)+"2"*(n-1), matriz)
n_jugada = n_patron/2
num = int("1"*n_patron)
for i in range(num, num*2+1):
if valor(i):
# print(i,jugada(str(i),matriz))
producto, jugada_i = jugada(str(i), matriz)
if producto <= minimo and count_zero(producto) <= count_zero(minimo):
minimo = producto
jugada_final = jugada_i
minimo_zeros = count_zero(minimo)
print(minimo_zeros)
print(jugada_final) | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
Input Specification:
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
Output Specification:
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
Demo Input:
['3\n1 2 3\n4 5 6\n7 8 9\n']
Demo Output:
['0\nDDRR\n']
Note:
none | ```python
def valor(x):
fake = "34567890"
x = str(x)
n = len(x)/2
k = 0
for i in x:
if i in fake:
k += 1
if k == 0 and x.count("1") == n and x.count("2") == n:
return True
else:
return False
def jugada(mov, matriz):
r, c = 0, 0
patron = ""
producto = matriz[0][0]
for i in mov:
if i == "1":
r += 1
patron += "D"
else:
c += 1
patron += "R"
# print("row ",r," col ",c)
producto *= matriz[r][c]
return producto, patron
def count_zero(x):
if x % 10 == 0:
return 1+count_zero(x/10)
else:
return 0
n = int(input())
matriz = []
for i in range(n):
matriz.append(list(map(int, input().split())))
# print(matriz)
n_patron = 2*n-2
minimo, _ = jugada("1"*(n-1)+"2"*(n-1), matriz)
n_jugada = n_patron/2
num = int("1"*n_patron)
for i in range(num, num*2+1):
if valor(i):
# print(i,jugada(str(i),matriz))
producto, jugada_i = jugada(str(i), matriz)
if producto <= minimo and count_zero(producto) <= count_zero(minimo):
minimo = producto
jugada_final = jugada_i
minimo_zeros = count_zero(minimo)
print(minimo_zeros)
print(jugada_final)
``` | 0 |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 21 73839",
"output": "9999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99991 623 36438",
"output": "9999150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99999 334 94854",
"output": "9999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99252 9827 84849",
"output": "9925270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99313 9833 10561",
"output": "9931330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "94885 55815 11417",
"output": "9488550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99492 58525 53481",
"output": "9949250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99858 28531 79193",
"output": "9985850000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "99136 47208 42607",
"output": "9913680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "63270 19953 5555",
"output": "-1"
},
{
"input": "10240 128 100000",
"output": "1024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "12 11 3",
"output": "12100"
},
{
"input": "14 12 99998",
"output": "1440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..."
},
{
"input": "1 11 3",
"output": "1100"
},
{
"input": "3 40 1",
"output": "-1"
},
{
"input": "150 100 10",
"output": "1500000000000"
},
{
"input": "5 10 1",
"output": "50"
},
{
"input": "1 15 10",
"output": "15000000000"
},
{
"input": "3 13 2",
"output": "390"
}
] | 1,676,707,195 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 11,366,400 | a,b,n=map(int,input().split())
for i in range(n):
flag=True
for i in range(10):
if int(str(a)+str(i))%b==0:
flag=False
a=int(str(a)+str(i))
break
if flag:
print("-1")
break
if flag==False:
print(a) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times.
Input Specification:
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
Output Specification:
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Demo Input:
['5 4 5\n', '12 11 1\n', '260 150 10\n']
Demo Output:
['524848\n', '121\n', '-1\n']
Note:
none | ```python
a,b,n=map(int,input().split())
for i in range(n):
flag=True
for i in range(10):
if int(str(a)+str(i))%b==0:
flag=False
a=int(str(a)+str(i))
break
if flag:
print("-1")
break
if flag==False:
print(a)
``` | 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,639,812,421 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 92 | 0 | def nod(x, y):
if x < y:
x, y = y, x
while y != 0:
d = y
y = x % y
x = d
return x
a, b, n = map(int, input().split())
while n != 0:
n = n - nod(a, n)
if n == 0:
r = '0'
print(r)
break
n -= nod(b, n)
if n == 0:
r = '1'
print(r)
break
| 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
def nod(x, y):
if x < y:
x, y = y, x
while y != 0:
d = y
y = x % y
x = d
return x
a, b, n = map(int, input().split())
while n != 0:
n = n - nod(a, n)
if n == 0:
r = '0'
print(r)
break
n -= nod(b, n)
if n == 0:
r = '1'
print(r)
break
``` | 3 |
|
122 | B | Lucky Substring | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string *s*, containing only digits. He needs to find a string that
- represents a lucky number without leading zeroes,- is not empty,- is contained in *s* as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya. | The single line contains a non-empty string *s* whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes. | In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes). | [
"047\n",
"16\n",
"472747\n"
] | [
"4\n",
"-1\n",
"7\n"
] | The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String *x* is lexicographically less than string *y* either if *x* is a prefix of *y*, or exists such *i* (1 ≤ *i* ≤ *min*(|*x*|, |*y*|)), that *x*<sub class="lower-index">*i*</sub> < *y*<sub class="lower-index">*i*</sub> and for any *j* (1 ≤ *j* < *i*) *x*<sub class="lower-index">*j*</sub> = *y*<sub class="lower-index">*j*</sub>. Here |*a*| denotes the length of string *a*.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample *s* has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | 1,000 | [
{
"input": "047",
"output": "4"
},
{
"input": "16",
"output": "-1"
},
{
"input": "472747",
"output": "7"
},
{
"input": "1925",
"output": "-1"
},
{
"input": "5486846414848445484",
"output": "4"
},
{
"input": "516160414",
"output": "4"
},
{
"input": "9458569865994896",
"output": "4"
},
{
"input": "94894948577777777884888",
"output": "7"
},
{
"input": "00000",
"output": "-1"
},
{
"input": "9589",
"output": "-1"
},
{
"input": "7665711",
"output": "7"
},
{
"input": "538772857",
"output": "7"
},
{
"input": "8679647744",
"output": "4"
},
{
"input": "23607019991994",
"output": "4"
},
{
"input": "86145305734278927901987281894864719533015270066521",
"output": "7"
},
{
"input": "22438808523154336905543301642540261833729318191",
"output": "4"
},
{
"input": "290732082244359495795943967215788554387079",
"output": "7"
},
{
"input": "6363333480463521971676988087733137609715",
"output": "7"
},
{
"input": "637789221789855555993957058",
"output": "7"
},
{
"input": "11536708648794535307468278326553811",
"output": "7"
},
{
"input": "619433861636130069773",
"output": "7"
},
{
"input": "7",
"output": "7"
},
{
"input": "00000000000000000000000000000000000000000000000000",
"output": "-1"
},
{
"input": "0000000000000000000000000000000000000047",
"output": "4"
},
{
"input": "8175012266795100056032281135654854227489558885698",
"output": "4"
},
{
"input": "8862708665262955384044574268728167940741129",
"output": "4"
},
{
"input": "538772857",
"output": "7"
},
{
"input": "94872076199824813574576121510803",
"output": "7"
},
{
"input": "44101164480392494025995467",
"output": "4"
},
{
"input": "0445460407410702955646485",
"output": "4"
},
{
"input": "91076008557028243309",
"output": "7"
},
{
"input": "33120039",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "74747474747474747474747474747474747474747474747474",
"output": "4"
},
{
"input": "74747474747474747474747774747474747474747474747474",
"output": "7"
},
{
"input": "74747474747474747474747474747474744474747474747474",
"output": "4"
},
{
"input": "47474747474747474747474747474747474747474747474747",
"output": "4"
},
{
"input": "40",
"output": "4"
},
{
"input": "07",
"output": "7"
},
{
"input": "007",
"output": "7"
},
{
"input": "44",
"output": "4"
},
{
"input": "74",
"output": "4"
}
] | 1,691,150,669 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | text = input()
empat = 0
tujuh = 0
for dt in text:
if dt == "4":
empat = empat + 1
elif dt == "7":
tujuh = tujuh + 1
if empat == 0 and tujuh == 0:
print(-1)
elif empat >= tujuh:
print(4)
else:
print(7)
quit()
| Title: Lucky Substring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string *s*, containing only digits. He needs to find a string that
- represents a lucky number without leading zeroes,- is not empty,- is contained in *s* as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input Specification:
The single line contains a non-empty string *s* whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output Specification:
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Demo Input:
['047\n', '16\n', '472747\n']
Demo Output:
['4\n', '-1\n', '7\n']
Note:
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String *x* is lexicographically less than string *y* either if *x* is a prefix of *y*, or exists such *i* (1 ≤ *i* ≤ *min*(|*x*|, |*y*|)), that *x*<sub class="lower-index">*i*</sub> < *y*<sub class="lower-index">*i*</sub> and for any *j* (1 ≤ *j* < *i*) *x*<sub class="lower-index">*j*</sub> = *y*<sub class="lower-index">*j*</sub>. Here |*a*| denotes the length of string *a*.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample *s* has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | ```python
text = input()
empat = 0
tujuh = 0
for dt in text:
if dt == "4":
empat = empat + 1
elif dt == "7":
tujuh = tujuh + 1
if empat == 0 and tujuh == 0:
print(-1)
elif empat >= tujuh:
print(4)
else:
print(7)
quit()
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,589,472,667 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 6,656,000 | n=input()
m=input()
res=""
for i in range(len(n)):
if n[i]!=m[i]:
res+='1'
else:
res+='0'
print(res) | 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
n=input()
m=input()
res=""
for i in range(len(n)):
if n[i]!=m[i]:
res+='1'
else:
res+='0'
print(res)
``` | 3.960352 |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
},
{
"input": "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88",
"output": "6742"
},
{
"input": "2\n100 68\n38 80",
"output": "9384"
}
] | 1,621,110,657 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 171 | 8,294,400 | import sys
def main():
inp = sys.stdin.read().strip().split('\n')
m = None
c = 0
for s in inp[1:]:
a, p = map(int, s.split())
if m == None or m > p: m = p
c += a*m
return c
print(main()) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Output Specification:
Print the minimum money needed to keep Duff happy for *n* days, in one line.
Demo Input:
['3\n1 3\n2 2\n3 1\n', '3\n1 3\n2 1\n3 2\n']
Demo Output:
['10\n', '8\n']
Note:
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | ```python
import sys
def main():
inp = sys.stdin.read().strip().split('\n')
m = None
c = 0
for s in inp[1:]:
a, p = map(int, s.split())
if m == None or m > p: m = p
c += a*m
return c
print(main())
``` | 3 |
|
614 | B | Gena's Code | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. | The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. | Print a single number without leading zeroes — the product of the number of tanks presented by each country. | [
"3\n5 10 1\n",
"4\n1 1 10 11\n",
"5\n0 3 1 100 1\n"
] | [
"50",
"110",
"0"
] | In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | 1,000 | [
{
"input": "3\n5 10 1",
"output": "50"
},
{
"input": "4\n1 1 10 11",
"output": "110"
},
{
"input": "5\n0 3 1 100 1",
"output": "0"
},
{
"input": "40\n10 100 10 1 10 10 100 10 10 100 10 100 100 10 1824868942 100 100 1 10 100 100 10 100 100 10 100 10 1 10 100 100 100 10 1 10 1 10 10 100 100",
"output": "1824868942000000000000000000000000000000000000000000000000000"
},
{
"input": "6\n1000000000000000000000000000000000000 6643573784 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000 1000000000000000000000000000000000000",
"output": "6643573784000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n9",
"output": "9"
},
{
"input": "2\n10 50",
"output": "500"
},
{
"input": "3\n500 1 10",
"output": "5000"
}
] | 1,662,642,328 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
#define all(item) item.begin(), item.end()
using namespace std;
const ll MOD = 1e9 + 7;
double EPS = 1e-9;
// 2d array traverse on 4 direction
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
// // 2d array traverse on 8 directions
// const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
// const int dy8[] = {1, 0, -1, 1, -1, 1, 0, -1};
// knight move on chessboard
// int dx8[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
// int dy8[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void Y() { cout << "YES\n"; }
void N() { cout << "NO\n"; }
void IOS()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.tie(NULL);
}
bool isPrime(ll num)
{
if (num == 1 || num == 0)
{
return false;
}
for (ll i = 2; i * i <= num; i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
ll fac(ll n)
{
if (n == 0)
{
return 1;
}
if (n == 1)
{
return 1;
}
return n * fac(n - 1);
}
ll lcm(ll a, ll b) { return (abs(a * b) / __gcd(a, b)); } // highest freq
template <typename T>
vector<T> getDivisors(T n)
{
vector<T> divisors;
for (T i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
divisors.push_back(i);
if (n % i == 0 && n / i != i)
{
divisors.push_back(n / i);
}
}
}
return divisors;
}
template <typename T>
T power(T x, T y, T mod)
{
if (x == 1)
{
return 1;
}
T res = 1;
while (y)
{
if (y & 1)
{
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y >>= 1;
}
return res;
}
template <typename T>
T power(T x, T y)
{
if (x == 1)
{
return 1;
}
T res = 1;
while (y)
{
if (y & 1)
{
res = (res * x);
y--;
}
x = (x * x);
y >>= 1;
}
return res;
}
ll mul(ll a, ll b)
{
return (a * b) % MOD;
}
ll npr(ll n, ll r)
{
ll res = 1;
for (ll i = n - r + 1; i <= n; i++)
{
res = mul(res, i);
}
return res;
}
ll ncr(ll n, ll r)
{
ll mx = max(r, n - r);
ll mi = min(r, n - r);
ll res = 1;
for (ll i = n - mi + 1; i <= n; i++)
{
res = res * i;
}
res = res / fac(mi);
return res;
}
double distance(int x1, int y1, int x2, int y2)
{
return sqrt((x1 - x2)*(x1-x2) + (y1 - y2)*(y1-y2));
}
struct edge{
int from, to;
double cost;
};
bool cmp(edge &e1, edge &e2){
return (e1.cost - e2.cost) < EPS;
}
struct DSU {
vector<int> p, rank, size;
int cnt;
DSU(int N): cnt(N) {
p = rank = size = vector<int>(N, 1);
for (int i = 0; i < N; i++) p[i] = i;
}
int find(int i) {
return p[i] == i ? i : p[i] = find(p[i]);
}
bool connected(int i, int j) {
return find(i) == find(j);
}
void join(int i, int j) {
if (connected(i, j)) return;
cnt--;
int x = find(i), y = find(j);
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
} else {
p[x] = y;
size[y] += size[x];
if (rank[x] == rank[y]) rank[y]++;
}
}
};
bool valid(string s){
int one = 0;
for(int i=0; i<s.size(); i++){
if(s[i] != '0' && s[i] != '1'){
return false;
}
if(s[i] == '1'){
one++;
}
}
if(one > 1){
return false;
}else{
return true;
}
}
int noZero(string s){
int ans = 0;
for(int i=0; i<s.size(); i++){
if(s[i] == '0'){
ans++;
}
}
return ans;
}
int main(){
IOS();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n; cin >> n;
string s;
int zero = 0;
string num = "";
bool ok = true;
for(int i=0; i<n; i++){
cin >> s;
if(s == "0"){
ok = false;
}else if(!valid(s)){
num = s;
}else if(s.size() != 1){
zero += noZero(s);
}
}
if(!ok){
cout << 0 << '\n';
}else{
if(num.empty()){
cout << 1;
}else{
cout << num;
}
for(int i=0; i<zero; i++){
cout << "0";
}
cout << '\n';
}
}
| Title: Gena's Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!
There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.
Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.
Input Specification:
The first line of the input contains the number of countries *n* (1<=≤<=*n*<=≤<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroes — the number of tanks of the *i*-th country.
It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000.
Output Specification:
Print a single number without leading zeroes — the product of the number of tanks presented by each country.
Demo Input:
['3\n5 10 1\n', '4\n1 1 10 11\n', '5\n0 3 1 100 1\n']
Demo Output:
['50', '110', '0']
Note:
In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.
In sample 3 number 3 is not beautiful, all others are beautiful. | ```python
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
#define all(item) item.begin(), item.end()
using namespace std;
const ll MOD = 1e9 + 7;
double EPS = 1e-9;
// 2d array traverse on 4 direction
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
// // 2d array traverse on 8 directions
// const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
// const int dy8[] = {1, 0, -1, 1, -1, 1, 0, -1};
// knight move on chessboard
// int dx8[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
// int dy8[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void Y() { cout << "YES\n"; }
void N() { cout << "NO\n"; }
void IOS()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.tie(NULL);
}
bool isPrime(ll num)
{
if (num == 1 || num == 0)
{
return false;
}
for (ll i = 2; i * i <= num; i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
ll fac(ll n)
{
if (n == 0)
{
return 1;
}
if (n == 1)
{
return 1;
}
return n * fac(n - 1);
}
ll lcm(ll a, ll b) { return (abs(a * b) / __gcd(a, b)); } // highest freq
template <typename T>
vector<T> getDivisors(T n)
{
vector<T> divisors;
for (T i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
divisors.push_back(i);
if (n % i == 0 && n / i != i)
{
divisors.push_back(n / i);
}
}
}
return divisors;
}
template <typename T>
T power(T x, T y, T mod)
{
if (x == 1)
{
return 1;
}
T res = 1;
while (y)
{
if (y & 1)
{
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y >>= 1;
}
return res;
}
template <typename T>
T power(T x, T y)
{
if (x == 1)
{
return 1;
}
T res = 1;
while (y)
{
if (y & 1)
{
res = (res * x);
y--;
}
x = (x * x);
y >>= 1;
}
return res;
}
ll mul(ll a, ll b)
{
return (a * b) % MOD;
}
ll npr(ll n, ll r)
{
ll res = 1;
for (ll i = n - r + 1; i <= n; i++)
{
res = mul(res, i);
}
return res;
}
ll ncr(ll n, ll r)
{
ll mx = max(r, n - r);
ll mi = min(r, n - r);
ll res = 1;
for (ll i = n - mi + 1; i <= n; i++)
{
res = res * i;
}
res = res / fac(mi);
return res;
}
double distance(int x1, int y1, int x2, int y2)
{
return sqrt((x1 - x2)*(x1-x2) + (y1 - y2)*(y1-y2));
}
struct edge{
int from, to;
double cost;
};
bool cmp(edge &e1, edge &e2){
return (e1.cost - e2.cost) < EPS;
}
struct DSU {
vector<int> p, rank, size;
int cnt;
DSU(int N): cnt(N) {
p = rank = size = vector<int>(N, 1);
for (int i = 0; i < N; i++) p[i] = i;
}
int find(int i) {
return p[i] == i ? i : p[i] = find(p[i]);
}
bool connected(int i, int j) {
return find(i) == find(j);
}
void join(int i, int j) {
if (connected(i, j)) return;
cnt--;
int x = find(i), y = find(j);
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
} else {
p[x] = y;
size[y] += size[x];
if (rank[x] == rank[y]) rank[y]++;
}
}
};
bool valid(string s){
int one = 0;
for(int i=0; i<s.size(); i++){
if(s[i] != '0' && s[i] != '1'){
return false;
}
if(s[i] == '1'){
one++;
}
}
if(one > 1){
return false;
}else{
return true;
}
}
int noZero(string s){
int ans = 0;
for(int i=0; i<s.size(); i++){
if(s[i] == '0'){
ans++;
}
}
return ans;
}
int main(){
IOS();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n; cin >> n;
string s;
int zero = 0;
string num = "";
bool ok = true;
for(int i=0; i<n; i++){
cin >> s;
if(s == "0"){
ok = false;
}else if(!valid(s)){
num = s;
}else if(s.size() != 1){
zero += noZero(s);
}
}
if(!ok){
cout << 0 << '\n';
}else{
if(num.empty()){
cout << 1;
}else{
cout << num;
}
for(int i=0; i<zero; i++){
cout << "0";
}
cout << '\n';
}
}
``` | -1 |
|
126 | B | Password | PROGRAMMING | 1,700 | [
"binary search",
"dp",
"hashing",
"string suffix structures",
"strings"
] | null | null | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. | You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. | Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. | [
"fixprefixsuffix\n",
"abcdabc\n"
] | [
"fix",
"Just a legend"
] | none | 1,000 | [
{
"input": "fixprefixsuffix",
"output": "fix"
},
{
"input": "abcdabc",
"output": "Just a legend"
},
{
"input": "qwertyqwertyqwerty",
"output": "qwerty"
},
{
"input": "papapapap",
"output": "papap"
},
{
"input": "aaaaaaaaaa",
"output": "aaaaaaaa"
},
{
"input": "ghbdtn",
"output": "Just a legend"
},
{
"input": "a",
"output": "Just a legend"
},
{
"input": "aa",
"output": "Just a legend"
},
{
"input": "ab",
"output": "Just a legend"
},
{
"input": "aaa",
"output": "a"
},
{
"input": "aba",
"output": "Just a legend"
},
{
"input": "aab",
"output": "Just a legend"
},
{
"input": "abb",
"output": "Just a legend"
},
{
"input": "abc",
"output": "Just a legend"
},
{
"input": "aaabaabaaaaab",
"output": "Just a legend"
},
{
"input": "aabaaabaaaaab",
"output": "aab"
},
{
"input": "aaabaaaabab",
"output": "Just a legend"
},
{
"input": "abcabcabcabcabc",
"output": "abcabcabc"
},
{
"input": "aaaaabaaaa",
"output": "aaaa"
},
{
"input": "aaaabaaaaaaa",
"output": "aaaa"
},
{
"input": "ghghghgxghghghg",
"output": "ghghg"
},
{
"input": "kincenvizh",
"output": "Just a legend"
},
{
"input": "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw",
"output": "Just a legend"
},
{
"input": "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx",
"output": "Just a legend"
},
{
"input": "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb",
"output": "nfbdzgdlbjhrlvfryyjb"
},
{
"input": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp",
"output": "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp"
},
{
"input": "abcazabca",
"output": "a"
}
] | 1,652,028,646 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 2,000 | 29,696,000 | from string import ascii_lowercase as lc
dt={}
for i in range(26):
dt[lc[i]]=i+3
s=input()
n=len(s)
m=972663749
a=911382323
l1,l2=[],[]
for i in range(n):
l1.append((dt[s[i]])%m)
if len(l2)==0:
l2.append(l1[-1])
else:
l2.append((l2[-1]*a+l1[-1])%m)
ps=[1]
for i in range(n-1):
ps.append((ps[-1]*a)%m)
lans=[]
for i in range(n-1):
if l2[i]==(l2[-1]-l2[-2-i]*ps[i+1])%m:
lans.append(i)
lans.sort
lans.reverse()
f=0
ans='Just a legend'
idx=-1
for i in range(len(lans)):
k1=lans[i]
for j in range(1,n-k1-1):
if l2[k1]==(l2[j+k1]-l2[j-1]*ps[k1+1])%m:
f=1
idx=k1
break
if f==1:
ans=s[:idx+1]
break
print(ans) | Title: Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*.
Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end.
Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened.
You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend.
Input Specification:
You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.
Output Specification:
Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes.
Demo Input:
['fixprefixsuffix\n', 'abcdabc\n']
Demo Output:
['fix', 'Just a legend']
Note:
none | ```python
from string import ascii_lowercase as lc
dt={}
for i in range(26):
dt[lc[i]]=i+3
s=input()
n=len(s)
m=972663749
a=911382323
l1,l2=[],[]
for i in range(n):
l1.append((dt[s[i]])%m)
if len(l2)==0:
l2.append(l1[-1])
else:
l2.append((l2[-1]*a+l1[-1])%m)
ps=[1]
for i in range(n-1):
ps.append((ps[-1]*a)%m)
lans=[]
for i in range(n-1):
if l2[i]==(l2[-1]-l2[-2-i]*ps[i+1])%m:
lans.append(i)
lans.sort
lans.reverse()
f=0
ans='Just a legend'
idx=-1
for i in range(len(lans)):
k1=lans[i]
for j in range(1,n-k1-1):
if l2[k1]==(l2[j+k1]-l2[j-1]*ps[k1+1])%m:
f=1
idx=k1
break
if f==1:
ans=s[:idx+1]
break
print(ans)
``` | 0 |
|
811 | B | Vladik and Complicated Book | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other. | First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik. | For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise. | [
"5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n",
"6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n"
] | [
"Yes\nNo\nYes\nYes\nNo\n",
"Yes\nNo\nYes\nNo\nYes\n"
] | Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | 1,000 | [
{
"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo"
},
{
"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3",
"output": "Yes\nNo\nYes\nNo\nYes"
},
{
"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 2\n6 8 7\n1 1 1\n7 9 9\n2 9 4",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo"
},
{
"input": "20 20\n18 17 2 3 16 15 1 9 12 8 20 11 13 14 4 5 19 7 10 6\n13 15 15\n1 1 1\n2 2 2\n11 14 13\n10 11 10\n2 8 6\n12 18 16\n4 8 8\n2 2 2\n5 11 11\n4 9 9\n5 6 6\n3 20 12\n8 8 8\n6 16 11\n9 18 18\n8 18 17\n1 1 1\n2 6 5\n1 4 3",
"output": "No\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "5 10\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3",
"output": "Yes\nNo\nYes\nYes\nNo\nYes\nNo\nYes\nYes\nNo"
}
] | 1,520,495,326 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 6,451,200 | arri = lambda: [int(s) for s in input().split()]
n, m = arri()
p = arri()
ans = []
for i in range(m):
l, r, x = arri()
no = l - 1
cur = p[x-1]
for i in range(l - 1, r):
if p[i] < cur:
no -=- 1
ans.append('Yes' if no == x- 1 else 'No')
print('\n'.join(ans)) | Title: Vladik and Complicated Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik had started reading a complicated book about algorithms containing *n* pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation *P*<==<=[*p*1,<=*p*2,<=...,<=*p**n*], where *p**i* denotes the number of page that should be read *i*-th in turn.
Sometimes Vladik’s mom sorted some subsegment of permutation *P* from position *l* to position *r* inclusive, because she loves the order. For every of such sorting Vladik knows number *x* — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has *p**x* changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.
Input Specification:
First line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.
Second line contains *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — permutation *P*. Note that elements in permutation are distinct.
Each of the next *m* lines contains three space-separated integers *l**i*, *r**i*, *x**i* (1<=≤<=*l**i*<=≤<=*x**i*<=≤<=*r**i*<=≤<=*n*) — left and right borders of sorted subsegment in *i*-th sorting and position that is interesting to Vladik.
Output Specification:
For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.
Demo Input:
['5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n', '6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n']
Demo Output:
['Yes\nNo\nYes\nYes\nNo\n', 'Yes\nNo\nYes\nNo\nYes\n']
Note:
Explanation of first test case:
1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No". 1. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes". 1. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes". 1. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No". | ```python
arri = lambda: [int(s) for s in input().split()]
n, m = arri()
p = arri()
ans = []
for i in range(m):
l, r, x = arri()
no = l - 1
cur = p[x-1]
for i in range(l - 1, r):
if p[i] < cur:
no -=- 1
ans.append('Yes' if no == x- 1 else 'No')
print('\n'.join(ans))
``` | 0 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,689,689,070 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 307,200 | a = int(input())
n = list(map(int, input().split()))
num1 = []
num2 = []
num3 = []
for i in range(0, a):
if n[i] == 1:
num1.append(i+1)
elif n[i] == 2:
num2.append(i+1)
elif n[i] == 3:
num3.append(i+1)
p = min(n.count(1),n.count(2) ,n.count(3))
print(p)
if p > 0:
for i in range(0, int(p)):
print(num1[i], end=" ")
print(num2[i], end=" ")
print(num3[i]) | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
a = int(input())
n = list(map(int, input().split()))
num1 = []
num2 = []
num3 = []
for i in range(0, a):
if n[i] == 1:
num1.append(i+1)
elif n[i] == 2:
num2.append(i+1)
elif n[i] == 3:
num3.append(i+1)
p = min(n.count(1),n.count(2) ,n.count(3))
print(p)
if p > 0:
for i in range(0, int(p)):
print(num1[i], end=" ")
print(num2[i], end=" ")
print(num3[i])
``` | 3 |
|
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,594,832,091 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 216 | 7,065,600 | def solve():
n, m, d = map(int, input().split())
a = []
l = list(map(int, input().split()))
thismod = l[0]%d
for i in range(m):
a.append(l[i])
if l[i]%d != thismod:
return -1
for i in range(1,n):
l = list(map(int, input().split()))
for j in range(m):
a.append(l[j])
if l[j]%d != thismod:
return -1
a.sort()
target = a[n*m//2]
#print(target)
score = 0
for i in range(n*m):
score += abs(a[i]-target)/d
return int(score)
print(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
def solve():
n, m, d = map(int, input().split())
a = []
l = list(map(int, input().split()))
thismod = l[0]%d
for i in range(m):
a.append(l[i])
if l[i]%d != thismod:
return -1
for i in range(1,n):
l = list(map(int, input().split()))
for j in range(m):
a.append(l[j])
if l[j]%d != thismod:
return -1
a.sort()
target = a[n*m//2]
#print(target)
score = 0
for i in range(n*m):
score += abs(a[i]-target)/d
return int(score)
print(solve())
``` | 3 |
|
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201",
"output": "2\n100 10101 "
},
{
"input": "314159",
"output": "9\n1 1 1 1 11 1011 101011 101011 111111 "
},
{
"input": "999999",
"output": "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 "
},
{
"input": "2",
"output": "2\n1 1 "
},
{
"input": "10",
"output": "1\n10 "
},
{
"input": "21",
"output": "2\n10 11 "
},
{
"input": "98",
"output": "9\n10 11 11 11 11 11 11 11 11 "
},
{
"input": "102030",
"output": "3\n10 1010 101010 "
},
{
"input": "909090",
"output": "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 "
},
{
"input": "909823",
"output": "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 "
},
{
"input": "1000000",
"output": "1\n1000000 "
},
{
"input": "111111",
"output": "1\n111111 "
},
{
"input": "123456",
"output": "6\n1 11 111 1111 11111 111111 "
},
{
"input": "987654",
"output": "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 "
},
{
"input": "908172",
"output": "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 "
},
{
"input": "8",
"output": "8\n1 1 1 1 1 1 1 1 "
},
{
"input": "100009",
"output": "9\n1 1 1 1 1 1 1 1 100001 "
},
{
"input": "900000",
"output": "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 "
},
{
"input": "1435",
"output": "5\n1 101 111 111 1111 "
},
{
"input": "1453",
"output": "5\n10 110 111 111 1111 "
}
] | 1,567,675,563 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n = int(input())
g = [100000 , 10000 , 1000 , 100 , 10 , 1]
l = []
s , m = 0 , 0
while n > 0:
s = 0
for x in g:
if n >= x :
s += x
n -= x
l += [s]
m += 1
print(m)
print(*l)
| Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
Output Specification:
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
Demo Input:
['9\n', '32\n']
Demo Output:
['9\n1 1 1 1 1 1 1 1 1 \n', '3\n10 11 11 \n']
Note:
none | ```python
n = int(input())
g = [100000 , 10000 , 1000 , 100 , 10 , 1]
l = []
s , m = 0 , 0
while n > 0:
s = 0
for x in g:
if n >= x :
s += x
n -= x
l += [s]
m += 1
print(m)
print(*l)
``` | 0 |
|
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,457,116 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string n;
cin >> n;
int pos = n.find_first_of("AOYIUEaoyiue");
while (pos + 1) {
n.erase(n.begin() + pos);
pos = n.find_first_of("AOYIUEaoyiue");
}
for (int i = 0; i < n.size(); ++i) {
if (n[i] < 97)
n[i] += 32;
}
for (int i = 0; i < n.size(); ++i)
cout << "." << n[i];
return 0;
} | 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string n;
cin >> n;
int pos = n.find_first_of("AOYIUEaoyiue");
while (pos + 1) {
n.erase(n.begin() + pos);
pos = n.find_first_of("AOYIUEaoyiue");
}
for (int i = 0; i < n.size(); ++i) {
if (n[i] < 97)
n[i] += 32;
}
for (int i = 0; i < n.size(); ++i)
cout << "." << n[i];
return 0;
}
``` | -1 |
|
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
},
{
"input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1",
"output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 "
},
{
"input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3",
"output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 "
},
{
"input": "10 17\n5 1\n8 1\n2 1\n2 6\n3 1\n5 7\n3 7\n8 6\n4 7\n2 7\n9 7\n10 7\n3 6\n4 1\n9 1\n8 7\n10 1",
"output": "7\n5 3 2 8 4 9 10 \n3\n1 7 6 "
},
{
"input": "10 15\n5 9\n7 8\n2 9\n1 9\n3 8\n3 9\n5 8\n1 8\n6 9\n7 9\n4 8\n4 9\n10 9\n10 8\n6 8",
"output": "2\n9 8 \n8\n1 5 7 3 4 10 6 2 "
},
{
"input": "10 9\n4 9\n1 9\n10 9\n2 9\n3 9\n6 9\n5 9\n7 9\n8 9",
"output": "1\n9 \n9\n1 4 10 2 3 6 5 7 8 "
},
{
"input": "2 1\n1 2",
"output": "1\n2 \n1\n1 "
},
{
"input": "10 10\n6 4\n9 1\n3 6\n6 7\n4 2\n9 6\n8 6\n5 7\n1 4\n6 10",
"output": "6\n9 4 3 7 8 10 \n4\n1 6 2 5 "
},
{
"input": "20 22\n20 8\n1 3\n3 18\n14 7\n19 6\n7 20\n14 8\n8 10\n2 5\n11 2\n4 19\n14 2\n7 11\n15 1\n12 15\n7 6\n11 13\n1 16\n9 12\n1 19\n17 3\n11 20",
"output": "-1"
},
{
"input": "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15",
"output": "-1"
},
{
"input": "1000 1\n839 771",
"output": "1\n839 \n1\n771 "
},
{
"input": "1000 1\n195 788",
"output": "1\n788 \n1\n195 "
},
{
"input": "100000 1\n42833 64396",
"output": "1\n64396 \n1\n42833 "
},
{
"input": "100000 1\n26257 21752",
"output": "1\n26257 \n1\n21752 "
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "-1"
}
] | 1,470,801,703 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 93 | 22,835,200 | n, m = map(int,input().split())
g = [set() for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
g[a-1].add(b-1)
g[b-1].add(a-1)
a = []
p = [-1]*n
for i in range(n):
if p[i] != -1: continue
p[i] = 0
a.append(i)
while a:
t = a.pop()
for elem in g[t]:
if p[elem] == p[t]:
print(-1)
exit
if p[elem] == -1:
p[elem] = not p[t]
a.append(elem)
print(p.count(0))
for i in range(n):
if p[i] == 0:
print(i+1, end = ' ')
print()
print(p.count(1))
for i in range(n):
if p[i] == 1:
print(i+1, end = ' ')
| Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges.
Output Specification:
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty.
Demo Input:
['4 2\n1 2\n2 3\n', '3 3\n1 2\n2 3\n1 3\n']
Demo Output:
['1\n2 \n2\n1 3 \n', '-1\n']
Note:
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | ```python
n, m = map(int,input().split())
g = [set() for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
g[a-1].add(b-1)
g[b-1].add(a-1)
a = []
p = [-1]*n
for i in range(n):
if p[i] != -1: continue
p[i] = 0
a.append(i)
while a:
t = a.pop()
for elem in g[t]:
if p[elem] == p[t]:
print(-1)
exit
if p[elem] == -1:
p[elem] = not p[t]
a.append(elem)
print(p.count(0))
for i in range(n):
if p[i] == 0:
print(i+1, end = ' ')
print()
print(p.count(1))
for i in range(n):
if p[i] == 1:
print(i+1, end = ' ')
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,604,341,933 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 108 | 0 | s = input()
word = "hello"
it = 0
for item in s:
if item == word[it]:
it += 1
if it == 5:
break
if it == 5:
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
word = "hello"
it = 0
for item in s:
if item == word[it]:
it += 1
if it == 5:
break
if it == 5:
print("YES")
else:
print("NO")
``` | 3.946 |
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,617,739,463 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n,m = input().split()
n = int(n)
m = int(m)
print n
print m
area = n*m
if n%2 == 0 or m%2 == 0:
print(int(area/2))
else:
print(int(area/2))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
n,m = input().split()
n = int(n)
m = int(m)
print n
print m
area = n*m
if n%2 == 0 or m%2 == 0:
print(int(area/2))
else:
print(int(area/2))
``` | -1 |
828 | B | Black Square | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | 750 | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB",
"output": "-1"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "2 4\nWWWW\nWBWW",
"output": "0"
},
{
"input": "4 5\nWWWWW\nBBWWW\nBBWWW\nWWWWW",
"output": "0"
},
{
"input": "5 4\nWWWW\nWWWW\nWWWB\nWWWW\nWWWW",
"output": "0"
},
{
"input": "10 5\nWWWWB\nWWWWW\nWWWBB\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW",
"output": "12"
},
{
"input": "5 10\nWWWWWWWWWW\nWWWWBWBBWW\nWWWWWWWWWW\nWWWWBWWWWW\nWWWWWWBWWW",
"output": "11"
},
{
"input": "20 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWBBWBWWWW\nWWBWWBWWWW\nWWWWBWWWWW\nWWWWBWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW",
"output": "9"
},
{
"input": "10 20\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWBW\nWWWWWWWWWWWWWWWWWBWW\nWWWWWWWWWWWWWWWWWWWW",
"output": "2"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "1 1\nB",
"output": "0"
},
{
"input": "2 2\nWW\nWW",
"output": "1"
},
{
"input": "2 2\nWW\nWB",
"output": "0"
},
{
"input": "2 2\nWW\nBW",
"output": "0"
},
{
"input": "2 2\nWW\nBB",
"output": "2"
},
{
"input": "2 2\nWB\nWW",
"output": "0"
},
{
"input": "2 2\nWB\nWB",
"output": "2"
},
{
"input": "2 2\nWB\nBW",
"output": "2"
},
{
"input": "2 2\nWB\nBB",
"output": "1"
},
{
"input": "2 2\nBW\nWW",
"output": "0"
},
{
"input": "2 2\nBW\nWB",
"output": "2"
},
{
"input": "2 2\nBW\nBW",
"output": "2"
},
{
"input": "2 2\nBW\nBB",
"output": "1"
},
{
"input": "2 2\nBB\nWW",
"output": "2"
},
{
"input": "2 2\nBB\nWB",
"output": "1"
},
{
"input": "2 2\nBB\nBW",
"output": "1"
},
{
"input": "2 2\nBB\nBB",
"output": "0"
},
{
"input": "1 2\nWW",
"output": "1"
},
{
"input": "1 2\nWB",
"output": "0"
},
{
"input": "1 2\nBW",
"output": "0"
},
{
"input": "2 1\nW\nW",
"output": "1"
},
{
"input": "2 1\nW\nB",
"output": "0"
},
{
"input": "2 1\nB\nW",
"output": "0"
},
{
"input": "2 1\nB\nB",
"output": "-1"
},
{
"input": "20 10\nWWBWWWBBWW\nWWWWWBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWBBBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWBWWWWWBWW\nWBWWBWWWBW\nWWBWBWWWWW\nWWWBWWBBWW\nWWBBWBWBWW\nBBWWWWWBWW\nWWBWWBBBWW\nWWWBWBBWWW\nWWWBBWBWWW\nWWWWWWWWWW\nWWWBWWWWWW\nWWWWWWWWWW",
"output": "-1"
},
{
"input": "10 20\nWWWWWWWBWWWWWWWBWWWB\nWWWBWWWBWWWWWWWWWWWW\nBWWWWWWWWWWWWWWWWWBB\nWWWWWWBWWBWWBWWWBWWW\nWWWWWWWWBWWBWWWBWWWW\nWBWWWWWWWBWWWWWWWWWW\nWWWBWBWWBWWWWWBBWWWB\nWWBBWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWBWWWWBW\nWWWWWWWWWWWWBWWBWWWB",
"output": "-1"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB",
"output": "0"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "-1"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB",
"output": "-1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB",
"output": "0"
},
{
"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "0"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "0"
},
{
"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "-1"
},
{
"input": "1 5\nWBBWW",
"output": "-1"
},
{
"input": "20 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB",
"output": "-1"
},
{
"input": "3 3\nWBW\nWBB\nWWW",
"output": "1"
},
{
"input": "4 6\nWWWWWW\nWWWBWW\nWWWWWB\nWWWWWW",
"output": "7"
},
{
"input": "5 5\nWBWBW\nWWWWW\nWWWWW\nWWWWW\nWWWWW",
"output": "7"
},
{
"input": "3 3\nBBB\nBBB\nBBB",
"output": "0"
},
{
"input": "5 5\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW",
"output": "23"
},
{
"input": "5 4\nWWBW\nBWWB\nWWWW\nWWWW\nWWWW",
"output": "13"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWWW\nWBBW",
"output": "12"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWBWW",
"output": "34"
},
{
"input": "3 3\nBBW\nWWW\nBWW",
"output": "6"
},
{
"input": "3 3\nBWB\nWWW\nBWW",
"output": "6"
},
{
"input": "6 6\nWBWWWW\nBWWWBW\nWWWWWW\nWWBWWW\nWWWWWW\nWWWWWW",
"output": "21"
},
{
"input": "3 3\nWWW\nWBW\nWWW",
"output": "0"
},
{
"input": "3 3\nBBB\nWWW\nWWW",
"output": "6"
},
{
"input": "5 5\nWWBWW\nWWBWW\nWBBBW\nWWBWW\nWWBWW",
"output": "18"
},
{
"input": "5 2\nWB\nWB\nWB\nWW\nWW",
"output": "-1"
},
{
"input": "4 7\nBBBBBWW\nWWWWWWW\nWWWWWWW\nWWWWWWW",
"output": "-1"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWW\nWWBB\nWWWW",
"output": "6"
},
{
"input": "4 4\nWWWW\nWBWW\nWWWW\nWWWW",
"output": "0"
},
{
"input": "2 5\nWWWWW\nBBBWW",
"output": "-1"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWBW\nWWWWWW\nWWWWWW\nWWBWWW",
"output": "33"
},
{
"input": "3 3\nWBW\nWBW\nWBW",
"output": "6"
},
{
"input": "3 5\nWWBBB\nBWBBB\nWWBBB",
"output": "-1"
},
{
"input": "5 5\nWWWWB\nBWWWW\nWWWWB\nWWWWW\nWWWWW",
"output": "22"
},
{
"input": "5 5\nBWWWB\nWWWWW\nWWWWW\nWWWWW\nBWWWW",
"output": "22"
},
{
"input": "4 5\nWWWWW\nBWWWW\nBBBWW\nWWWWW",
"output": "5"
},
{
"input": "4 4\nBBBB\nWWWW\nWWWW\nWWWW",
"output": "12"
},
{
"input": "4 6\nWWWWWW\nBWWWWW\nBWWWWW\nBBBBBB",
"output": "-1"
},
{
"input": "3 6\nWWWWWW\nBBBWWW\nWWWWWW",
"output": "6"
},
{
"input": "5 2\nWW\nBW\nBW\nBB\nWW",
"output": "-1"
},
{
"input": "5 5\nWWWWW\nWWWWW\nBBBBB\nWWWWW\nWWWWW",
"output": "20"
},
{
"input": "5 5\nWWWWW\nWWWWW\nWWWWB\nWBWWW\nWWWWW",
"output": "14"
},
{
"input": "1 5\nWWBWW",
"output": "0"
},
{
"input": "1 3\nBBB",
"output": "-1"
},
{
"input": "2 4\nWWBW\nBWBW",
"output": "-1"
},
{
"input": "6 6\nBBBBBB\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW",
"output": "30"
},
{
"input": "4 4\nWWWW\nWWWW\nWWWW\nWWWW",
"output": "1"
},
{
"input": "3 3\nWWW\nWWW\nWWB",
"output": "0"
},
{
"input": "5 1\nB\nB\nW\nW\nW",
"output": "-1"
},
{
"input": "2 3\nWBW\nWBW",
"output": "2"
},
{
"input": "5 2\nWW\nWB\nWB\nWB\nWW",
"output": "-1"
},
{
"input": "5 5\nWWWWW\nBWWWW\nWWWWB\nWWWWW\nWWWWW",
"output": "23"
}
] | 1,550,500,002 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 124 | 307,200 | while True:
try:
n,m=map(int,input().split())
a=[]
x1=y1=11111111
x2=y2=z=0
for i in range(0, n):
x=list(input())
a.append(x)
for i in range(0,n):
for j in range(0,m):
if a[i][j]=='B':
z+=1
x1 = min(x1, i)
x2 = max(x2, i)
y1 = min(y1, j)
y2 = max(y2, j)
if z==0:
print(1)
continue
ans=max(x2-x1,y2-y1)+1
if ans>n or ans>m:
print(-1)
else:
print(ans*ans-z)
except EOFError:
break | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output Specification:
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Demo Input:
['5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n', '1 2\nBB\n', '3 3\nWWW\nWWW\nWWW\n']
Demo Output:
['5\n', '-1\n', '1\n']
Note:
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | ```python
while True:
try:
n,m=map(int,input().split())
a=[]
x1=y1=11111111
x2=y2=z=0
for i in range(0, n):
x=list(input())
a.append(x)
for i in range(0,n):
for j in range(0,m):
if a[i][j]=='B':
z+=1
x1 = min(x1, i)
x2 = max(x2, i)
y1 = min(y1, j)
y2 = max(y2, j)
if z==0:
print(1)
continue
ans=max(x2-x1,y2-y1)+1
if ans>n or ans>m:
print(-1)
else:
print(ans*ans-z)
except EOFError:
break
``` | 3 |
|
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\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",
"output": "1"
},
{
"input": "2\n10000000 10000000",
"output": "1"
},
{
"input": "5\n100000000 100000001 100000000 100000001 100000000",
"output": "2"
},
{
"input": "9\n4 3 4 3 4 1 3 3 1",
"output": "3"
},
{
"input": "3\n10000000 1000000000 10000000",
"output": "2"
},
{
"input": "12\n5 6 6 5 6 1 9 9 9 9 9 1",
"output": "6"
},
{
"input": "5\n5 5 1 2 1",
"output": "2"
},
{
"input": "5\n2 2 1 3 1",
"output": "2"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "3\n100000005 1000000000 100000005",
"output": "2"
},
{
"input": "5\n1 2 2 2 1",
"output": "4"
},
{
"input": "3\n10000 1000000 10000",
"output": "2"
},
{
"input": "3\n999999999 999999998 999999998",
"output": "1"
},
{
"input": "6\n2 1 1 2 3 4",
"output": "1"
},
{
"input": "4\n1000000000 900000000 900000000 1000000000",
"output": "1"
},
{
"input": "5\n7 7 2 7 2",
"output": "2"
},
{
"input": "6\n10 10 1 20 20 1",
"output": "3"
},
{
"input": "2\n999999999 999999999",
"output": "1"
},
{
"input": "10\n100000 100000 1 2 3 4 5 6 7 1",
"output": "7"
},
{
"input": "10\n3 3 1 2 2 1 10 10 10 10",
"output": "3"
},
{
"input": "5\n900000000 900000001 900000000 900000001 900000001",
"output": "2"
},
{
"input": "5\n3 3 2 5 2",
"output": "2"
},
{
"input": "2\n100000000 100000000",
"output": "1"
},
{
"input": "10\n10 15 10 2 54 54 54 54 2 10",
"output": "5"
},
{
"input": "2\n999999 999999",
"output": "1"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "5\n1000000000 100000000 1000000000 1000000000 100000000",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "2"
},
{
"input": "5\n1 3 2 3 1",
"output": "4"
},
{
"input": "5\n2 2 1 4 1",
"output": "2"
},
{
"input": "6\n1 2 2 2 2 1",
"output": "5"
},
{
"input": "7\n3 7 6 7 6 7 3",
"output": "6"
},
{
"input": "8\n1 2 2 2 2 1 2 2",
"output": "5"
},
{
"input": "10\n2 2 2 3 3 1 3 3 3 1",
"output": "4"
},
{
"input": "2\n88888888 88888888",
"output": "1"
},
{
"input": "3\n100000000 100000000 100000000",
"output": "1"
},
{
"input": "10\n1 3 2 4 5 5 4 3 2 1",
"output": "9"
},
{
"input": "5\n2 2 1 2 1",
"output": "2"
},
{
"input": "6\n900000005 900000000 900000001 900000000 900000001 900000001",
"output": "2"
},
{
"input": "5\n41 41 1 41 1",
"output": "2"
},
{
"input": "6\n5 5 1 3 3 1",
"output": "3"
},
{
"input": "8\n1 2 2 2 1 2 2 2",
"output": "4"
},
{
"input": "7\n6 6 6 6 1 8 1",
"output": "2"
},
{
"input": "3\n999999999 1000000000 999999999",
"output": "2"
},
{
"input": "5\n5 5 4 10 4",
"output": "2"
},
{
"input": "11\n2 2 3 4 1 5 3 4 2 5 1",
"output": "6"
},
{
"input": "5\n3 5 4 5 3",
"output": "4"
},
{
"input": "6\n6 6 6 6 1 1",
"output": "1"
},
{
"input": "7\n11 1 3 2 3 1 11",
"output": "4"
},
{
"input": "5\n3 3 1 2 1",
"output": "2"
},
{
"input": "5\n4 4 2 5 2",
"output": "2"
},
{
"input": "4\n10000099 10000567 10000099 10000234",
"output": "2"
},
{
"input": "4\n100000009 100000011 100000012 100000009",
"output": "3"
},
{
"input": "2\n1000000 1000000",
"output": "1"
},
{
"input": "2\n10000010 10000010",
"output": "1"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "8\n2 6 2 8 1 9 8 1",
"output": "3"
},
{
"input": "5\n7 7 1 8 1",
"output": "2"
},
{
"input": "7\n1 3 2 3 2 3 1",
"output": "6"
},
{
"input": "7\n2 3 2 1 3 4 1",
"output": "3"
},
{
"input": "5\n1000000000 999999999 1000000000 1000000000 999999999",
"output": "3"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "5\n5 5 3 5 3",
"output": "2"
},
{
"input": "6\n2 3 3 3 3 2",
"output": "5"
},
{
"input": "4\n1 1 2 2",
"output": "1"
},
{
"input": "5\n1 1 2 2 2",
"output": "1"
},
{
"input": "6\n2 1 1 2 2 2",
"output": "1"
},
{
"input": "5\n1000000000 1000000000 100000000 1000000000 100000000",
"output": "2"
},
{
"input": "7\n2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "8\n2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "10\n2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "11\n2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "12\n2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "13\n2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "14\n2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "15\n2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "16\n2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "17\n2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "18\n2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "4\n1000000000 100000000 100000000 1000000000",
"output": "1"
},
{
"input": "21\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "4\n1 2 3 1",
"output": "3"
},
{
"input": "8\n5 5 5 5 3 5 5 3",
"output": "3"
},
{
"input": "7\n2 3 2 1 4 4 1",
"output": "3"
},
{
"input": "6\n3 3 1 2 4 1",
"output": "3"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "5\n3 3 2 8 2",
"output": "2"
},
{
"input": "5\n1 2 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 1 2",
"output": "2"
},
{
"input": "5\n3 1 1 3 2",
"output": "1"
},
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "4\n2 2 1 1",
"output": "1"
},
{
"input": "5\n1 2 2 1 2",
"output": "3"
},
{
"input": "7\n2 1 2 1 1 2 1",
"output": "1"
},
{
"input": "9\n200000 500000 500000 500000 200000 500000 500000 500000 500000",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "85\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 1",
"output": "84"
},
{
"input": "5\n1000000000 1000000000 999999999 1000000000 999999999",
"output": "2"
},
{
"input": "5\n2 1 2 2 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n1 2 1 1",
"output": "1"
},
{
"input": "6\n1 3 4 2 4 1",
"output": "5"
},
{
"input": "9\n2 2 5 1 6 8 7 9 1",
"output": "5"
},
{
"input": "10\n1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 999999999",
"output": "6"
},
{
"input": "7\n3 3 1 2 4 1 2",
"output": "3"
},
{
"input": "7\n3 3 1 2 3 4 1",
"output": "4"
},
{
"input": "8\n10 5 10 1 10 10 10 1",
"output": "4"
}
] | 1,516,515,302 | 2,822 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 7,270,400 | n = int(input())
a = list(map(int, input().split()))
last = -1
ans = []
for i in range(n):
if a[i] == min(a):
if last == -1:
last = i
else:
ans.append(i - last)
last = i
print(min(ans)) | Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
Input Specification:
The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Output Specification:
Print the only number — distance between two nearest minimums in the array.
Demo Input:
['2\n3 3\n', '3\n5 6 5\n', '9\n2 1 3 5 4 1 2 3 1\n']
Demo Output:
['1\n', '2\n', '3\n']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
last = -1
ans = []
for i in range(n):
if a[i] == min(a):
if last == -1:
last = i
else:
ans.append(i - last)
last = i
print(min(ans))
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,679,511,174 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 46 | 0 | n = int(input())
words = [input() for _ in range(n)]
new_words = []
for word in words:
if len(word) > 10:
curr = f"{word[0]}{len(word)-2}{word[-1]}"
else:
curr = word
new_words.append(curr)
[print(word) for word in new_words] | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
n = int(input())
words = [input() for _ in range(n)]
new_words = []
for word in words:
if len(word) > 10:
curr = f"{word[0]}{len(word)-2}{word[-1]}"
else:
curr = word
new_words.append(curr)
[print(word) for word in new_words]
``` | 3.977 |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins.
Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing? | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1\n2 3",
"output": "YES"
},
{
"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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "35\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884",
"output": "YES"
},
{
"input": "5\n1 2 3 4 10 10 6 7 8 9",
"output": "YES"
},
{
"input": "2\n1 1 1 2",
"output": "NO"
},
{
"input": "2\n10 4 4 4",
"output": "NO"
},
{
"input": "2\n2 3 3 3",
"output": "NO"
},
{
"input": "4\n1 2 3 4 5 4 6 7",
"output": "NO"
},
{
"input": "4\n2 5 4 5 8 3 1 5",
"output": "YES"
},
{
"input": "4\n8 2 2 4 1 4 10 9",
"output": "NO"
},
{
"input": "2\n3 8 10 2",
"output": "YES"
},
{
"input": "3\n1 3 4 4 5 6",
"output": "NO"
},
{
"input": "2\n3 3 3 4",
"output": "NO"
},
{
"input": "2\n1 1 2 2",
"output": "YES"
},
{
"input": "2\n1 1 3 3",
"output": "YES"
},
{
"input": "2\n1 2 3 2",
"output": "NO"
},
{
"input": "10\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4",
"output": "NO"
},
{
"input": "3\n1 2 3 3 4 5",
"output": "NO"
},
{
"input": "2\n2 2 1 1",
"output": "YES"
},
{
"input": "7\n1 2 3 4 5 6 7 7 8 9 10 11 12 19",
"output": "NO"
},
{
"input": "5\n1 2 3 4 5 3 3 5 6 7",
"output": "YES"
},
{
"input": "4\n1 1 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "51\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224",
"output": "YES"
},
{
"input": "3\n3 3 3 2 3 2",
"output": "NO"
},
{
"input": "2\n5 3 3 6",
"output": "YES"
},
{
"input": "2\n1 2 2 3",
"output": "NO"
},
{
"input": "2\n1 3 2 2",
"output": "NO"
},
{
"input": "2\n1 3 3 4",
"output": "NO"
},
{
"input": "2\n1 2 2 2",
"output": "NO"
},
{
"input": "3\n1 2 7 19 19 7",
"output": "NO"
},
{
"input": "3\n1 2 3 3 5 6",
"output": "NO"
},
{
"input": "2\n1 2 2 4",
"output": "NO"
},
{
"input": "2\n6 6 5 5",
"output": "YES"
},
{
"input": "2\n3 1 3 1",
"output": "YES"
},
{
"input": "3\n1 2 3 3 1 1",
"output": "YES"
},
{
"input": "3\n3 2 1 3 4 5",
"output": "NO"
},
{
"input": "3\n4 5 6 4 2 1",
"output": "NO"
},
{
"input": "3\n1 1 2 3 2 4",
"output": "NO"
},
{
"input": "3\n100 99 1 1 1 1",
"output": "NO"
},
{
"input": "3\n1 2 3 6 5 3",
"output": "NO"
},
{
"input": "2\n2 2 1 2",
"output": "NO"
},
{
"input": "4\n1 2 3 4 5 6 7 4",
"output": "NO"
},
{
"input": "3\n1 2 3 1 1 1",
"output": "NO"
},
{
"input": "3\n6 5 3 3 1 3",
"output": "NO"
},
{
"input": "2\n1 2 1 2",
"output": "YES"
},
{
"input": "3\n1 2 5 6 8 6",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5 3 3 3 3 3",
"output": "NO"
},
{
"input": "2\n1 2 4 2",
"output": "NO"
},
{
"input": "3\n7 7 4 5 319 19",
"output": "NO"
},
{
"input": "3\n1 2 4 4 3 5",
"output": "YES"
},
{
"input": "3\n3 2 3 4 5 2",
"output": "NO"
},
{
"input": "5\n1 2 3 4 4 5 3 6 7 8",
"output": "NO"
},
{
"input": "3\n3 3 4 4 5 1",
"output": "YES"
},
{
"input": "2\n3 4 3 3",
"output": "NO"
},
{
"input": "2\n2 5 4 4",
"output": "NO"
},
{
"input": "5\n1 2 3 3 4 5 6 7 8 4",
"output": "NO"
},
{
"input": "3\n1 2 3 3 5 5",
"output": "NO"
},
{
"input": "2\n3 4 4 4",
"output": "NO"
},
{
"input": "2\n1 4 5 4",
"output": "NO"
},
{
"input": "2\n1 2 3 3",
"output": "YES"
},
{
"input": "2\n1 1 2 1",
"output": "NO"
},
{
"input": "4\n1 1 1 1 2 2 2 2",
"output": "YES"
},
{
"input": "4\n1 2 3 5 6 7 8 5",
"output": "NO"
},
{
"input": "2\n4 3 3 1",
"output": "NO"
},
{
"input": "3\n3 1 2 4 3 5",
"output": "NO"
},
{
"input": "3\n1 2 3 3 4 6",
"output": "NO"
},
{
"input": "4\n2 2 2 4 5 5 5 5",
"output": "YES"
},
{
"input": "2\n1 3 4 3",
"output": "NO"
},
{
"input": "2\n3 3 2 3",
"output": "NO"
},
{
"input": "2\n1 2 1 1",
"output": "NO"
},
{
"input": "3\n1 3 4 4 2 5",
"output": "YES"
},
{
"input": "4\n4 7 1 2 3 5 6 4",
"output": "NO"
},
{
"input": "2\n3 2 2 2",
"output": "NO"
},
{
"input": "1\n2 1",
"output": "YES"
},
{
"input": "2\n3 3 1 2",
"output": "YES"
},
{
"input": "1\n8 6",
"output": "YES"
},
{
"input": "7\n6 7 6 7 3 1 9 4 6 10 8 2 5 7",
"output": "NO"
},
{
"input": "2\n3 9 2 1",
"output": "YES"
},
{
"input": "2\n3 3 3 3",
"output": "NO"
}
] | 1,634,257,927 | 127 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n = int(input())
A = list(map(int, input().split()))
A.sort()
B = A[0:n]
C = A[n:]
if max(B) < max(C):
print('YES')
else:
print('NO')
| Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·*n* players into two teams with *n* people each in such a way that the first team always wins.
Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing?
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000).
Output Specification:
If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
Demo Input:
['2\n1 3 2 4\n', '1\n3 3\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
n = int(input())
A = list(map(int, input().split()))
A.sort()
B = A[0:n]
C = A[n:]
if max(B) < max(C):
print('YES')
else:
print('NO')
``` | 0 |
|
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location! | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
{
"input": "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ",
"output": "contest"
},
{
"input": "10\nPVO\nDMN->PVO\nDMN->PVO\nPVO->DMN\nDMN->PVO\nPVO->DMN\nPVO->DMN\nPVO->DMN\nDMN->PVO\nPVO->DMN\nDMN->PVO",
"output": "home"
},
{
"input": "11\nIAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nRUQ->IAU\nIAU->RUQ\nIAU->RUQ\nRUQ->IAU",
"output": "contest"
},
{
"input": "10\nHPN\nDFI->HPN\nHPN->KAB\nHPN->DFI\nVSO->HPN\nHPN->KZX\nHPN->VSO\nKZX->HPN\nLDW->HPN\nKAB->HPN\nHPN->LDW",
"output": "home"
},
{
"input": "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE->FGH\nFGH->KQK\nFGH->QRE\nKQK->FGH\nFGH->UBK\nBRZ->FGH\nFGH->ALX\nALX->FGH\nFGH->KQK",
"output": "contest"
},
{
"input": "50\nPFH\nJFV->PFH\nBVP->PFH\nPFH->BVP\nPFH->JFV\nPFH->ETQ\nPFH->LQJ\nZTO->PFH\nPFH->BVP\nPFH->RXO\nPFH->ZTO\nHWL->PFH\nPFH->HIV\nPFH->AFP\nPFH->HWL\nOBB->PFH\nHIV->PFH\nPFH->LSR\nAFP->PFH\nLQJ->PFH\nHWL->PFH\nETQ->PFH\nPFH->HWL\nLSR->PFH\nWBR->PFH\nBNZ->PFH\nHQR->PFH\nZTO->PFH\nPFH->WBR\nPFH->BYJ\nRXO->PFH\nFHZ->PFH\nFHZ->PFH\nPFN->PFH\nPFH->GMB\nPFH->JFV\nJFV->PFH\nGNZ->PFH\nPFH->BNZ\nPFH->GNZ\nPFH->HQR\nBYJ->PFH\nGMB->PFH\nPFH->FHZ\nPFH->FHZ\nPFH->ZTO\nPFH->UGD\nBVP->PFH\nUGD->PFH\nPFH->PFN\nPFH->OBB",
"output": "home"
},
{
"input": "1\nAAK\nAAK->ABA",
"output": "contest"
},
{
"input": "1\nXYZ\nXYZ->XYR",
"output": "contest"
}
] | 1,618,559,155 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 62 | 0 | n = int(input())
ha = str(input())
for _ in range(0,n):
tl = str(input())
if n % 2 == 0:
print('home')
else:
print('contest') | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:
- this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home.
Please help them to determine Jinotega's location!
Input Specification:
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.
It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
Output Specification:
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
Demo Input:
['4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n', '3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n']
Demo Output:
['home\n', 'contest\n']
Note:
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | ```python
n = int(input())
ha = str(input())
for _ in range(0,n):
tl = str(input())
if n % 2 == 0:
print('home')
else:
print('contest')
``` | 3 |
|
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,536,897,643 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | a=int(input())
b=int(input())
if(a>0 and b>0):
if(b==a+1):
print("YES")
else:
print("NO") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
a=int(input())
b=int(input())
if(a>0 and b>0):
if(b==a+1):
print("YES")
else:
print("NO")
``` | -1 |
|
958 | A1 | Death Stars (easy) | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct.
Two rebel spies have provided her with the maps of the solar system. Each map is an *N*<=×<=*N* grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.
Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out. | The first line of the input contains one number *N* (1<=≤<=*N*<=≤<=10) – the dimension of each map. Next *N* lines each contain *N* characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next *N* lines each contain *N* characters, depicting the second map in the same format. | The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations. | [
"4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX\n",
"2\nXX\nOO\nXO\nOX\n"
] | [
"Yes\n",
"No\n"
] | In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. | 0 | [
{
"input": "4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX",
"output": "Yes"
},
{
"input": "2\nXX\nOO\nXO\nOX",
"output": "No"
},
{
"input": "1\nO\nO",
"output": "Yes"
},
{
"input": "1\nX\nO",
"output": "No"
},
{
"input": "2\nOX\nXX\nOX\nXX",
"output": "Yes"
},
{
"input": "2\nOX\nXO\nXO\nOX",
"output": "Yes"
},
{
"input": "2\nOX\nOX\nXX\nOX",
"output": "No"
},
{
"input": "2\nOO\nOO\nOO\nOO",
"output": "Yes"
},
{
"input": "2\nOX\nOX\nXO\nXO",
"output": "Yes"
},
{
"input": "10\nXXXOOOOXOX\nOOOXXXOXXO\nXOXXXXOOXX\nXOOOXXOXOO\nOOXOOOOOOX\nXXXXOXOOOO\nXXXOOXOXOX\nOOOOXOXOXX\nXOXXOXOOXO\nOOOOOXOOOO\nXXXOOOOXOX\nOOOXXXOXXO\nXOXXXXOOXX\nXOOOXXOXOO\nOOXOOOOOOX\nXXXXOXOOOO\nXXXOOXOXOX\nOOOOXOXOXX\nXOXXOXOOXO\nOOOOOXOOOO",
"output": "Yes"
},
{
"input": "10\nXXOXXOXOOX\nOOOOXOOXXO\nOXXXOOXOOO\nOOXOOOOOOO\nXXXOXOXXXX\nOXXXXOXXOO\nOXXXXOOXXX\nXXOXXOXOXO\nOOOXOOOOOO\nXOOXOOOOXX\nXOOXOOOOXX\nOOOXOOOOOO\nXXOXXOXOXO\nOXXXXOOXXX\nOXXXXOXXOO\nXXXOXOXXXX\nOOXOOOOOOO\nOXXXOOXOOO\nOOOOXOOXXO\nXXOXXOXOOX",
"output": "Yes"
},
{
"input": "10\nXXOOOOOXXO\nOXOOXOOXXO\nXOOXOXXXXO\nOXXXXOXOXO\nXXXOXXOXOO\nOXOOOOOXOX\nXOXOXOOOXO\nOXXXOOOOOX\nXXOOOOOXOO\nXOXXXOOXXX\nXXOXOXOXOX\nOXXOXXXOXX\nXOXXOXXOOO\nXOXOOOXXOO\nXOOXOXXOXO\nOOOOOXOXOO\nOXOOOOXXOO\nXXOOXXOXXX\nXOOXOOXXXX\nXOXOXOOOOO",
"output": "No"
},
{
"input": "10\nXOOXOXXXXX\nXOXXOXOXXX\nOOOXOXOOOX\nOOOXXXOOXX\nOXOXXOXOXO\nOXXOXOOOOO\nOXOOXXOXXO\nOOXOXXXXOX\nXOXXXXOOXX\nXOOOOXXOOX\nXXXOOOXXXX\nOXOXOXXOXX\nOOXXOOOOXX\nXOXOOXOOOX\nXXXXOOXXXX\nOXXXXXXOOO\nOXOOOXXXXX\nOXXOXOOOXO\nOOOXXXOOOO\nXXOOOOOOXX",
"output": "Yes"
},
{
"input": "10\nXXOOXOOOXO\nXXOXXXXXXX\nXOOOXOOXXX\nOXOOOXXXXO\nXOOOOOOOOO\nXXOXXXXOOX\nOOOXOXOOOX\nXOXOOXOOXO\nOOXOOXOXXO\nXOXOXOXXOO\nOOOXXOOXXO\nOXXOOOOXOX\nXXOOOOXXXO\nXOOOXOXOXO\nOXXXXOXOXO\nXOOOXOOXXX\nOOOXXOOOXO\nXXXOOOOOOO\nOOOOXOXOXX\nXOXOXXOXXX",
"output": "No"
},
{
"input": "10\nXOOOOXOOOX\nOOOOOOOXXX\nOXOOOXXOXO\nOOXXXOOXOX\nOOXXOOOXXO\nXXXXOXOXXX\nXXXOOXOOOO\nXXXXOOXXXO\nOXXXXXXOXX\nXXXOOOXOXO\nXOOOXOOOOX\nXXXOOOOOOO\nOXOXXOOOXO\nXOXOOXXXOO\nOXXOOOXXOO\nXXXOXOXXXX\nOOOOXOOXXX\nOXXXOOXXXX\nXXOXXXXXXO\nOXOXOOOXXX",
"output": "Yes"
},
{
"input": "10\nXOXXOXXOOX\nOXXOXOXXXX\nXXOOXOXOOO\nOXOOOOXOOO\nOOOOOOOXOX\nXXOXXOOXOX\nXOXOXOOOOX\nOXOXOOXXOX\nXOXOXOXXXO\nOOXOXXXXXX\nOOXOOXXXXX\nXOXOXOXXXO\nOXOXOOXXOX\nXOXXXOOOOX\nXXOXXOOXOX\nOOOOOOOXOX\nOXOOOOXOOO\nXXOOXOXOOO\nOXXOXOXXXX\nXOXOOXXOOX",
"output": "No"
},
{
"input": "10\nXXXOXOOXXX\nOOXXOXXOXO\nOOOOXOOXOX\nXOOXOXOOXX\nXOXXOXOOXX\nOOOXXOXOXX\nOOOXOOOOXO\nOOXOOXXOXX\nXXOXOOXOOX\nOXXXOOXOXX\nXXOXOOXXXO\nXOOXOOXOXX\nXXOXXOOXOO\nOXOOOOXOOO\nXXOXOXXOOO\nXXOOXOXXOX\nXXOOXOXOOX\nXOXOOXOOOO\nOXOXXOXXOO\nXXXOOXOXXX",
"output": "Yes"
},
{
"input": "10\nXOXXXXXXXX\nOOOOXXXOXO\nXOXXXXOOXX\nXXXOXXXXXO\nOXXXXOXOOO\nOOOOOXOXXX\nXOOOXOOXXX\nXOOOXXXXOO\nOXOOXOXXOX\nOXOXXOXXOX\nXXOXXOOXOX\nOOOXXOXXXX\nXXXXXOXOOX\nXXXOOXXOXO\nOOXOXOXXXX\nXXXXOXXXXX\nXOOOOXOXOX\nOOOXOXXXXX\nXXOOOXXOOO\nOOXXOOXOOX",
"output": "No"
},
{
"input": "10\nXXXOOOOOXO\nXXOXOOXOXX\nXOXXXXXXXO\nXOXOXOOXXX\nXXOOXXOXXO\nOOOOOOOOXX\nOOXOXXOOXX\nXXXXOXXOOO\nXOXOXXXOXX\nOXXOXXOOOO\nOXOXOXXOXO\nXXXXXXXOXO\nOOXXXOOOOO\nOXXOOOOXXO\nOOXOXOXXXX\nOOXXXOXOXX\nOXXOOOOXOO\nXOXXOOXXXX\nXXOOXOOXOX\nXXXXXOOXXO",
"output": "Yes"
},
{
"input": "10\nXXOXOOOOXX\nXOXXXOXOXO\nOXXXOOXOOO\nXXOXOOXXOX\nXXOXXOXXOO\nOOOXXXXOXO\nOXXXOXOXOO\nOXOXXXXXXX\nXXXOOXXXXX\nXXOOXOOXXO\nXOOOOXXOXX\nXXXXOXXXOX\nOXOXOOOXXO\nOOXXXXXXXX\nXOXOXXOOXO\nOXXXXOOOXX\nOXXXXXXXXO\nXXXXOXXOOO\nXXXOXOOOXX\nOXXXOOXOOX",
"output": "No"
},
{
"input": "10\nXOXXXXXOOO\nOXXOOXXOXX\nXXXXXOOXOX\nOOOOOXOXOX\nOXXOXXXOXO\nXOOXOXXXXX\nXOOOOOOOOX\nOOXXOOXXXX\nOOOOXXOOOX\nXXXXXOOOXX\nXXOOOXXXXX\nXOOOXXOOOO\nXXXXOOXXOO\nXOOOOOOOOX\nXXXXXOXOOX\nOXOXXXOXXO\nXOXOXOOOOO\nXOXOOXXXXX\nXXOXXOOXXO\nOOOXXXXXOX",
"output": "Yes"
},
{
"input": "10\nXXOOOOOXOX\nOOOOXXXOXX\nOOOXOOOOXX\nOXXXXXXOOX\nXOOXOXOOXX\nXOOOOOOXXO\nXXXOOOOXOO\nOOOOXOXOOO\nOXOOOOOXOX\nXXOXXXOXOX\nXXOOOXXXXO\nOOOOXXOOXO\nXXOXXOOOOX\nXOXOOOXOXO\nXOOOOXXOXO\nXOXOOOXOXO\nXOOXOXXXXO\nOOOXOOXOOO\nXXOXOXXOOX\nXOOXXXOOOX",
"output": "No"
},
{
"input": "3\nOXO\nOXO\nOOO\nOOO\nOXO\nOXO",
"output": "Yes"
},
{
"input": "3\nOXX\nOOO\nXXO\nOOX\nXOO\nOOO",
"output": "No"
},
{
"input": "4\nXXXX\nXXOO\nOOOX\nXXOX\nXXOX\nXXOX\nXOOO\nXOXX",
"output": "Yes"
},
{
"input": "4\nOXOO\nXOXX\nOOOO\nOXXX\nOXOO\nXXXO\nOXOO\nOOOO",
"output": "No"
},
{
"input": "5\nXXXXO\nOXOXO\nXOXOO\nXOXXX\nXOXXX\nXXXXO\nOXOXO\nXOXOO\nXOXXX\nXOXXX",
"output": "Yes"
},
{
"input": "5\nXOXXX\nXOXXO\nOXOOX\nOOXXX\nOOXXX\nXOXXO\nXXXXO\nOXOOX\nXXXOX\nOOOXX",
"output": "No"
},
{
"input": "6\nOOOOOX\nOXOXXX\nXXOOOO\nXXXOXX\nXOOOOX\nOOOXOX\nXXXOXX\nOOXOXO\nXOOOXO\nOOXOOO\nOOXXXO\nOXXXOO",
"output": "Yes"
},
{
"input": "6\nXOOXOO\nXXOOXO\nOXXOOO\nXOOXOO\nOXXXXX\nOOOOXX\nXXOXOO\nOXOOXO\nOOXOOX\nXXOXXO\nOXOOXX\nOOOOXX",
"output": "No"
},
{
"input": "7\nOOXXOOX\nXOXOOXO\nOOOXOOO\nXXOOOXX\nXXXXXOX\nXOXOOOO\nXOXOOOX\nOXOXXXX\nOOOXXOO\nXXOOXXX\nXOXOXOO\nOOOOXOO\nOXOXOOO\nXOOXXOX",
"output": "Yes"
},
{
"input": "7\nXOXOOXO\nXOOOXXO\nXOOXXXO\nXOOXXOO\nOXXOOXX\nXXOOOXO\nXXOXXXX\nXOXOOXX\nXOOOXXO\nXOOOXXO\nXOOXXOO\nXXXXOXX\nXXOOOXO\nXXOXOOX",
"output": "No"
},
{
"input": "8\nOXOXXXXX\nXXXXOXOO\nOXOXOXOX\nXXXOXXOX\nOXXOXXXX\nXXOXXXOO\nXXXXOOOO\nOXXXOOOO\nOOOOXXXO\nOOOOXXXX\nOOXXXOXX\nXXXXOXXO\nXOXXOXXX\nXOXOXOXO\nOOXOXXXX\nXXXXXOXO",
"output": "Yes"
},
{
"input": "8\nOXOOOOOO\nXOXOXXXO\nOXXXXXOX\nOOXXOXOO\nXOOOXOOO\nXOOXXOXO\nOOXXXXXX\nXXXOOXXX\nOXOOXXOO\nXOXOOOOX\nOOXXOOXX\nOOXXOXXO\nOXXOXXXX\nOXOXXOXO\nOXOOOXXX\nOOXOOOXX",
"output": "No"
},
{
"input": "9\nXXXOXOOXO\nXOOOOXOOO\nOOXXOXOXO\nXXXXOXOXX\nXXXXXXOXO\nOOXOXXOXX\nXXOXXXXXO\nXXXOXOOOO\nXXOOXOOXX\nXXXOXOOXO\nXOOOOXOOO\nOOXXOXOXO\nXXXXOXOXX\nXXXXXXOXO\nOOXOXXOXX\nXXOXXXXXO\nXXXOXOOOO\nXXOOXOOXX",
"output": "Yes"
},
{
"input": "9\nOXOXXXXOX\nXOXXOXOOO\nOOXOOOXOO\nOOOXXOXOX\nOOXOOOOXX\nOXXXOXOOO\nOOOXXOXOO\nOOXOXXOXO\nOOXOOOXOX\nOXOOOOXOO\nXOOOOXOOO\nOXXOXXOXO\nXXOXOXXOO\nXOOOOOOXO\nXXOOOXOXO\nXOXOOOXOX\nOOXOXOOXO\nXOOXXOOOX",
"output": "No"
}
] | 1,526,178,133 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #使用deepcopy使lista不被改变
#双引号要打一对 不然要出事
#初始化别加int
import copy
lista=[]
listb=[]
temp=[]
a=int(input())
flag=0
mark=0
for i in range(0,a):
str=input()
for j in range(0,a):
temp.append(str[j])
lista.append(temp)
temp=[]
for i in range(0,a):
str=input()
for j in range(0,a):
temp.append(str[j])
listb.append(temp)
temp=[]
listacpy =copy.deepcopy(lista)
#转90°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-j][i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转180°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-i][a-1-j]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转270°
for i in range(0,a):
for j in range(0,a):
listacpy[j][a-1-i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
#翻面
listtemp=copy.deepcopy(lista)
for i in range(0,a):
for j in range(0,a):
lista[i][j]=listtemp[i][a-1-j]
mark = 0
listacpy =copy.deepcopy(lista)
#转90°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-j][i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转180°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-i][a-1-j]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转270°
for i in range(0,a):
for j in range(0,a):
listacpy[j][a-1-i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
if(flag==1):
print("yes")
else:
print("no")
| Title: Death Stars (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct.
Two rebel spies have provided her with the maps of the solar system. Each map is an *N*<=×<=*N* grid, where each cell is either occupied by a star or empty. To see whether the information is correct, Heidi needs to know whether the two maps are of the same solar system, or if possibly one of the spies is actually an Empire double agent, feeding her false information.
Unfortunately, spies may have accidentally rotated a map by 90, 180, or 270 degrees, or flipped it along the vertical or the horizontal axis, before delivering it to Heidi. If Heidi can rotate or flip the maps so that two of them become identical, then those maps are of the same solar system. Otherwise, there are traitors in the Rebel ranks! Help Heidi find out.
Input Specification:
The first line of the input contains one number *N* (1<=≤<=*N*<=≤<=10) – the dimension of each map. Next *N* lines each contain *N* characters, depicting the first map: 'X' indicates a star, while 'O' indicates an empty quadrant of space. Next *N* lines each contain *N* characters, depicting the second map in the same format.
Output Specification:
The only line of output should contain the word Yes if the maps are identical, or No if it is impossible to match them by performing rotations and translations.
Demo Input:
['4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX\n', '2\nXX\nOO\nXO\nOX\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first test, you can match the first map to the second map by first flipping the first map along the vertical axis, and then by rotating it 90 degrees clockwise. | ```python
#使用deepcopy使lista不被改变
#双引号要打一对 不然要出事
#初始化别加int
import copy
lista=[]
listb=[]
temp=[]
a=int(input())
flag=0
mark=0
for i in range(0,a):
str=input()
for j in range(0,a):
temp.append(str[j])
lista.append(temp)
temp=[]
for i in range(0,a):
str=input()
for j in range(0,a):
temp.append(str[j])
listb.append(temp)
temp=[]
listacpy =copy.deepcopy(lista)
#转90°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-j][i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转180°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-i][a-1-j]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转270°
for i in range(0,a):
for j in range(0,a):
listacpy[j][a-1-i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
#翻面
listtemp=copy.deepcopy(lista)
for i in range(0,a):
for j in range(0,a):
lista[i][j]=listtemp[i][a-1-j]
mark = 0
listacpy =copy.deepcopy(lista)
#转90°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-j][i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转180°
for i in range(0,a):
for j in range(0,a):
listacpy[a-1-i][a-1-j]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
mark = 0
#转270°
for i in range(0,a):
for j in range(0,a):
listacpy[j][a-1-i]=lista[i][j]
for i in range(0,a):
for j in range(0,a):
if(listacpy[i][j]!=listb[i][j]):
mark=1
break
if(mark==1):
break
if(mark==0):
flag=1
if(flag==1):
print("yes")
else:
print("no")
``` | -1 |
|
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggglgpep",
"output": "2"
},
{
"input": "iegdlraaidefgegiagrdfhihe",
"output": "2"
},
{
"input": "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg",
"output": "1"
},
{
"input": "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw",
"output": "2"
},
{
"input": "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbkvviwntdhqscvkmphnkkljizndnbjt",
"output": "3"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "99"
},
{
"input": "ikiikiikikiiikkkkkikkkkiiiiikkiiikkiikiikkkkikkkikikkikiiikkikikiiikikkkiiikkkikkikkikkkkiiikkiiiiii",
"output": "10"
},
{
"input": "ovovhoovvhohhhvhhvhhvhovoohovhhoooooovohvooooohvvoooohvvovhhvhovhhvoovhvhvoovovvhooovhhooovohvhhovhv",
"output": "8"
},
{
"input": "ccwckkkycccccckwckwkwkwkkkkyycykcccycyckwywcckwykcycykkkwcycwwcykcwkwkwwykwkwcykywwwyyykckkyycckwcwk",
"output": "5"
},
{
"input": "ttketfkefktfztezzkzfkkeetkkfktftzktezekkeezkeeetteeteefetefkzzzetekfftkeffzkktffzkzzeftfeezfefzffeef",
"output": "4"
},
{
"input": "rtharczpfznrgdnkltchafduydgbgkdjqrmjqyfmpwjwphrtsjbmswkanjlprbnduaqbcjqxlxmkspkhkcnzbqwxonzxxdmoigti",
"output": "2"
},
{
"input": "fplrkfklvwdeiynbjgaypekambmbjfnoknlhczhkdmljicookdywdgpnlnqlpunnkebnikgcgcjefeqhknvlynmvjcegvcdgvvdb",
"output": "2"
},
{
"input": "txbciieycswqpniwvzipwlottivvnfsysgzvzxwbctcchfpvlbcjikdofhpvsknptpjdbxemtmjcimetkemdbettqnbvzzbdyxxb",
"output": "2"
},
{
"input": "fmubmfwefikoxtqvmaavwjxmoqltapexkqxcsztpezfcltqavuicefxovuswmqimuikoppgqpiapqutkczgcvxzutavkujxvpklv",
"output": "3"
},
{
"input": "ipsrjylhpkjvlzncfixipstwcicxqygqcfrawpzzvckoveyqhathglblhpkjvlzncfixipfajaqobtzvthmhgbuawoxoknirclxg",
"output": "15"
},
{
"input": "kcnjsntjzcbgzjscrsrjkrbytqsrptzspzctjrorsyggrtkcnjsntjzcbgzjscrsrjyqbrtpcgqirsrrjbbbrnyqstnrozcoztt",
"output": "20"
},
{
"input": "unhcfnrhsqetuerjqcetrhlsqgfnqfntvkgxsscquolxxroqgtchffyccetrhlsqgfnqfntvkgxsscquolxxroqgtchffhfqvx",
"output": "37"
},
{
"input": "kkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckkkkkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckckckkc",
"output": "46"
},
{
"input": "mlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydbrxdmlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydik",
"output": "47"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "0"
},
{
"input": "tttttbttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttmttttttt",
"output": "85"
},
{
"input": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffff",
"output": "61"
},
{
"input": "cccccccccccccccccccccccwcccccccccccccccccccccuccccccccccccccnccccccccccccccccccccccccccccccccccccccc",
"output": "38"
},
{
"input": "ffffffffffffffffffffffffffufffgfffffffffffffffffffffffffffffffffffffffgffffffftffffffgffffffffffffff",
"output": "38"
},
{
"input": "rrrrrrrrrrrrrrrrrrrlhbrrrrrrrrurrrrrrrfrrqrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrewrrrrrrryrrxrrrrrrrrrrr",
"output": "33"
},
{
"input": "vyvvvvvvvvzvvvvvzvvvwvvvvrvvvvvvvvvvvvvvvrvvvvvvvvvpkvvpvgvvvvvvvvvvvvvgvvvvvvvvvvvvvvvvvvysvvvbvvvv",
"output": "17"
},
{
"input": "cbubbbbbbbbbbfbbbbbbbbjbobbbbbbbbbbibbubbbbjbbbnzgbbzbbfbbbbbbbbbbbfbpbbbbbbbbbbygbbbgbabbbbbbbhibbb",
"output": "12"
},
{
"input": "lrqrrrrrrrjrrrrrcdrrgrrmwvrrrrrrrrrxfzrmrmrryrrrurrrdrrrrrrrrrrererrrsrrrrrrrrrrrqrrrrcrrwjsrrlrrrrr",
"output": "10"
},
{
"input": "ssssusisisosscssssztzessssyspskjssvosiissussszsosssslsssdsssvssvsssslsssmsfjasjsssssowscsjsssszsspss",
"output": "8"
},
{
"input": "uukuuuumueuuuujuukgdhbztuuuubbguuocuozfaunqufjujuguyuuvkuuauubuubuucuvtjuuuuuusduduuuuuuuueunuuuuuzu",
"output": "7"
},
{
"input": "jpkkgwklngwqcfzmwkkpcwkkkkkekkkekkkdsykqwjkkkhkkkxdnukkkkkkmkqykkkxqklkskkrkkkkkqqjikkkkkkpknkkkkkoh",
"output": "7"
},
{
"input": "bmzbbfbbhqxwthtbbisbbbbbtbbfbbpbfbbpbkbjfbcbbbbzbbbdwmbbbrnvqdbbtbbuglrnbbbbvmbyblebbabibrevaxbbjbqb",
"output": "6"
},
{
"input": "qqqmqqqsbteqqopsuqiqumrqzpqnqgqeniqqkyqqyqqqpxzqeqqquhdqquhqqqfqjirqaqqaquxqoqqjqqqqbjbgqcqqqqicnkqc",
"output": "4"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaavaaaaaaauaaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "44"
},
{
"input": "a",
"output": "0"
},
{
"input": "fg",
"output": "0"
},
{
"input": "yy",
"output": "1"
},
{
"input": "abcabcabc",
"output": "6"
},
{
"input": "qwerqwedqwes",
"output": "3"
}
] | 1,681,300,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | s = input()#abcd
c ,t = 0, 0
for i in range (0 , len(s)):
for j in range (i + 1, len(s)):
c = s.count(s[i:j])
if c > 1:
t = t + 1
print(t)
| Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Specification:
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.
Output Specification:
Output one number — length of the longest substring that can be met in the string at least twice.
Demo Input:
['abcd\n', 'ababa\n', 'zzz\n']
Demo Output:
['0', '3', '2']
Note:
none | ```python
s = input()#abcd
c ,t = 0, 0
for i in range (0 , len(s)):
for j in range (i + 1, len(s)):
c = s.count(s[i:j])
if c > 1:
t = t + 1
print(t)
``` | 0 |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him. | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length. | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 5 6 11",
"output": "TRIANGLE"
},
{
"input": "1 1 1 1",
"output": "TRIANGLE"
},
{
"input": "10 20 30 40",
"output": "TRIANGLE"
},
{
"input": "45 25 5 15",
"output": "IMPOSSIBLE"
},
{
"input": "20 5 8 13",
"output": "TRIANGLE"
},
{
"input": "10 30 7 20",
"output": "SEGMENT"
},
{
"input": "3 2 3 2",
"output": "TRIANGLE"
},
{
"input": "70 10 100 30",
"output": "SEGMENT"
},
{
"input": "4 8 16 2",
"output": "IMPOSSIBLE"
},
{
"input": "3 3 3 10",
"output": "TRIANGLE"
},
{
"input": "1 5 5 5",
"output": "TRIANGLE"
},
{
"input": "13 25 12 1",
"output": "SEGMENT"
},
{
"input": "10 100 7 3",
"output": "SEGMENT"
},
{
"input": "50 1 50 100",
"output": "TRIANGLE"
},
{
"input": "50 1 100 49",
"output": "SEGMENT"
},
{
"input": "49 51 100 1",
"output": "SEGMENT"
},
{
"input": "5 11 2 25",
"output": "IMPOSSIBLE"
},
{
"input": "91 50 9 40",
"output": "IMPOSSIBLE"
},
{
"input": "27 53 7 97",
"output": "IMPOSSIBLE"
},
{
"input": "51 90 24 8",
"output": "IMPOSSIBLE"
},
{
"input": "3 5 1 1",
"output": "IMPOSSIBLE"
},
{
"input": "13 49 69 15",
"output": "IMPOSSIBLE"
},
{
"input": "16 99 9 35",
"output": "IMPOSSIBLE"
},
{
"input": "27 6 18 53",
"output": "IMPOSSIBLE"
},
{
"input": "57 88 17 8",
"output": "IMPOSSIBLE"
},
{
"input": "95 20 21 43",
"output": "IMPOSSIBLE"
},
{
"input": "6 19 32 61",
"output": "IMPOSSIBLE"
},
{
"input": "100 21 30 65",
"output": "IMPOSSIBLE"
},
{
"input": "85 16 61 9",
"output": "IMPOSSIBLE"
},
{
"input": "5 6 19 82",
"output": "IMPOSSIBLE"
},
{
"input": "1 5 1 3",
"output": "IMPOSSIBLE"
},
{
"input": "65 10 36 17",
"output": "IMPOSSIBLE"
},
{
"input": "81 64 9 7",
"output": "IMPOSSIBLE"
},
{
"input": "11 30 79 43",
"output": "IMPOSSIBLE"
},
{
"input": "1 1 5 3",
"output": "IMPOSSIBLE"
},
{
"input": "21 94 61 31",
"output": "IMPOSSIBLE"
},
{
"input": "49 24 9 74",
"output": "IMPOSSIBLE"
},
{
"input": "11 19 5 77",
"output": "IMPOSSIBLE"
},
{
"input": "52 10 19 71",
"output": "SEGMENT"
},
{
"input": "2 3 7 10",
"output": "SEGMENT"
},
{
"input": "1 2 6 3",
"output": "SEGMENT"
},
{
"input": "2 6 1 8",
"output": "SEGMENT"
},
{
"input": "1 2 4 1",
"output": "SEGMENT"
},
{
"input": "4 10 6 2",
"output": "SEGMENT"
},
{
"input": "2 10 7 3",
"output": "SEGMENT"
},
{
"input": "5 2 3 9",
"output": "SEGMENT"
},
{
"input": "6 1 4 10",
"output": "SEGMENT"
},
{
"input": "10 6 4 1",
"output": "SEGMENT"
},
{
"input": "3 2 9 1",
"output": "SEGMENT"
},
{
"input": "22 80 29 7",
"output": "SEGMENT"
},
{
"input": "2 6 3 9",
"output": "SEGMENT"
},
{
"input": "3 1 2 1",
"output": "SEGMENT"
},
{
"input": "3 4 7 1",
"output": "SEGMENT"
},
{
"input": "8 4 3 1",
"output": "SEGMENT"
},
{
"input": "2 8 3 5",
"output": "SEGMENT"
},
{
"input": "4 1 2 1",
"output": "SEGMENT"
},
{
"input": "8 1 3 2",
"output": "SEGMENT"
},
{
"input": "6 2 1 8",
"output": "SEGMENT"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "3 6 3 3",
"output": "TRIANGLE"
},
{
"input": "4 10 4 4",
"output": "TRIANGLE"
},
{
"input": "1 1 2 1",
"output": "TRIANGLE"
},
{
"input": "3 3 3 6",
"output": "TRIANGLE"
},
{
"input": "5 4 5 5",
"output": "TRIANGLE"
},
{
"input": "8 7 8 8",
"output": "TRIANGLE"
},
{
"input": "3 3 3 1",
"output": "TRIANGLE"
},
{
"input": "1 1 6 6",
"output": "TRIANGLE"
},
{
"input": "1 9 1 9",
"output": "TRIANGLE"
},
{
"input": "7 2 2 7",
"output": "TRIANGLE"
},
{
"input": "7 2 3 2",
"output": "TRIANGLE"
},
{
"input": "4 4 10 10",
"output": "TRIANGLE"
},
{
"input": "7 7 10 7",
"output": "TRIANGLE"
},
{
"input": "4 4 4 5",
"output": "TRIANGLE"
},
{
"input": "1 10 9 2",
"output": "TRIANGLE"
},
{
"input": "1 8 2 7",
"output": "TRIANGLE"
},
{
"input": "4 3 2 8",
"output": "TRIANGLE"
},
{
"input": "5 9 5 3",
"output": "TRIANGLE"
},
{
"input": "4 10 3 5",
"output": "TRIANGLE"
}
] | 1,609,240,827 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 204,800 | visited=[0]*4
l=[]
result=0
def dfs(s):
global result
if s==3:
print(l)
return check()
else:
for i in range(4):
if visited[i]==0:
visited[i]=1
l.append(t[i])
get=dfs(s+1)
if get:
result=max(result,get)
if result==2:
return 2
l.pop()
visited[i]=0
def check():
n1,n2,n3=l
if n1+n2>n3 and n2+n3>n1 and n1+n3>n2:
return 2
elif n1+n2>=n3 and n2+n3>=n1 and n1+n3>=n2:
return 1
return 0
t=list(map(int,input().split()))
dfs(0)
if result==1:
print('SEGMENT')
elif result==2:
print('TRIANGLE')
elif result==0:
print('IMPOSSIBLE')
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.
The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.
Input Specification:
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output Specification:
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.
Demo Input:
['4 2 1 3\n', '7 2 2 4\n', '3 5 9 1\n']
Demo Output:
['TRIANGLE\n', 'SEGMENT\n', 'IMPOSSIBLE\n']
Note:
none | ```python
visited=[0]*4
l=[]
result=0
def dfs(s):
global result
if s==3:
print(l)
return check()
else:
for i in range(4):
if visited[i]==0:
visited[i]=1
l.append(t[i])
get=dfs(s+1)
if get:
result=max(result,get)
if result==2:
return 2
l.pop()
visited[i]=0
def check():
n1,n2,n3=l
if n1+n2>n3 and n2+n3>n1 and n1+n3>n2:
return 2
elif n1+n2>=n3 and n2+n3>=n1 and n1+n3>=n2:
return 1
return 0
t=list(map(int,input().split()))
dfs(0)
if result==1:
print('SEGMENT')
elif result==2:
print('TRIANGLE')
elif result==0:
print('IMPOSSIBLE')
``` | 0 |
159 | C | String Manipulation 1.0 | PROGRAMMING | 1,400 | [
"*special",
"binary search",
"brute force",
"data structures",
"strings"
] | null | null | One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can't undo the change.
For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc".
Polycarpus learned that some user initially registered under nickname *t*, where *t* is a concatenation of *k* copies of string *s*. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name. | The first line contains an integer *k* (1<=≤<=*k*<=≤<=2000). The second line contains a non-empty string *s*, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer *n* (0<=≤<=*n*<=≤<=20000) — the number of username changes. Each of the next *n* lines contains the actual changes, one per line. The changes are written as "*p**i* *c**i*" (without the quotes), where *p**i* (1<=≤<=*p**i*<=≤<=200000) is the number of occurrences of letter *c**i*, *c**i* is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1. | Print a single string — the user's final name after all changes are applied to it. | [
"2\nbac\n3\n2 a\n1 b\n2 c\n",
"1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n"
] | [
"acb\n",
"baa\n"
] | Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb". | 1,500 | [
{
"input": "2\nbac\n3\n2 a\n1 b\n2 c",
"output": "acb"
},
{
"input": "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b",
"output": "baa"
},
{
"input": "1\naabbabbb\n7\n2 a\n1 a\n1 a\n2 b\n1 b\n3 b\n1 b",
"output": "b"
},
{
"input": "1\na\n0",
"output": "a"
},
{
"input": "4\ndb\n5\n1 d\n2 d\n2 b\n1 d\n2 b",
"output": "bdb"
},
{
"input": "10\nbabcbcbcba\n40\n24 b\n14 a\n19 b\n25 b\n26 c\n7 c\n5 c\n2 a\n4 c\n7 a\n46 b\n14 a\n28 b\n4 c\n5 a\n10 c\n4 c\n4 b\n12 a\n4 a\n30 b\n4 a\n16 b\n4 c\n4 c\n23 b\n8 c\n20 c\n12 c\n2 a\n9 c\n37 b\n11 c\n27 b\n16 c\n5 b\n6 b\n3 c\n4 b\n16 b",
"output": "babcbcbbbabbbbbbbccbbacbcbabacbbaabcbcbabbcbcbbbcbbcababcbba"
},
{
"input": "10\nbcbccaacab\n40\n37 c\n21 a\n18 a\n5 b\n1 a\n8 c\n9 a\n38 c\n10 b\n12 c\n18 a\n23 a\n20 c\n7 b\n33 c\n4 c\n22 c\n28 c\n9 a\n12 a\n22 a\n1 b\n6 a\n31 c\n19 b\n19 a\n15 a\n6 c\n11 c\n18 b\n19 c\n24 c\n8 a\n16 c\n2 c\n12 b\n8 a\n14 c\n18 b\n19 c",
"output": "cbcaabbccaaabbcccacabbccbbcbccabbcaacbbbcaacbccabbccaabbbcab"
},
{
"input": "10\nccbcabbaca\n40\n2 c\n8 b\n26 b\n12 b\n24 a\n29 a\n20 c\n17 b\n32 c\n9 c\n16 b\n13 b\n19 a\n3 c\n2 b\n18 c\n4 a\n13 c\n8 c\n5 c\n13 a\n19 c\n26 c\n13 c\n6 c\n3 c\n4 a\n5 a\n9 c\n8 b\n9 c\n2 c\n19 a\n5 a\n12 c\n10 c\n2 b\n19 c\n21 a\n16 b",
"output": "cbaaacbbbcabbcacccabbaaabcabcabaacbbacaccbcabaccbcbaacbcabbc"
},
{
"input": "10\nabaabbaaac\n40\n10 b\n24 a\n15 a\n7 b\n22 b\n23 b\n50 a\n43 a\n2 c\n24 b\n9 b\n5 c\n6 c\n18 b\n33 a\n5 c\n2 a\n3 c\n2 b\n27 a\n2 c\n4 a\n1 c\n6 a\n1 b\n12 b\n31 a\n13 b\n35 a\n2 c\n40 a\n24 a\n1 c\n31 a\n17 b\n4 b\n1 c\n12 b\n4 b\n39 a",
"output": "aabaaababaaaaabaaaaaabaaabaabbaabaabaaaaaababaaaabaaaaabbaaa"
},
{
"input": "10\nabbaa\n10\n20 a\n2 b\n25 a\n22 a\n13 a\n5 b\n17 b\n1 a\n16 b\n6 a",
"output": "baaabbaabaaabbaabbaaabbaaabbaabbaabaabaa"
}
] | 1,567,263,972 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define iFor(a,b) for(int i=a;i<b;i++)
#define lFor(a,b) for(ll i=a;i<b;i++)
#define testcase() int t;scanf("%d",&t);while(t--)
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,c,p;
string st,res="";
char s;
cin>>n;
cin>>st;
cin>>c;
string stri=st;
iFor(0,n-1)
st+=stri;
while(c--){
cin>>p>>s;
ll v=0;
iFor(0,st.length()){
if(st[i]==s)v++;
if(v==p){
st[i]='#';
break;
}
}
}
iFor(0,st.length()){
if(st[i]!='#')
res+=st[i];
}
cout<<st<<endl;
cout<<res<<endl;
return 0;
}
| Title: String Manipulation 1.0
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can't undo the change.
For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc".
Polycarpus learned that some user initially registered under nickname *t*, where *t* is a concatenation of *k* copies of string *s*. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name.
Input Specification:
The first line contains an integer *k* (1<=≤<=*k*<=≤<=2000). The second line contains a non-empty string *s*, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer *n* (0<=≤<=*n*<=≤<=20000) — the number of username changes. Each of the next *n* lines contains the actual changes, one per line. The changes are written as "*p**i* *c**i*" (without the quotes), where *p**i* (1<=≤<=*p**i*<=≤<=200000) is the number of occurrences of letter *c**i*, *c**i* is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1.
Output Specification:
Print a single string — the user's final name after all changes are applied to it.
Demo Input:
['2\nbac\n3\n2 a\n1 b\n2 c\n', '1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n']
Demo Output:
['acb\n', 'baa\n']
Note:
Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb". | ```python
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define iFor(a,b) for(int i=a;i<b;i++)
#define lFor(a,b) for(ll i=a;i<b;i++)
#define testcase() int t;scanf("%d",&t);while(t--)
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,c,p;
string st,res="";
char s;
cin>>n;
cin>>st;
cin>>c;
string stri=st;
iFor(0,n-1)
st+=stri;
while(c--){
cin>>p>>s;
ll v=0;
iFor(0,st.length()){
if(st[i]==s)v++;
if(v==p){
st[i]='#';
break;
}
}
}
iFor(0,st.length()){
if(st[i]!='#')
res+=st[i];
}
cout<<st<<endl;
cout<<res<<endl;
return 0;
}
``` | -1 |
|
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
"output": "-1"
},
{
"input": "20",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "-1"
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "11",
"output": "-1"
},
{
"input": "21",
"output": "-1"
},
{
"input": "50",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 "
},
{
"input": "51",
"output": "-1"
},
{
"input": "52",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 "
},
{
"input": "84",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 "
},
{
"input": "86",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "33",
"output": "-1"
},
{
"input": "34",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 "
},
{
"input": "36",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 "
},
{
"input": "38",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 "
},
{
"input": "40",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 "
},
{
"input": "42",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 "
},
{
"input": "44",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 "
},
{
"input": "46",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 "
},
{
"input": "48",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 "
}
] | 1,688,279,790 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | n = int(input())
result = []
if n%2 == 0:
for i in range(1,n+1):
if i%2 != 0:
result.append(str(i+1))
else:
result.append(str(i-1))
print(" ".join(result))
else:
print(-1)
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
Input Specification:
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
Output Specification:
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
Demo Input:
['1\n', '2\n', '4\n']
Demo Output:
['-1\n', '2 1 \n', '2 1 4 3 \n']
Note:
none | ```python
n = int(input())
result = []
if n%2 == 0:
for i in range(1,n+1):
if i%2 != 0:
result.append(str(i+1))
else:
result.append(str(i-1))
print(" ".join(result))
else:
print(-1)
``` | 3 |
|
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped. | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 8",
"output": "13"
},
{
"input": "7 2",
"output": "7"
},
{
"input": "24 15",
"output": "36"
},
{
"input": "19 30",
"output": "47"
},
{
"input": "15 31",
"output": "44"
},
{
"input": "14 15",
"output": "27"
},
{
"input": "58 33",
"output": "89"
},
{
"input": "15 25",
"output": "38"
},
{
"input": "59 45",
"output": "102"
},
{
"input": "3 73",
"output": "74"
},
{
"input": "48 1",
"output": "47"
},
{
"input": "100 25",
"output": "122"
},
{
"input": "40 49",
"output": "86"
},
{
"input": "85 73",
"output": "155"
},
{
"input": "29 1",
"output": "28"
},
{
"input": "74 25",
"output": "97"
},
{
"input": "24 57",
"output": "78"
},
{
"input": "23 12",
"output": "33"
},
{
"input": "2 99",
"output": "99"
},
{
"input": "98 2",
"output": "97"
},
{
"input": "2 97",
"output": "97"
},
{
"input": "30 54",
"output": "81"
},
{
"input": "32 53",
"output": "82"
},
{
"input": "32 54",
"output": "84"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 2",
"output": "3"
}
] | 1,679,240,502 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
using namespace std;
int main() {
int a1, a2, s = 0;
cin >> a1 >> a2;
for (;;) {
if (a1 >= a2 && a1>0 && a2>0) {
a1 -= 2;
a2 += 1;
if(a1>=0 && a2>=0)s += 1;
}
else if (a1 < a2 && a1>0 && a2>0){
a2 -= 2;
a1 += 1;
if (a1 >= 0 && a2 >= 0)s += 1;
}
if (a1 <= 0 || a2 <= 0)break;
}
cout << s;
return 0;
} | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
Input Specification:
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output Specification:
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
Demo Input:
['3 5\n', '4 4\n']
Demo Output:
['6\n', '5\n']
Note:
In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped. | ```python
#include<iostream>
using namespace std;
int main() {
int a1, a2, s = 0;
cin >> a1 >> a2;
for (;;) {
if (a1 >= a2 && a1>0 && a2>0) {
a1 -= 2;
a2 += 1;
if(a1>=0 && a2>=0)s += 1;
}
else if (a1 < a2 && a1>0 && a2>0){
a2 -= 2;
a1 += 1;
if (a1 >= 0 && a2 >= 0)s += 1;
}
if (a1 <= 0 || a2 <= 0)break;
}
cout << s;
return 0;
}
``` | -1 |
|
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,513,460,554 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | a, b = map(int, input().split())
print(["NO", "YES"][[0, 1].count(b-a)]) | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
a, b = map(int, input().split())
print(["NO", "YES"][[0, 1].count(b-a)])
``` | 0 |
|
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output": "423654797"
},
{
"input": "-623563697",
"output": "-62356367"
},
{
"input": "645894116",
"output": "645894116"
},
{
"input": "-384381709",
"output": "-38438170"
},
{
"input": "437587210",
"output": "437587210"
},
{
"input": "-297534606",
"output": "-29753460"
},
{
"input": "891773002",
"output": "891773002"
},
{
"input": "-56712976",
"output": "-5671296"
},
{
"input": "963662765",
"output": "963662765"
},
{
"input": "-272656295",
"output": "-27265625"
},
{
"input": "383441522",
"output": "383441522"
},
{
"input": "-477665112",
"output": "-47766511"
},
{
"input": "791725034",
"output": "791725034"
},
{
"input": "-812168727",
"output": "-81216872"
},
{
"input": "528894922",
"output": "528894922"
},
{
"input": "-479977172",
"output": "-47997712"
},
{
"input": "568044564",
"output": "568044564"
},
{
"input": "-392784794",
"output": "-39278474"
},
{
"input": "925596634",
"output": "925596634"
},
{
"input": "-836078769",
"output": "-83607876"
},
{
"input": "71036059",
"output": "71036059"
},
{
"input": "-337396162",
"output": "-33739612"
},
{
"input": "87129297",
"output": "87129297"
},
{
"input": "-648171877",
"output": "-64817187"
},
{
"input": "20218400",
"output": "20218400"
},
{
"input": "10",
"output": "10"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "-1000000000",
"output": "-100000000"
},
{
"input": "-102",
"output": "-10"
},
{
"input": "-120",
"output": "-10"
},
{
"input": "-20",
"output": "0"
},
{
"input": "-15",
"output": "-1"
},
{
"input": "-5575533",
"output": "-557553"
},
{
"input": "-50",
"output": "0"
},
{
"input": "-31",
"output": "-1"
},
{
"input": "-55",
"output": "-5"
},
{
"input": "-81",
"output": "-1"
},
{
"input": "-99",
"output": "-9"
},
{
"input": "-23",
"output": "-2"
},
{
"input": "-41",
"output": "-1"
},
{
"input": "-24",
"output": "-2"
},
{
"input": "46",
"output": "46"
}
] | 1,690,774,124 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n = input()
if n[0] != '-':
print(n)
else:
print(n[1:-2]+min(n[-1],n[-2])) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
Input Specification:
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
Output Specification:
In a single line print an integer — the maximum state of the bank account that Ilya can get.
Demo Input:
['2230\n', '-10\n', '-100003\n']
Demo Output:
['2230\n', '0\n', '-10000\n']
Note:
In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | ```python
n = input()
if n[0] != '-':
print(n)
else:
print(n[1:-2]+min(n[-1],n[-2]))
``` | 0 |
|
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n1 2 3 3 4",
"output": "3"
},
{
"input": "4\n1 2 2 3",
"output": "2"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n1 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "2"
},
{
"input": "11\n1 2 3 1 2 3 2 1 2 3 4",
"output": "4"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "9"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n3 2 1",
"output": "1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "7"
},
{
"input": "1\n1234394",
"output": "1"
}
] | 1,691,951,671 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | import sys
t = int(input(""))
b = [int(j) for j in sys.stdin.readline().split()]
c = 0
d = 1
for i in range(0, t-1):
if b[i] < b[i+1]:
d += 1
else:
if d > c:
c = d
d = 1
if d > c:
c = d
print(d)
| Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Input Specification:
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the maximum length of an increasing subarray of the given array.
Demo Input:
['5\n1 7 2 11 15\n', '6\n100 100 100 100 100 100\n', '3\n1 2 3\n']
Demo Output:
['3\n', '1\n', '3\n']
Note:
none | ```python
import sys
t = int(input(""))
b = [int(j) for j in sys.stdin.readline().split()]
c = 0
d = 1
for i in range(0, t-1):
if b[i] < b[i+1]:
d += 1
else:
if d > c:
c = d
d = 1
if d > c:
c = d
print(d)
``` | 0 |
|
68 | A | Irrational problem | PROGRAMMING | 1,100 | [
"implementation",
"number theory"
] | A. Irrational problem | 2 | 256 | Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*.
It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.
Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers with property that probability that *f*(*x*)<==<=*x* is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number *x* if there exist at least 7 permutations of numbers *p*1,<=*p*2,<=*p*3,<=*p*4, for which *f*(*x*)<==<=*x*. | First line of the input will contain 6 integers, separated by spaces: *p*1,<=*p*2,<=*p*3,<=*p*4,<=*a*,<=*b* (1<=≤<=*p*1,<=*p*2,<=*p*3,<=*p*4<=≤<=1000,<=0<=≤<=*a*<=≤<=*b*<=≤<=31415).
It is guaranteed that numbers *p*1,<=*p*2,<=*p*3,<=*p*4 will be pairwise distinct. | Output the number of integers in the given range that have the given property. | [
"2 7 1 8 2 8\n",
"20 30 40 50 0 100\n",
"31 41 59 26 17 43\n"
] | [
"0\n",
"20\n",
"9\n"
] | none | 500 | [
{
"input": "2 7 1 8 2 8",
"output": "0"
},
{
"input": "20 30 40 50 0 100",
"output": "20"
},
{
"input": "31 41 59 26 17 43",
"output": "9"
},
{
"input": "1 2 3 4 0 0",
"output": "1"
},
{
"input": "1 2 3 4 1 1",
"output": "0"
},
{
"input": "1 2 999 1000 30 40",
"output": "0"
},
{
"input": "17 18 19 20 17 20",
"output": "0"
},
{
"input": "17 18 19 20 16 20",
"output": "1"
},
{
"input": "41 449 328 474 150 709",
"output": "0"
},
{
"input": "467 329 936 440 117 700",
"output": "212"
},
{
"input": "258 811 952 491 931 993",
"output": "0"
},
{
"input": "823 431 359 590 153 899",
"output": "206"
},
{
"input": "292 370 404 698 699 876",
"output": "0"
},
{
"input": "442 705 757 527 868 893",
"output": "0"
},
{
"input": "642 273 18 885 675 788",
"output": "0"
},
{
"input": "291 303 656 660 126 704",
"output": "165"
},
{
"input": "225 862 522 617 630 725",
"output": "0"
},
{
"input": "17 847 715 732 502 778",
"output": "0"
},
{
"input": "41 449 328 474 15724 19169",
"output": "0"
},
{
"input": "467 329 936 440 5705 28145",
"output": "0"
},
{
"input": "258 811 952 491 2995 11942",
"output": "0"
},
{
"input": "823 431 359 590 153 3902",
"output": "206"
},
{
"input": "292 370 404 698 19718 19895",
"output": "0"
},
{
"input": "442 705 757 527 1869 19912",
"output": "0"
},
{
"input": "642 273 18 885 23811 28703",
"output": "0"
},
{
"input": "291 303 656 660 7711 15141",
"output": "0"
},
{
"input": "225 862 522 617 1246 1341",
"output": "0"
},
{
"input": "17 847 715 732 778 27529",
"output": "0"
},
{
"input": "997 998 999 1000 0 31415",
"output": "997"
},
{
"input": "1 2 3 4 0 31415",
"output": "1"
},
{
"input": "541 931 822 948 131 193",
"output": "63"
},
{
"input": "956 800 909 916 89 194",
"output": "106"
},
{
"input": "735 794 942 991 419 490",
"output": "72"
},
{
"input": "818 926 827 575 153 395",
"output": "243"
},
{
"input": "792 858 887 679 179 356",
"output": "178"
},
{
"input": "937 683 742 515 366 373",
"output": "8"
},
{
"input": "616 747 501 875 146 264",
"output": "119"
},
{
"input": "760 773 638 655 111 196",
"output": "86"
},
{
"input": "697 855 997 589 97 192",
"output": "96"
},
{
"input": "998 834 706 722 277 475",
"output": "199"
},
{
"input": "100 101 102 103 10 20",
"output": "11"
}
] | 1,699,738,544 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 218 | 1,638,400 | from itertools import permutations as per
p1, p2, p3, p4, a, b = map(int, input().split())
p = list(per([p1, p2, p3, p4], 4))
x = 0
for i in range(a, b + 1):
c = 0
for j in p:
if (((i % j[0]) % j[1]) % j[2]) % j[3] == i:
c += 1
if c >= 7:
x += 1
print(x) | Title: Irrational problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya was given this problem for homework:
You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*.
It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.
Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers with property that probability that *f*(*x*)<==<=*x* is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number *x* if there exist at least 7 permutations of numbers *p*1,<=*p*2,<=*p*3,<=*p*4, for which *f*(*x*)<==<=*x*.
Input Specification:
First line of the input will contain 6 integers, separated by spaces: *p*1,<=*p*2,<=*p*3,<=*p*4,<=*a*,<=*b* (1<=≤<=*p*1,<=*p*2,<=*p*3,<=*p*4<=≤<=1000,<=0<=≤<=*a*<=≤<=*b*<=≤<=31415).
It is guaranteed that numbers *p*1,<=*p*2,<=*p*3,<=*p*4 will be pairwise distinct.
Output Specification:
Output the number of integers in the given range that have the given property.
Demo Input:
['2 7 1 8 2 8\n', '20 30 40 50 0 100\n', '31 41 59 26 17 43\n']
Demo Output:
['0\n', '20\n', '9\n']
Note:
none | ```python
from itertools import permutations as per
p1, p2, p3, p4, a, b = map(int, input().split())
p = list(per([p1, p2, p3, p4], 4))
x = 0
for i in range(a, b + 1):
c = 0
for j in p:
if (((i % j[0]) % j[1]) % j[2]) % j[3] == i:
c += 1
if c >= 7:
x += 1
print(x)
``` | 3.942448 |
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,651,282,913 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 512,000 | n=int(input())
a=[int(x) for x in input().split(" ")]
maxn=105
minprime=[0]*maxn
i=2
while i*i<maxn:
if minprime[i]==0:
j=i*i
while j<maxn:
if minprime[j]==0: minprime[j]=i
j+=i
i+=1
for i in range(1, maxn):
if minprime[i]==0: minprime[i]=i
dp=[0]*maxn
for i in range(n):
x=a[i]
st=set()
while x>1:
st.add(minprime[x])
x//=minprime[x]
mx=0
for j in st: mx=max(mx, dp[j])
mx+=1
for j in st: dp[j]=mx
print(max(dp))
| 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
n=int(input())
a=[int(x) for x in input().split(" ")]
maxn=105
minprime=[0]*maxn
i=2
while i*i<maxn:
if minprime[i]==0:
j=i*i
while j<maxn:
if minprime[j]==0: minprime[j]=i
j+=i
i+=1
for i in range(1, maxn):
if minprime[i]==0: minprime[i]=i
dp=[0]*maxn
for i in range(n):
x=a[i]
st=set()
while x>1:
st.add(minprime[x])
x//=minprime[x]
mx=0
for j in st: mx=max(mx, dp[j])
mx+=1
for j in st: dp[j]=mx
print(max(dp))
``` | 0 |
|
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better. | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"
},
{
"input": "0\n2",
"output": "***\n*0*\n*2*\n***"
},
{
"input": "O\no\nd",
"output": "***\n*O*\n*o*\n*d*\n***"
},
{
"input": "0v uO M6Sy",
"output": "************\n*0v uO M6Sy*\n************"
},
{
"input": "fm v\nOL U W",
"output": "**********\n* fm v *\n*OL U W*\n**********"
},
{
"input": "vb\nJ\nyU\nZ",
"output": "****\n*vb*\n*J *\n*yU*\n* Z*\n****"
},
{
"input": "N\nSV\nEh\n6f\nX6\n9e",
"output": "****\n*N *\n*SV*\n*Eh*\n*6f*\n*X6*\n*9e*\n****"
},
{
"input": "Pj\nA\nFA\nP\nVJ\nU\nEb\nW",
"output": "****\n*Pj*\n*A *\n*FA*\n* P*\n*VJ*\n*U *\n*Eb*\n* W*\n****"
},
{
"input": "T\n7j\nS\nb\nq8\nVZ\nn\n4T\niZ\npA",
"output": "****\n*T *\n*7j*\n* S*\n*b *\n*q8*\n*VZ*\n* n*\n*4T*\n*iZ*\n*pA*\n****"
},
{
"input": "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\nSr\n\n\nV\n\n5\n\nAq\n\n\n\nJ\nR\n\n04\nJ\nv\nhU\n\n\n\nY\nG\n4\n\nG\nb\n\n\n9\n\n6\nd\n\n2\n\n\nE\n7\n\nr\n\n\n\n\nKC\ns\nE\n\nab\n4\nx\n\n\n\n\n\nEe\n4\n\nl\n\np\n\nG\nM\n\n\nn\n\n\nm0\n\nw\n\n\nP\n\n\n\n0",
"output": "****\n*8 *\n* *\n* *\n* *\n* y*\n*W *\n* *\n* *\n* *\n*3B*\n* *\n* w*\n*V *\n* *\n* *\n* *\n* L*\n*Sr*\n* *\n* *\n*V *\n* *\n* 5*\n* *\n*Aq*\n* *\n* *\n* *\n*J *\n* R*\n* *\n*04*\n*J *\n* v*\n*hU*\n* *\n* *\n* *\n*Y *\n* G*\n*4 *\n* *\n* G*\n*b *\n* *\n* *\n* 9*\n* *\n*6 *\n* d*\n* *\n*2 *\n* *\n* *\n* E*\n*7 *\n* *\n* r*\n* *\n* *\n* *\n* *\n*KC*\n*s *\n* E*\n* *\n*ab*\n*4 *\n* x*\n* *\n* *\n* *\n* *\n* *\n*Ee*\n*4 *\n* *\n* l*\n* *\n*p *\n* *\n* G*\n*M *\n* *\n*..."
},
{
"input": "U",
"output": "***\n*U*\n***"
}
] | 1,658,330,003 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | g=0
l=[]
while True:
try: a=input()
except: break
l.append(a)
s=len(a)
if g<s:
g=s
print('*'*g+'*'+'*')
for i in l:
print('*',end='')
t=(g-len(i))//2
print(' '*t,end=i)
print(' '*(g-(t+len(i))),end='*')
print('')
print('*'*g+'*'+'*') | Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck!
Input Specification:
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Output Specification:
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
Demo Input:
['This is\n\nCodeforces\nBeta\nRound\n5\n', 'welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n']
Demo Output:
['************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n', '****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n']
Note:
none | ```python
g=0
l=[]
while True:
try: a=input()
except: break
l.append(a)
s=len(a)
if g<s:
g=s
print('*'*g+'*'+'*')
for i in l:
print('*',end='')
t=(g-len(i))//2
print(' '*t,end=i)
print(' '*(g-(t+len(i))),end='*')
print('')
print('*'*g+'*'+'*')
``` | 0 |
959 | A | Mahmoud and Ehab and the even-odd game | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd.
If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? | The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. | Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. | [
"1\n",
"2\n"
] | [
"Ehab",
"Mahmoud"
] | In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins. | 500 | [
{
"input": "1",
"output": "Ehab"
},
{
"input": "2",
"output": "Mahmoud"
},
{
"input": "10000",
"output": "Mahmoud"
},
{
"input": "33333",
"output": "Ehab"
},
{
"input": "5",
"output": "Ehab"
},
{
"input": "1000000000",
"output": "Mahmoud"
},
{
"input": "999999999",
"output": "Ehab"
},
{
"input": "123123123",
"output": "Ehab"
},
{
"input": "22222221",
"output": "Ehab"
},
{
"input": "22222220",
"output": "Mahmoud"
},
{
"input": "3",
"output": "Ehab"
},
{
"input": "4",
"output": "Mahmoud"
},
{
"input": "6",
"output": "Mahmoud"
},
{
"input": "7",
"output": "Ehab"
},
{
"input": "8",
"output": "Mahmoud"
},
{
"input": "9",
"output": "Ehab"
},
{
"input": "10",
"output": "Mahmoud"
},
{
"input": "536870912",
"output": "Mahmoud"
},
{
"input": "536870913",
"output": "Ehab"
},
{
"input": "536870911",
"output": "Ehab"
}
] | 1,633,064,585 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 6,758,400 | x = int(input());a = print
a("Mahmoud") if x%2 == 0 else a('Ehab')
| Title: Mahmoud and Ehab and the even-odd game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that:
- 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd.
If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?
Input Specification:
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output Specification:
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
Demo Input:
['1\n', '2\n']
Demo Output:
['Ehab', 'Mahmoud']
Note:
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins.
In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins. | ```python
x = int(input());a = print
a("Mahmoud") if x%2 == 0 else a('Ehab')
``` | 3 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,664,889,859 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 654 | 11,980,800 | import sys
sys.setrecursionlimit(1700)
x = int(input())
arr = [int(i) for i in input().split(" ")]
tend_set = {1, 2, 3}
ans = []
def foo(arr, ans):
tend_set = {1, 2, 3}
arr_2 = []
dict = {}
for i in range(len(arr)):
if arr[i] != 0:
dict.setdefault(arr[i], 0)
dict[arr[i]] = i
if tend_set.issubset(map(int, dict.keys())):
break
if not tend_set.issubset(arr):
return ans
for i in dict.values():
arr_2.append(i + 1)
arr[i] = 0
ans.append(arr_2)
return foo(arr, ans)
x = foo(arr, ans)
print(len(x))
for i in x:
print(*i)
| Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
import sys
sys.setrecursionlimit(1700)
x = int(input())
arr = [int(i) for i in input().split(" ")]
tend_set = {1, 2, 3}
ans = []
def foo(arr, ans):
tend_set = {1, 2, 3}
arr_2 = []
dict = {}
for i in range(len(arr)):
if arr[i] != 0:
dict.setdefault(arr[i], 0)
dict[arr[i]] = i
if tend_set.issubset(map(int, dict.keys())):
break
if not tend_set.issubset(arr):
return ans
for i in dict.values():
arr_2.append(i + 1)
arr[i] = 0
ans.append(arr_2)
return foo(arr, ans)
x = foo(arr, ans)
print(len(x))
for i in x:
print(*i)
``` | 3 |
|
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
{
"input": "10\n4447444444",
"output": "0000000003"
},
{
"input": "10\n5810438174",
"output": "0147609473"
},
{
"input": "30\n027027027027027027027027027027",
"output": "027027027027027027027027027027"
},
{
"input": "50\n41012516454101251645410125164541012516454101251645",
"output": "01076781720107678172010767817201076781720107678172"
},
{
"input": "72\n464553044645330446455304464553064645530445455304464553044645530446455304",
"output": "001011960020119600201196002011960020119600201996002011960020119620201196"
},
{
"input": "100\n2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031",
"output": "0005996121738545755443472571416650525236761083528703911639570359104365792010332041424619191680979818"
},
{
"input": "200\n79025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544",
"output": "00274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086"
},
{
"input": "100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656",
"output": "0000000000000000000000000000000000000000006000000000000030000010000900100009000030000000000000002006"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,698,636,643 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n = int(input())
myString = input()
myMin = myString
for char in myString:
x = 10 - int(char)
ch = ''.join([str((int(digit) + x) % 10) for digit in myString])
if int(myMin) > int(ch):
myMin = ch
print(myMin)
| Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display.
Output Specification:
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
Demo Input:
['3\n579\n', '4\n2014\n']
Demo Output:
['024\n', '0142\n']
Note:
none | ```python
n = int(input())
myString = input()
myMin = myString
for char in myString:
x = 10 - int(char)
ch = ''.join([str((int(digit) + x) % 10) for digit in myString])
if int(myMin) > int(ch):
myMin = ch
print(myMin)
``` | 0 |
|
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output": "4"
},
{
"input": "8 8 2 2 2",
"output": "6"
},
{
"input": "5 50 5 5 60",
"output": "110"
},
{
"input": "100 100 100 100 100",
"output": "200"
},
{
"input": "1 1 1 1 1",
"output": "2"
},
{
"input": "29 29 20 20 20",
"output": "58"
},
{
"input": "20 29 20 29 20",
"output": "58"
},
{
"input": "31 31 20 20 20",
"output": "60"
},
{
"input": "20 20 20 31 31",
"output": "60"
},
{
"input": "20 31 20 31 20",
"output": "60"
},
{
"input": "20 20 20 30 30",
"output": "60"
},
{
"input": "30 30 20 20 20",
"output": "60"
},
{
"input": "8 1 8 8 8",
"output": "9"
},
{
"input": "1 1 1 8 1",
"output": "9"
},
{
"input": "1 2 3 4 5",
"output": "15"
},
{
"input": "100 99 98 97 96",
"output": "490"
},
{
"input": "1 1 100 100 100",
"output": "2"
},
{
"input": "100 100 99 99 98",
"output": "296"
},
{
"input": "98 99 100 99 100",
"output": "296"
},
{
"input": "1 90 1 91 1",
"output": "181"
},
{
"input": "60 1 75 1 92",
"output": "227"
},
{
"input": "15 40 90 40 90",
"output": "95"
},
{
"input": "1 1 15 20 20",
"output": "17"
},
{
"input": "90 11 11 10 10",
"output": "110"
},
{
"input": "20 21 22 23 24",
"output": "110"
},
{
"input": "1 1 2 98 99",
"output": "199"
},
{
"input": "3 7 7 7 10",
"output": "13"
},
{
"input": "1 3 3 3 1",
"output": "2"
},
{
"input": "1 9 9 9 10",
"output": "11"
},
{
"input": "100 1 1 1 1",
"output": "101"
},
{
"input": "2 2 2 100 100",
"output": "6"
},
{
"input": "1 2 2 2 2",
"output": "3"
},
{
"input": "1 1 2 2 5",
"output": "7"
},
{
"input": "1 2 3 4 1",
"output": "9"
},
{
"input": "11 10 10 10 10",
"output": "21"
},
{
"input": "2 2 2 10 10",
"output": "6"
},
{
"input": "1 1 1 1 4",
"output": "5"
},
{
"input": "98 98 98 98 23",
"output": "121"
},
{
"input": "1 2 3 100 100",
"output": "6"
},
{
"input": "2 2 5 10 10",
"output": "9"
},
{
"input": "2 2 3 3 3",
"output": "4"
},
{
"input": "1 1 1 1 2",
"output": "3"
},
{
"input": "12 12 7 7 7",
"output": "21"
}
] | 1,594,291,290 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 109 | 6,963,200 | t = sorted(list(map(int, input().split())))
if len(set(t)) == 5:
print(sum(t))
else:
prev = 0
total = 0
count = 0
output = 0
for i in t:
if prev != i:
count = 0
total = 0
if count != 3:
total += i
count += 1
if count >= 2:
output = max(total, output)
prev = i
print(sum(t) - output) | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
Input Specification:
The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards.
Output Specification:
Print the minimum possible sum of numbers written on remaining cards.
Demo Input:
['7 3 7 3 20\n', '7 9 3 1 8\n', '10 10 10 10 10\n']
Demo Output:
['26\n', '28\n', '20\n']
Note:
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20. | ```python
t = sorted(list(map(int, input().split())))
if len(set(t)) == 5:
print(sum(t))
else:
prev = 0
total = 0
count = 0
output = 0
for i in t:
if prev != i:
count = 0
total = 0
if count != 3:
total += i
count += 1
if count >= 2:
output = max(total, output)
prev = i
print(sum(t) - output)
``` | 3 |
|
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 1,596,063,718 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 202 | 24,780,800 | n = int(input())
myd = {}
arr = [int(x) for x in input().split()]
for i in range(n):
myd[arr[i]] = i
print(arr[min(myd.values())]) | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input Specification:
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output Specification:
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Demo Input:
['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n']
Demo Output:
['3\n', '2\n']
Note:
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | ```python
n = int(input())
myd = {}
arr = [int(x) for x in input().split()]
for i in range(n):
myd[arr[i]] = i
print(arr[min(myd.values())])
``` | 3 |
|
134 | A | Average Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). | The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers. | Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line. | [
"5\n1 2 3 4 5\n",
"4\n50 50 50 50\n"
] | [
"1\n3 ",
"4\n1 2 3 4 "
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "1\n3 "
},
{
"input": "4\n50 50 50 50",
"output": "4\n1 2 3 4 "
},
{
"input": "3\n2 3 1",
"output": "1\n1 "
},
{
"input": "2\n4 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "2\n1 2 "
},
{
"input": "10\n3 3 3 3 3 4 3 3 3 2",
"output": "8\n1 2 3 4 5 7 8 9 "
},
{
"input": "10\n15 7 10 7 7 7 4 4 7 2",
"output": "5\n2 4 5 6 9 "
},
{
"input": "6\n2 2 2 2 2 2",
"output": "6\n1 2 3 4 5 6 "
},
{
"input": "6\n3 3 3 3 3 3",
"output": "6\n1 2 3 4 5 6 "
},
{
"input": "4\n6 6 6 7",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "3\n3 3 4",
"output": "0"
},
{
"input": "5\n7 6 6 6 6",
"output": "0"
},
{
"input": "4\n3 5 5 9",
"output": "0"
},
{
"input": "3\n99 100 99",
"output": "0"
},
{
"input": "4\n5 6 5 5",
"output": "0"
},
{
"input": "6\n1 1 2 1 1 1",
"output": "0"
},
{
"input": "2\n4 5",
"output": "0"
},
{
"input": "4\n1 1 1 2",
"output": "0"
},
{
"input": "3\n1 2 4",
"output": "0"
},
{
"input": "6\n1 1 2 3 3 3",
"output": "0"
},
{
"input": "4\n4 5 5 4",
"output": "0"
},
{
"input": "3\n2 3 5",
"output": "0"
},
{
"input": "3\n2 1 1",
"output": "0"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "4\n1 2 3 4",
"output": "0"
},
{
"input": "5\n1 2 3 4 6",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "4\n3 4 5 1",
"output": "0"
},
{
"input": "3\n2 3 2",
"output": "0"
},
{
"input": "3\n3 4 4",
"output": "0"
},
{
"input": "3\n10 5 7",
"output": "0"
},
{
"input": "3\n5 6 5",
"output": "0"
},
{
"input": "4\n1 2 3 7",
"output": "0"
},
{
"input": "5\n2 2 3 3 3",
"output": "0"
},
{
"input": "3\n4 3 6",
"output": "0"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 "
}
] | 1,683,135,703 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 483 | 13,516,800 | n = int(input())
a = list(map(int, input().split()))
h = []
summ = 0
for i in range(0,n):
summ += a[i]
for i in range(0,n):
if (summ - a[i])//(n-1) == a[i]:
h.append(i+1)
print(len(h))
for i in range(0, len(h)):
print(h[i], end = " ")
# Wed May 03 2023 20:41:42 GMT+0300 (Moscow Standard Time)
| Title: Average Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one).
Input Specification:
The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers.
Output Specification:
Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.
Demo Input:
['5\n1 2 3 4 5\n', '4\n50 50 50 50\n']
Demo Output:
['1\n3 ', '4\n1 2 3 4 ']
Note:
none | ```python
n = int(input())
a = list(map(int, input().split()))
h = []
summ = 0
for i in range(0,n):
summ += a[i]
for i in range(0,n):
if (summ - a[i])//(n-1) == a[i]:
h.append(i+1)
print(len(h))
for i in range(0, len(h)):
print(h[i], end = " ")
# Wed May 03 2023 20:41:42 GMT+0300 (Moscow Standard Time)
``` | 0 |
|
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars. | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"output": "20"
},
{
"input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20",
"output": "10"
},
{
"input": "7 5 1\n0 100 2 2 0 2 1",
"output": "20"
},
{
"input": "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "10"
},
{
"input": "100 50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "490"
},
{
"input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0",
"output": "10"
},
{
"input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "980"
},
{
"input": "100 1 100\n0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10"
},
{
"input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 98",
"output": "890"
},
{
"input": "7 4 5\n1 0 6 0 5 6 0",
"output": "10"
},
{
"input": "7 4 5\n1 6 5 0 0 6 0",
"output": "10"
},
{
"input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0",
"output": "90"
},
{
"input": "2 1 100\n0 1",
"output": "10"
},
{
"input": "2 2 100\n1 0",
"output": "10"
},
{
"input": "10 1 88\n0 95 0 0 0 0 0 94 0 85",
"output": "90"
},
{
"input": "10 2 14\n2 0 1 26 77 39 41 100 13 32",
"output": "10"
},
{
"input": "10 3 11\n0 0 0 0 0 62 0 52 1 35",
"output": "60"
},
{
"input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88",
"output": "10"
},
{
"input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82",
"output": "70"
},
{
"input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1",
"output": "180"
},
{
"input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0",
"output": "210"
},
{
"input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37",
"output": "80"
},
{
"input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77",
"output": "190"
},
{
"input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84",
"output": "190"
},
{
"input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15",
"output": "580"
},
{
"input": "97 44 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51 19",
"output": "520"
},
{
"input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67",
"output": "490"
},
{
"input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23",
"output": "890"
},
{
"input": "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14",
"output": "970"
},
{
"input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10",
"output": "990"
},
{
"input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10",
"output": "490"
},
{
"input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2",
"output": "500"
},
{
"input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20",
"output": "50"
},
{
"input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0",
"output": "990"
},
{
"input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0",
"output": "10"
},
{
"input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51",
"output": "140"
},
{
"input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4",
"output": "390"
},
{
"input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68",
"output": "130"
},
{
"input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59",
"output": "10"
},
{
"input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32",
"output": "10"
},
{
"input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98",
"output": "160"
},
{
"input": "5 2 20\n27 0 32 21 19",
"output": "30"
},
{
"input": "6 4 10\n10 0 0 0 0 10",
"output": "20"
},
{
"input": "8 7 100\n1 0 0 0 0 0 0 1",
"output": "10"
},
{
"input": "5 3 20\n1 21 0 0 1",
"output": "20"
},
{
"input": "4 3 1\n0 0 0 1",
"output": "10"
},
{
"input": "5 2 3\n4 0 5 6 1",
"output": "30"
},
{
"input": "5 3 87\n88 89 0 1 90",
"output": "10"
},
{
"input": "5 3 20\n15 30 0 15 35",
"output": "10"
},
{
"input": "6 3 50\n0 0 0 1 2 0",
"output": "10"
},
{
"input": "6 4 9\n100 9 10 0 0 9",
"output": "20"
},
{
"input": "5 4 20\n0 20 0 0 20",
"output": "10"
},
{
"input": "6 3 3\n1 5 0 2 2 0",
"output": "10"
},
{
"input": "5 4 100\n0 1 0 0 1",
"output": "10"
}
] | 1,621,576,809 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 77 | 0 | n,m,k=map(int,input().split())
a=list(map(int,input().split()))
p1=m-2
p2=m
i=1
j=1
ans=[]
while p1>=0 or p2<n:
if p1>=0 and a[p1]<=k and a[p1]!=0:
ans.append(i)
if p2<n and a[p2]<=k and a[p2]!=0:
ans.append(j)
p1-=1
i+=1
j+=1
p2+=1
print(min(ans)*10)
| Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house *i* and house *i*<=+<=1 (1<=≤<=*i*<=<<=*n*) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given *n* integers *a*1,<=*a*2,<=...,<=*a**n* that denote the availability and the prices of the houses. If house *i* is occupied, and therefore cannot be bought, then *a**i* equals 0. Otherwise, house *i* can be bought, and *a**i* represents the money required to buy it, in dollars.
As Zane has only *k* dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
Input Specification:
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — denoting the availability and the prices of the houses.
It is guaranteed that *a**m*<==<=0 and that it is possible to purchase some house with no more than *k* dollars.
Output Specification:
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
Demo Input:
['5 1 20\n0 27 32 21 19\n', '7 3 50\n62 0 0 0 99 33 22\n', '10 5 100\n1 0 1 0 0 0 0 0 1 1\n']
Demo Output:
['40', '30', '20']
Note:
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 and house 7 are 40 meters away. | ```python
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
p1=m-2
p2=m
i=1
j=1
ans=[]
while p1>=0 or p2<n:
if p1>=0 and a[p1]<=k and a[p1]!=0:
ans.append(i)
if p2<n and a[p2]<=k and a[p2]!=0:
ans.append(j)
p1-=1
i+=1
j+=1
p2+=1
print(min(ans)*10)
``` | 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,689,569,507 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 171 | 16,998,400 | import sys, io, os
import math
import bisect
import heapq
import string
import re
from decimal import *
from collections import defaultdict,Counter,deque
input = sys.stdin.readline
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def WRITE(out):
return print('\n'.join(map(str, out)))
def WS(out):
return print(' '.join(map(str, out)))
def WNS(out):
return print(''.join(map(str, out)))
def WSNOPRINT(out):
return ''.join(map(str, out))
'''
'''
def solve():
lucky = [4,7]
nums = [4,7]
while nums[-1] < 10**9:
for i in range(len(nums)):
for d in lucky:
nums.append(nums[i]*10 + d)
print(nums.index(II()) + 1)
solve()
| 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
import sys, io, os
import math
import bisect
import heapq
import string
import re
from decimal import *
from collections import defaultdict,Counter,deque
input = sys.stdin.readline
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def WRITE(out):
return print('\n'.join(map(str, out)))
def WS(out):
return print(' '.join(map(str, out)))
def WNS(out):
return print(''.join(map(str, out)))
def WSNOPRINT(out):
return ''.join(map(str, out))
'''
'''
def solve():
lucky = [4,7]
nums = [4,7]
while nums[-1] < 10**9:
for i in range(len(nums)):
for d in lucky:
nums.append(nums[i]*10 + d)
print(nums.index(II()) + 1)
solve()
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,694,278,397 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 122 | 2,867,200 | t=int(input())
for h in range(t):
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
flag=0
for j in range(1,n):
if arr[j]-arr[j-1]>1:
flag=1
if flag==1:
print("NO")
else:
print("YES")
#
| 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
t=int(input())
for h in range(t):
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
flag=0
for j in range(1,n):
if arr[j]-arr[j-1]>1:
flag=1
if flag==1:
print("NO")
else:
print("YES")
#
``` | -1 |
690 | C1 | Brain Network (easy) | PROGRAMMING | 1,300 | [] | null | null | One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:
1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false.
If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid. | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*). | The output consists of one line, containing either yes or no depending on whether the nervous system is valid. | [
"4 4\n1 2\n2 3\n3 1\n4 1\n",
"6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n"
] | [
"no\n",
"yes\n"
] | none | 0 | [
{
"input": "4 4\n1 2\n2 3\n3 1\n4 1",
"output": "no"
},
{
"input": "6 5\n1 2\n2 3\n3 4\n4 5\n3 6",
"output": "yes"
},
{
"input": "2 1\n1 2",
"output": "yes"
},
{
"input": "3 3\n2 1\n1 3\n3 2",
"output": "no"
},
{
"input": "3 2\n1 2\n2 3",
"output": "yes"
},
{
"input": "9 8\n1 2\n2 3\n3 4\n4 1\n5 6\n6 7\n7 8\n8 9",
"output": "no"
},
{
"input": "8 7\n6 2\n1 5\n4 8\n4 7\n6 7\n8 3\n8 1",
"output": "yes"
},
{
"input": "200 5\n93 101\n199 164\n14 94\n115 61\n106 156",
"output": "no"
},
{
"input": "10 9\n6 5\n9 2\n4 7\n2 3\n7 3\n3 4\n10 6\n1 2\n5 8",
"output": "no"
},
{
"input": "10 9\n2 3\n6 8\n10 1\n1 8\n6 7\n8 7\n10 5\n7 10\n2 5",
"output": "no"
},
{
"input": "10 9\n3 2\n4 1\n6 1\n7 1\n9 2\n6 9\n5 2\n7 9\n3 7",
"output": "no"
}
] | 1,468,157,263 | 2,623 | Python 3 | RUNTIME_ERROR | TESTS | 12 | 186 | 716,800 | def dfs(v, pr):
global used
global p
global f
if not f:
return None
if used[v]:
f = False
used[v] = True
for i in range(len(p[v])):
if p[v][i] != pr:
dfs(p[v][i], v)
n, m = map(int, input().split())
p = []
for i in range(n):
p.append([])
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
p[a].append(b)
p[b].append(a)
used = [False] * n
f = True
for i in range(n):
if i != 0 and not used[i]:
f = False
break
if not used[i]:
dfs(i, -1)
if f:
print('yes')
else:
print('no')
| Title: Brain Network (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of *n* brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:
1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains). 1. There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false.
If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.
Input Specification:
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*).
Output Specification:
The output consists of one line, containing either yes or no depending on whether the nervous system is valid.
Demo Input:
['4 4\n1 2\n2 3\n3 1\n4 1\n', '6 5\n1 2\n2 3\n3 4\n4 5\n3 6\n']
Demo Output:
['no\n', 'yes\n']
Note:
none | ```python
def dfs(v, pr):
global used
global p
global f
if not f:
return None
if used[v]:
f = False
used[v] = True
for i in range(len(p[v])):
if p[v][i] != pr:
dfs(p[v][i], v)
n, m = map(int, input().split())
p = []
for i in range(n):
p.append([])
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
p[a].append(b)
p[b].append(a)
used = [False] * n
f = True
for i in range(n):
if i != 0 and not used[i]:
f = False
break
if not used[i]:
dfs(i, -1)
if f:
print('yes')
else:
print('no')
``` | -1 |
|
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books. | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"input": "999",
"output": "2889"
},
{
"input": "55",
"output": "101"
},
{
"input": "222222222",
"output": "1888888896"
},
{
"input": "8",
"output": "8"
},
{
"input": "13",
"output": "17"
},
{
"input": "313",
"output": "831"
},
{
"input": "1342",
"output": "4261"
},
{
"input": "30140",
"output": "139594"
},
{
"input": "290092",
"output": "1629447"
},
{
"input": "2156660",
"output": "13985516"
},
{
"input": "96482216",
"output": "760746625"
},
{
"input": "943006819",
"output": "8375950269"
},
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "7"
},
{
"input": "35",
"output": "61"
},
{
"input": "996",
"output": "2880"
},
{
"input": "6120",
"output": "23373"
},
{
"input": "30660",
"output": "142194"
},
{
"input": "349463",
"output": "1985673"
},
{
"input": "8171970",
"output": "56092686"
},
{
"input": "36123011",
"output": "277872985"
},
{
"input": "986747865",
"output": "8769619683"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "11"
},
{
"input": "11",
"output": "13"
},
{
"input": "101",
"output": "195"
},
{
"input": "1000",
"output": "2893"
},
{
"input": "1001",
"output": "2897"
},
{
"input": "9999",
"output": "38889"
},
{
"input": "10000",
"output": "38894"
},
{
"input": "10001",
"output": "38899"
},
{
"input": "99999",
"output": "488889"
},
{
"input": "100000",
"output": "488895"
},
{
"input": "100001",
"output": "488901"
},
{
"input": "999999",
"output": "5888889"
},
{
"input": "1000001",
"output": "5888903"
},
{
"input": "9999999",
"output": "68888889"
},
{
"input": "10000000",
"output": "68888897"
},
{
"input": "10000001",
"output": "68888905"
},
{
"input": "99999999",
"output": "788888889"
},
{
"input": "100000000",
"output": "788888898"
},
{
"input": "100000001",
"output": "788888907"
},
{
"input": "999999999",
"output": "8888888889"
},
{
"input": "95",
"output": "181"
},
{
"input": "995",
"output": "2877"
},
{
"input": "9995",
"output": "38873"
},
{
"input": "99995",
"output": "488869"
},
{
"input": "999999995",
"output": "8888888853"
},
{
"input": "999999998",
"output": "8888888880"
}
] | 1,478,509,663 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 140 | 0 | n=input()
p=len(n)
print((int(n)+1)*p-int('1'*p)) | Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library.
Output Specification:
Print the number of digits needed to number all the books.
Demo Input:
['13\n', '4\n']
Demo Output:
['17\n', '4\n']
Note:
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | ```python
n=input()
p=len(n)
print((int(n)+1)*p-int('1'*p))
``` | 3 |
|
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
"input": "rxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrrrxrrxrrxrxxxrxrrxrrxrxrxxxxxrxxxxrrrxrxxrxxrxxxrrrrrxrrxrrxrr",
"output": "rxaxraxrxaxaxrararxaxararaxrxarxarxrxrarxraxraxrxaxrxraxraxrxrxaxaxrxaxararxrxarxarxaxrararxraxraxra"
},
{
"input": "aazz",
"output": "baza"
},
{
"input": "zz",
"output": "za"
},
{
"input": "gg",
"output": "ga"
},
{
"input": "qasdasd",
"output": "qasdasd"
},
{
"input": "aa",
"output": "ba"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "zza",
"output": "zba"
},
{
"input": "g",
"output": "g"
},
{
"input": "nnop",
"output": "naop"
},
{
"input": "xx",
"output": "xa"
}
] | 1,554,052,853 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 93 | 0 | s = list(input())
for i in range(1, len(s) - 1):
if s[i - 1] == s[i]:
s[i] = [j for j in 'xyz' if not(s[i] == j or s[i + 1] == j)][0]
if s[-1] == s[-2]:
if s[-1] == 'x':
s[-1] = 'y'
else:
s[-1] = 'x'
print(''.join(s)) | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task!
Input Specification:
The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters.
Output Specification:
Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters.
Demo Input:
['aab\n', 'caaab\n', 'zscoder\n']
Demo Output:
['bab\n', 'cabab\n', 'zscoder\n']
Note:
none | ```python
s = list(input())
for i in range(1, len(s) - 1):
if s[i - 1] == s[i]:
s[i] = [j for j in 'xyz' if not(s[i] == j or s[i + 1] == j)][0]
if s[-1] == s[-2]:
if s[-1] == 'x':
s[-1] = 'y'
else:
s[-1] = 'x'
print(''.join(s))
``` | -1 |
|
505 | B | Mr. Kitayuta's Colorful Graph | PROGRAMMING | 1,400 | [
"dfs and similar",
"dp",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you two integers — *u**i* and *v**i*.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly. | The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*).
The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries.
Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*. | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | 1,000 | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input": "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2",
"output": "3"
},
{
"input": "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2",
"output": "5"
}
] | 1,421,588,921 | 2,921 | Python 3 | OK | TESTS | 29 | 109 | 716,800 | from collections import deque
def BFS(graph,a,b):
q = deque()
q.append(a)
visited = [ False for _ in range(len(graph))]
while len(q):
v = q.pop()
if visited[v]:
continue
for x in graph[v]:
if not visited[x]:
q.append(x)
visited[v] = True
return visited[b]
n, m = map(int, input().split())
color = {}
for i in range(m):
v1, v2, c = map(int, input().split())
if c not in color:
color[c] = [ [] for _ in range(n+1) ]
color[c][v1].append(v2)
color[c][v2].append(v1)
q = int(input())
for _ in range(q):
a, b = map(int, input().split())
ans = 0
for i in color:
if BFS(color[i], a, b):
ans += 1
print(ans) | Title: Mr. Kitayuta's Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has just bought an undirected graph consisting of *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you two integers — *u**i* and *v**i*.
Find the number of the colors that satisfy the following condition: the edges of that color connect vertex *u**i* and vertex *v**i* directly or indirectly.
Input Specification:
The first line of the input contains space-separated two integers — *n* and *m* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers — *a**i*, *b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i* (1<=≤<=*c**i*<=≤<=*m*). Note that there can be multiple edges between two vertices. However, there are no multiple edges of the same color between two vertices, that is, if *i*<=≠<=*j*, (*a**i*,<=*b**i*,<=*c**i*)<=≠<=(*a**j*,<=*b**j*,<=*c**j*).
The next line contains a integer — *q* (1<=≤<=*q*<=≤<=100), denoting the number of the queries.
Then follows *q* lines, containing space-separated two integers — *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). It is guaranteed that *u**i*<=≠<=*v**i*.
Output Specification:
For each query, print the answer in a separate line.
Demo Input:
['4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n', '5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n']
Demo Output:
['2\n1\n0\n', '1\n1\n1\n1\n2\n']
Note:
Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | ```python
from collections import deque
def BFS(graph,a,b):
q = deque()
q.append(a)
visited = [ False for _ in range(len(graph))]
while len(q):
v = q.pop()
if visited[v]:
continue
for x in graph[v]:
if not visited[x]:
q.append(x)
visited[v] = True
return visited[b]
n, m = map(int, input().split())
color = {}
for i in range(m):
v1, v2, c = map(int, input().split())
if c not in color:
color[c] = [ [] for _ in range(n+1) ]
color[c][v1].append(v2)
color[c][v2].append(v1)
q = int(input())
for _ in range(q):
a, b = map(int, input().split())
ans = 0
for i in color:
if BFS(color[i], a, b):
ans += 1
print(ans)
``` | 3 |
|
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B. | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "A>C\nA>B\nB<C",
"output": "BCA"
},
{
"input": "C<B\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nA>B\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nA<C",
"output": "ABC"
},
{
"input": "C<B\nB<A\nC>A",
"output": "Impossible"
},
{
"input": "B<C\nC<A\nA>B",
"output": "BCA"
},
{
"input": "A>B\nC<B\nC<A",
"output": "CBA"
},
{
"input": "B>A\nC>B\nA>C",
"output": "Impossible"
},
{
"input": "B<A\nC>B\nC>A",
"output": "BAC"
},
{
"input": "A<B\nC>B\nA<C",
"output": "ABC"
},
{
"input": "A<B\nC<A\nB<C",
"output": "Impossible"
},
{
"input": "A>C\nC<B\nB>A",
"output": "CAB"
},
{
"input": "C>A\nA<B\nB>C",
"output": "ACB"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "B>C\nB>A\nA<C",
"output": "ACB"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA<B\nB>C",
"output": "ACB"
},
{
"input": "B>A\nA>C\nB>C",
"output": "CAB"
},
{
"input": "B<A\nA<C\nC<B",
"output": "Impossible"
},
{
"input": "A<C\nB>C\nA>B",
"output": "Impossible"
},
{
"input": "B>A\nC<A\nC>B",
"output": "Impossible"
},
{
"input": "A>C\nC>B\nB<A",
"output": "BCA"
},
{
"input": "B<C\nB<A\nA>C",
"output": "BCA"
},
{
"input": "A>B\nC>B\nA<C",
"output": "BAC"
},
{
"input": "C<B\nC<A\nB<A",
"output": "CBA"
},
{
"input": "A<C\nA>B\nB>C",
"output": "Impossible"
},
{
"input": "B>A\nB>C\nA<C",
"output": "ACB"
},
{
"input": "B>C\nC<A\nB<A",
"output": "CBA"
},
{
"input": "C>A\nB>A\nB>C",
"output": "ACB"
},
{
"input": "B<A\nB>C\nA<C",
"output": "Impossible"
},
{
"input": "B<C\nA<B\nC>A",
"output": "ABC"
},
{
"input": "C<B\nB>A\nA>C",
"output": "CAB"
},
{
"input": "A>B\nC>A\nB<C",
"output": "BAC"
},
{
"input": "A>B\nB>C\nC<A",
"output": "CBA"
},
{
"input": "B>C\nC>A\nA>B",
"output": "Impossible"
},
{
"input": "B<A\nB>C\nC<A",
"output": "CBA"
},
{
"input": "C>B\nB>A\nC>A",
"output": "ABC"
},
{
"input": "A>C\nA>B\nB>C",
"output": "CBA"
},
{
"input": "B<C\nA>B\nA<C",
"output": "BAC"
},
{
"input": "C>A\nC<B\nB>A",
"output": "ACB"
},
{
"input": "C>B\nA<B\nC<A",
"output": "Impossible"
},
{
"input": "A<C\nC<B\nA>B",
"output": "Impossible"
},
{
"input": "B>C\nA<B\nA<C",
"output": "ACB"
},
{
"input": "C>A\nA<B\nC>B",
"output": "ABC"
}
] | 1,672,228,227 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | # Wadea #
s1 = input()
s2 = input()
s3 = input()
if s1 == "A>B" or s1 == "B<A":
if s2 == "B>C" or s2 == "C<B":
if s3 == "A>C" or s3 == "C<A":
print("CBA")
elif s3 == "C>A" or s3 == "A<C":
print("Impossible")
elif s2 == "C>B" or s2 == "B<C":
if s3 == "C>A" or "A<C":
print("BAC")
elif s3 == "A>C" or s3 == "C<A":
print("BCA")
elif s1 == "A<B" or s1 == "B>A":
if s2 == "B>C" or s2 == "C<B":
if s3 == "A>C" or s3 == "C<A":
print("CAB")
elif s3 == "C>A" or s3 == "A<C":
print("ACB")
elif s2 == "C>B" or s2 == "B<C":
if s3 == "C>A" or "A<C":
print("ABC")
elif s3 == "A>C" or s3 == "C<A":
print("Impossible") | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.
Input Specification:
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.
Output Specification:
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.
Demo Input:
['A>B\nC<B\nA>C\n', 'A<B\nB>C\nC>A\n']
Demo Output:
['CBA', 'ACB']
Note:
none | ```python
# Wadea #
s1 = input()
s2 = input()
s3 = input()
if s1 == "A>B" or s1 == "B<A":
if s2 == "B>C" or s2 == "C<B":
if s3 == "A>C" or s3 == "C<A":
print("CBA")
elif s3 == "C>A" or s3 == "A<C":
print("Impossible")
elif s2 == "C>B" or s2 == "B<C":
if s3 == "C>A" or "A<C":
print("BAC")
elif s3 == "A>C" or s3 == "C<A":
print("BCA")
elif s1 == "A<B" or s1 == "B>A":
if s2 == "B>C" or s2 == "C<B":
if s3 == "A>C" or s3 == "C<A":
print("CAB")
elif s3 == "C>A" or s3 == "A<C":
print("ACB")
elif s2 == "C>B" or s2 == "B<C":
if s3 == "C>A" or "A<C":
print("ABC")
elif s3 == "A>C" or s3 == "C<A":
print("Impossible")
``` | 0 |
997 | A | Convert to Ones | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones? | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones. | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | 500 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
{
"input": "1 314253869 261764879\n0",
"output": "261764879"
},
{
"input": "1 491511050 399084767\n1",
"output": "0"
},
{
"input": "2 163093925 214567542\n00",
"output": "214567542"
},
{
"input": "2 340351106 646854722\n10",
"output": "646854722"
},
{
"input": "2 222640995 489207317\n01",
"output": "489207317"
},
{
"input": "2 399898176 552898277\n11",
"output": "0"
},
{
"input": "2 690218164 577155357\n00",
"output": "577155357"
},
{
"input": "2 827538051 754412538\n10",
"output": "754412538"
},
{
"input": "2 636702427 259825230\n01",
"output": "259825230"
},
{
"input": "2 108926899 102177825\n11",
"output": "0"
},
{
"input": "3 368381052 440077270\n000",
"output": "440077270"
},
{
"input": "3 505700940 617334451\n100",
"output": "617334451"
},
{
"input": "3 499624340 643020827\n010",
"output": "1142645167"
},
{
"input": "3 75308005 971848814\n110",
"output": "971848814"
},
{
"input": "3 212627893 854138703\n001",
"output": "854138703"
},
{
"input": "3 31395883 981351561\n101",
"output": "981351561"
},
{
"input": "3 118671447 913685773\n011",
"output": "913685773"
},
{
"input": "3 255991335 385910245\n111",
"output": "0"
},
{
"input": "3 688278514 268200134\n000",
"output": "268200134"
},
{
"input": "3 825598402 445457315\n100",
"output": "445457315"
},
{
"input": "3 300751942 45676507\n010",
"output": "91353014"
},
{
"input": "3 517900980 438071829\n110",
"output": "438071829"
},
{
"input": "3 400190869 280424424\n001",
"output": "280424424"
},
{
"input": "3 577448050 344115384\n101",
"output": "344115384"
},
{
"input": "3 481435271 459737939\n011",
"output": "459737939"
},
{
"input": "3 931962412 913722450\n111",
"output": "0"
},
{
"input": "4 522194562 717060616\n0000",
"output": "717060616"
},
{
"input": "4 659514449 894317797\n1000",
"output": "894317797"
},
{
"input": "4 71574977 796834337\n0100",
"output": "868409314"
},
{
"input": "4 248832158 934154224\n1100",
"output": "934154224"
},
{
"input": "4 71474110 131122047\n0010",
"output": "202596157"
},
{
"input": "4 308379228 503761290\n1010",
"output": "812140518"
},
{
"input": "4 272484957 485636409\n0110",
"output": "758121366"
},
{
"input": "4 662893590 704772137\n1110",
"output": "704772137"
},
{
"input": "4 545183479 547124732\n0001",
"output": "547124732"
},
{
"input": "4 684444619 722440661\n1001",
"output": "722440661"
},
{
"input": "4 477963686 636258459\n0101",
"output": "1114222145"
},
{
"input": "4 360253575 773578347\n1101",
"output": "773578347"
},
{
"input": "4 832478048 910898234\n0011",
"output": "910898234"
},
{
"input": "4 343185412 714767937\n1011",
"output": "714767937"
},
{
"input": "4 480505300 892025118\n0111",
"output": "892025118"
},
{
"input": "4 322857895 774315007\n1111",
"output": "0"
},
{
"input": "4 386548854 246539479\n0000",
"output": "246539479"
},
{
"input": "4 523868742 128829368\n1000",
"output": "128829368"
},
{
"input": "4 956155921 11119257\n0100",
"output": "22238514"
},
{
"input": "4 188376438 93475808\n1100",
"output": "93475808"
},
{
"input": "4 754947032 158668188\n0010",
"output": "317336376"
},
{
"input": "4 927391856 637236921\n1010",
"output": "1274473842"
},
{
"input": "4 359679035 109461393\n0110",
"output": "218922786"
},
{
"input": "4 991751283 202031630\n1110",
"output": "202031630"
},
{
"input": "4 339351517 169008463\n0001",
"output": "169008463"
},
{
"input": "4 771638697 346265644\n1001",
"output": "346265644"
},
{
"input": "4 908958584 523522825\n0101",
"output": "1047045650"
},
{
"input": "4 677682252 405812714\n1101",
"output": "405812714"
},
{
"input": "4 815002139 288102603\n0011",
"output": "288102603"
},
{
"input": "4 952322026 760327076\n1011",
"output": "760327076"
},
{
"input": "4 663334158 312481698\n0111",
"output": "312481698"
},
{
"input": "4 840591339 154834293\n1111",
"output": "0"
},
{
"input": "14 3 11\n10110100011001",
"output": "20"
},
{
"input": "19 1 1\n1010101010101010101",
"output": "9"
},
{
"input": "1 10 1\n1",
"output": "0"
},
{
"input": "1 100 1\n1",
"output": "0"
},
{
"input": "5 1000 1\n11111",
"output": "0"
},
{
"input": "5 10 1\n11111",
"output": "0"
},
{
"input": "7 3 2\n1111111",
"output": "0"
},
{
"input": "5 1 10\n10101",
"output": "11"
},
{
"input": "1 3 2\n1",
"output": "0"
},
{
"input": "2 10 1\n11",
"output": "0"
},
{
"input": "4 148823922 302792601\n1010",
"output": "451616523"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "5 2 3\n00011",
"output": "3"
},
{
"input": "1 5 0\n1",
"output": "0"
},
{
"input": "7 2 3\n1001001",
"output": "5"
},
{
"input": "10 1 1000000000\n1111010111",
"output": "1000000001"
},
{
"input": "25 999999998 999999999\n1011001110101010100111001",
"output": "7999999985"
},
{
"input": "2 0 1\n00",
"output": "1"
},
{
"input": "2 1 100\n10",
"output": "100"
},
{
"input": "7 20 3\n1111111",
"output": "0"
},
{
"input": "1 1 0\n1",
"output": "0"
},
{
"input": "3 1 10\n010",
"output": "11"
},
{
"input": "2 1 0\n11",
"output": "0"
},
{
"input": "7 100 3\n1111111",
"output": "0"
},
{
"input": "5 1 1000\n10101",
"output": "1001"
},
{
"input": "5 2 1\n11111",
"output": "0"
},
{
"input": "1 1000 1\n1",
"output": "0"
},
{
"input": "1 799543940 488239239\n1",
"output": "0"
},
{
"input": "6 1 1000\n010101",
"output": "1002"
},
{
"input": "5 11 1\n11111",
"output": "0"
},
{
"input": "5 2 3\n10101",
"output": "5"
},
{
"input": "3 10 1\n111",
"output": "0"
},
{
"input": "7 9 10\n1001011",
"output": "19"
},
{
"input": "5 5 6\n10101",
"output": "11"
},
{
"input": "1 1000000000 0\n1",
"output": "0"
},
{
"input": "4 0 1\n0101",
"output": "1"
},
{
"input": "8 2 3\n10101010",
"output": "9"
},
{
"input": "6 3 100\n010101",
"output": "106"
},
{
"input": "3 3 2\n111",
"output": "0"
},
{
"input": "1 20 1\n1",
"output": "0"
},
{
"input": "2 1 2\n01",
"output": "2"
}
] | 1,534,395,304 | 2,704 | Python 3 | WRONG_ANSWER | TESTS | 15 | 218 | 1,024,000 | a=input().split()
n=int(a[0])
x=int(a[1])
y=int(a[2])
a=input()
swaps = 0
add=True
for i in range(n):
if add==True and a[i]=='0':
swaps+=1
add=False
if a[i]=='1':
add=True
tot1 = swaps*y
tot2 = (swaps-1)*x+y
if tot1>tot2:
print(tot2)
else:
print(tot1)
| Title: Convert to Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input Specification:
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones.
Output Specification:
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
Demo Input:
['5 1 10\n01000\n', '5 10 1\n01000\n', '7 2 3\n1111111\n']
Demo Output:
['11\n', '2\n', '0\n']
Note:
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | ```python
a=input().split()
n=int(a[0])
x=int(a[1])
y=int(a[2])
a=input()
swaps = 0
add=True
for i in range(n):
if add==True and a[i]=='0':
swaps+=1
add=False
if a[i]=='1':
add=True
tot1 = swaps*y
tot2 = (swaps-1)*x+y
if tot1>tot2:
print(tot2)
else:
print(tot1)
``` | 0 |
|
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
"output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000"
},
{
"input": "2\n-1000000000 1000000000",
"output": "2000000000 2000000000\n2000000000 2000000000"
},
{
"input": "10\n1 10 12 15 59 68 130 912 1239 9123",
"output": "9 9122\n2 9113\n2 9111\n3 9108\n9 9064\n9 9055\n62 8993\n327 8211\n327 7884\n7884 9122"
},
{
"input": "5\n-2 -1 0 1 2",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "5\n-2 -1 0 1 3",
"output": "1 5\n1 4\n1 3\n1 3\n2 5"
},
{
"input": "3\n-10000 1 10000",
"output": "10001 20000\n9999 10001\n9999 20000"
},
{
"input": "5\n-1000000000 -999999999 -999999998 -999999997 -999999996",
"output": "1 4\n1 3\n1 2\n1 3\n1 4"
},
{
"input": "10\n-857422304 -529223472 82412729 145077145 188538640 265299215 527377039 588634631 592896147 702473706",
"output": "328198832 1559896010\n328198832 1231697178\n62664416 939835033\n43461495 1002499449\n43461495 1045960944\n76760575 1122721519\n61257592 1384799343\n4261516 1446056935\n4261516 1450318451\n109577559 1559896010"
},
{
"input": "10\n-876779400 -829849659 -781819137 -570920213 18428128 25280705 121178189 219147240 528386329 923854124",
"output": "46929741 1800633524\n46929741 1753703783\n48030522 1705673261\n210898924 1494774337\n6852577 905425996\n6852577 902060105\n95897484 997957589\n97969051 1095926640\n309239089 1405165729\n395467795 1800633524"
},
{
"input": "30\n-15 1 21 25 30 40 59 60 77 81 97 100 103 123 139 141 157 158 173 183 200 215 226 231 244 256 267 279 289 292",
"output": "16 307\n16 291\n4 271\n4 267\n5 262\n10 252\n1 233\n1 232\n4 215\n4 211\n3 195\n3 192\n3 189\n16 169\n2 154\n2 156\n1 172\n1 173\n10 188\n10 198\n15 215\n11 230\n5 241\n5 246\n12 259\n11 271\n11 282\n10 294\n3 304\n3 307"
},
{
"input": "10\n-1000000000 -999999999 -999999997 -999999996 -999999995 -999999994 -999999992 -999999990 -999999988 -999999986",
"output": "1 14\n1 13\n1 11\n1 10\n1 9\n1 8\n2 8\n2 10\n2 12\n2 14"
},
{
"input": "50\n-50000 -49459 -48875 -48456 -48411 -48096 -47901 -47500 -47150 -46808 -46687 -46679 -46337 -45747 -45604 -45194 -44752 -44242 -44231 -44122 -43636 -43274 -42916 -42881 -42386 -42095 -41830 -41618 -41145 -40897 -40534 -40007 -39761 -39389 -39104 -38909 -38630 -38561 -38364 -38255 -38214 -38084 -37959 -37607 -37202 -36890 -36681 -36136 -36123 -35886",
"output": "541 14114\n541 13573\n419 12989\n45 12570\n45 12525\n195 12210\n195 12015\n350 11614\n342 11264\n121 10922\n8 10801\n8 10793\n342 10451\n143 9861\n143 9718\n410 9308\n442 8866\n11 8356\n11 8345\n109 8236\n362 7750\n358 7388\n35 7084\n35 7119\n291 7614\n265 7905\n212 8170\n212 8382\n248 8855\n248 9103\n363 9466\n246 9993\n246 10239\n285 10611\n195 10896\n195 11091\n69 11370\n69 11439\n109 11636\n41 11745\n41 11786\n125 11916\n125 12041\n352 12393\n312 12798\n209 13110\n209 13319\n13 13864\n13 13877\n237 141..."
},
{
"input": "3\n-1000000000 999999999 1000000000",
"output": "1999999999 2000000000\n1 1999999999\n1 2000000000"
}
] | 1,600,144,898 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 307,200 | n = int(input())
entrada = input().split(' ')
inicio = int(entrada[0])
fim = int(entrada[n -1])
m = int(entrada[len(entrada)//2])
for i in range(len(entrada)+1):
x = 0
y = 0
if(i == len(entrada)-1):
x = abs(inicio - fim)
y = abs(fim - int(entrada[i - 1]))
print (y,x)
break
if(int(entrada[i]) < m):
x = abs(int(entrada[i]) - fim)
else:
x = abs(int(entrada[i]) - inicio)
if(i == 0 and len(entrada) > 1):
y = abs(int(entrada[i]) - int(entrada[i + 1]))
elif(abs(int(entrada[i]) - int(entrada[i + 1])) > abs(int(entrada[i]) - int(entrada[i - 1]))):
y = abs(int(entrada[i]) - int(entrada[i - 1]))
else:
y = abs(int(entrada[i]) - int(entrada[i + 1]))
print (y,x)
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values *min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
Input Specification:
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Output Specification:
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
Demo Input:
['4\n-5 -2 2 7\n', '2\n-1 1\n']
Demo Output:
['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n']
Note:
none | ```python
n = int(input())
entrada = input().split(' ')
inicio = int(entrada[0])
fim = int(entrada[n -1])
m = int(entrada[len(entrada)//2])
for i in range(len(entrada)+1):
x = 0
y = 0
if(i == len(entrada)-1):
x = abs(inicio - fim)
y = abs(fim - int(entrada[i - 1]))
print (y,x)
break
if(int(entrada[i]) < m):
x = abs(int(entrada[i]) - fim)
else:
x = abs(int(entrada[i]) - inicio)
if(i == 0 and len(entrada) > 1):
y = abs(int(entrada[i]) - int(entrada[i + 1]))
elif(abs(int(entrada[i]) - int(entrada[i + 1])) > abs(int(entrada[i]) - int(entrada[i - 1]))):
y = abs(int(entrada[i]) - int(entrada[i - 1]))
else:
y = abs(int(entrada[i]) - int(entrada[i + 1]))
print (y,x)
``` | 0 |
|
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "081"
},
{
"input": "4\n3811",
"output": "38-11"
},
{
"input": "5\n21583",
"output": "215-83"
},
{
"input": "8\n33408349",
"output": "33-40-83-49"
},
{
"input": "9\n988808426",
"output": "988-80-84-26"
},
{
"input": "10\n0180990956",
"output": "01-80-99-09-56"
},
{
"input": "15\n433488906230138",
"output": "433-48-89-06-23-01-38"
},
{
"input": "22\n7135498415686025907059",
"output": "71-35-49-84-15-68-60-25-90-70-59"
},
{
"input": "49\n2429965524999668169991253653390090510755018570235",
"output": "242-99-65-52-49-99-66-81-69-99-12-53-65-33-90-09-05-10-75-50-18-57-02-35"
},
{
"input": "72\n491925337784111770500147619881727525570039735507439360627744863794794290",
"output": "49-19-25-33-77-84-11-17-70-50-01-47-61-98-81-72-75-25-57-00-39-73-55-07-43-93-60-62-77-44-86-37-94-79-42-90"
},
{
"input": "95\n32543414456047900690980198395035321172843693417425457554204776648220562494524275489599199209210",
"output": "325-43-41-44-56-04-79-00-69-09-80-19-83-95-03-53-21-17-28-43-69-34-17-42-54-57-55-42-04-77-66-48-22-05-62-49-45-24-27-54-89-59-91-99-20-92-10"
},
{
"input": "97\n9362344595153688016434451101547661156123505108492010669557671355055642365998461003851354321478898",
"output": "936-23-44-59-51-53-68-80-16-43-44-51-10-15-47-66-11-56-12-35-05-10-84-92-01-06-69-55-76-71-35-50-55-64-23-65-99-84-61-00-38-51-35-43-21-47-88-98"
},
{
"input": "98\n65521815795893886057122984634320900545031770769333931308009346017867969790810907868670369236928568",
"output": "65-52-18-15-79-58-93-88-60-57-12-29-84-63-43-20-90-05-45-03-17-70-76-93-33-93-13-08-00-93-46-01-78-67-96-97-90-81-09-07-86-86-70-36-92-36-92-85-68"
},
{
"input": "99\n455213856470326729480192345541970106407563996625458559297407682539801838244443866898560852503660390",
"output": "455-21-38-56-47-03-26-72-94-80-19-23-45-54-19-70-10-64-07-56-39-96-62-54-58-55-92-97-40-76-82-53-98-01-83-82-44-44-38-66-89-85-60-85-25-03-66-03-90"
},
{
"input": "100\n4004223124942730640235383244438257614581534320356060987241659784249551110165034719443327659510644224",
"output": "40-04-22-31-24-94-27-30-64-02-35-38-32-44-43-82-57-61-45-81-53-43-20-35-60-60-98-72-41-65-97-84-24-95-51-11-01-65-03-47-19-44-33-27-65-95-10-64-42-24"
}
] | 1,623,964,795 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 4 | 218 | 2,150,400 | n = int(input())
x = int(input())
lovely = []
while x>0:
lovely.append(x%10)
x = x//10
lovely.reverse()
x = lovely
if n==2:
print(x[0],end = "")
print(x[1])
elif n==3:
print(x[0],end = "")
print(x[1],end = "")
print(x[2], end = "")
else:
if n%2==0:
for i in range(0,n-2,2):
print(x[i],end = "")
print(x[i+1], end = "-")
print(x[-2],end = "")
print(x[-1], end = "")
else:
for i in range(0,n-3,2):
print(x[i],end = "")
print(x[i+1], end = "-")
print(x[-3],end = "")
print(x[-2],end = "")
print(x[-1],end = "")
| Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups.
Output Specification:
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
Demo Input:
['6\n549871\n', '7\n1198733\n']
Demo Output:
['54-98-71', '11-987-33\n']
Note:
none | ```python
n = int(input())
x = int(input())
lovely = []
while x>0:
lovely.append(x%10)
x = x//10
lovely.reverse()
x = lovely
if n==2:
print(x[0],end = "")
print(x[1])
elif n==3:
print(x[0],end = "")
print(x[1],end = "")
print(x[2], end = "")
else:
if n%2==0:
for i in range(0,n-2,2):
print(x[i],end = "")
print(x[i+1], end = "-")
print(x[-2],end = "")
print(x[-1], end = "")
else:
for i in range(0,n-3,2):
print(x[i],end = "")
print(x[i+1], end = "-")
print(x[-3],end = "")
print(x[-2],end = "")
print(x[-1],end = "")
``` | -1 |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 1,676,016,260 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 93 | 0 | n = input()
num = ""
for i in range(len(n)):
temp = int(n[i])
if temp > 9 - temp:
temp = 9 - temp
num += str(temp)
if num[0] == "0":
num = num.replace("0", "9", 1)
print(num) | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Output Specification:
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
Demo Input:
['27\n', '4545\n']
Demo Output:
['22\n', '4444\n']
Note:
none | ```python
n = input()
num = ""
for i in range(len(n)):
temp = int(n[i])
if temp > 9 - temp:
temp = 9 - temp
num += str(temp)
if num[0] == "0":
num = num.replace("0", "9", 1)
print(num)
``` | 3 |
|
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game? | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 2010 10 247 3269 671 2986 942 758 1146 77 1545 3745 1547 2250 2565 217 1406 2070 3010 3404 404 1528 2352 138 2065 3047 3656 2188 2919 2616 2083 1280 2977 2681 548 4000 1667 1489 1109 3164 1565 2653 3260 3463 903 1824 3679 2308 245 2689 2063 648 568 766 785 2984 3812 440 1172 2730",
"output": "4000"
},
{
"input": "68\n477 1931 3738 3921 2306 1823 3328 2057 661 3993 2967 3520 171 1739 1525 1817 209 3475 1902 2666 518 3283 3412 3040 3383 2331 1147 1460 1452 1800 1327 2280 82 1416 2200 2388 3238 1879 796 250 1872 114 121 2042 1853 1645 211 2061 1472 2464 726 1989 1746 489 1380 1128 2819 2527 2939 622 678 265 2902 1111 2032 1453 3850 1621",
"output": "3993"
},
{
"input": "30\n30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "30"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n69",
"output": "69"
}
] | 1,627,492,875 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 6,963,200 |
if __name__ == "__main__":
m = map(int,input().split())
data = [int(item) for item in input().split()]
result = data[0]
e = data[0]
for i in range(0,len(data)-1):
gap = data[i] -data[i+1]
if gap < 0 and e < data[i+1] :
result += abs(gap)
e = e + gap
print(result) | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is to reach *n*-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as *k*) to the next one (its number will be *k*<=+<=1). When the player have made such a move, its energy increases by *h**k*<=-<=*h**k*<=+<=1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Output Specification:
Print a single number representing the minimum number of dollars paid by Caisa.
Demo Input:
['5\n3 4 3 2 4\n', '3\n4 4 4\n']
Demo Output:
['4\n', '4\n']
Note:
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | ```python
if __name__ == "__main__":
m = map(int,input().split())
data = [int(item) for item in input().split()]
result = data[0]
e = data[0]
for i in range(0,len(data)-1):
gap = data[i] -data[i+1]
if gap < 0 and e < data[i+1] :
result += abs(gap)
e = e + gap
print(result)
``` | 0 |
|
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round. | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976",
"output": "999975"
},
{
"input": "25\n13 15 24 2 21 18 9 4 16 6 10 25 20 11 23 17 8 3 1 12 5 19 22 14 7",
"output": "0"
},
{
"input": "10\n17 11 7 13 18 12 14 5 16 2",
"output": "0"
},
{
"input": "22\n22 14 23 20 11 21 4 12 3 8 7 9 19 10 13 17 15 1 5 18 16 2",
"output": "0"
},
{
"input": "21\n6 21 24 3 10 23 14 2 26 12 8 1 15 13 9 5 19 20 4 16 22",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n100 60",
"output": "75"
},
{
"input": "4\n999 581 787 236",
"output": "974"
},
{
"input": "6\n198 397 732 1234 309 827",
"output": "1209"
},
{
"input": "11\n6494 3961 1858 4351 8056 780 7720 6211 1961 8192 3621",
"output": "8167"
},
{
"input": "14\n18809 9534 11652 6493 8929 9370 4125 23888 16403 3559 23649 19243 14289 17852",
"output": "23863"
},
{
"input": "18\n24939 35558 47058 70307 26221 12866 3453 40422 47557 36322 40698 64060 10825 77777 48645 26124 4859 64222",
"output": "77752"
},
{
"input": "24\n633483 654321 122445 481150 347578 37803 525083 151084 211073 358699 339420 452023 219553 119727 74852 66750 371279 405099 618894 649977 235337 607819 81649 649804",
"output": "654296"
},
{
"input": "25\n58115 794098 753382 484882 238434 674285 690118 858677 196185 173301 349729 918792 600745 636016 122678 366783 137179 377098 917081 369620 449039 379412 503678 1000000 292099",
"output": "999975"
},
{
"input": "2\n26 27",
"output": "2"
},
{
"input": "3\n40 30 35",
"output": "15"
},
{
"input": "2\n46 45",
"output": "21"
},
{
"input": "3\n1 25 90",
"output": "65"
},
{
"input": "5\n14 15 16 30 92",
"output": "67"
},
{
"input": "2\n1000 1001",
"output": "976"
},
{
"input": "25\n3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28 2",
"output": "3"
}
] | 1,576,941,708 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 155 | 1,228,800 | k=int(input())
a=list(map(int,input().split()))
m=max(a)
l=[]
c1=c2=0
for i in a:
if(i>25):
l.append(i)
for i in range(1,26):
if i not in a:
c1+=1
for i in range(26,m+1):
if i not in a:
c2+=1
if(k==25):
print(c1+c2)
else:
print(c2+len(l)) | Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.
Input Specification:
The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Output Specification:
Print the minimum possible number of contestants that declined the invitation to compete onsite.
Demo Input:
['25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n', '5\n16 23 8 15 4\n', '3\n14 15 92\n']
Demo Output:
['3\n', '0\n', '67\n']
Note:
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | ```python
k=int(input())
a=list(map(int,input().split()))
m=max(a)
l=[]
c1=c2=0
for i in a:
if(i>25):
l.append(i)
for i in range(1,26):
if i not in a:
c1+=1
for i in range(26,m+1):
if i not in a:
c2+=1
if(k==25):
print(c1+c2)
else:
print(c2+len(l))
``` | 3 |
|
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese.
Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7 3 9\n100",
"output": "10"
},
{
"input": "BSC\n100 1 1\n100 1 1\n100",
"output": "51"
},
{
"input": "SBBCCSBB\n1 50 100\n31 59 21\n100000",
"output": "370"
},
{
"input": "BBBBCCCCCCCCCCCCCCCCCCCCSSSSBBBBBBBBSS\n100 100 100\n1 1 1\n3628800",
"output": "95502"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n200",
"output": "0"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n2000",
"output": "1"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300",
"output": "0"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n300000000",
"output": "42858"
},
{
"input": "BBBBBBBBBBCCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n10 20 40\n100 100 100\n914159265358",
"output": "130594181"
},
{
"input": "SSSSSSSSSSBBBBBBBBBCCCCCCCCCCCCCCCCCCCSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSBB\n31 53 97\n13 17 31\n914159265358",
"output": "647421579"
},
{
"input": "BBBCSBSBBSSSSCCCCBBCSBBBBSSBBBCBSCCSSCSSCSBSSSCCCCBSCSSBSSSCCCBBCCCSCBCBBCCSCCCCSBBCCBBBBCCCCCCBSSCB\n91 87 17\n64 44 43\n958532915587",
"output": "191668251"
},
{
"input": "CSSCBBCCCSBSCBBBCSBBBCBSBCSCBCSCBCBSBCBCSSBBSBBCBBBBSCSBBCCBCCBCBBSBSBCSCSBBSSBBCSSBCSCSCCSSBCBBCBSB\n56 34 48\n78 6 96\n904174875419",
"output": "140968956"
},
{
"input": "CCSCCCSBBBSCBSCSCCSSBBBSSBBBSBBBCBCSSBCSCBBCCCBCBCBCCCSSBSBBCCCCCBBSCBSCBCBBCBBCSSBCSBSSCCSCCSCCBBBS\n33 73 67\n4 56 42\n886653164314",
"output": "277425898"
},
{
"input": "SBCSSCBBSSBCSSBBBSSBSCBSSSCBBSBBBBCSBCSBSCBSCBSCBSBSSCCCCBSBCCBCBSCCCBSCCBSBBCBSSCCCCSBSBBBSSSBCSCBC\n94 16 85\n14 18 91\n836590091442",
"output": "217522127"
},
{
"input": "BSCSBSCCSCSSCCCSBCSSBCBBSCCBSCCSSSSSSSSSCCSBSCCBBCBBSBSCCCCBCSBSBSSBBBBBSSBSSCBCCSSBSSSCBBCSBBSBCCCB\n67 54 8\n36 73 37\n782232051273",
"output": "154164772"
},
{
"input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSSBSBSCBBSBBCSSSSBBBBSBBCBCSBBCBCSSBBCSBSCCSCSBCSCBSCCBBCSC\n71 71 52\n52 88 3\n654400055575",
"output": "137826467"
},
{
"input": "CBBCBSBCCSCBSSCCBCSBCSBBSCBBCSCCBSCCSCSBBSBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCSC\n100 1 1\n1 17 23\n954400055575",
"output": "1355681897"
},
{
"input": "C\n100 100 100\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n100 100 100\n100 100 100\n1000000000000",
"output": "100000001"
},
{
"input": "B\n100 100 100\n1 1 1\n1",
"output": "101"
},
{
"input": "SC\n2 1 1\n1 1 1\n100000000000",
"output": "50000000001"
},
{
"input": "B\n100 1 1\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n1 1 1\n100 100 100\n1000000000000",
"output": "100000000"
},
{
"input": "CC\n1 1 1\n100 100 100\n1",
"output": "0"
},
{
"input": "B\n100 100 100\n1 1 1\n1000000000000",
"output": "1000000000100"
},
{
"input": "BSC\n100 100 100\n1 1 1\n1000000000000",
"output": "333333333433"
},
{
"input": "BSC\n100 100 100\n1 1 1\n1",
"output": "100"
}
] | 1,666,108,098 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 21 | 77 | 0 | import sys
import math
from collections import defaultdict,Counter
from itertools import permutations
from collections import deque
def sin():
return int(sys.stdin.readline())
def array():
return list(map(int, sys.stdin.readline().strip().split()))
def two():
return map(int, sys.stdin.readline().strip().split())
def multiple():
return [int(x) for x in sys.stdin.readline().split()]
def string():
return sys.stdin.readline().strip()
def sqrt(x):
low , high = 0 , x
while low <= high:
mid = (low + high) // 2
if mid * mid <= x < (mid+1) * (mid+1):
return mid
elif x < mid * mid:
high = mid - 1
else:
low = mid + 1
s = string()
nb , ns , nc = multiple()
pb , ps , pc = multiple()
ruble = sin()
b_count = s_count = c_count = 0
for i in s:
if i == "B":
b_count += 1
if i == "S":
s_count += 1
if i == "C":
c_count += 1
def solve(burger , money):
x = b_count * burger
req_x = max(0 , x - nb)
money -= (req_x * pb)
if money < 0:
return False
y = s_count * burger
req_y = max(0 , y - ns)
money -= (req_y * ps)
if money < 0:
return False
z = c_count * burger
req_z = max(0 , z - nc)
money -= (req_z * pc)
if money < 0:
return False
return True
low = 0
high = 333333333333
while low <= high:
mid = (low + high) >> 1
if solve(mid , ruble):
low = mid + 1
else:
high = mid - 1
print(high) | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has *n**b* pieces of bread, *n**s* pieces of sausage and *n**c* pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are *p**b* rubles for a piece of bread, *p**s* for a piece of sausage and *p**c* for a piece of cheese.
Polycarpus has *r* rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
Input Specification:
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n**b*, *n**s*, *n**c* (1<=≤<=*n**b*,<=*n**s*,<=*n**c*<=≤<=100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers *p**b*, *p**s*, *p**c* (1<=≤<=*p**b*,<=*p**s*,<=*p**c*<=≤<=100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer *r* (1<=≤<=*r*<=≤<=1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
Demo Input:
['BBBSSC\n6 4 1\n1 2 3\n4\n', 'BBC\n1 10 1\n1 10 1\n21\n', 'BSC\n1 1 1\n1 1 3\n1000000000000\n']
Demo Output:
['2\n', '7\n', '200000000001\n']
Note:
none | ```python
import sys
import math
from collections import defaultdict,Counter
from itertools import permutations
from collections import deque
def sin():
return int(sys.stdin.readline())
def array():
return list(map(int, sys.stdin.readline().strip().split()))
def two():
return map(int, sys.stdin.readline().strip().split())
def multiple():
return [int(x) for x in sys.stdin.readline().split()]
def string():
return sys.stdin.readline().strip()
def sqrt(x):
low , high = 0 , x
while low <= high:
mid = (low + high) // 2
if mid * mid <= x < (mid+1) * (mid+1):
return mid
elif x < mid * mid:
high = mid - 1
else:
low = mid + 1
s = string()
nb , ns , nc = multiple()
pb , ps , pc = multiple()
ruble = sin()
b_count = s_count = c_count = 0
for i in s:
if i == "B":
b_count += 1
if i == "S":
s_count += 1
if i == "C":
c_count += 1
def solve(burger , money):
x = b_count * burger
req_x = max(0 , x - nb)
money -= (req_x * pb)
if money < 0:
return False
y = s_count * burger
req_y = max(0 , y - ns)
money -= (req_y * ps)
if money < 0:
return False
z = c_count * burger
req_z = max(0 , z - nc)
money -= (req_z * pc)
if money < 0:
return False
return True
low = 0
high = 333333333333
while low <= high:
mid = (low + high) >> 1
if solve(mid , ruble):
low = mid + 1
else:
high = mid - 1
print(high)
``` | 0 |
|
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3",
"output": "16"
},
{
"input": "10\n2 3 0 1 3 1 2 2 1 0",
"output": "3"
},
{
"input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n3 3",
"output": "0"
},
{
"input": "3\n3 3 3",
"output": "0"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "2\n0 2",
"output": "1"
},
{
"input": "10\n2 2 3 3 3 3 2 1 3 2",
"output": "2"
},
{
"input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0",
"output": "11"
},
{
"input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1",
"output": "4"
},
{
"input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2",
"output": "3"
},
{
"input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0",
"output": "12"
},
{
"input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3",
"output": "5"
},
{
"input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2",
"output": "4"
},
{
"input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1",
"output": "16"
},
{
"input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3",
"output": "5"
},
{
"input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3",
"output": "3"
},
{
"input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0",
"output": "22"
},
{
"input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2",
"output": "9"
},
{
"input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3",
"output": "2"
},
{
"input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0",
"output": "21"
},
{
"input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2",
"output": "11"
},
{
"input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2",
"output": "7"
},
{
"input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0",
"output": "28"
},
{
"input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1",
"output": "10"
},
{
"input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3",
"output": "8"
},
{
"input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2",
"output": "29"
},
{
"input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3",
"output": "8"
},
{
"input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0",
"output": "32"
},
{
"input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2",
"output": "16"
},
{
"input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3",
"output": "7"
},
{
"input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0",
"output": "40"
},
{
"input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2",
"output": "13"
},
{
"input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3",
"output": "7"
},
{
"input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0",
"output": "44"
},
{
"input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2",
"output": "15"
},
{
"input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3",
"output": "8"
},
{
"input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1",
"output": "35"
},
{
"input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3",
"output": "13"
},
{
"input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3",
"output": "6"
},
{
"input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1",
"output": "43"
},
{
"input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1",
"output": "16"
},
{
"input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1",
"output": "10"
},
{
"input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0",
"output": "51"
},
{
"input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1",
"output": "16"
},
{
"input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1",
"output": "11"
},
{
"input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1",
"output": "56"
},
{
"input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0",
"output": "17"
},
{
"input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3",
"output": "9"
},
{
"input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0",
"output": "54"
},
{
"input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3",
"output": "19"
},
{
"input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3",
"output": "9"
},
{
"input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1",
"output": "57"
},
{
"input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1",
"output": "17"
},
{
"input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2",
"output": "9"
},
{
"input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1",
"output": "61"
},
{
"input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2",
"output": "15"
},
{
"input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2",
"output": "14"
},
{
"input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2",
"output": "63"
},
{
"input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3",
"output": "15"
},
{
"input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "0"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"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": "50"
},
{
"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": "50"
},
{
"input": "99\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",
"output": "49"
},
{
"input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "2\n0 3",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 0",
"output": "1"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n3 0",
"output": "1"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0",
"output": "50"
}
] | 1,694,745,864 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 307,200 | from collections import *
from bisect import *
from heapq import *
from itertools import *
from math import *
import sys
r=lambda:map(int, sys.stdin.readline().rstrip().split())
# t,=r();
# for _ in range(t):
n,=r()
arr=list(r())
consecutive_freq_map =[(k,len(list(v))) for k,v in groupby(arr)]
holiday_cnt = 0
prev = (0,0)
for idx,i in enumerate(consecutive_freq_map):
k,v = i
if k == 0:
holiday_cnt+=v
elif k == 1 or k == 2:
holiday_cnt += v//2
else:
if idx+1 == len(consecutive_freq_map):
holiday_cnt += v//2
continue
if v % 2 ==0 and prev[0] == i[0]:
holiday_cnt+=1
if v % 2 ==1 and prev[0] != i[0]:
holiday_cnt+=1
prev = k,v
print(holiday_cnt) | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Output Specification:
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days.
Demo Input:
['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | ```python
from collections import *
from bisect import *
from heapq import *
from itertools import *
from math import *
import sys
r=lambda:map(int, sys.stdin.readline().rstrip().split())
# t,=r();
# for _ in range(t):
n,=r()
arr=list(r())
consecutive_freq_map =[(k,len(list(v))) for k,v in groupby(arr)]
holiday_cnt = 0
prev = (0,0)
for idx,i in enumerate(consecutive_freq_map):
k,v = i
if k == 0:
holiday_cnt+=v
elif k == 1 or k == 2:
holiday_cnt += v//2
else:
if idx+1 == len(consecutive_freq_map):
holiday_cnt += v//2
continue
if v % 2 ==0 and prev[0] == i[0]:
holiday_cnt+=1
if v % 2 ==1 and prev[0] != i[0]:
holiday_cnt+=1
prev = k,v
print(holiday_cnt)
``` | 0 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,679,024,969 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n,m=map(int,input().split())
l=list(map(int,input().split()))
max_value = l[0] # Initialize max_value to the first element of the list
max_index = 0 # Initialize max_index to 0
for i in range(1, len(l)):
if l[i] >= max_value:
max_value = l[i]
max_index = i
#print(max_value)
print(max_index+1) | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
max_value = l[0] # Initialize max_value to the first element of the list
max_index = 0 # Initialize max_index to 0
for i in range(1, len(l)):
if l[i] >= max_value:
max_value = l[i]
max_index = i
#print(max_value)
print(max_index+1)
``` | 0 |
|
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate. | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12",
"output": "712"
},
{
"input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6",
"output": "482"
},
{
"input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28",
"output": "6469"
},
{
"input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31",
"output": "1340"
},
{
"input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61",
"output": "329"
},
{
"input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16",
"output": "5753"
},
{
"input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29",
"output": "0"
},
{
"input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25",
"output": "851"
},
{
"input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4",
"output": "5884"
},
{
"input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1",
"output": "14170"
},
{
"input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30",
"output": "6650"
},
{
"input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20",
"output": "11786"
},
{
"input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28",
"output": "3182"
},
{
"input": "1 26\n26",
"output": "0"
},
{
"input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26",
"output": "1807"
},
{
"input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4",
"output": "946"
},
{
"input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2",
"output": "3164"
},
{
"input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16",
"output": "1262"
},
{
"input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18",
"output": "2024"
},
{
"input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15",
"output": "1984"
},
{
"input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55",
"output": "740"
},
{
"input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4",
"output": "14888"
},
{
"input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40",
"output": "13118"
},
{
"input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76",
"output": "3030"
},
{
"input": "100 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": "19700"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "19696"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "0"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 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": "0"
},
{
"input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100",
"output": "2"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1",
"output": "16"
},
{
"input": "3 5\n5 5 5",
"output": "0"
},
{
"input": "7 7\n1 1 1 1 1 1 1",
"output": "77"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "100 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": "19700"
},
{
"input": "4 10\n10 10 10 10",
"output": "0"
},
{
"input": "1 10\n10",
"output": "0"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3 10\n10 10 10",
"output": "0"
},
{
"input": "2 4\n3 4",
"output": "0"
},
{
"input": "1 2\n2",
"output": "0"
},
{
"input": "3 4\n4 4 4",
"output": "0"
},
{
"input": "3 2\n2 2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "0"
},
{
"input": "3 3\n3 3 3",
"output": "0"
},
{
"input": "2 9\n8 9",
"output": "0"
},
{
"input": "3 10\n9 10 10",
"output": "0"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "0"
},
{
"input": "2 10\n10 10",
"output": "0"
},
{
"input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14",
"output": "0"
},
{
"input": "2 10\n9 10",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 4",
"output": "0"
},
{
"input": "3 5\n4 5 5",
"output": "0"
},
{
"input": "5 4\n4 4 4 4 4",
"output": "0"
},
{
"input": "2 10\n10 9",
"output": "0"
},
{
"input": "4 5\n3 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "3 10\n10 10 9",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "4 10\n9 10 10 10",
"output": "0"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "2 5\n4 5",
"output": "0"
},
{
"input": "5 10\n10 10 10 10 10",
"output": "0"
},
{
"input": "2 6\n6 6",
"output": "0"
},
{
"input": "2 9\n9 9",
"output": "0"
},
{
"input": "3 10\n10 9 10",
"output": "0"
},
{
"input": "4 40\n39 40 40 40",
"output": "0"
},
{
"input": "3 4\n3 4 4",
"output": "0"
},
{
"input": "9 9\n9 9 9 9 9 9 9 9 9",
"output": "0"
},
{
"input": "1 4\n4",
"output": "0"
},
{
"input": "4 7\n1 1 1 1",
"output": "44"
},
{
"input": "1 5\n5",
"output": "0"
},
{
"input": "3 1\n1 1 1",
"output": "0"
},
{
"input": "1 100\n100",
"output": "0"
},
{
"input": "2 7\n3 5",
"output": "10"
},
{
"input": "3 6\n6 6 6",
"output": "0"
},
{
"input": "4 2\n1 2 2 2",
"output": "0"
},
{
"input": "4 5\n4 5 5 5",
"output": "0"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "35"
},
{
"input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1",
"output": "0"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 4 5",
"output": "0"
},
{
"input": "3 7\n1 1 1",
"output": "33"
},
{
"input": "2 5\n5 5",
"output": "0"
},
{
"input": "1 7\n1",
"output": "11"
},
{
"input": "6 7\n1 1 1 1 1 1",
"output": "66"
},
{
"input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64",
"output": "10077"
},
{
"input": "8 7\n1 1 1 1 1 1 1 1",
"output": "88"
},
{
"input": "3 2\n2 2 2",
"output": "0"
},
{
"input": "6 5\n5 5 5 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 4 1 1",
"output": "8"
},
{
"input": "1 5\n1",
"output": "7"
},
{
"input": "10 10\n10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "2 3\n2 3",
"output": "0"
},
{
"input": "1 9\n9",
"output": "0"
},
{
"input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 4",
"output": "0"
}
] | 1,500,101,964 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 77 | 5,529,600 | import math
string = input()
numbers = string.split()
a, b = int(numbers[0]), int(numbers[1])
string = input()
s = sum(list(map(int, string.split())))
n = 0
def roundup(x):
if x - math.floor(x) < 0.5:
return math.floor(x)
else:
return math.ceil(x)
while roundup(s / a) < b:
s += b
a += 1
n += 1
print(n) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Output Specification:
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
Demo Input:
['2 10\n8 9\n', '3 5\n4 4 4\n']
Demo Output:
['4', '3']
Note:
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate. | ```python
import math
string = input()
numbers = string.split()
a, b = int(numbers[0]), int(numbers[1])
string = input()
s = sum(list(map(int, string.split())))
n = 0
def roundup(x):
if x - math.floor(x) < 0.5:
return math.floor(x)
else:
return math.ceil(x)
while roundup(s / a) < b:
s += b
a += 1
n += 1
print(n)
``` | 3 |
|
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.
The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.
You are asked to calculate the maximum total number of soldiers that may be killed during the game. | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "750"
},
{
"input": "1000",
"output": "1500"
},
{
"input": "2000",
"output": "3000"
},
{
"input": "50000",
"output": "75000"
},
{
"input": "10000",
"output": "15000"
},
{
"input": "25460",
"output": "38190"
},
{
"input": "54646",
"output": "81969"
},
{
"input": "59790",
"output": "89685"
},
{
"input": "578456",
"output": "867684"
},
{
"input": "56798056",
"output": "85197084"
},
{
"input": "8457980",
"output": "12686970"
},
{
"input": "5687986",
"output": "8531979"
},
{
"input": "10984932",
"output": "16477398"
},
{
"input": "99999994",
"output": "149999991"
},
{
"input": "99999996",
"output": "149999994"
},
{
"input": "99999998",
"output": "149999997"
},
{
"input": "100000000",
"output": "150000000"
}
] | 1,626,966,567 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 6,963,200 | n=input()
n=int(n)
x,y=list(range(0,n)),list(range(0,n))
for i in range(0,int(n/3+1)):
for j in range(0,3):
if j%2==0:
x.pop(0)
else:
y.pop(0)
print(2*n-int(len(x)+len(y))) | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.
The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.
You are asked to calculate the maximum total number of soldiers that may be killed during the game.
Input Specification:
The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields.
Output Specification:
Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.
Demo Input:
['2\n', '4\n']
Demo Output:
['3\n', '6\n']
Note:
The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | ```python
n=input()
n=int(n)
x,y=list(range(0,n)),list(range(0,n))
for i in range(0,int(n/3+1)):
for j in range(0,3):
if j%2==0:
x.pop(0)
else:
y.pop(0)
print(2*n-int(len(x)+len(y)))
``` | 0 |
638 | D | Three-dimensional Turtle Super Computer | PROGRAMMING | 1,800 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×<=1<=×<=1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer number from 1 to *n*, the line number from 1 to *m* and the column number from 1 to *k*.
In the process of the Super Computer's work the CPUs can send each other messages by the famous turtle scheme: CPU (*x*,<=*y*,<=*z*) can send messages to CPUs (*x*<=+<=1,<=*y*,<=*z*), (*x*,<=*y*<=+<=1,<=*z*) and (*x*,<=*y*,<=*z*<=+<=1) (of course, if they exist), there is no feedback, that is, CPUs (*x*<=+<=1,<=*y*,<=*z*), (*x*,<=*y*<=+<=1,<=*z*) and (*x*,<=*y*,<=*z*<=+<=1) cannot send messages to CPU (*x*,<=*y*,<=*z*).
Over time some CPUs broke down and stopped working. Such CPUs cannot send messages, receive messages or serve as intermediates in transmitting messages. We will say that CPU (*a*,<=*b*,<=*c*) controls CPU (*d*,<=*e*,<=*f*) , if there is a chain of CPUs (*x**i*,<=*y**i*,<=*z**i*), such that (*x*1<==<=*a*,<=*y*1<==<=*b*,<=*z*1<==<=*c*), (*x**p*<==<=*d*,<=*y**p*<==<=*e*,<=*z**p*<==<=*f*) (here and below *p* is the length of the chain) and the CPU in the chain with number *i* (*i*<=<<=*p*) can send messages to CPU *i*<=+<=1.
Turtles are quite concerned about the denial-proofness of the system of communication between the remaining CPUs. For that they want to know the number of critical CPUs. A CPU (*x*,<=*y*,<=*z*) is critical, if turning it off will disrupt some control, that is, if there are two distinctive from (*x*,<=*y*,<=*z*) CPUs: (*a*,<=*b*,<=*c*) and (*d*,<=*e*,<=*f*), such that (*a*,<=*b*,<=*c*) controls (*d*,<=*e*,<=*f*) before (*x*,<=*y*,<=*z*) is turned off and stopped controlling it after the turning off. | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100) — the dimensions of the Super Computer.
Then *n* blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to *n*. Each block consists of *m* lines, *k* characters in each — the description of a layer in the format of an *m*<=×<=*k* table. Thus, the state of the CPU (*x*,<=*y*,<=*z*) is corresponded to the *z*-th character of the *y*-th line of the block number *x*. Character "1" corresponds to a working CPU and character "0" corresponds to a malfunctioning one. The blocks are separated by exactly one empty line. | Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control. | [
"2 2 3\n000\n000\n\n111\n111\n",
"3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n",
"1 1 10\n0101010101\n"
] | [
"2\n",
"19\n",
"0\n"
] | In the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1).
In the second sample all processors except for the corner ones are critical.
In the third sample there is not a single processor controlling another processor, so the answer is 0. | 2,000 | [
{
"input": "2 2 3\n000\n000\n\n111\n111",
"output": "2"
},
{
"input": "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111",
"output": "19"
},
{
"input": "1 1 10\n0101010101",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "3 1 1\n1\n\n1\n\n1",
"output": "1"
},
{
"input": "3 1 1\n1\n\n0\n\n1",
"output": "0"
},
{
"input": "1 3 1\n1\n1\n1",
"output": "1"
},
{
"input": "1 3 1\n1\n0\n1",
"output": "0"
},
{
"input": "1 1 3\n111",
"output": "1"
},
{
"input": "1 1 3\n101",
"output": "0"
},
{
"input": "1 1 3\n011",
"output": "0"
},
{
"input": "1 1 3\n110",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 1 100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "0"
},
{
"input": "1 1 100\n0000011111011101001100111010100111000100010100010110111110110011000000111111011111001111000011111010",
"output": "21"
},
{
"input": "1 1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "98"
},
{
"input": "1 100 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "0"
},
{
"input": "1 100 1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n0\n1\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n0\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n0\n0",
"output": "10"
},
{
"input": "1 100 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "98"
},
{
"input": "100 1 1\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0\n\n0",
"output": "0"
},
{
"input": "100 1 1\n0\n\n1\n\n1\n\n1\n\n0\n\n0\n\n0\n\n1\n\n1\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n1\n\n1\n\n0\n\n0\n\n1\n\n1\n\n1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n1\n\n1\n\n0\n\n1\n\n1\n\n1\n\n0\n\n1\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n0\n\n0\n\n0\n\n0\n\n1\n\n0\n\n1\n\n0\n\n0\n\n1\n\n1\n\n1\n\n0\n\n1\n\n1\n\n0\n\n1\n\n1\n\n1\n\n0\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n0\n\n0\n\n1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n1\n\n0\n\n1\n\n1\n\n0\n\n0\n\n0\n\n0\n\n0\n\n1\n\n1\n\n1\n\n1\n\n1\n\n0\n\n1\n\n1\n\n1\n\n1\n\n1\n\n0",
"output": "17"
},
{
"input": "100 1 1\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1\n\n1",
"output": "98"
},
{
"input": "6 8 3\n011\n001\n000\n100\n111\n110\n100\n100\n\n000\n100\n011\n001\n011\n000\n100\n111\n\n110\n111\n011\n110\n101\n001\n110\n000\n\n100\n000\n110\n001\n110\n010\n110\n011\n\n101\n111\n010\n110\n101\n111\n011\n110\n\n100\n111\n111\n011\n101\n110\n110\n110",
"output": "46"
}
] | 1,458,482,253 | 7,053 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 62 | 4,915,200 | def Core(params, data):
res = 0
for n in range(params[0]):
key = False
if n>0 and n<(params[0]-1):
key = True
for m in range(params[1]):
for k in range(params[2]):
if data[n][m][k] == 1:
if key and (data[n-1][m][k] == 1 or data[n+1][m][k] == 1):
res += 1
elif m>0 and m<(params[1]-1) and (data[n][m-1][k] == 1 or data[n][m+1][k] == 1):
res += 1
elif k>0 and k<(params[2]-1) and (data[n][m][k-1] == 1 or data[n][m][k+1] == 1):
res += 1
print (res)
params = [int(num) for num in input().split(" ")]
data = []
for i in range(params[0]):
data.append([])
for j in range(params[1]):
data[i].append([int(num) for num in input()])
if i < params[0]-1:
input()
Core(params, data) | Title: Three-dimensional Turtle Super Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×<=1<=×<=1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer number from 1 to *n*, the line number from 1 to *m* and the column number from 1 to *k*.
In the process of the Super Computer's work the CPUs can send each other messages by the famous turtle scheme: CPU (*x*,<=*y*,<=*z*) can send messages to CPUs (*x*<=+<=1,<=*y*,<=*z*), (*x*,<=*y*<=+<=1,<=*z*) and (*x*,<=*y*,<=*z*<=+<=1) (of course, if they exist), there is no feedback, that is, CPUs (*x*<=+<=1,<=*y*,<=*z*), (*x*,<=*y*<=+<=1,<=*z*) and (*x*,<=*y*,<=*z*<=+<=1) cannot send messages to CPU (*x*,<=*y*,<=*z*).
Over time some CPUs broke down and stopped working. Such CPUs cannot send messages, receive messages or serve as intermediates in transmitting messages. We will say that CPU (*a*,<=*b*,<=*c*) controls CPU (*d*,<=*e*,<=*f*) , if there is a chain of CPUs (*x**i*,<=*y**i*,<=*z**i*), such that (*x*1<==<=*a*,<=*y*1<==<=*b*,<=*z*1<==<=*c*), (*x**p*<==<=*d*,<=*y**p*<==<=*e*,<=*z**p*<==<=*f*) (here and below *p* is the length of the chain) and the CPU in the chain with number *i* (*i*<=<<=*p*) can send messages to CPU *i*<=+<=1.
Turtles are quite concerned about the denial-proofness of the system of communication between the remaining CPUs. For that they want to know the number of critical CPUs. A CPU (*x*,<=*y*,<=*z*) is critical, if turning it off will disrupt some control, that is, if there are two distinctive from (*x*,<=*y*,<=*z*) CPUs: (*a*,<=*b*,<=*c*) and (*d*,<=*e*,<=*f*), such that (*a*,<=*b*,<=*c*) controls (*d*,<=*e*,<=*f*) before (*x*,<=*y*,<=*z*) is turned off and stopped controlling it after the turning off.
Input Specification:
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100) — the dimensions of the Super Computer.
Then *n* blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to *n*. Each block consists of *m* lines, *k* characters in each — the description of a layer in the format of an *m*<=×<=*k* table. Thus, the state of the CPU (*x*,<=*y*,<=*z*) is corresponded to the *z*-th character of the *y*-th line of the block number *x*. Character "1" corresponds to a working CPU and character "0" corresponds to a malfunctioning one. The blocks are separated by exactly one empty line.
Output Specification:
Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control.
Demo Input:
['2 2 3\n000\n000\n\n111\n111\n', '3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n', '1 1 10\n0101010101\n']
Demo Output:
['2\n', '19\n', '0\n']
Note:
In the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1).
In the second sample all processors except for the corner ones are critical.
In the third sample there is not a single processor controlling another processor, so the answer is 0. | ```python
def Core(params, data):
res = 0
for n in range(params[0]):
key = False
if n>0 and n<(params[0]-1):
key = True
for m in range(params[1]):
for k in range(params[2]):
if data[n][m][k] == 1:
if key and (data[n-1][m][k] == 1 or data[n+1][m][k] == 1):
res += 1
elif m>0 and m<(params[1]-1) and (data[n][m-1][k] == 1 or data[n][m+1][k] == 1):
res += 1
elif k>0 and k<(params[2]-1) and (data[n][m][k-1] == 1 or data[n][m][k+1] == 1):
res += 1
print (res)
params = [int(num) for num in input().split(" ")]
data = []
for i in range(params[0]):
data.append([])
for j in range(params[1]):
data[i].append([int(num) for num in input()])
if i < params[0]-1:
input()
Core(params, data)
``` | 0 |
|
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round. | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976",
"output": "999975"
},
{
"input": "25\n13 15 24 2 21 18 9 4 16 6 10 25 20 11 23 17 8 3 1 12 5 19 22 14 7",
"output": "0"
},
{
"input": "10\n17 11 7 13 18 12 14 5 16 2",
"output": "0"
},
{
"input": "22\n22 14 23 20 11 21 4 12 3 8 7 9 19 10 13 17 15 1 5 18 16 2",
"output": "0"
},
{
"input": "21\n6 21 24 3 10 23 14 2 26 12 8 1 15 13 9 5 19 20 4 16 22",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n100 60",
"output": "75"
},
{
"input": "4\n999 581 787 236",
"output": "974"
},
{
"input": "6\n198 397 732 1234 309 827",
"output": "1209"
},
{
"input": "11\n6494 3961 1858 4351 8056 780 7720 6211 1961 8192 3621",
"output": "8167"
},
{
"input": "14\n18809 9534 11652 6493 8929 9370 4125 23888 16403 3559 23649 19243 14289 17852",
"output": "23863"
},
{
"input": "18\n24939 35558 47058 70307 26221 12866 3453 40422 47557 36322 40698 64060 10825 77777 48645 26124 4859 64222",
"output": "77752"
},
{
"input": "24\n633483 654321 122445 481150 347578 37803 525083 151084 211073 358699 339420 452023 219553 119727 74852 66750 371279 405099 618894 649977 235337 607819 81649 649804",
"output": "654296"
},
{
"input": "25\n58115 794098 753382 484882 238434 674285 690118 858677 196185 173301 349729 918792 600745 636016 122678 366783 137179 377098 917081 369620 449039 379412 503678 1000000 292099",
"output": "999975"
},
{
"input": "2\n26 27",
"output": "2"
},
{
"input": "3\n40 30 35",
"output": "15"
},
{
"input": "2\n46 45",
"output": "21"
},
{
"input": "3\n1 25 90",
"output": "65"
},
{
"input": "5\n14 15 16 30 92",
"output": "67"
},
{
"input": "2\n1000 1001",
"output": "976"
},
{
"input": "25\n3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28 2",
"output": "3"
}
] | 1,505,584,256 | 956 | Python 3 | OK | TESTS | 25 | 452 | 3,993,600 | K = int(input())
R = list(map(int, input().split()))
R.sort()
iv = [False]*(R[-1]+1)
for r in R:
iv[r] = True
ans = 0
for r in range(1, R[-1]+1):
if not iv[r] and K < 25:
iv[r] = True
K += 1
if not iv[r]:
ans += 1
print(ans)
| Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible contestant must either accept or decline the invitation. Whenever a contestant declines, the highest ranked contestant not yet invited is invited to take the place of the one that declined. This continues until 25 contestants have accepted invitations.
After the qualifying round completes, you know *K* of the onsite finalists, as well as their qualifying ranks (which start at 1, there are no ties). Determine the minimum possible number of contestants that declined the invitation to compete onsite in the final round.
Input Specification:
The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Output Specification:
Print the minimum possible number of contestants that declined the invitation to compete onsite.
Demo Input:
['25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n', '5\n16 23 8 15 4\n', '3\n14 15 92\n']
Demo Output:
['3\n', '0\n', '67\n']
Note:
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | ```python
K = int(input())
R = list(map(int, input().split()))
R.sort()
iv = [False]*(R[-1]+1)
for r in R:
iv[r] = True
ans = 0
for r in range(1, R[-1]+1):
if not iv[r] and K < 25:
iv[r] = True
K += 1
if not iv[r]:
ans += 1
print(ans)
``` | 3 |
|
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 87 200 62 168 51 185 192 118",
"output": "48"
},
{
"input": "1 1\n10000",
"output": "5000"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "2 2\n2 2",
"output": "1"
}
] | 1,490,804,979 | 1,479 | Python 3 | OK | TESTS | 31 | 155 | 12,902,400 | # -*- coding: utf-8 -*-
"""
Created on Wed Mar 29 21:32:29 2017
@author: vushesh
"""
import math
n ,k = map(int, input().split(' '))
a = list(map(int,input().split(' ')))
count = 0
for i in range(n):
count += int(math.ceil(a[i]/k))
count = int(math.ceil(count/2 ))
print(count)
| Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
Output Specification:
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
Demo Input:
['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n']
Demo Output:
['3\n', '5\n']
Note:
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | ```python
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 29 21:32:29 2017
@author: vushesh
"""
import math
n ,k = map(int, input().split(' '))
a = list(map(int,input().split(' ')))
count = 0
for i in range(n):
count += int(math.ceil(a[i]/k))
count = int(math.ceil(count/2 ))
print(count)
``` | 3 |
|
988 | C | Equal Sums | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | null | null | You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals to the sum of the changed sequence $j$ (its length will be equal to $n_j - 1$).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals $0$) sequence is $0$. | The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of sequences.
Then $k$ pairs of lines follow, each pair containing a sequence.
The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i < 2 \cdot 10^5$) — the length of the $i$-th sequence. The second line of the $i$-th pair contains a sequence of $n_i$ integers $a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$.
The elements of sequences are integer numbers from $-10^4$ to $10^4$.
The sum of lengths of all given sequences don't exceed $2 \cdot 10^5$, i.e. $n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$. | If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line — two integers $j$, $y$ ($1 \le j \le k, 1 \le y \le n_j$). It means that the sum of the elements of the $i$-th sequence without the element with index $x$ equals to the sum of the elements of the $j$-th sequence without the element with index $y$.
Two chosen sequences must be distinct, i.e. $i \ne j$. You can print them in any order.
If there are multiple possible answers, print any of them. | [
"2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n",
"3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n",
"4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n"
] | [
"YES\n2 6\n1 2\n",
"NO\n",
"YES\n2 2\n4 1\n"
] | In the first example there are two sequences $[2, 3, 1, 3, 2]$ and $[1, 1, 2, 2, 2, 1]$. You can remove the second element from the first sequence to get $[2, 1, 3, 2]$ and you can remove the sixth element from the second sequence to get $[1, 1, 2, 2, 2]$. The sums of the both resulting sequences equal to $8$, i.e. the sums are equal. | 0 | [
{
"input": "2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1",
"output": "YES\n2 1\n1 4"
},
{
"input": "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3",
"output": "NO"
},
{
"input": "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2",
"output": "YES\n4 1\n2 5"
},
{
"input": "2\n2\n0 -10000\n2\n10000 0",
"output": "YES\n2 1\n1 2"
}
] | 1,642,584,524 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 54,681,600 | """
-*- coding: utf-8 -*-
Created on Wed Jan 19 14:45:34 2022
@author: Tausif Khan Arnob
"""
li = []
for t in range(int(input())):
n = int(input())
a = [*map(int, input().split())]
s = sum(a)
li.extend([s-a[i], t+1, i+1] for i in range(n))
li = sorted(li, key = lambda x:[x[0], x[1],])
for x, y in zip(li, li[1:]):
if x[0] == y[0] and x[1] != y[1]:
exit(print('YES\n', x[1], x[2], '\n', y[1], y[2]))
print('NO') | Title: Equal Sums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals to the sum of the changed sequence $j$ (its length will be equal to $n_j - 1$).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals $0$) sequence is $0$.
Input Specification:
The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of sequences.
Then $k$ pairs of lines follow, each pair containing a sequence.
The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i < 2 \cdot 10^5$) — the length of the $i$-th sequence. The second line of the $i$-th pair contains a sequence of $n_i$ integers $a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$.
The elements of sequences are integer numbers from $-10^4$ to $10^4$.
The sum of lengths of all given sequences don't exceed $2 \cdot 10^5$, i.e. $n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$.
Output Specification:
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line — two integers $j$, $y$ ($1 \le j \le k, 1 \le y \le n_j$). It means that the sum of the elements of the $i$-th sequence without the element with index $x$ equals to the sum of the elements of the $j$-th sequence without the element with index $y$.
Two chosen sequences must be distinct, i.e. $i \ne j$. You can print them in any order.
If there are multiple possible answers, print any of them.
Demo Input:
['2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n', '3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n', '4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n']
Demo Output:
['YES\n2 6\n1 2\n', 'NO\n', 'YES\n2 2\n4 1\n']
Note:
In the first example there are two sequences $[2, 3, 1, 3, 2]$ and $[1, 1, 2, 2, 2, 1]$. You can remove the second element from the first sequence to get $[2, 1, 3, 2]$ and you can remove the sixth element from the second sequence to get $[1, 1, 2, 2, 2]$. The sums of the both resulting sequences equal to $8$, i.e. the sums are equal. | ```python
"""
-*- coding: utf-8 -*-
Created on Wed Jan 19 14:45:34 2022
@author: Tausif Khan Arnob
"""
li = []
for t in range(int(input())):
n = int(input())
a = [*map(int, input().split())]
s = sum(a)
li.extend([s-a[i], t+1, i+1] for i in range(n))
li = sorted(li, key = lambda x:[x[0], x[1],])
for x, y in zip(li, li[1:]):
if x[0] == y[0] and x[1] != y[1]:
exit(print('YES\n', x[1], x[2], '\n', y[1], y[2]))
print('NO')
``` | 0 |
|
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "5000000000020"
},
{
"input": "1000000000000 750000000001 100 10",
"output": "2499999999990"
},
{
"input": "42 1 1 1",
"output": "0"
},
{
"input": "1 1000000000000 1 100",
"output": "100"
},
{
"input": "7 2 3 7",
"output": "3"
},
{
"input": "999999999 2 1 1",
"output": "1"
},
{
"input": "999999999999 10000000007 100 100",
"output": "70100"
},
{
"input": "10000000001 2 1 1",
"output": "1"
},
{
"input": "29 6 1 2",
"output": "1"
},
{
"input": "99999999999 6 100 100",
"output": "300"
},
{
"input": "1000000000000 7 3 8",
"output": "8"
},
{
"input": "99999999999 2 1 1",
"output": "1"
},
{
"input": "1 2 1 1",
"output": "1"
},
{
"input": "999999999999 2 1 1",
"output": "1"
},
{
"input": "9 2 1 1",
"output": "1"
},
{
"input": "17 4 5 5",
"output": "5"
},
{
"input": "100000000000 3 1 1",
"output": "1"
},
{
"input": "100 7 1 1",
"output": "2"
},
{
"input": "1000000000000 3 100 100",
"output": "100"
},
{
"input": "70 3 10 10",
"output": "10"
},
{
"input": "1 2 5 1",
"output": "1"
},
{
"input": "1000000000000 3 1 1",
"output": "1"
},
{
"input": "804289377 846930887 78 16",
"output": "3326037780"
},
{
"input": "1000000000000 9 55 55",
"output": "55"
},
{
"input": "957747787 424238336 87 93",
"output": "10162213695"
},
{
"input": "25 6 1 2",
"output": "2"
},
{
"input": "22 7 3 8",
"output": "8"
},
{
"input": "10000000000 1 1 1",
"output": "0"
},
{
"input": "999999999999 2 10 10",
"output": "10"
},
{
"input": "999999999999 2 100 100",
"output": "100"
},
{
"input": "100 3 3 8",
"output": "6"
},
{
"input": "99999 2 1 1",
"output": "1"
},
{
"input": "100 3 2 5",
"output": "4"
},
{
"input": "1000000000000 13 10 17",
"output": "17"
},
{
"input": "7 2 1 2",
"output": "1"
},
{
"input": "10 3 1 2",
"output": "2"
},
{
"input": "5 2 2 2",
"output": "2"
},
{
"input": "100 3 5 2",
"output": "2"
},
{
"input": "7 2 1 1",
"output": "1"
},
{
"input": "70 4 1 1",
"output": "2"
},
{
"input": "10 4 1 1",
"output": "2"
},
{
"input": "6 7 41 42",
"output": "41"
},
{
"input": "10 3 10 1",
"output": "1"
},
{
"input": "5 5 2 3",
"output": "0"
},
{
"input": "1000000000000 3 99 99",
"output": "99"
},
{
"input": "7 3 100 1",
"output": "1"
},
{
"input": "7 2 100 5",
"output": "5"
},
{
"input": "1000000000000 1 23 33",
"output": "0"
},
{
"input": "30 7 1 1",
"output": "2"
},
{
"input": "100 3 1 1",
"output": "1"
},
{
"input": "90001 300 100 1",
"output": "1"
},
{
"input": "13 4 1 2",
"output": "2"
},
{
"input": "1000000000000 6 1 3",
"output": "2"
},
{
"input": "50 4 5 100",
"output": "10"
},
{
"input": "999 2 1 1",
"output": "1"
},
{
"input": "5 2 5 5",
"output": "5"
},
{
"input": "20 3 3 3",
"output": "3"
},
{
"input": "3982258181 1589052704 87 20",
"output": "16083055460"
},
{
"input": "100 3 1 3",
"output": "2"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "19 10 100 100",
"output": "100"
},
{
"input": "23 3 100 1",
"output": "2"
},
{
"input": "25 7 100 1",
"output": "4"
},
{
"input": "100 9 1 2",
"output": "2"
},
{
"input": "9999999999 2 1 100",
"output": "1"
},
{
"input": "1000000000000 2 1 1",
"output": "0"
},
{
"input": "10000 3 1 1",
"output": "1"
},
{
"input": "22 7 1 6",
"output": "6"
},
{
"input": "100000000000 1 1 1",
"output": "0"
},
{
"input": "18 7 100 1",
"output": "4"
},
{
"input": "10003 4 1 100",
"output": "1"
},
{
"input": "3205261341 718648876 58 11",
"output": "3637324207"
},
{
"input": "8 3 100 1",
"output": "2"
},
{
"input": "15 7 1 1",
"output": "1"
},
{
"input": "1000000000000 1 20 20",
"output": "0"
},
{
"input": "16 7 3 2",
"output": "4"
},
{
"input": "1000000000000 1 1 1",
"output": "0"
},
{
"input": "7 3 1 100",
"output": "2"
},
{
"input": "16 3 1 100",
"output": "2"
},
{
"input": "13 4 1 10",
"output": "3"
},
{
"input": "10 4 5 5",
"output": "10"
},
{
"input": "14 3 1 100",
"output": "1"
},
{
"input": "100 33 100 1",
"output": "1"
},
{
"input": "22 7 1 8",
"output": "6"
},
{
"input": "10 4 2 1",
"output": "2"
},
{
"input": "6 4 2 2",
"output": "4"
},
{
"input": "17 4 2 1",
"output": "1"
},
{
"input": "7 3 100 10",
"output": "10"
},
{
"input": "702 7 3 2",
"output": "4"
},
{
"input": "8 3 1 5",
"output": "1"
},
{
"input": "3 2 5 2",
"output": "2"
},
{
"input": "99 19 1 7",
"output": "15"
},
{
"input": "16 3 100 1",
"output": "1"
},
{
"input": "100 34 1 100",
"output": "2"
},
{
"input": "100 33 1 1",
"output": "1"
},
{
"input": "2 3 4 3",
"output": "4"
},
{
"input": "15 4 4 10",
"output": "4"
},
{
"input": "1144108931 470211273 45 79",
"output": "11993619960"
},
{
"input": "2 3 3 4",
"output": "3"
},
{
"input": "29 5 4 9",
"output": "4"
},
{
"input": "15 7 1 5",
"output": "5"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "1 1 3 4",
"output": "0"
},
{
"input": "10 12 2 1",
"output": "4"
},
{
"input": "1 2 3 4",
"output": "3"
}
] | 1,587,374,955 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 307,200 | chip=input()
a=int(chip[0])
b=int(chip[2])
c=int(chip[4])
d=int(chip[6])
tempi=a
tempo=1
temp=0
min=d*a
flag=True
if a%b==0:
print('hello')
print(0)
else:
for i in range(1,10):
a=tempi+tempo
if a%b==0:
break
tempo+=1
if min>tempo*c:
min=tempo*c
print(min)
else:
print(min)
| Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
Input Specification:
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
Output Specification:
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
Demo Input:
['9 7 3 8\n', '2 7 3 7\n', '30 6 17 19\n']
Demo Output:
['15\n', '14\n', '0\n']
Note:
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | ```python
chip=input()
a=int(chip[0])
b=int(chip[2])
c=int(chip[4])
d=int(chip[6])
tempi=a
tempo=1
temp=0
min=d*a
flag=True
if a%b==0:
print('hello')
print(0)
else:
for i in range(1,10):
a=tempi+tempo
if a%b==0:
break
tempo+=1
if min>tempo*c:
min=tempo*c
print(min)
else:
print(min)
``` | -1 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,672,579,692 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | s=input()
t="hello"
m=0
for i in s:
if i==t[m]:
m+=1
if m>=4:
print("yes")
break
else:
print('no')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s=input()
t="hello"
m=0
for i in s:
if i==t[m]:
m+=1
if m>=4:
print("yes")
break
else:
print('no')
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") *a* and *b*. Then you try to turn *a* into *b* using two types of operations:
- Write *parity*(*a*) to the end of *a*. For example, . - Remove the first character of *a*. For example, . You cannot perform this operation if *a* is empty.
You can use as many operations as you want. The problem is, is it possible to turn *a* into *b*?
The *parity* of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise. | The first line contains the string *a* and the second line contains the string *b* (1<=≤<=|*a*|,<=|*b*|<=≤<=1000). Both strings contain only the characters "0" and "1". Here |*x*| denotes the length of the string *x*. | Print "YES" (without quotes) if it is possible to turn *a* into *b*, and "NO" (without quotes) otherwise. | [
"01011\n0110\n",
"0011\n1110\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 | 0 | [
{
"input": "01011\n0110",
"output": "YES"
},
{
"input": "0011\n1110",
"output": "NO"
},
{
"input": "11111\n111111",
"output": "YES"
},
{
"input": "0110011\n01100110",
"output": "YES"
},
{
"input": "10000100\n011110",
"output": "NO"
},
{
"input": "1\n0",
"output": "YES"
},
{
"input": "0\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "NO"
},
{
"input": "0\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "NO"
},
{
"input": "1\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "YES"
},
{
"input": "11\n110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "YES"
},
{
"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11",
"output": "YES"
},
{
"input": "11\n111",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "1\n0",
"output": "YES"
}
] | 1,594,921,883 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 20,172,800 | a = input()
b = input() # ris finale
if a == b:
print("YES")
elif b == "1" and a == "0" or b == "0" and a == "1":
print("NO")
else:
if b[0]==0 or b[0]==a[0]:
print("YES")
else:
print("NO")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") *a* and *b*. Then you try to turn *a* into *b* using two types of operations:
- Write *parity*(*a*) to the end of *a*. For example, . - Remove the first character of *a*. For example, . You cannot perform this operation if *a* is empty.
You can use as many operations as you want. The problem is, is it possible to turn *a* into *b*?
The *parity* of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.
Input Specification:
The first line contains the string *a* and the second line contains the string *b* (1<=≤<=|*a*|,<=|*b*|<=≤<=1000). Both strings contain only the characters "0" and "1". Here |*x*| denotes the length of the string *x*.
Output Specification:
Print "YES" (without quotes) if it is possible to turn *a* into *b*, and "NO" (without quotes) otherwise.
Demo Input:
['01011\n0110\n', '0011\n1110\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110 | ```python
a = input()
b = input() # ris finale
if a == b:
print("YES")
elif b == "1" and a == "0" or b == "0" and a == "1":
print("NO")
else:
if b[0]==0 or b[0]==a[0]:
print("YES")
else:
print("NO")
``` | 0 |
|
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter. | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input": "20 287 3845 5",
"output": "YES\n39.646277165210"
},
{
"input": "48 6428 9807 83",
"output": "NO"
},
{
"input": "72 5272 4552 64",
"output": "NO"
},
{
"input": "100 4117 5106 34",
"output": "NO"
},
{
"input": "20 2961 9852 15",
"output": "YES\n180.991437129723"
},
{
"input": "48 1805 3109 93",
"output": "NO"
},
{
"input": "72 8534 7042 65",
"output": "NO"
},
{
"input": "1 47 80 68",
"output": "YES\n1.388102806810"
},
{
"input": "4 495 8813 1",
"output": "YES\n0.706823517575"
},
{
"input": "5 2797 5925 9",
"output": "YES\n9.553973511669"
},
{
"input": "1 8324 4362 23",
"output": "YES\n1.505007106354"
},
{
"input": "6 1976 8455 3",
"output": "YES\n6.674898722265"
},
{
"input": "7 2644 8080 5",
"output": "YES\n12.900417790197"
},
{
"input": "3 4183 5491 98",
"output": "YES\n6.162185601824"
},
{
"input": "2 8591 320 101",
"output": "YES\n9999.259991757254"
},
{
"input": "10000 10000 10000 10000",
"output": "NO"
},
{
"input": "2 5000 12 3",
"output": "YES\n6099.653943875812"
},
{
"input": "10 1000 100 1",
"output": "YES\n3659.792366325487"
}
] | 1,472,121,318 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 62 | 4,608,000 | d,h,v,e = map(int, input().split())
s = 3.14159265354/4*d*d
if s*e-v >= 0.0:
print("NO")
else:
print("YES")
print(h/(v/s-e))
| Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter.
Input Specification:
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup.
Output Specification:
If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104.
Demo Input:
['1 2 3 100\n', '1 1 1 1\n']
Demo Output:
['NO\n', 'YES\n3.659792366325\n']
Note:
In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | ```python
d,h,v,e = map(int, input().split())
s = 3.14159265354/4*d*d
if s*e-v >= 0.0:
print("NO")
else:
print("YES")
print(h/(v/s-e))
``` | 3 |
|
612 | A | The Text Splitting | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them. | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | 0 | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"output": "1\n1"
},
{
"input": "10 8 1\nuTl9w4lcdo",
"output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no"
},
{
"input": "20 6 4\nfmFRpk2NrzSvnQC9gB61",
"output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61"
},
{
"input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6",
"output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6"
},
{
"input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde",
"output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde"
},
{
"input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu",
"output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu"
},
{
"input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj",
"output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj"
},
{
"input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY",
"output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY"
},
{
"input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc",
"output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc"
},
{
"input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE",
"output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE"
},
{
"input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB",
"output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB"
},
{
"input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ",
"output": "-1"
},
{
"input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn",
"output": "-1"
},
{
"input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT",
"output": "-1"
},
{
"input": "10 3 1\nXQ2vXLPShy",
"output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny"
},
{
"input": "4 2 3\naaaa",
"output": "2\naa\naa"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb"
},
{
"input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 2 3\nhavanahavan",
"output": "4\nha\nvan\naha\nvan"
},
{
"input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa"
},
{
"input": "17 3 5\ngopstopmipodoshli",
"output": "5\ngop\nsto\npmi\npod\noshli"
},
{
"input": "5 4 3\nfoyku",
"output": "-1"
},
{
"input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"output": "-1"
},
{
"input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit",
"output": "-1"
},
{
"input": "11 2 3\nqibwnnvqqgo",
"output": "4\nqi\nbwn\nnvq\nqgo"
},
{
"input": "4 4 3\nhhhh",
"output": "1\nhhhh"
},
{
"input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh"
},
{
"input": "10 5 9\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "10 5 9\naaaaaaaaaa",
"output": "2\naaaaa\naaaaa"
},
{
"input": "11 3 2\nmlmqpohwtsf",
"output": "5\nmlm\nqp\noh\nwt\nsf"
},
{
"input": "3 3 2\nzyx",
"output": "1\nzyx"
},
{
"input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "4 2 3\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "3 2 3\nejt",
"output": "1\nejt"
},
{
"input": "5 2 4\nzyxwv",
"output": "-1"
},
{
"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na"
},
{
"input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa"
},
{
"input": "3 2 2\nzyx",
"output": "-1"
},
{
"input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
"output": "-1"
},
{
"input": "26 8 9\nabcabcabcabcabcabcabcabcab",
"output": "3\nabcabcab\ncabcabcab\ncabcabcab"
},
{
"input": "6 3 5\naaaaaa",
"output": "2\naaa\naaa"
},
{
"input": "3 2 3\nzyx",
"output": "1\nzyx"
},
{
"input": "5 5 2\naaaaa",
"output": "1\naaaaa"
},
{
"input": "4 3 2\nzyxw",
"output": "2\nzy\nxw"
},
{
"input": "5 4 3\nzyxwv",
"output": "-1"
},
{
"input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab"
},
{
"input": "3 2 2\naaa",
"output": "-1"
},
{
"input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj",
"output": "-1"
},
{
"input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc",
"output": "-1"
},
{
"input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab"
},
{
"input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca",
"output": "-1"
},
{
"input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb",
"output": "-1"
},
{
"input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy",
"output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy"
},
{
"input": "16 3 7\naaaaaaaaaaaaaaaa",
"output": "4\naaa\naaa\naaa\naaaaaaa"
},
{
"input": "11 10 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 8 8\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "11 7 3\naaaaaaaaaaa",
"output": "-1"
},
{
"input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab",
"output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab"
},
{
"input": "11 3 2\naaaaaaaaaaa",
"output": "5\naaa\naa\naa\naa\naa"
},
{
"input": "14 9 4\nabcdefghijklmn",
"output": "-1"
},
{
"input": "9 9 5\n123456789",
"output": "1\n123456789"
},
{
"input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw",
"output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw"
},
{
"input": "17 16 3\ndxyhgtsxtuyljmclj",
"output": "-1"
},
{
"input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd",
"output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd"
},
{
"input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor",
"output": "-1"
},
{
"input": "7 5 3\nzyxwvut",
"output": "-1"
},
{
"input": "17 16 4\nctvfhkiakagcilrdw",
"output": "-1"
}
] | 1,451,395,929 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 |
n, p, q = map(int, input().split())
s = input()
for i in range(n//p):
if (n - i * p) % q == 0:
for j in range(i):
print(s[j*p:j*p+p])
for j in range((n-i*p)//q):
print(s[i*p+j*q:i*p+j*q+q])
import sys
sys.exit()
print(-1)
| Title: The Text Splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test).
Input Specification:
The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits.
Output Specification:
If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* — from left to right.
If there are several solutions print any of them.
Demo Input:
['5 2 3\nHello\n', '10 9 5\nCodeforces\n', '6 4 5\nPrivet\n', '8 1 1\nabacabac\n']
Demo Output:
['2\nHe\nllo\n', '2\nCodef\norces\n', '-1\n', '8\na\nb\na\nc\na\nb\na\nc\n']
Note:
none | ```python
n, p, q = map(int, input().split())
s = input()
for i in range(n//p):
if (n - i * p) % q == 0:
for j in range(i):
print(s[j*p:j*p+p])
for j in range((n-i*p)//q):
print(s[i*p+j*q:i*p+j*q+q])
import sys
sys.exit()
print(-1)
``` | 0 |
|
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*). | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
{
"input": "70 38 66",
"output": "9"
},
{
"input": "54 4 38",
"output": "17"
},
{
"input": "3 1 69",
"output": "2"
},
{
"input": "11 9 60",
"output": "0"
},
{
"input": "71 49 65",
"output": "0"
},
{
"input": "78 55 96",
"output": "20"
},
{
"input": "2765 768 9020",
"output": "248635"
},
{
"input": "3478 1728 9727",
"output": "336578"
},
{
"input": "9678 6173 5658",
"output": "541409"
},
{
"input": "1138 570 6666",
"output": "75290"
},
{
"input": "7754 204 9038",
"output": "700603"
},
{
"input": "8403 7401 4769",
"output": "393339"
},
{
"input": "4909 2111 8860",
"output": "432827"
},
{
"input": "6571 6449 8965",
"output": "582642"
},
{
"input": "9178 2255 7996",
"output": "731618"
},
{
"input": "6151 6148 3746",
"output": "224269"
},
{
"input": "8890 5449 8734",
"output": "771004"
},
{
"input": "7879 2590 2818",
"output": "219441"
},
{
"input": "8484 6400 547",
"output": "40008"
},
{
"input": "7835 6710 1639",
"output": "121706"
},
{
"input": "2379 1436 9663",
"output": "228447"
},
{
"input": "6487 5670 8",
"output": "0"
},
{
"input": "4470 2543 6",
"output": "0"
},
{
"input": "7261 5328 10",
"output": "0"
},
{
"input": "3871 3795 7",
"output": "0"
},
{
"input": "9620 6557 6",
"output": "0"
},
{
"input": "4890 1112 5",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 1 10000",
"output": "99"
},
{
"input": "10000 1 1",
"output": "99"
},
{
"input": "10000 1 10000",
"output": "999999"
},
{
"input": "10000 10000 1",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "990000"
},
{
"input": "67 1 3",
"output": "2"
},
{
"input": "7878 4534 9159",
"output": "717013"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "3271 5 50",
"output": "1631"
}
] | 1,612,298,057 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | import math
citizens,wizards,percentage=map(int,input().split())
needednNumber=math.ceil((percentage*citizens)/100)
clonesNumber= math.ceil(needednNumber - wizards )
if wizards > needednNumber :
print(needednNumber)
else:
print(clonesNumber)
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
Input Specification:
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=><=*n*).
Output Specification:
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
Demo Input:
['10 1 14\n', '20 10 50\n', '1000 352 146\n']
Demo Output:
['1\n', '0\n', '1108\n']
Note:
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | ```python
import math
citizens,wizards,percentage=map(int,input().split())
needednNumber=math.ceil((percentage*citizens)/100)
clonesNumber= math.ceil(needednNumber - wizards )
if wizards > needednNumber :
print(needednNumber)
else:
print(clonesNumber)
``` | 0 |
|
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe from the left is called safe *i*. There are *n* banknotes left in all the safes in total. The *i*-th banknote is in safe *x**i*. Oleg is now at safe *a*. There are two security guards, one of which guards the safe *b* such that *b*<=<<=*a*, i.e. the first guard is to the left of Oleg. The other guard guards the safe *c* so that *c*<=><=*a*, i.e. he is to the right of Oleg.
The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather. | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of banknotes.
The next line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109), denoting that the *i*-th banknote is located in the *x**i*-th safe. Note that *x**i* are not guaranteed to be distinct. | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.
For the second sample, Oleg can't take any banknotes without bumping into any of the security guards. | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output": "0"
},
{
"input": "3 2 5\n4\n1 3 4 5",
"output": "2"
},
{
"input": "3 2 4\n1\n1",
"output": "0"
},
{
"input": "6 4 8\n1\n4",
"output": "0"
},
{
"input": "2 1 3\n1\n3",
"output": "0"
}
] | 1,590,867,080 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | a,b,c=map(int,input().split())
n=int(input(""))
x=list(map(int,input().split()))
sub=x[b:c-1]
total=0
for i in (x[b:c-1]):
total=total+x.count(i)
print(total) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe from the left is called safe *i*. There are *n* banknotes left in all the safes in total. The *i*-th banknote is in safe *x**i*. Oleg is now at safe *a*. There are two security guards, one of which guards the safe *b* such that *b*<=<<=*a*, i.e. the first guard is to the left of Oleg. The other guard guards the safe *c* so that *c*<=><=*a*, i.e. he is to the right of Oleg.
The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather.
Input Specification:
The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of banknotes.
The next line of input contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109), denoting that the *i*-th banknote is located in the *x**i*-th safe. Note that *x**i* are not guaranteed to be distinct.
Output Specification:
Output a single integer: the maximum number of banknotes Oleg can take.
Demo Input:
['5 3 7\n8\n4 7 5 5 3 6 2 8\n', '6 5 7\n5\n1 5 7 92 3\n']
Demo Output:
['4\n', '0\n']
Note:
In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.
For the second sample, Oleg can't take any banknotes without bumping into any of the security guards. | ```python
a,b,c=map(int,input().split())
n=int(input(""))
x=list(map(int,input().split()))
sub=x[b:c-1]
total=0
for i in (x[b:c-1]):
total=total+x.count(i)
print(total)
``` | 0 |
|
577 | A | Multiplication Table | PROGRAMMING | 1,000 | [
"implementation",
"number theory"
] | null | null | Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. | The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. | Print a single number: the number of times *x* occurs in the table. | [
"10 5\n",
"6 12\n",
"5 13\n"
] | [
"2\n",
"4\n",
"0\n"
] | A table for the second sample test is given below. The occurrences of number 12 are marked bold. | 500 | [
{
"input": "10 5",
"output": "2"
},
{
"input": "6 12",
"output": "4"
},
{
"input": "5 13",
"output": "0"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "1 1000000000",
"output": "0"
},
{
"input": "100000 1000000000",
"output": "16"
},
{
"input": "100000 362880",
"output": "154"
},
{
"input": "1 4",
"output": "0"
},
{
"input": "9 12",
"output": "4"
},
{
"input": "10 123",
"output": "0"
},
{
"input": "9551 975275379",
"output": "0"
},
{
"input": "17286 948615687",
"output": "0"
},
{
"input": "58942 936593001",
"output": "0"
},
{
"input": "50000 989460910",
"output": "4"
},
{
"input": "22741 989460910",
"output": "0"
},
{
"input": "22740 989460910",
"output": "0"
},
{
"input": "100000 989460910",
"output": "4"
},
{
"input": "100000 98280",
"output": "128"
},
{
"input": "100000 997920",
"output": "222"
},
{
"input": "100000 720720",
"output": "226"
},
{
"input": "100000 2162160",
"output": "282"
},
{
"input": "100000 4324320",
"output": "320"
},
{
"input": "100000 8648640",
"output": "348"
},
{
"input": "100000 183783600",
"output": "438"
},
{
"input": "100000 551350800",
"output": "392"
},
{
"input": "40000 551350800",
"output": "150"
},
{
"input": "20000 400000000",
"output": "1"
},
{
"input": "19999 400000000",
"output": "0"
},
{
"input": "19999 399960001",
"output": "1"
},
{
"input": "31621 999887641",
"output": "1"
},
{
"input": "31622 999887641",
"output": "1"
},
{
"input": "31620 999887641",
"output": "0"
},
{
"input": "100000 999887641",
"output": "3"
},
{
"input": "100000 25",
"output": "3"
},
{
"input": "100000 1",
"output": "1"
},
{
"input": "100000 3628800",
"output": "220"
},
{
"input": "100000 39916800",
"output": "328"
},
{
"input": "100000 479001600",
"output": "254"
},
{
"input": "4 9",
"output": "1"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "20 100",
"output": "3"
},
{
"input": "10 3",
"output": "2"
},
{
"input": "4 4",
"output": "3"
},
{
"input": "2 4",
"output": "1"
},
{
"input": "89874 1",
"output": "1"
}
] | 1,694,642,548 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | x,y=input().split()
x=int(x)
y=int(y)
c=0
if y>x*x:
print(c)
else:
n=1
while n<=x:
if y%n==0:
if y//n<=x:
c+=1
n+=1
print(c)
| Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1.
You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*.
Input Specification:
The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table.
Output Specification:
Print a single number: the number of times *x* occurs in the table.
Demo Input:
['10 5\n', '6 12\n', '5 13\n']
Demo Output:
['2\n', '4\n', '0\n']
Note:
A table for the second sample test is given below. The occurrences of number 12 are marked bold. | ```python
x,y=input().split()
x=int(x)
y=int(y)
c=0
if y>x*x:
print(c)
else:
n=1
while n<=x:
if y%n==0:
if y//n<=x:
c+=1
n+=1
print(c)
``` | 3 |
|
272 | D | Dima and Two Sequences | PROGRAMMING | 1,600 | [
"combinatorics",
"math",
"sortings"
] | null | null | Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that the *x*-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.
Dima considers two assembled sequences (*p*1,<=*q*1),<=(*p*2,<=*q*2),<=...,<=(*p*2·*n*,<=*q*2·*n*) and (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x*2·*n*,<=*y*2·*n*) distinct, if there is such *i* (1<=≤<=*i*<=≤<=2·*n*), that (*p**i*,<=*q**i*)<=≠<=(*x**i*,<=*y**i*).
As the answer can be rather large, print the remainder from dividing the answer by number *m*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces.
The last line contains integer *m* (2<=≤<=*m*<=≤<=109<=+<=7). | In the single line print the remainder after dividing the answer to the problem by number *m*. | [
"1\n1\n2\n7\n",
"2\n1 2\n2 3\n11\n"
] | [
"1\n",
"2\n"
] | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | 2,000 | [
{
"input": "1\n1\n2\n7",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n11",
"output": "2"
},
{
"input": "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5 3 10 4 4 6 9 9 3 2 6 6\n4 3 8 4 4 2 4 6 6 3 3 5 8 4 1 6 2 7 6 1 6 10 7 9 2 9 2 9 10 1 1 1 1 7 4 5 3 6 8 6 10 4 3 4 8 6 5 3 1 2 2 4 1 9 1 3 1 9 6 8 9 4 8 8 4 2 1 4 6 2 6 3 4 7 7 7 8 10 7 8 8 6 4 10 10 7 4 5 5 8 3 8 2 8 6 4 5 2 10 2\n29056621",
"output": "5236748"
},
{
"input": "100\n6 1 10 4 8 7 7 3 2 4 6 3 2 5 3 7 1 6 9 8 3 10 1 6 8 1 4 2 5 6 3 5 4 6 3 10 2 8 10 4 2 6 4 5 3 1 8 6 9 8 5 2 7 1 10 5 10 2 9 1 6 4 9 5 2 4 6 7 10 10 10 6 6 9 2 3 3 1 2 4 1 6 9 8 4 10 10 9 9 2 5 7 10 1 9 7 6 6 4 5\n4 9 2 5 5 4 6 9 1 2 6 3 8 9 4 4 4 3 1 3 6 2 9 1 10 6 5 1 9 10 6 2 10 9 8 7 8 2 1 5 8 4 3 2 10 9 5 7 1 8 4 4 4 2 1 3 4 5 3 6 10 3 8 9 5 6 3 9 3 6 5 1 9 1 4 3 8 4 4 8 10 6 4 9 8 4 2 3 1 9 9 1 4 1 8 4 7 9 10 9\n66921358",
"output": "12938646"
},
{
"input": "100\n2 2 10 3 5 6 4 7 9 8 2 7 5 5 1 7 5 9 2 2 10 3 6 10 9 9 10 7 3 9 7 8 8 3 9 3 9 3 3 6 3 7 9 9 7 10 9 1 1 3 6 2 9 5 9 9 6 2 6 5 6 8 2 10 1 1 6 8 8 4 5 2 6 8 8 5 9 2 3 3 7 7 10 5 4 2 10 6 7 6 5 4 10 6 10 3 9 9 1 5\n3 5 6 4 2 3 2 9 3 8 3 1 10 7 4 3 6 9 3 5 9 5 3 10 4 7 9 7 4 3 3 6 9 8 1 1 10 9 1 6 8 8 8 2 1 6 10 1 8 6 3 5 7 7 10 4 6 6 9 1 5 3 5 10 4 4 1 7 9 7 5 10 6 5 4 1 9 6 4 5 7 3 1 10 2 10 6 6 1 10 7 5 1 4 2 9 2 7 3 10\n727992321",
"output": "340960284"
},
{
"input": "100\n2 5 5 6 5 2 8 10 6 1 5 3 10 3 8 6 4 5 7 9 7 1 3 3 5 2 3 7 9 3 7 2 7 6 7 10 5 9 2 4 8 2 3 8 6 6 8 4 1 2 10 5 2 8 4 3 1 3 8 3 2 4 4 6 8 1 9 8 9 9 1 7 1 9 2 4 6 2 1 9 2 7 9 6 6 7 1 9 3 1 6 10 3 9 10 5 3 3 9 8\n6 5 3 1 3 3 8 6 5 4 2 3 9 3 9 9 10 5 10 6 7 8 8 7 8 4 2 4 4 9 1 3 1 5 8 4 8 9 7 9 7 8 4 9 9 9 4 2 9 1 3 10 6 4 5 3 2 8 1 5 1 8 10 10 3 3 7 1 2 4 4 3 3 5 9 8 9 8 5 9 4 8 10 6 7 4 1 9 4 7 1 8 3 3 5 9 8 6 5 4\n608692736",
"output": "550164992"
},
{
"input": "2\n1 2\n1 2\n4",
"output": "1"
},
{
"input": "4\n1 2 3 4\n4 3 2 1\n1009",
"output": "16"
},
{
"input": "5\n1 2 3 3 5\n1 2 3 5 3\n12",
"output": "0"
},
{
"input": "1\n1000000000\n1000000000\n2",
"output": "1"
},
{
"input": "2\n1 2\n2 2\n4",
"output": "3"
}
] | 1,665,035,209 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 186 | 10,444,800 | from math import *
def freq(l):
d = {}
for i in l:
d[i] =d.get(i,0)+1
return d
def modInverse(b,m):
g = gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def modDivide(a,b,m):
a = a % m
inv = modInverse(b,m)
if(inv == -1):
return a//b
else:
return (inv*a) % m
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mod = int(input())
c = 0
for i in range(n):
if a[i] == b[i]:
c+=1
d_f = {0:1}
for i in range(1,10**5+1):
d_f[i] = (i%mod*d_f[i-1]%mod)%mod
a.sort()
b.sort()
sum = 1
d = freq(a)
for i in b:
d[i] =d.get(i,0)+1
for i in d:
sum = (sum * d_f[d[i]]) % mod
print(modDivide(sum,2**c,mod))
| Title: Dima and Two Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that the *x*-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.
Dima considers two assembled sequences (*p*1,<=*q*1),<=(*p*2,<=*q*2),<=...,<=(*p*2·*n*,<=*q*2·*n*) and (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x*2·*n*,<=*y*2·*n*) distinct, if there is such *i* (1<=≤<=*i*<=≤<=2·*n*), that (*p**i*,<=*q**i*)<=≠<=(*x**i*,<=*y**i*).
As the answer can be rather large, print the remainder from dividing the answer by number *m*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces.
The last line contains integer *m* (2<=≤<=*m*<=≤<=109<=+<=7).
Output Specification:
In the single line print the remainder after dividing the answer to the problem by number *m*.
Demo Input:
['1\n1\n2\n7\n', '2\n1 2\n2 3\n11\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | ```python
from math import *
def freq(l):
d = {}
for i in l:
d[i] =d.get(i,0)+1
return d
def modInverse(b,m):
g = gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def modDivide(a,b,m):
a = a % m
inv = modInverse(b,m)
if(inv == -1):
return a//b
else:
return (inv*a) % m
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mod = int(input())
c = 0
for i in range(n):
if a[i] == b[i]:
c+=1
d_f = {0:1}
for i in range(1,10**5+1):
d_f[i] = (i%mod*d_f[i-1]%mod)%mod
a.sort()
b.sort()
sum = 1
d = freq(a)
for i in b:
d[i] =d.get(i,0)+1
for i in d:
sum = (sum * d_f[d[i]]) % mod
print(modDivide(sum,2**c,mod))
``` | -1 |
|
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp",
"output": "0"
},
{
"input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH",
"output": "-1"
},
{
"input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt",
"output": "1"
},
{
"input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL",
"output": "1"
},
{
"input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo",
"output": "1"
},
{
"input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja",
"output": "-1"
},
{
"input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy",
"output": "1"
},
{
"input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR",
"output": "1"
},
{
"input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd",
"output": "1"
},
{
"input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI",
"output": "-1"
},
{
"input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC",
"output": "-1"
},
{
"input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl",
"output": "-1"
},
{
"input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo",
"output": "-1"
},
{
"input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV",
"output": "-1"
},
{
"input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ",
"output": "-1"
},
{
"input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK",
"output": "-1"
},
{
"input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys",
"output": "1"
},
{
"input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy",
"output": "-1"
},
{
"input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK",
"output": "-1"
},
{
"input": "UG\nak",
"output": "1"
},
{
"input": "JZR\nVae",
"output": "-1"
},
{
"input": "a\nZ",
"output": "-1"
},
{
"input": "rk\nkv",
"output": "1"
},
{
"input": "RvuT\nbJzE",
"output": "1"
},
{
"input": "PPS\nydq",
"output": "-1"
},
{
"input": "q\nq",
"output": "0"
},
{
"input": "peOw\nIgSJ",
"output": "1"
},
{
"input": "PyK\noKN",
"output": "1"
},
{
"input": "O\ni",
"output": "1"
},
{
"input": "NmGY\npDlP",
"output": "-1"
},
{
"input": "nG\nZf",
"output": "-1"
},
{
"input": "m\na",
"output": "1"
},
{
"input": "MWyB\nWZEV",
"output": "-1"
},
{
"input": "Gre\nfxc",
"output": "1"
},
{
"input": "Ooq\nwap",
"output": "-1"
},
{
"input": "XId\nlbB",
"output": "1"
},
{
"input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF",
"output": "0"
},
{
"input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD",
"output": "0"
},
{
"input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA",
"output": "0"
},
{
"input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ",
"output": "0"
},
{
"input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG",
"output": "0"
},
{
"input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ",
"output": "0"
},
{
"input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ",
"output": "0"
},
{
"input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi",
"output": "0"
},
{
"input": "abac\nadaa",
"output": "-1"
},
{
"input": "Bbc\nabc",
"output": "1"
},
{
"input": "aaaba\naaaab",
"output": "1"
}
] | 1,699,199,022 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 154 | 2,867,200 | str_1 = input().lower()
str_2 = input().lower()
alf = {"a":1,
"b":2,
"c":3,
"d":4,
"e":5,
"f":6,
"g":7,
"h":8,
"i":9,
"j":10,
"k":11,
"l":12,
"m":13,
"n":14,
"o":15,
"p":16,
"q":17,
"r":18,
"s":19,
"t":20,
"u":21,
"v":22,
"w":23,
"x":24,
"y":25,
"z":26,
}
for i in range(len(str_1)):
if str_1[i] in alf :
str_1 = str_1.replace(str_1[i],' '+str(alf[str_1[i]]))
if str_2[i] in alf:
str_2 = str_2.replace(str_2[i],' '+str(alf[str_2[i]]))
str_1=list(str_1.split(' '))
str_2=list(str_2.split(' '))
def spr(str_1,str_2):
for i in range(len(str_1)):
if str_1[i] != str_2[i]:
if int(str_1[i]) > int(str_2[i]):
return "1"
else:
return "-1"
else:
return "0"
print(spr(str_1,str_2)) | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Input Specification:
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
Output Specification:
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
Demo Input:
['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | ```python
str_1 = input().lower()
str_2 = input().lower()
alf = {"a":1,
"b":2,
"c":3,
"d":4,
"e":5,
"f":6,
"g":7,
"h":8,
"i":9,
"j":10,
"k":11,
"l":12,
"m":13,
"n":14,
"o":15,
"p":16,
"q":17,
"r":18,
"s":19,
"t":20,
"u":21,
"v":22,
"w":23,
"x":24,
"y":25,
"z":26,
}
for i in range(len(str_1)):
if str_1[i] in alf :
str_1 = str_1.replace(str_1[i],' '+str(alf[str_1[i]]))
if str_2[i] in alf:
str_2 = str_2.replace(str_2[i],' '+str(alf[str_2[i]]))
str_1=list(str_1.split(' '))
str_2=list(str_2.split(' '))
def spr(str_1,str_2):
for i in range(len(str_1)):
if str_1[i] != str_2[i]:
if int(str_1[i]) > int(str_2[i]):
return "1"
else:
return "-1"
else:
return "0"
print(spr(str_1,str_2))
``` | -1 |
816 | B | Karen and Coffee | PROGRAMMING | 1,400 | [
"binary search",
"data structures",
"implementation"
] | null | null | To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range? | The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. | [
"3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n",
"2 1 1\n1 1\n200000 200000\n90 100\n"
] | [
"3\n3\n0\n4\n",
"0\n"
] | In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | 1,000 | [
{
"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100",
"output": "3\n3\n0\n4"
},
{
"input": "2 1 1\n1 1\n200000 200000\n90 100",
"output": "0"
},
{
"input": "1 1 1\n1 1\n1 1",
"output": "1"
},
{
"input": "1 1 1\n200000 200000\n200000 200000",
"output": "1"
}
] | 1,689,050,988 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 45 | 358 | 13,004,800 | input=__import__('sys').stdin.readline
n,k,q=map(int,input().split())
arr=[0]*200003
for i in range(n):
l,r=map(int,input().split())
arr[l]+=1
arr[r+1]-=1
ans=[0]*200003
for i in range(1,len(arr)):
arr[i]+=arr[i-1]
ans[i]=ans[i-1]+(1 if arr[i]>=k else 0)
for i in range(q):
l,r=map(int,input().split())
print(ans[r]-ans[l-1]) | Title: Karen and Coffee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To stay woke and attentive during classes, Karen needs some coffee!
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".
She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range?
Input Specification:
The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.
The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
Output Specification:
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
Demo Input:
['3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n', '2 1 1\n1 1\n200000 200000\n90 100\n']
Demo Output:
['3\n3\n0\n4\n', '0\n']
Note:
In the first test case, Karen knows 3 recipes.
1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
A temperature is admissible if at least 2 recipes recommend it.
She asks 4 questions.
In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.
In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.
In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.
In the second test case, Karen knows 2 recipes.
1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.
A temperature is admissible if at least 1 recipe recommends it.
In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none. | ```python
input=__import__('sys').stdin.readline
n,k,q=map(int,input().split())
arr=[0]*200003
for i in range(n):
l,r=map(int,input().split())
arr[l]+=1
arr[r+1]-=1
ans=[0]*200003
for i in range(1,len(arr)):
arr[i]+=arr[i-1]
ans[i]=ans[i-1]+(1 if arr[i]>=k else 0)
for i in range(q):
l,r=map(int,input().split())
print(ans[r]-ans[l-1])
``` | 3 |
|
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible. | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdefghijklmnopqrstuvwxxx",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxya",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "cdaaaaaaaaabcdjklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "cdabcdefghijklmnopqrstuvwxyzxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "zazaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zazbcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abbbefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaa"
},
{
"input": "abcdefghijklmaopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyx",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaz"
},
{
"input": "zaaaazaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zabcdzefghijklmnopqrstuvwxyzaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaa"
},
{
"input": "aaaaaafghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyzz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaz"
},
{
"input": "abcdefghijklmnopqrstuvwaxy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaa"
},
{
"input": "abcdefghijklmnapqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvnxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaa"
},
{
"input": "abcdefghijklmnopqrstuvwxyzzzz",
"output": "abcdefghijklmnopqrstuvwxyzzzz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aacceeggiikkmmooqqssuuwwya",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aacdefghijklmnopqrstuvwxyyy",
"output": "abcdefghijklmnopqrstuvwxyzy"
},
{
"input": "abcaefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zaaacaaaaaaaaaaaaaaaaaaaayy",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdedccdcdccdcdcdcdcdcddccdcdcdc",
"output": "abcdefghijklmnopqrstuvwxyzcdcdcdc"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdecdcdcddcdcdcdcdcdcdcd",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "a",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaa"
},
{
"input": "aaadefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaa"
},
{
"input": "abbbbbbbbbbbbbbbbbbbbbbbbz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aacceeggiikkmmaacceeggiikkmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy",
"output": "abcdefghijklmnopqrstuvwxyzmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "phqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxf",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaap",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zabcdefghijklmnopqrstuvwxyz",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "rveviaomdienfygifatviahordebxazoxflfgzslhyzowhxbhqzpsgellkoimnwkvhpbijorhpggwfjexivpqbcbmqjyghkbq",
"output": "rveviaomdienfygifbtvichordefxgzoxhlijzslkyzowlxmnqzpsopqrstuvwxyzhpbijorhpggwfjexivpqbcbmqjyghkbq"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknly",
"output": "xtlsgypsfadpooefxzbcoejuvpvdeoygpofylgphnpljvrvipyjmyklwqnqrqpmxunopqrvstwuxwvwxyzbxcoksfzkvatxdknly"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxsa",
"output": "jqcfvsavebixhiocdefphgmsmhijkylwsmpynoypqrxstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqh",
"output": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldcefsdrefynghiyjkxxplmornopqrstuvwxyzopkmcoqh"
},
{
"input": "abadefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zazsazcbbbbbbbbbbbbbbbbbbbbbbb",
"output": "zazsbzcdefghijklmnopqrstuvwxyz"
},
{
"input": "zazsazcbbbbbbbbbbbbbbbbbbbbbyb",
"output": "zazsbzcdefghijklmnopqrstuvwxyz"
},
{
"input": "bbcdefghijklmnopqrstuvwxyzzz",
"output": "-1"
},
{
"input": "zaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "zzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zzzzzabcdefghijklmnopqrstuvwxyza"
},
{
"input": "kkimnfjbbgggicykcciwtoazomcvisigagkjwhyrmojmoebnqoadpmockfjxibdtvrbedrsdoundbcpkfdqdidqdmxdltink",
"output": "kkimnfjbbgggicykcciwtoazomcvisigbgkjwhyrmojmoecnqodepmofkgjxihitvrjklrsmounopqrstuvwxyzdmxdltink"
},
{
"input": "cawgathqceccscakbazmhwbefvygjbcfyihcbgga",
"output": "-1"
},
{
"input": "acrsbyszsbfslzbqzzamcmrypictkcheddehvxdipaxaannjodzyfxgtfnwababzjraapqbqbfzhbiewlzz",
"output": "acrsbyszscfslzdqzzemfmrypigtkhijklmnvxopqrxstuvwxyzyfxgtfnwababzjraapqbqbfzhbiewlzz"
},
{
"input": "ggcebbheeblbioxdvtlrtkxeuilonazpebcbqpzz",
"output": "-1"
},
{
"input": "zzzzabcdefghijklmnopqrstuvwxy",
"output": "-1"
},
{
"input": "zabcdefghijklmnopqrstuvwxy",
"output": "-1"
},
{
"input": "babcdefghijklmnopqrstuvwxyz",
"output": "babcdefghijklmnopqrstuvwxyz"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
] | 1,619,499,612 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 3,174,400 | import bisect
import collections
import copy
import enum
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
s = input()
for i in range(len(s)-25):
if s[i]=='a':
bs = s[i:i+26]
if all(bs[i]<=chr(i+ord('a')) for i in range(26)):
print(s[:i]+string.ascii_lowercase+s[i+26:])
exit()
print(-1) | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.
Input Specification:
The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters.
Output Specification:
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
Demo Input:
['aacceeggiikkmmooqqssuuwwyy\n', 'thereisnoanswer\n']
Demo Output:
['abcdefghijklmnopqrstuvwxyz\n', '-1\n']
Note:
none | ```python
import bisect
import collections
import copy
import enum
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
s = input()
for i in range(len(s)-25):
if s[i]=='a':
bs = s[i:i+26]
if all(bs[i]<=chr(i+ord('a')) for i in range(26)):
print(s[:i]+string.ascii_lowercase+s[i+26:])
exit()
print(-1)
``` | 0 |
|
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input": "2\n100 100",
"output": "2"
},
{
"input": "3\n100 100 100",
"output": "3"
},
{
"input": "11\n1 2 3 4 5 6 5 4 3 2 1",
"output": "11"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "61"
},
{
"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 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1",
"output": "81"
},
{
"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 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1",
"output": "85"
},
{
"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 1 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 100 7 6 5 4 3 2 1",
"output": "61"
},
{
"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 100 8 7 6 1 4 3 2 1",
"output": "96"
},
{
"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 100 10 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"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 1 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 100 11 10 9 8 7 6 5 4 3 2 1",
"output": "55"
},
{
"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 1 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 100 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "59"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 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 100 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "86"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "83"
},
{
"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 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "74"
},
{
"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 100 9 8 7 6 5 4 3 2 1",
"output": "100"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "52"
},
{
"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 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1",
"output": "98"
},
{
"input": "10\n1 4 4 4 4 4 1 2 4 3",
"output": "7"
}
] | 1,596,038,005 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 216 | 6,963,200 | def get_max_sections1(array):
is_increasing = True
max = 0
cur_max = 0
prev = 0
for i in array:
if is_increasing:
if prev <= i:
cur_max += 1
else:
cur_max += 1
is_increasing = False
else:
if prev >= i:
cur_max += 1
else:
is_increasing = True
cur_max = 2
prev = i
if cur_max > max:
max = cur_max
return max
def get_max_sections(array):
is_increasing = True
max = 0
cur_max = 0
prev = 0
for i in array:
if is_increasing:
if prev > i:
is_increasing = False
else:
if prev < i:
is_increasing = True
cur_max = 1
cur_max += 1
prev = i
if cur_max > max:
max = cur_max
return max
def calculate_max_sections(array):
a = get_max_sections(array)
b = get_max_sections(array[::-1])
return a if a > b else b
n = input()
array = input()
array = list(map(lambda x: int(x), array.split(' ')))
print(calculate_max_sections(array))
# assert calculate_max_sections([1, 2, 1, 1, 1, 3, 3, 4]) == 6
# assert calculate_max_sections([1, 2, 1, 2, 1]) == 3
# assert calculate_max_sections([2]) == 1
# assert calculate_max_sections([1, 2, 3, 4, 5, 4, 3, 2, 1]) == 9
# assert calculate_max_sections([4, 3, 2, 1, 1, 2, 3, 4]) == 5
# assert calculate_max_sections([6, 5, 6, 5, 6]) == 3
| Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output Specification:
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Demo Input:
['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n']
Demo Output:
['1\n', '3\n', '6\n']
Note:
none | ```python
def get_max_sections1(array):
is_increasing = True
max = 0
cur_max = 0
prev = 0
for i in array:
if is_increasing:
if prev <= i:
cur_max += 1
else:
cur_max += 1
is_increasing = False
else:
if prev >= i:
cur_max += 1
else:
is_increasing = True
cur_max = 2
prev = i
if cur_max > max:
max = cur_max
return max
def get_max_sections(array):
is_increasing = True
max = 0
cur_max = 0
prev = 0
for i in array:
if is_increasing:
if prev > i:
is_increasing = False
else:
if prev < i:
is_increasing = True
cur_max = 1
cur_max += 1
prev = i
if cur_max > max:
max = cur_max
return max
def calculate_max_sections(array):
a = get_max_sections(array)
b = get_max_sections(array[::-1])
return a if a > b else b
n = input()
array = input()
array = list(map(lambda x: int(x), array.split(' ')))
print(calculate_max_sections(array))
# assert calculate_max_sections([1, 2, 1, 1, 1, 3, 3, 4]) == 6
# assert calculate_max_sections([1, 2, 1, 2, 1]) == 3
# assert calculate_max_sections([2]) == 1
# assert calculate_max_sections([1, 2, 3, 4, 5, 4, 3, 2, 1]) == 9
# assert calculate_max_sections([4, 3, 2, 1, 1, 2, 3, 4]) == 5
# assert calculate_max_sections([6, 5, 6, 5, 6]) == 3
``` | 3.93303 |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++",
"output": "4"
},
{
"input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++",
"output": "-10"
},
{
"input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X",
"output": "-14"
},
{
"input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X",
"output": "3"
},
{
"input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X",
"output": "-5"
},
{
"input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X",
"output": "1"
},
{
"input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--",
"output": "1"
},
{
"input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++",
"output": "-3"
},
{
"input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X",
"output": "1"
},
{
"input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++",
"output": "8"
},
{
"input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++",
"output": "-1"
},
{
"input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--",
"output": "-5"
},
{
"input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--",
"output": "1"
},
{
"input": "1\nX--",
"output": "-1"
}
] | 1,698,760,940 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 61 | 0 | t = int(input())
c = 0
for i in range(t):
s = input()
if s[1] == '+': c += 1
else: c -= 1
print(c) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1.
A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.
A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.
You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Output Specification:
Print a single integer — the final value of *x*.
Demo Input:
['1\n++X\n', '2\nX++\n--X\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
t = int(input())
c = 0
for i in range(t):
s = input()
if s[1] == '+': c += 1
else: c -= 1
print(c)
``` | 3 |
|
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost.
Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost.
It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1",
"output": "LIVE\nDEAD"
},
{
"input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3",
"output": "DEAD\nLIVE"
},
{
"input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1",
"output": "LIVE\nLIVE"
},
{
"input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3",
"output": "DEAD\nDEAD"
}
] | 1,557,920,016 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 218 | 307,200 | n=int(input())
a=[]
x1,y1=0,0
x2,y2=0,0
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
for i in a:
if i[0]==1:
x1+=i[1]
y1+=i[2]
elif i[0]==2:
x2+=i[1]
y2+=i[2]
if x1>=y1:
print('LIVE')
else:
print('DEAD')
if x2>=y2:
print('LIVE')
else:
print('DEAD') | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost.
Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.
Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost.
It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
Output Specification:
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format.
Demo Input:
['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n']
Demo Output:
['LIVE\nLIVE\n', 'LIVE\nDEAD\n']
Note:
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.
Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | ```python
n=int(input())
a=[]
x1,y1=0,0
x2,y2=0,0
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
for i in a:
if i[0]==1:
x1+=i[1]
y1+=i[2]
elif i[0]==2:
x2+=i[1]
y2+=i[2]
if x1>=y1:
print('LIVE')
else:
print('DEAD')
if x2>=y2:
print('LIVE')
else:
print('DEAD')
``` | 3 |
|
554 | B | Ohana Cleans Up | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"strings"
] | null | null | Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean. | The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty. | The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. | [
"4\n0101\n1000\n1111\n0101\n",
"3\n111\n111\n111\n"
] | [
"2\n",
"3\n"
] | In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything. | 500 | [
{
"input": "4\n0101\n1000\n1111\n0101",
"output": "2"
},
{
"input": "3\n111\n111\n111",
"output": "3"
},
{
"input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "9"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011",
"output": "6"
},
{
"input": "20\n10101011101000011010\n11111010001100110101\n01011100010000001111\n10110100000101010011\n11010001110111101101\n00100110011011101010\n01000110101011001100\n01101100111101101101\n10111010010100111100\n00010010110001101110\n10111110010000101010\n10010111110100100100\n11010111001111110100\n11110111101100000001\n00011010100111011000\n11110001011000011010\n10001101010000011011\n01010101110010000111\n11100110111101101111\n11011111110010001111",
"output": "1"
},
{
"input": "10\n1001000000\n0111101111\n1111001011\n1000010100\n0111101111\n0101100110\n1001000000\n1000010100\n0111101111\n1001000000",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000",
"output": "10"
},
{
"input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111",
"output": "10"
},
{
"input": "10\n1000000000\n0100000000\n0010000000\n0001000000\n0000100000\n0000010000\n0000001000\n0000000100\n0000000010\n0000000001",
"output": "1"
},
{
"input": "2\n10\n01",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "4\n0000\n0000\n1111\n1111",
"output": "2"
},
{
"input": "11\n10000000001\n10000000001\n10000000001\n10000000001\n10001000001\n10001000000\n10001000001\n10001000001\n10001000000\n10001000000\n10001000100",
"output": "4"
}
] | 1,474,209,060 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 0 | I=input
s=[I()for _ in '0'*int(I())]
print(max(s.count(i)for i in s)) | Title: Ohana Cleans Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.
Input Specification:
The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100).
The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty.
Output Specification:
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
Demo Input:
['4\n0101\n1000\n1111\n0101\n', '3\n111\n111\n111\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything. | ```python
I=input
s=[I()for _ in '0'*int(I())]
print(max(s.count(i)for i in s))
``` | 3 |
|
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.
Your task is to find the number of successful students in the group. | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces. | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "3 4\n2553\n6856\n5133",
"output": "2"
},
{
"input": "8 7\n6264676\n7854895\n3244128\n2465944\n8958761\n1378945\n3859353\n6615285",
"output": "6"
},
{
"input": "9 8\n61531121\n43529859\n18841327\n88683622\n98995641\n62741632\n57441743\n49396792\n63381994",
"output": "4"
},
{
"input": "10 20\n26855662887514171367\n48525577498621511535\n47683778377545341138\n47331616748732562762\n44876938191354974293\n24577238399664382695\n42724955594463126746\n79187344479926159359\n48349683283914388185\n82157191115518781898",
"output": "9"
},
{
"input": "20 15\n471187383859588\n652657222494199\n245695867594992\n726154672861295\n614617827782772\n862889444974692\n373977167653235\n645434268565473\n785993468314573\n722176861496755\n518276853323939\n723712762593348\n728935312568886\n373898548522463\n769777587165681\n247592995114377\n182375946483965\n497496542536127\n988239919677856\n859844339819143",
"output": "18"
},
{
"input": "13 9\n514562255\n322655246\n135162979\n733845982\n473117129\n513967187\n965649829\n799122777\n661249521\n298618978\n659352422\n747778378\n723261619",
"output": "11"
},
{
"input": "75 1\n2\n3\n8\n3\n2\n1\n3\n1\n5\n1\n5\n4\n8\n8\n4\n2\n5\n1\n7\n6\n3\n2\n2\n3\n5\n5\n2\n4\n7\n7\n9\n2\n9\n5\n1\n4\n9\n5\n2\n4\n6\n6\n3\n3\n9\n3\n3\n2\n3\n4\n2\n6\n9\n1\n1\n1\n1\n7\n2\n3\n2\n9\n7\n4\n9\n1\n7\n5\n6\n8\n3\n4\n3\n4\n6",
"output": "7"
},
{
"input": "92 3\n418\n665\n861\n766\n529\n416\n476\n676\n561\n995\n415\n185\n291\n176\n776\n631\n556\n488\n118\n188\n437\n496\n466\n131\n914\n118\n766\n365\n113\n897\n386\n639\n276\n946\n759\n169\n494\n837\n338\n351\n783\n311\n261\n862\n598\n132\n246\n982\n575\n364\n615\n347\n374\n368\n523\n132\n774\n161\n552\n492\n598\n474\n639\n681\n635\n342\n516\n483\n141\n197\n571\n336\n175\n596\n481\n327\n841\n133\n142\n146\n246\n396\n287\n582\n556\n996\n479\n814\n497\n363\n963\n162",
"output": "23"
},
{
"input": "100 1\n1\n6\n9\n1\n1\n5\n5\n4\n6\n9\n6\n1\n7\n8\n7\n3\n8\n8\n7\n6\n2\n1\n5\n8\n7\n3\n5\n4\n9\n7\n1\n2\n4\n1\n6\n5\n1\n3\n9\n4\n5\n8\n1\n2\n1\n9\n7\n3\n7\n1\n2\n2\n2\n2\n3\n9\n7\n2\n4\n7\n1\n6\n8\n1\n5\n6\n1\n1\n2\n9\n7\n4\n9\n1\n9\n4\n1\n3\n5\n2\n4\n4\n6\n5\n1\n4\n5\n8\n4\n7\n6\n5\n6\n9\n5\n8\n1\n5\n1\n6",
"output": "10"
},
{
"input": "100 2\n71\n87\n99\n47\n22\n87\n49\n73\n21\n12\n77\n43\n18\n41\n78\n62\n61\n16\n64\n89\n81\n54\n53\n92\n93\n94\n68\n93\n15\n68\n42\n93\n28\n19\n86\n16\n97\n17\n11\n43\n72\n76\n54\n95\n58\n53\n48\n45\n85\n85\n74\n21\n44\n51\n89\n75\n76\n17\n38\n62\n81\n22\n66\n59\n89\n85\n91\n87\n12\n97\n52\n87\n43\n89\n51\n58\n57\n98\n78\n68\n82\n41\n87\n29\n75\n72\n48\n14\n35\n71\n74\n91\n66\n67\n42\n98\n52\n54\n22\n41",
"output": "21"
},
{
"input": "5 20\n11111111111111111111\n11111111111111111111\n11111111111111111111\n99999999999999999999\n11111111111111111119",
"output": "2"
},
{
"input": "3 3\n111\n111\n999",
"output": "1"
},
{
"input": "3 3\n119\n181\n711",
"output": "3"
},
{
"input": "15 5\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111\n91728\n11828\n11111",
"output": "15"
},
{
"input": "2 20\n22222222222222222222\n11111111111111111111",
"output": "1"
},
{
"input": "3 3\n233\n222\n111",
"output": "2"
},
{
"input": "4 15\n222222222222222\n111111111111119\n111111111111119\n111111111111111",
"output": "3"
},
{
"input": "4 1\n1\n9\n9\n9",
"output": "3"
},
{
"input": "3 3\n123\n321\n132",
"output": "3"
},
{
"input": "3 3\n113\n332\n322",
"output": "3"
},
{
"input": "2 100\n2222222222222222222222222222222222222222222222222222222222222222222222221222222222222222222222222222\n1111111111111111111111111111111111111111111111111111111111111111111111119111111111111111111111111111",
"output": "2"
},
{
"input": "3 3\n321\n231\n123",
"output": "3"
},
{
"input": "2 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222",
"output": "1"
},
{
"input": "3 3\n221\n111\n111",
"output": "3"
}
] | 1,579,627,437 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 109 | 307,200 | n,m=map(int,input().split())
A=[]
max_subject_marks=[0]*m
for i in range(n):
s=input()
A.append(s)
for j in range(m):
max_subject_marks[j]=max(max_subject_marks[j],int(s[j]))
cnt=0
for i in A:
flag=0
for j in range(m):
marks=int(i[j])
if(marks==max_subject_marks[j]):
flag=1
break
if flag:
cnt+=1
print(cnt) | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.
Your task is to find the number of successful students in the group.
Input Specification:
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
Output Specification:
Print the single number — the number of successful students in the given group.
Demo Input:
['3 3\n223\n232\n112\n', '3 5\n91728\n11828\n11111\n']
Demo Output:
['2\n', '3\n']
Note:
In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | ```python
n,m=map(int,input().split())
A=[]
max_subject_marks=[0]*m
for i in range(n):
s=input()
A.append(s)
for j in range(m):
max_subject_marks[j]=max(max_subject_marks[j],int(s[j]))
cnt=0
for i in A:
flag=0
for j in range(m):
marks=int(i[j])
if(marks==max_subject_marks[j]):
flag=1
break
if flag:
cnt+=1
print(cnt)
``` | 3 |
|
316 | A2 | Special Task | PROGRAMMING | 1,400 | [
"math"
] | null | null | Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string *s* with the following structure:
- if *s**i* = "?", then the digit that goes *i*-th in the safe code can be anything (between 0 to 9, inclusively); - if *s**i* is a digit (between 0 to 9, inclusively), then it means that there is digit *s**i* on position *i* in code; - if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. - The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night... | The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
- 1<=≤<=|*s*|<=≤<=5.
The input limits for scoring 100 points are (subproblems A1+A2):
- 1<=≤<=|*s*|<=≤<=105.
Here |*s*| means the length of string *s*. | Print the number of codes that match the given hint. | [
"AJ\n",
"1?AA\n"
] | [
"81\n",
"100\n"
] | none | 70 | [
{
"input": "AJ",
"output": "81"
},
{
"input": "1?AA",
"output": "100"
},
{
"input": "?",
"output": "9"
},
{
"input": "7",
"output": "1"
},
{
"input": "A",
"output": "9"
},
{
"input": "BBB?",
"output": "90"
},
{
"input": "BC??",
"output": "8100"
},
{
"input": "CC",
"output": "9"
},
{
"input": "CB?",
"output": "810"
},
{
"input": "B??C?",
"output": "81000"
},
{
"input": "BB?C?",
"output": "8100"
},
{
"input": "?BCB?",
"output": "8100"
},
{
"input": "?C",
"output": "90"
},
{
"input": "??C?C",
"output": "9000"
},
{
"input": "???2",
"output": "900"
},
{
"input": "9???",
"output": "1000"
},
{
"input": "GJH2?",
"output": "6480"
},
{
"input": "7I9G4",
"output": "90"
},
{
"input": "JG50?",
"output": "810"
},
{
"input": "CDEFG",
"output": "27216"
},
{
"input": "1023456789??????????????????????????????????????ABCDIFGHIJ",
"output": "362880000000000000000000000000000000000000000"
}
] | 1,371,055,136 | 13,136 | Python 3 | COMPILATION_ERROR | TESTS2 | 0 | 0 | 0 | #include <cstdio>
#include <ctime>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
#include <utility>
#include <deque>
#define elif else if
using namespace std;
bool used[300],f[300];
long long int x[30];
long long int F[10];
vector<char> vecchar;
main(){
string s;
cin>>s;
int cnt=0,st=0;
for(int i=0;i<(int) s.length();i++){
if(!used[s[i]]&&s[i]<='J'&&s[i]>='A') {
vecchar.push_back(s[i]);
if(i==0)F[s[i]]=9;
else F[s[i]]=10-cnt;
cnt++;
used[s[i]]=true;
}
else if(s[i]=='?') st++;
}
long long int ans=1;
if(s[0]=='?') ans=9,st--;
for(int i=0;i<(int) vecchar.size();i++){
ans=ans*F[vecchar[i]];
}
cout<<ans;
for(int i=0;i<st;i++)
putchar('0');}
| Title: Special Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string *s* with the following structure:
- if *s**i* = "?", then the digit that goes *i*-th in the safe code can be anything (between 0 to 9, inclusively); - if *s**i* is a digit (between 0 to 9, inclusively), then it means that there is digit *s**i* on position *i* in code; - if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. - The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input Specification:
The first line contains string *s* — the hint to the safe code. String *s* consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string *s* doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
- 1<=≤<=|*s*|<=≤<=5.
The input limits for scoring 100 points are (subproblems A1+A2):
- 1<=≤<=|*s*|<=≤<=105.
Here |*s*| means the length of string *s*.
Output Specification:
Print the number of codes that match the given hint.
Demo Input:
['AJ\n', '1?AA\n']
Demo Output:
['81\n', '100\n']
Note:
none | ```python
#include <cstdio>
#include <ctime>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
#include <utility>
#include <deque>
#define elif else if
using namespace std;
bool used[300],f[300];
long long int x[30];
long long int F[10];
vector<char> vecchar;
main(){
string s;
cin>>s;
int cnt=0,st=0;
for(int i=0;i<(int) s.length();i++){
if(!used[s[i]]&&s[i]<='J'&&s[i]>='A') {
vecchar.push_back(s[i]);
if(i==0)F[s[i]]=9;
else F[s[i]]=10-cnt;
cnt++;
used[s[i]]=true;
}
else if(s[i]=='?') st++;
}
long long int ans=1;
if(s[0]=='?') ans=9,st--;
for(int i=0;i<(int) vecchar.size();i++){
ans=ans*F[vecchar[i]];
}
cout<<ans;
for(int i=0;i<st;i++)
putchar('0');}
``` | -1 |
|
432 | B | Football Kit | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Consider a football tournament where *n* teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the *i*-th team has color *x**i* and the kit for away games of this team has color *y**i* (*x**i*<=≠<=*y**i*).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (*n*(*n*<=-<=1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of teams. Next *n* lines contain the description of the teams. The *i*-th line contains two space-separated numbers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=105; *x**i*<=≠<=*y**i*) — the color numbers for the home and away kits of the *i*-th team. | For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input. | [
"2\n1 2\n2 1\n",
"3\n1 2\n2 1\n1 3\n"
] | [
"2 0\n2 0\n",
"3 1\n4 0\n2 2\n"
] | none | 1,000 | [
{
"input": "2\n1 2\n2 1",
"output": "2 0\n2 0"
},
{
"input": "3\n1 2\n2 1\n1 3",
"output": "3 1\n4 0\n2 2"
},
{
"input": "2\n1 2\n1 2",
"output": "1 1\n1 1"
},
{
"input": "2\n1 2\n3 4",
"output": "1 1\n1 1"
},
{
"input": "3\n1 100000\n1 100000\n100000 2",
"output": "3 1\n3 1\n2 2"
},
{
"input": "5\n3 2\n3 4\n2 5\n3 2\n4 3",
"output": "5 3\n5 3\n4 4\n5 3\n7 1"
},
{
"input": "6\n2 3\n2 1\n2 1\n3 2\n3 2\n3 1",
"output": "8 2\n5 5\n5 5\n8 2\n8 2\n5 5"
},
{
"input": "10\n2 1\n1 3\n4 1\n2 3\n4 1\n1 4\n2 4\n2 1\n2 3\n3 4",
"output": "11 7\n10 8\n11 7\n10 8\n11 7\n11 7\n11 7\n11 7\n10 8\n11 7"
},
{
"input": "30\n1 10\n1 7\n6 10\n2 6\n10 2\n1 8\n3 8\n10 2\n7 4\n10 4\n9 1\n3 7\n1 8\n2 5\n3 4\n2 7\n3 1\n6 9\n8 10\n4 1\n5 1\n7 8\n6 7\n9 8\n7 3\n6 2\n9 1\n7 1\n8 9\n9 6",
"output": "32 26\n33 25\n32 26\n33 25\n32 26\n31 27\n31 27\n32 26\n30 28\n30 28\n33 25\n33 25\n31 27\n30 28\n30 28\n33 25\n33 25\n33 25\n32 26\n33 25\n33 25\n31 27\n33 25\n31 27\n33 25\n32 26\n33 25\n33 25\n33 25\n33 25"
},
{
"input": "30\n14 1\n12 5\n16 18\n17 9\n17 5\n13 4\n5 17\n10 8\n13 9\n11 9\n11 5\n15 11\n12 17\n10 7\n20 4\n9 8\n4 18\n10 6\n6 18\n3 16\n14 9\n8 17\n12 14\n18 11\n3 10\n1 15\n4 17\n7 20\n11 18\n18 13",
"output": "30 28\n30 28\n31 27\n30 28\n30 28\n31 27\n31 27\n30 28\n30 28\n30 28\n30 28\n32 26\n31 27\n30 28\n31 27\n30 28\n31 27\n30 28\n31 27\n30 28\n30 28\n31 27\n31 27\n32 26\n32 26\n30 28\n31 27\n30 28\n31 27\n31 27"
},
{
"input": "30\n25 8\n25 4\n21 9\n25 1\n7 16\n23 21\n22 17\n27 29\n7 29\n20 3\n13 23\n7 13\n16 18\n25 14\n13 17\n28 15\n10 23\n25 18\n2 3\n23 13\n30 8\n13 15\n20 15\n11 29\n10 23\n5 16\n4 14\n4 30\n7 20\n11 1",
"output": "29 29\n31 27\n29 29\n29 29\n30 28\n30 28\n29 29\n29 29\n29 29\n29 29\n31 27\n32 26\n29 29\n29 29\n29 29\n29 29\n31 27\n29 29\n29 29\n32 26\n29 29\n29 29\n29 29\n29 29\n31 27\n30 28\n29 29\n30 28\n31 27\n29 29"
},
{
"input": "2\n100000 1\n1 100000",
"output": "2 0\n2 0"
},
{
"input": "20\n1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000",
"output": "19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19\n19 19"
}
] | 1,663,168,087 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
# import sys
# for i in range(int(input())):
# n,m=map(int,input().split())
arr=[list(map(int,input().split())) for i in range(n)]
# arr=list(map(int,input().split()))
# power=int(input())
h=0
a=0
for i in range(n):
for j in range(n):
if i!=j:
# print(i,j)
if arr[j][1]==arr[i][0]:
h+=1
else:
a+=1
print((n-1)+h,a)
h=0
a=0 | Title: Football Kit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a football tournament where *n* teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the *i*-th team has color *x**i* and the kit for away games of this team has color *y**i* (*x**i*<=≠<=*y**i*).
In the tournament, each team plays exactly one home game and exactly one away game with each other team (*n*(*n*<=-<=1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.
Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of teams. Next *n* lines contain the description of the teams. The *i*-th line contains two space-separated numbers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=105; *x**i*<=≠<=*y**i*) — the color numbers for the home and away kits of the *i*-th team.
Output Specification:
For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.
Demo Input:
['2\n1 2\n2 1\n', '3\n1 2\n2 1\n1 3\n']
Demo Output:
['2 0\n2 0\n', '3 1\n4 0\n2 2\n']
Note:
none | ```python
n=int(input())
# import sys
# for i in range(int(input())):
# n,m=map(int,input().split())
arr=[list(map(int,input().split())) for i in range(n)]
# arr=list(map(int,input().split()))
# power=int(input())
h=0
a=0
for i in range(n):
for j in range(n):
if i!=j:
# print(i,j)
if arr[j][1]==arr[i][0]:
h+=1
else:
a+=1
print((n-1)+h,a)
h=0
a=0
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 1,510,504,219 | 1,519 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 62 | 0 | n = int(input())
A = input().split()
A = [int(i) for i in A]
m = max(A)
count = [0]*m
for i in range (0,m):
count[i] = A.count(i+1)
value = [0]*m
for i in range (0,m):
if count[i] == 0: value[i] = 0
else: value[i] = 1
A.reverse()
for i in range (0,n):
k = A[i]
if value.count(1) ==1:
print (value.index(1)+1)
break
else:
value[k-1] = 0 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input Specification:
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output Specification:
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Demo Input:
['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n']
Demo Output:
['3\n', '2\n']
Note:
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | ```python
n = int(input())
A = input().split()
A = [int(i) for i in A]
m = max(A)
count = [0]*m
for i in range (0,m):
count[i] = A.count(i+1)
value = [0]*m
for i in range (0,m):
if count[i] == 0: value[i] = 0
else: value[i] = 1
A.reverse()
for i in range (0,n):
k = A[i]
if value.count(1) ==1:
print (value.index(1)+1)
break
else:
value[k-1] = 0
``` | -1 |
|
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77",
"output": "87"
},
{
"input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93",
"output": "84"
},
{
"input": "6 100\n10 9 8 7 6 5",
"output": "0"
},
{
"input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46",
"output": "78"
},
{
"input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44",
"output": "0"
},
{
"input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62",
"output": "4"
},
{
"input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71",
"output": "0"
},
{
"input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1",
"output": "0"
},
{
"input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27",
"output": "63"
},
{
"input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22",
"output": "38"
},
{
"input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83",
"output": "91"
},
{
"input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14",
"output": "79"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24",
"output": "91"
},
{
"input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49",
"output": "83"
},
{
"input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70",
"output": "94"
},
{
"input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42",
"output": "43"
},
{
"input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0",
"output": "100"
},
{
"input": "3 1\n1 2 3",
"output": "0"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "0"
},
{
"input": "3 100\n1 2 3",
"output": "0"
},
{
"input": "2 100\n0 0",
"output": "0"
},
{
"input": "2 90\n10 5",
"output": "0"
},
{
"input": "2 5\n5 4",
"output": "0"
},
{
"input": "3 1\n19 20 1",
"output": "18"
},
{
"input": "5 1\n5 10 7 4 20",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "0"
}
] | 1,517,023,382 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 5,632,000 | # max(a[i] - a[i - 1] - c),i = 2..n
n,c=map(int,input().split())
a=list(map(int,input().split()))
t=[]
for i in range(0,n-2):
t.append(a[i]-a[i+1]-c)
print(max(0,max(t))) | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
Input Specification:
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n']
Demo Output:
['3\n', '97\n', '0\n']
Note:
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | ```python
# max(a[i] - a[i - 1] - c),i = 2..n
n,c=map(int,input().split())
a=list(map(int,input().split()))
t=[]
for i in range(0,n-2):
t.append(a[i]-a[i+1]-c)
print(max(0,max(t)))
``` | -1 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,555,577,535 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | def say_no():
print("NO")
exit()
def check(a,x):
x=s.find(a,x+1)
if x==-1:
say_no()
return -1
return x+1
s=input()
x=0
for i in "hello":
x=check(i,x)
print("YES") | 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
def say_no():
print("NO")
exit()
def check(a,x):
x=s.find(a,x+1)
if x==-1:
say_no()
return -1
return x+1
s=input()
x=0
for i in "hello":
x=check(i,x)
print("YES")
``` | 0 |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e",
"output": "lellelleel"
}
] | 1,490,396,923 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 4,608,000 | letters, designers = [int(x) for x in input().split(' ')]
name = input()
alphabet = [(x + 97) for x in range(26)]
for _ in range(designers):
letter1, letter2 = input().split(' ')
for i in range(26):
if alphabet[i] == ord(letter1):
alphabet[i] = ord(letter2)
elif alphabet[i] == ord(letter2):
alphabet[i] = ord(letter1)
for letter in name:
print(chr(alphabet[ord(letter) - 97]), end='')
print() | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Output Specification:
Print the new name of the corporation.
Demo Input:
['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n']
Demo Output:
['molice\n', 'cdcbcdcfcdc\n']
Note:
In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
letters, designers = [int(x) for x in input().split(' ')]
name = input()
alphabet = [(x + 97) for x in range(26)]
for _ in range(designers):
letter1, letter2 = input().split(' ')
for i in range(26):
if alphabet[i] == ord(letter1):
alphabet[i] = ord(letter2)
elif alphabet[i] == ord(letter2):
alphabet[i] = ord(letter1)
for letter in name:
print(chr(alphabet[ord(letter) - 97]), end='')
print()
``` | 0 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,664,915,632 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 512,000 | number = int(input())
case = input()
numberOf0 = case.count('0')
numberOf1 = case.count('1')
if numberOf0 < numberOf1:
print(len(case)- 2*numberOf0)
else:
print(len(case)- 2*numberOf1) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
number = int(input())
case = input()
numberOf0 = case.count('0')
numberOf1 = case.count('1')
if numberOf0 < numberOf1:
print(len(case)- 2*numberOf0)
else:
print(len(case)- 2*numberOf1)
``` | 3 |
|
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n2 2 1 1 1",
"output": "2"
},
{
"input": "7\n1 1 2 2 1 2 1",
"output": "3"
},
{
"input": "10\n1 2 2 1 2 2 1 2 1 1",
"output": "5"
},
{
"input": "5\n2 2 2 1 2",
"output": "1"
},
{
"input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2",
"output": "10"
},
{
"input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2",
"output": "34"
},
{
"input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2",
"output": "32"
},
{
"input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2",
"output": "9"
},
{
"input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1",
"output": "11"
},
{
"input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2",
"output": "100"
},
{
"input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2",
"output": "123"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "3\n2 2 1",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "1"
},
{
"input": "4\n2 1 1 1",
"output": "1"
},
{
"input": "5\n1 1 1 1 2",
"output": "2"
},
{
"input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1"
},
{
"input": "38\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 1",
"output": "1"
},
{
"input": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2",
"output": "1"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "3"
},
{
"input": "5\n2 1 1 1 1",
"output": "2"
},
{
"input": "9\n1 1 1 1 1 1 2 2 2",
"output": "4"
},
{
"input": "10\n2 2 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "2"
}
] | 1,667,785,979 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 67 | 139 | 23,756,800 | from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import operator
import sys
input = sys.stdin.readline
def solve():
n = int(input())
A = list(map(int, input().split()))
ct = Counter(A)
# max(1s//3, min(2s, 1s) + (1s-min(2s,1s))//3)
print(min(ct[2], ct[1]) + (ct[1] - min(ct[2], ct[1]))//3)
def main():
tests = 1
for _ in range(tests):
solve()
if __name__ == "__main__":
main() | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input Specification:
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Output Specification:
Print the maximum number of teams of three people the coach can form.
Demo Input:
['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n']
Demo Output:
['1\n', '0\n', '3\n', '1\n']
Note:
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | ```python
from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import operator
import sys
input = sys.stdin.readline
def solve():
n = int(input())
A = list(map(int, input().split()))
ct = Counter(A)
# max(1s//3, min(2s, 1s) + (1s-min(2s,1s))//3)
print(min(ct[2], ct[1]) + (ct[1] - min(ct[2], ct[1]))//3)
def main():
tests = 1
for _ in range(tests):
solve()
if __name__ == "__main__":
main()
``` | 3 |
|
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,689,605,454 | 2,147,483,647 | Python 3 | OK | TESTS | 103 | 1,200 | 13,619,200 | s = int(input())
li = sorted(map(int, input().split()))
d = int(input())
for i in range(d):
n = int(input())
low = 0
high = s - 1
while low <= high:
mid = (low + high) // 2
if li[mid] <= n:
low = mid + 1
else:
high = mid - 1
print(low) | 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
s = int(input())
li = sorted(map(int, input().split()))
d = int(input())
for i in range(d):
n = int(input())
low = 0
high = s - 1
while low <= high:
mid = (low + high) // 2
if li[mid] <= n:
low = mid + 1
else:
high = mid - 1
print(low)
``` | 3 |
|
985 | D | Sand Fortress | PROGRAMMING | 2,100 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand on the beach, so you brought *n* packs of sand with you. Let height *h**i* of the sand pillar on some spot *i* be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with *H* sand packs to the left of the first spot and you should prevent sand from going over it.
Finally you ended up with the following conditions to building the castle:
- *h*1<=≤<=*H*: no sand from the leftmost spot should go over the fence; - For any |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen; - : you want to spend all the sand you brought with you.
As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible.
Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold. | The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively. | Print the minimum number of spots you can occupy so the all the castle building conditions hold. | [
"5 2\n",
"6 8\n"
] | [
"3\n",
"3\n"
] | Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are occupied in them.
And here are some invalid ones:
- *n* = 5, *H* = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...] - *n* = 6, *H* = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...] | 0 | [
{
"input": "5 2",
"output": "3"
},
{
"input": "6 8",
"output": "3"
},
{
"input": "20 4",
"output": "7"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1414213562"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 1000000000000000000",
"output": "1"
},
{
"input": "1000000000000000000 1",
"output": "1999999999"
},
{
"input": "1036191544337895 45523434",
"output": "45523434"
},
{
"input": "1036191544337896 45523434",
"output": "45523435"
},
{
"input": "1036191544337895 45523433",
"output": "45523435"
},
{
"input": "1036191544337895 1",
"output": "64379858"
},
{
"input": "1036191544337895 1000000000000000000",
"output": "45523434"
},
{
"input": "30 3",
"output": "9"
},
{
"input": "30 4",
"output": "8"
},
{
"input": "6 100",
"output": "3"
},
{
"input": "7 100",
"output": "4"
},
{
"input": "1000000000000000000 99999999999",
"output": "1414213562"
},
{
"input": "999999997351043581 1000000000000000000",
"output": "1414213561"
},
{
"input": "911343366122896086 1416605974",
"output": "1350069158"
},
{
"input": "828974163639871882 2010864527",
"output": "1287613423"
},
{
"input": "696616491401388220 958775125",
"output": "1191798158"
},
{
"input": "999999999000000000 1",
"output": "1999999998"
},
{
"input": "961245465290770608 1687994843",
"output": "1386539192"
},
{
"input": "692106376966414549 974053139",
"output": "1186035874"
},
{
"input": "12 1",
"output": "6"
},
{
"input": "806680349368385877 1068656310",
"output": "1278847474"
}
] | 1,534,367,454 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | n, h = map(int, input().split())
l, r = 0, n
while r - l > 1:
m = (r + l) // 2
s = min(m, h)
if h * max(0, m - h) + s * (s + 1) // 2 < n:
l = m
else:
r = m
print(r) | Title: Sand Fortress
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right.
Obviously, there is not enough sand on the beach, so you brought *n* packs of sand with you. Let height *h**i* of the sand pillar on some spot *i* be the number of sand packs you spent on it. You can't split a sand pack to multiple pillars, all the sand from it should go to a single one. There is a fence of height equal to the height of pillar with *H* sand packs to the left of the first spot and you should prevent sand from going over it.
Finally you ended up with the following conditions to building the castle:
- *h*1<=≤<=*H*: no sand from the leftmost spot should go over the fence; - For any |*h**i*<=-<=*h**i*<=+<=1|<=≤<=1: large difference in heights of two neighboring pillars can lead sand to fall down from the higher one to the lower, you really don't want this to happen; - : you want to spend all the sand you brought with you.
As you have infinite spots to build, it is always possible to come up with some valid castle structure. Though you want the castle to be as compact as possible.
Your task is to calculate the minimum number of spots you can occupy so that all the aforementioned conditions hold.
Input Specification:
The only line contains two integer numbers *n* and *H* (1<=≤<=*n*,<=*H*<=≤<=1018) — the number of sand packs you have and the height of the fence, respectively.
Output Specification:
Print the minimum number of spots you can occupy so the all the castle building conditions hold.
Demo Input:
['5 2\n', '6 8\n']
Demo Output:
['3\n', '3\n']
Note:
Here are the heights of some valid castles:
- *n* = 5, *H* = 2, [2, 2, 1, 0, ...], [2, 1, 1, 1, 0, ...], [1, 0, 1, 2, 1, 0, ...] - *n* = 6, *H* = 8, [3, 2, 1, 0, ...], [2, 2, 1, 1, 0, ...], [0, 1, 0, 1, 2, 1, 1, 0...] (this one has 5 spots occupied)
The first list for both cases is the optimal answer, 3 spots are occupied in them.
And here are some invalid ones:
- *n* = 5, *H* = 2, [3, 2, 0, ...], [2, 3, 0, ...], [1, 0, 2, 2, ...] - *n* = 6, *H* = 8, [2, 2, 2, 0, ...], [6, 0, ...], [1, 4, 1, 0...], [2, 2, 1, 0, ...] | ```python
n, h = map(int, input().split())
l, r = 0, n
while r - l > 1:
m = (r + l) // 2
s = min(m, h)
if h * max(0, m - h) + s * (s + 1) // 2 < n:
l = m
else:
r = m
print(r)
``` | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.