You are given N counters, initially set to 0, and you have two possible operations on them:
- increase(X) − counter X is increased by 1,
- max counter − all counters are set to the maximum value of any counter.
A non-empty array A of M integers is given. This array represents consecutive operations:
- if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
- if A[K] = N + 1 then operation K is max counter.
For example, given integer N = 5 and array A such that:
A[0] = 3 A[1] = 4 A[2] = 4 A[3] = 6 A[4] = 1 A[5] = 4 A[6] = 4the values of the counters after each consecutive operation will be:
(0, 0, 1, 0, 0) (0, 0, 1, 1, 0) (0, 0, 1, 2, 0) (2, 2, 2, 2, 2) (3, 2, 2, 2, 2) (3, 2, 2, 3, 2) (3, 2, 2, 4, 2)The goal is to calculate the value of every counter after all operations.
Write a function:
def solution(n, a)
that, given an integer N and a non-empty array A consisting of M integers, returns a sequence of integers representing the values of the counters.
Result array should be returned as an array of integers.
For example, given:
A[0] = 3 A[1] = 4 A[2] = 4 A[3] = 6 A[4] = 1 A[5] = 4 A[6] = 4the function should return [3, 2, 2, 4, 2], as explained above.
Write an efficient algorithm for the following assumptions:
- N and M are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..N + 1].
exec.rb:8:in `block in solution': undefined method `+' for nil:NilClass (NoMethodError) from exec.rb:5:in `each' from exec.rb:5:in `each_with_index' from exec.rb:5:in `solution' from exec.rb:130:in `<main>'
3 0 4 1 4 2 6 3 1 4 4 5 4 6
exec.rb:10:in `block in solution': undefined method `+' for nil:NilClass (NoMethodError) from exec.rb:5:in `each' from exec.rb:5:in `each_with_index' from exec.rb:5:in `solution' from exec.rb:132:in `<main>'stdout:
0 3 1 4 2 4 3 6
0 3 1 4 2 4 3 6 4 1 5 4 6 4
[0, 0, 0, 0, 0] 0 [0, 0, 0, 0, 1] 1 [1, 0, 0, 0, 1] 2 [1, 1, 0, 0, 1] 3 [1, 1, 1, 0, 1] 4 [1, 1, 1, 1, 1] 5 [1, 1, 1, 1, 2] 6 [2, 2, 2, 2, 2]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 4 [3, 2, 2, 3, 2] 4 [3, 2, 2, 4, 2]
def solution(n, a)
counters = [0] * n
p counters
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
else
max = counters.max
counters = [max] * n
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 4 [3, 2, 2, 3, 2] 4 [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 6 [3, 3, 3, 3, 3] 4 [3, 3, 3, 4, 3]
def solution(n, a)
counters = [0] * n
p counters
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
else
max = counters.max
counters = [max] * n
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [6, 6, 6, 6]]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 4 [3, 2, 2, 3, 2] 4 [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 6 [3, 3, 3, 3, 3] 4 [3, 3, 3, 4, 3]
function result: [0, 0, 0, 0, 0]
[0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
continue if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
continue if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 4 [3, 2, 2, 3, 2] 4 [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 6 [3, 3, 3, 3, 3] 4 [3, 3, 3, 4, 3]
exec.rb:13:in `block in solution': undefined local variable or method `continue' for main:Object (NameError) from exec.rb:7:in `each' from exec.rb:7:in `each_with_index' from exec.rb:7:in `solution' from exec.rb:136:in `<main>'stdout:
[0, 0, 0, 0, 0] 1 [1, 0, 0, 0, 0] 6 [1, 1, 1, 1, 1] 6
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 4 [3, 2, 2, 3, 2] 4 [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 6 [3, 3, 3, 3, 3] 4 [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0] 1 [1, 0, 0, 0, 0] 6 [1, 1, 1, 1, 1] 6 2 [1, 2, 1, 1, 1]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
# next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
# next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 4 [3, 2, 2, 3, 2] 4 [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 1, 0, 0] 4 [0, 0, 1, 1, 0] 4 [0, 0, 1, 2, 0] 6 [2, 2, 2, 2, 2] 1 [3, 2, 2, 2, 2] 6 [3, 3, 3, 3, 3] 4 [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0] 1 [1, 0, 0, 0, 0] 6 [1, 1, 1, 1, 1] 6 [1, 1, 1, 1, 1] 2 [1, 2, 1, 1, 1]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 4 [3, 2, 2, 2, 2] [3, 2, 2, 3, 2] 4 [3, 2, 2, 3, 2] [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 6 [3, 2, 2, 2, 2] [3, 3, 3, 3, 3] 4 [3, 3, 3, 3, 3] [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0] 1 [0, 0, 0, 0, 0] [1, 0, 0, 0, 0] 6 [1, 0, 0, 0, 0] [1, 1, 1, 1, 1] 6 [1, 1, 1, 1, 1] 2 [1, 1, 1, 1, 1] [1, 2, 1, 1, 1]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
puts "running max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] running max [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 4 [3, 2, 2, 2, 2] [3, 2, 2, 3, 2] 4 [3, 2, 2, 3, 2] [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] running max [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 6 [3, 2, 2, 2, 2] running max [3, 3, 3, 3, 3] 4 [3, 3, 3, 3, 3] [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0] 1 [0, 0, 0, 0, 0] [1, 0, 0, 0, 0] 6 [1, 0, 0, 0, 0] running max [1, 1, 1, 1, 1] 6 [1, 1, 1, 1, 1] 2 [1, 1, 1, 1, 1] [1, 2, 1, 1, 1]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
puts "running max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] running max [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 4 [3, 2, 2, 2, 2] [3, 2, 2, 3, 2] 4 [3, 2, 2, 3, 2] [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] running max [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 6 [3, 2, 2, 2, 2] running max [3, 3, 3, 3, 3] 4 [3, 3, 3, 3, 3] [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0] 1 [0, 0, 0, 0, 0] [1, 0, 0, 0, 0] 6 [1, 0, 0, 0, 0] running max [1, 1, 1, 1, 1] 6 [1, 1, 1, 1, 1] 2 [1, 1, 1, 1, 1] [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
[0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] running max [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
puts val
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
puts "running max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] running max [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 4 [3, 2, 2, 2, 2] [3, 2, 2, 3, 2] 4 [3, 2, 2, 3, 2] [3, 2, 2, 4, 2]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0] 3 [0, 0, 0, 0, 0] [0, 0, 1, 0, 0] 4 [0, 0, 1, 0, 0] [0, 0, 1, 1, 0] 4 [0, 0, 1, 1, 0] [0, 0, 1, 2, 0] 6 [0, 0, 1, 2, 0] running max [2, 2, 2, 2, 2] 1 [2, 2, 2, 2, 2] [3, 2, 2, 2, 2] 6 [3, 2, 2, 2, 2] running max [3, 3, 3, 3, 3] 4 [3, 3, 3, 3, 3] [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0] 1 [0, 0, 0, 0, 0] [1, 0, 0, 0, 0] 6 [1, 0, 0, 0, 0] running max [1, 1, 1, 1, 1] 6 [1, 1, 1, 1, 1] 2 [1, 1, 1, 1, 1] [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
[0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] running max [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0] 6 [0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
[0, 0, 0, 0, 0] 1 [0, 0, 0, 0, 0] [1, 0, 0, 0, 0] 1 [1, 0, 0, 0, 0] [2, 0, 0, 0, 0] 1 [2, 0, 0, 0, 0] [3, 0, 0, 0, 0]
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
puts "running max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
p counters
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
p counters
end
counters
end
def solution(n, a)
counters = [0] * n
p counters
last_op = ""
a.each_with_index do |val, i|
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
function result: [3, 3, 3, 4, 3]
[0, 0, 0, 0, 0]
function result: [1, 2, 1, 1, 1]
[0, 0, 0, 0, 0]
function result: [0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
def solution(n, a)
counters = [0] * n
last_op = ""
a.each_with_index do |val, i|
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
function result: [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
def solution(n, a)
counters = [0] * n
last_op = ""
a.each_with_index do |val, i|
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
[1, [2]]
function result: [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
function result: [0]
def solution(n, a)
counters = [0] * n
last_op = ""
a.each_with_index do |val, i|
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
[1, [2]]
[1, [1]]
function result: [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
function result: [0]
function result: [1]
def solution(n, a)
counters = [0] * n
last_op = ""
a.each_with_index do |val, i|
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
[1, [2]]
[1, [1]]
function result: [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
function result: [0]
function result: [1]
def solution(n, a)
counters = [0] * n
last_op = ""
a.each_with_index do |val, i|
if val <= n then
counters[val-1] += 1
last_op = "inc"
else
next if last_op == "max"
max = counters.max
counters = [max] * n
last_op = "max"
end
end
counters
end
[5, [3, 4, 4, 6, 1, 6, 4]]
[5, [1, 6, 6, 2]]
[5, [6, 6, 6]]
[5, [1, 1, 1]]
[1, [2]]
[1, [1]]
function result: [3, 3, 3, 4, 3]
function result: [1, 2, 1, 1, 1]
function result: [0, 0, 0, 0, 0]
function result: [3, 0, 0, 0, 0]
function result: [0]
function result: [1]
The following issues have been detected: timeout errors.
large random test, 2120 max_counter operations
running time: 3.56 sec., time limit: 0.35 sec.
large random test, 10000 max_counter operations
running time: >6.00 sec., time limit: 0.53 sec.