#author :Fuad Ashraful Mehmet
#date: 17th April 2020

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
sum=Array.new(n)
rsum=Array.new(n)
bestl=Array.new(n)
bestr=Array.new(n)
astart=Array.new(n)
bstart=Array.new(n)
n.times do |i|
  if i<k
    sum[i]=(i>0?sum[i-1]:0)+a[i]
    rsum[n-i-1]=(i>0?rsum[n-i]:0)+a[n-i-1]
  else
    sum[i]=sum[i-1]+a[i]-a[i-k]
    rsum[n-i-1]=rsum[n-i]+a[n-i-1]-a[n-i+k-1]
  end

  if i==0
    bestr[n-1]=rsum[n-1]
    bstart[n-1]=n-1
  else
    if bestr[n-i] > rsum[n-i-1]
      bestr[n-i-1] = bestr[n-i]
      bstart[n-i-1] = bstart[n-i]
    else
      bestr[n-i-1] = rsum[n-i-1]
      bstart[n-i-1] = n-i-1
    end
  end
end

max=0
besta=0
bestb=0
for i in k-1..n-k-1
  s = sum[i]+bestr[i+1]
  if max < s
    max = s
    besta=i
    bestb=bstart[i+1]
  end
end

puts "#{besta+2-k} #{bestb+1}"

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
sum=Array.new(n)
rsum=Array.new(n)
bestl=Array.new(n)
bestr=Array.new(n)
astart=Array.new(n)
bstart=Array.new(n)
n.times do |i|
  if i<k
    sum[i]=(i>0?sum[i-1]:0)+a[i]
    rsum[n-i-1]=(i>0?rsum[n-i]:0)+a[n-i-1]
  else
    sum[i]=sum[i-1]+a[i]-a[i-k]
    rsum[n-i-1]=rsum[n-i]+a[n-i-1]-a[n-i+k-1]
  end

  if i==0
    bestr[n-1]=rsum[n-1]
    bstart[n-1]=n-1
  else
    if bestr[n-i] > rsum[n-i-1]
      bestr[n-i-1] = bestr[n-i]
      bstart[n-i-1] = bstart[n-i]
    else
      bestr[n-i-1] = rsum[n-i-1]
      bstart[n-i-1] = n-i-1
    end
  end
end

max=0
besta=0
bestb=0
for i in k-1..n-k-1
  s = sum[i]+bestr[i+1]
  if max < s
    max = s
    besta=i
    bestb=bstart[i+1]
  end
end

#p sum
#p rsum
#p bestr
#p bstart
puts "#{besta+2-k} #{bestb+1}"

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap, pos, heap_pos)
	x = heap.pop
	return if heap.length == 0
	heap[pos] = x
	heap_pos[-heap[pos][1]] = pos
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos+1] <=> heap[child_pos]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
		heap_pos[-heap[pos][1]] = pos
		heap_pos[-heap[child_pos][1]] = child_pos
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
heap_pos = {}
heap.each_with_index do |item, i|
	sum, key = item
	heap_pos[-key] = i
end
best_indices = nil
(0..n-2*k).each do |i|
	value, j = heap[0]
	score = sums[i] + value
	if score > best_score
		best_indices = [i+1, -j+1]
		best_score = score
	end
	remove(heap, heap_pos[i+k], heap_pos)
end
puts best_indices.join(' ')

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
left, right = 0, k
best_score = sums[left] + sums[right]
best_left, best_right = left, right
while right != n-k
	right += 1
	(right..n-k).each do |seek|
		right = seek if sums[seek] > sums[right]
	end
	left += 1
	(left..right-k).each do |seek|
		left = seek if sums[seek] > sums[left]
	end
	score = sums[left]+sums[right]
	if score > best_score
		best_score, best_left, best_right = score, left, right
	end
end
puts '%d %d' % [best_left+1, best_right+1]
puts best_score

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
a, b = 0, k
(1..n-k).each do |i|
	sum = sums[i]
	if sum > sums[a] and (i-b).abs >= k
		if (i-a).abs >= k and (sums[b] < sums[a] or (sums[b] == sums[a] and b > a))
			b = i
		else
			a = i
		end
	elsif sum > sums[b] and (i-a).abs >= k
		b = i
	end
end
puts '%d %d' % [[a, b].min + 1, [a, b].max + 1]

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap, pos, heap_pos)
	x = heap.pop
	return if pos == heap.length
	heap[pos] = x
	heap_pos[-heap[pos][1]] = pos
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
		heap_pos[-heap[pos][1]] = pos
		heap_pos[-heap[child_pos][1]] = child_pos
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
heap_pos = {}
heap.each_with_index do |item, i|
	sum, key = item
	heap_pos[-key] = i
end
best_a, best_b = nil, nil
(0..n-2*k).each do |a|
	sum, b = heap[0]
	score = sums[a] + sum
	if score > best_score
		best_a, best_b = a+1, -b+1
		best_score = score
	end
	remove(heap, heap_pos[a+k], heap_pos)
end
puts '%d %d' % [best_a, best_b]
#puts best_score

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap)
	x = heap.pop
	return if heap.length == 0
	heap[0] = x
	pos = 0
	while true
		child_pos = 2*pos+1
		break if child_pos >= x.length
		if child_pos+1 < x.length and heap[child_pos+1] > heap[child_pos]
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
best_indices = nil
(0..n-2*k).each do |i|
	score, j = heap[0]
	if score > best_score
		best_indices = [i+1, -j+1]
		best_score = score
	end
end
puts best_indices.join(' ')

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
a, b = 0, k
(k+1..n-k).each do |i|
	sum = sums[i]
	if sum > sums[a] and i-b >= k
		if sums[b] < sums[a] and i-a >= k
			b = i
		else
			a = i
		end
	elsif sum > sums[b] and i-a >= k
		b = i
	end
end
puts '%d %d' % [[a, b].min + 1, [a, b].max + 1]

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap, pos, heap_pos)
	x = heap.pop
	return if pos == heap.length
	heap[pos] = x
	heap_pos[-heap[pos][1]] = pos
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
		heap_pos[-heap[pos][1]] = pos
		heap_pos[-heap[child_pos][1]] = child_pos
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
heap_pos = {}
heap.each_with_index do |item, i|
	sum, key = item
	heap_pos[-key] = i
end
best_a, best_b = nil, nil
(0..n-2*k).each do |a|
	sum, b = heap[0]
	score = sums[a] + sum
	if score > best_score
		best_a, best_b = a+1, -b+1
		best_score = score
	end
	remove(heap, heap_pos[a+k], heap_pos)
end
puts '%d %d' % [best_a, best_b]
puts best_score

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap, pos, heap_pos)
	x = heap.pop
	return if heap.length == 0
	heap[pos] = x
	heap_pos[-heap[pos][1]] = pos
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
		heap_pos[-heap[pos][1]] = pos
		heap_pos[-heap[child_pos][1]] = child_pos
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
heap_pos = {}
heap.each_with_index do |item, i|
	sum, key = item
	heap_pos[-key] = i
end
best_indices = nil
(0..n-2*k).each do |i|
	value, j = heap[0]
	score = sums[i] + value
	if score > best_score
		best_indices = [i+1, -j+1]
		best_score = score
	end
	remove(heap, heap_pos[i+k], heap_pos)
end
puts best_indices.join(' ')

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap, pos, heap_pos)
	x = heap.pop
	return if heap.length == 0
	heap[pos] = x
	heap_pos[-heap[pos][1]] = pos
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
		heap_pos[-heap[pos][1]] = pos
		heap_pos[-heap[child_pos][1]] = child_pos
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
heap_pos = {}
heap.each_with_index do |item, i|
	sum, key = item
	heap_pos[-key] = i
end
best_a, best_b = nil, nil
(0..n-2*k).each do |a|
	sum, b = heap[0]
	score = sums[a] + sum
	if score > best_score
		best_a, best_b = a+1, -b+1
		best_score = score
	end
	remove(heap, heap_pos[a+k], heap_pos)
end
puts '%d %d' % [best_a, best_b]
puts best_score

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
best = [[sum, 0]]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
	if sum <= best[-1][0]
		best.push(best[-1])
	else
		best.push([sum, i-k+1])
	end
end
left, right = 0, k
(k+1..n-k).each do |i|
	if best[i-k][0] + sums[i] > sums[left] + sums[right]
		left, right = best[i-k][1], i
	end
end
puts '%d %d' % [left+1, right+1]
puts sums[left] + sums[right]

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap, pos, heap_pos)
	x = heap.pop
	return if heap.length == 0
	heap[pos] = x
	heap_pos[-heap[pos][1]] = pos
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos] <=> heap[child_pos+1]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
		heap_pos[-heap[pos][1]] = pos
		heap_pos[-heap[child_pos][1]] = child_pos
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
heap_pos = {}
heap.each_with_index do |item, i|
	sum, key = item
	heap_pos[-key] = i
end
best_a, best_b = nil, nil
(0..n-2*k).each do |a|
	sum, b = heap[0]
	score = sums[a] + sum
	if score > best_score
		best_a, best_b = a+1, -b+1
		best_score = score
	end
	remove(heap, heap_pos[a+k], heap_pos)
end
puts '%d %d' % [best_a, best_b]
#puts best_score

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
best_score = -1
best_left, best_right = -1, -1
left, right = nil, k-1
while right != n-k
	left = right-k+1
	right += 1
	(right..n-k).each do |seek|
		right = seek if sums[seek] > sums[right]
	end
	(left..right-k).each do |seek|
		left = seek if sums[seek] > sums[left]
	end
	break if 2*[sums[left], sums[right]].max <= best_score
	score = sums[left]+sums[right]
	if score > best_score
		best_score, best_left, best_right = score, left, right
	end
end
puts '%d %d' % [best_left+1, best_right+1]

def add(heap, x)
	heap.push(x)
	pos = heap.length-1
	while pos != 0
		parent_pos = (pos-1)/2
		break if (heap[parent_pos] <=> x) >= 0
		heap[parent_pos], heap[pos] = heap[pos], heap[parent_pos]
		pos  = parent_pos
	end
end
def remove(heap)
	x = heap.pop
	return if heap.length == 0
	heap[0] = x
	pos = 0
	while true
		child_pos = 2*pos+1
		break if child_pos >= heap.length
		if child_pos+1 < heap.length and (heap[child_pos+1] <=> heap[child_pos]) == -1
			child_pos = child_pos+1
		end
		break if (heap[pos] <=> heap[child_pos]) >= 0
		heap[child_pos], heap[pos] = heap[pos], heap[child_pos]
	end
end

n, k = STDIN.readline.split.map {|s| s.to_i }
values = STDIN.readline.split.map {|s| s.to_i }
sum = values[0..k-1].inject(:+)
sums = [sum]
(k..n-1).each do |i|
	sum += values[i] - values[i-k]
	sums.push(sum)
end
heap = []
(k..n-k).each {|i| add(heap, [sums[i], -i]) }
best_score = 0
best_indices = nil
(0..n-2*k).each do |i|
	value, j = heap[0]
	score = sums[i] + value
	if score > best_score
		best_indices = [i+1, -j+1]
		best_score = score
	end
	remove(heap)
end
puts best_indices.join(' ')


x = gets.chomp.to_i;
a = gets.strip.split(' ').map(&:to_i);

a = a.sort;
for i in 0 ... (x - 1) / 2
	a[i] = 0;
	a[a.length - i - 1] = 0;
end

a.each do |num|
	if num != 0
		puts num;
		exit;
	end

end

# cook your code here

n = gets.to_i

arr = gets.split.map { |x| x.to_i }

arr = arr.sort!

puts arr[(n-1)/2]

n = gets.to_i
as = gets.split.map(&:to_i)
puts as.sort[(n.to_f/2).ceil-1]

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i).sort
x = n / 2
x -= 1 if n.even?
puts a[x]

# -*- coding: utf-8 -*-

n = gets.to_i
ar = gets.split.map(&:to_i)
ar.sort!
if n.odd?
    puts ar[n/2]
else
    puts ar[n/2 - 1]
end

r = -> { gets.split.map &:to_i }

n = r[].first

arr = r[].sort

p arr[(n - 1) / 2]

n = gets.to_i
puts gets.split.map(&:to_i).sort[(n - 1) / 2]

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i).sort
puts a[n / 2]

x = gets.chomp.to_i;
a = gets.strip.split(' ').map(&:to_i);

for i in 0 ... x / 2
	a[i] = 0;
	a[a.length - i - 1] = 0;
end

a.each do |num|
	if num.nonzero?
		puts num;
		exit;
	end

end

x = gets.chomp.to_i;
a = gets.strip.split(' ').map(&:to_i);

a = a.sort;
for i in 0 ... x / 2
	a[i] = 0;
	a[a.length - i - 1] = 0;
end

a.each do |num|
	if num != 0
		puts num;
		exit;
	end

end


t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    hash = Hash.new(0)
    a.each do |i|
        ii = i.to_s(2).size
        hash[ii] += 1
    end
    count = 0
    hash.each do |i,j|
        if j >= 2
            ans = (j * (j-1)) / 2
            count += ans
        end
    end
    puts count
end

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)

  ans = 0
  counter = Hash.new(0)

  a.each do |x|
    l = x.to_s(2).size
    ans += counter[l]
    counter[l] += 1
  end

  puts ans
end


r = []
gets.to_i.times { |i|
ar = gets.split(' ').map{ |x| x.to_i }
if ar[0] != 0 then  r.push(Rational(-ar[1], ar[0])); end
}

puts r.uniq.size

#!/usr/bin/ruby
require 'set'
n = $stdin.gets.to_i
s = Set.new
n.times do |i|
  k, b = *$stdin.gets.split.map(&:to_i)
  if k != 0
    s.add -b.to_r/k
  end
end
puts s.size

#!/usr/bin/ruby
n = $stdin.gets.to_i
h = Hash.new { |h, k| h[k] = [] }
n.times do
  k, b = *$stdin.gets.split.map(&:to_i)
  if k != 0
    h[-b.to_r/k].push k
  end
end
ans = 0
h.values.each do |a|
  if a.inject(0, :+) != 0
    ans += 1
  end
end
puts ans

#!/usr/bin/ruby
n = $stdin.gets.to_i
h = Hash.new { |h, k| h[k] = [] }
n.times do
  k, b = *$stdin.gets.split.map(&:to_i)
  if k != 0
    h[b.to_r/k].push k
  end
end
ans = 0
h.values.each do |a|
  x = 0
  y = 0
  a.each do |k|
    x += k
  end
  if x != 0
    ans += 1
  end
end
puts ans


#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

# c.rb

def main()
    n, a = gets.chomp.split(" ").map{|s| next s.to_i }
    d = gets.chomp.split(" ").map{|s| next s.to_i }
    s = d.inject{|ret, i| next ret + i }
    r = []
    d.each_with_index do |di, i|
        ss = s - di
        least = [1, a - ss].max
        most = [di, a - (n - 1)].min
        cand = most - least + 1
        r << di - cand
    end

    puts(r * " ")
end

if __FILE__ == $0 then
    main()
end

n,a = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
sum = d.inject(:+)

ans = d.map do |di|
  less = [0, a - (sum - di) - 1].max
  more = [0, di - (a - (n - 1))].max

  less + more
end

puts ans.join(' ')

n, sum = gets.split(' ').map(&:to_i)
ds = gets.split(' ').map(&:to_i)
max = ds.reduce(:+)

n.times do |i|
  d = ds[i]
  other_max = max-d

  my_min = 1
  if sum > other_max
    my_min = sum-other_max
  end
  my_max = [sum - (n-1), d].min

  print ' ' if i != 0
  print (d - [(my_max-my_min+1), 0].max)
end
print "\n"


l, r, k = gets.chomp.split(' ').map(&:to_i)

ans = []

power = 1

while power <= r do
  if power >= l then
    ans << power
  end
  power *= k
end

if ans.size == 0 then
  puts -1
else
  puts ans.join(' ')
end

l, r, k = gets.split.map(&:to_i)

a = 1

a *= k while a < l

f = true

while a <= r
  print " " if not f
  f = false
  print a
  a *= k
end

if f
  puts "-1"
elsif
  puts
end

l, r, k = gets.split.map(&:to_i)
x = 1
done = 0
while x<=r
    if x>=l
        print(x," ")
        done=1
    end
    x*=k
end

if done==0
    p -1
end

    require 'scanf'

	x=scanf("%d")[0]
    y=scanf("%d")[0]
    k=scanf("%d")[0]
	o=1
	ch=1
	while o<x

		o*=k
	end
	while o>=x&&o<=y

		print o
        print " "
		o*=k
		ch=0
	end
	if ch==1
		puts -1
	end

require 'scanf'

while s = $stdin.gets() do
  l, r, k = s.scanf("%d %d %d")
  n = 1
  f = false
  while n <= r do
    if l <= n && n <= r then
      if f then
        print(" ")
      end
      f = true
      print(n)
    end
    n *= k;
  end
  if f then
    puts("");
  else
    puts("-1");
  end
end

l,r,k = gets.chomp.split.map(&:to_i)
ans = []
c = 1
while c <= r
  ans << c if l <= c
  c *= k
end

puts ans.size == 0 ? -1 : ans.join(" ")

#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end
############################################################

l, r, k = gis
v = 1
a = []
loop do
    if v <= r
        a << v if v >= l
    else
        break
    end
    v *= k
end

if a.empty?
    puts '-1'
else
    puts a * " "
end

l,r,k=gets.split.map(&:to_i)
a=[]
64.times{|i|a.push k**i if k**i>=l&&k**i<=r}
puts (a.last)? a.join(' '):-1

a=gets.chomp.split(" ").map{|i| i.to_i}

ans=0
i=0
loop do
if a[2]**i>=a[0] && a[2]**i<=a[1]
printf "#{a[2]**i} "
ans+=1
end
i+=1
break if a[2]**i>a[1]
end
if ans==0
puts "-1"
end

l,r,k=gets.split.map(&:to_i)
ans=[]
64.times do |i|
	break if k**i>r
	ans.push k**i if k**i>=l
end
ans=[-1] if !ans.last
puts ans.join(' ')

l, r, k = gets.chomp.split.map(&:to_i)

ll = (Math.log(l) / Math.log(k)).round
lr = (Math.log(r) / Math.log(k)).round
ns = (ll..lr).map { |x| k**x }.select { |x| l <= x && x <= r }

if ns.size == 0
  puts -1
else
  puts ns.*' '
end

def solve(l, r, k)
   ans = []
   p = 0
   while k**p <= r do
      ans << k**p
      p+= 1
   end
   ret = []
   for i in ans do
      if i >= l && i <= r
          ret << i
      end
   end
   return -1 if ret.length == 0
   return ret.join(' ')
end
l, r, k = gets.strip.split(" ").map(&:to_i)
puts solve(l, r, k)

s = gets.to_s

m = Array.new(s.split(" "))

l = m[0].to_i
r = m[1].to_i
k = m[2].to_i

s = ""

for i in 0 ... 74
	p = k ** i
	if l <= p && p <= r
		s += (p.to_s + " ")
	end
end

if s == "" then puts "-1"
else puts s end

a = gets.chomp.split(" ").map{|x| x.to_i}
kek = 0
purkka = false
a[1].times do |i|
  s = a[2] ** i
  if s <= a[1] and s >= a[0]
     puts s
     purkka = true
  elsif (s > a[1])
    break
  end
end
puts "-1" if not purkka

#!/usr/bin/ruby

l,r,k = gets.strip.split.map {|num| num.to_i}

num = k
while num < l do
	num *= k
end

if l == 1
	num = 1
end

if l <= num and num <= r
	while l <= num and num <= r do
		print num
		print ' '
		num *= k
	end
	puts ''
else
	puts -1
end

numbers = gets.split(" ")
first = numbers[0].to_i
last = numbers[1].to_i
potencial = numbers[2].to_i
res = ""
first_exponencial = Math.log10(first)/Math.log10(potencial)
last_exponencial = Math.log(last)/Math.log10(potencial)
array = []
if first_exponencial - first_exponencial.to_i > 0
	first_exponent  = first_exponencial.to_i + 1
else
	first_exponent = first_exponencial.to_i
end
for i in first_exponent.to_i..last_exponencial.to_i
	if potencial ** i <= last && potencial**i >= first
		array << potencial ** i
	end
end
array.each do |current|
	res << current.to_s + " "
end
if array.size == 0
	puts "-1"
else
	puts res
end

l, r, k = gets.chomp.split(" ").map(&:to_i)

from = Math.log(l, k)
to = Math.log(r, k)

a = ((from.floor)..(to.ceil)).to_a.map{|i| k**i}.keep_if{|i| i >= l and i <= r}
if a.length == 0 then
  puts -1
else
  puts a.join(" ")
end

input = gets.chomp
i = input.split(" ")

l = i[0].to_i
r = i[1].to_i
k = i[2].to_i

aux = 1
flag = false

while aux<=r
	if aux>=l
		flag = true
		print "#{aux} "
	end
	aux *= k
end

if !flag
	print "-1 "
end

print "\n"

l,r,k = gets.split.map(&:to_i)

x=1
t=0

60.times{
    if (x>=l && x<=r)
        print x , " "
        t=1
    end

    x=x*k
    if (x>r) then break; end
}

if (t==0)
    print -1
end

class Solver
	def main
		l, r, k = gets.split.map { |x| x.to_i }
		ans = []
		64.times do |i|
			x = k ** i
			ans << x if x.between? l, r
		end
		if ans.empty?
			puts -1
		else
			puts ans.join ' '
		end
	end
end

Solver.new.main

a=gets.chomp.split(" ")
num=a[2].to_i
min=(Math.log(a[0].to_i,num)).ceil
max=(Math.log(a[1].to_i,num)).floor
if min-max==1
puts "-1"
else
min.upto(max) do |i|
printf "#{num**i} "
end
end

def solve(l, r, k)
   if k < l || k > r
       return "-1"
   end
   printed = false
   p = 0
   ans = ""
   while k**p <= r do
        if k**p >= l
           ans << (k**p).to_s << " "
           printed = true
       end
       p += 1
   end
   return "-1" if printed == false
   return ans.strip
end
l, r, k = gets.strip.split(" ").map(&:to_i)
puts solve(l, r, k)

def solve(l, r, k)
   if k < l || k > r
       return "-1"
   end
   printed = false
   p = 0
   ans = ""
   while k**p <= r do
       ans << k**p << " "
       p += 1
       printed = true
   end
   return "-1" if printed == false
   return ans.strip
end
l, r, k = gets.strip.split(" ").map(&:to_i)
puts solve(l, r, k)

def solve(l, r, k)
   if k < l || k > r
       return "-1"
   end
   printed = false
   p = 0
   ans = ""
   while k**p <= r do
       ans << (k**p).to_s << " "
       p += 1
       printed = true
   end
   return "-1" if printed == false
   return ans.strip
end
l, r, k = gets.strip.split(" ").map(&:to_i)
puts solve(l, r, k)

numbers = gets.split(" ")
first = numbers[0].to_i
last = numbers[1].to_i
potencial = numbers[2].to_i
res = ""
first_exponencial = Math.log10(first)/Math.log10(potencial)
last_exponencial = Math.log(last)/Math.log10(potencial)
array = []
if first_exponencial - first_exponencial.to_i > 0
	first_exponent  = first_exponencial.to_i + 1.0
else
	first_exponent = first_exponencial.to_i
end
for i in first_exponent.to_i..last_exponencial.to_i
	if potencial ** i <= last + 1
		array << potencial ** i
	end
end
array.each do |current|
	res << current.to_s + " "
end
if array.size == 0
	puts "-1"
else
	puts res
end

numbers = gets.split(" ")
first = numbers[0].to_i
last = numbers[1].to_i
potencial = numbers[2].to_i
res = ""
first_exponencial = Math.log(first, potencial)
last_exponencial = Math.log(last, potencial)
array = []
if first_exponencial - first_exponencial.to_i > 0
	first_exponent  = first_exponencial.to_i + 1
else
	first_exponent = first_exponencial.to_i
end
for i in first_exponent.to_i..last_exponencial.to_i
	if potencial ** i <= last
		array << potencial ** i
	end
end
array.each do |current|
	res << current.to_s + " "
end
if array.size == 0
	puts "-1"
else
	puts res
end

numbers = gets.split(" ")
first = numbers[0].to_i
last = numbers[1].to_i
potencial = numbers[2].to_i
res = ""
first_exponencial = Math.log(first, potencial)
last_exponencial = Math.log(last, potencial)
array = []
if first_exponencial - first_exponencial.to_i > 0
	first_exponent  = first_exponencial.to_i + 1
else
	first_exponent = first_exponencial.to_i
end
for i in first_exponent.to_i..last_exponencial.to_i
	if potencial ** i < last
		array << potencial ** i
	end
end
array.each do |current|
	res << current.to_s + " "
end
if array.size == 0
	puts "-1"
else
	puts res
end

numbers = gets.split(" ")
first = numbers[0].to_i
last = numbers[1].to_i
potencial = numbers[2].to_i
res = ""
first_exponencial = Math.log(first, potencial)
last_exponencial = Math.log(last, potencial)
array = []
if first_exponencial - first_exponencial.to_i > 0
	first_exponent  = first_exponencial.to_i + 1
else
	first_exponent = first_exponencial.to_i
end
for i in first_exponent.to_i..last_exponencial.to_i
	array << potencial ** i
end
array.each do |current|
	res << current.to_s + " "
end
if array.size == 0
	puts "-1"
else
	puts res
end

numbers = gets.split(" ")
first = numbers[0].to_i
last = numbers[1].to_i
potencial = numbers[2].to_i
res = ""
first_exponencial = Math.log10(first)/Math.log10(potencial)
last_exponencial = Math.log(last)/Math.log10(potencial)
array = []
if first_exponencial - first_exponencial.to_i > 0
	first_exponent  = first_exponencial.to_i + 1
else
	first_exponent = first_exponencial.to_i
end
for i in first_exponent.to_i..last_exponencial.to_i
	if potencial ** i <= last
		array << potencial ** i
	end
end
array.each do |current|
	res << current.to_s + " "
end
if array.size == 0
	puts "-1"
else
	puts res
end

l, r, k = gets.chomp.split(" ").map(&:to_i)

from = Math.log(l, k)
to = Math.log(r, k)

if to.floor - from.ceil <= 0 then
  puts -1
else
  puts ((from.ceil)..(to.floor)).to_a.map{|i| k**i}.join(" ")
end


gets
m=$<.map{|e|e.chomp.split.map(&:to_i)}
p [m,m.transpose].reduce(0){|r,m|
 c=0
 m.each{|e|
  s=e.count 1
  l=e.size
  if s==1
   c+=l-1
  elsif s>1
   x=e.index 1
   y=e.reverse.index 1
   c+=x+2*(l-(x+y)-s)+y
  end
 }
 r+c
}

def f(m)
 c=0
 m.each{|e|
  s=e.count 1
  l=e.size
  if s==1
   c+=l-1
  elsif s>1
   x=e.index 1
   y=e.reverse.index 1
   c+=x+2*(l-(x+y)-s)+y
  end
 }
 c
end
gets
m=$<.map{|e|e.chomp.split.map(&:to_i)}
p f(m)+f(m.transpose)

H,W=gets.split.map(&:to_i)
m=$<.map{|e|e.chomp.tr(' ','').chars}
col=m.map{|e|e.join.to_i(2)}.reduce(:&)
row=m.transpose.map{|e|e.join.to_i(2)}.reduce(:&)
r=0
H.times{|h|W.times{|w|
 r+=1 if m[h][w]=='0' and col[w]>0||row[h]>0
}}
p r


t = gets.chomp.to_i
while t>0 do
    tmp = gets.chomp.split(" ")
    n = tmp[0].to_i
    k = tmp[1].to_i
    a = gets.chomp.split(" ")
    cnt = Array.new(205,0)
    for i in 0..n-1
        cnt[a[i].to_i] += 1
    end
    ans = 1
    while k>=0 do
        if cnt[ans]==0 then
            k -= 1
        end
        ans += 1
    end
    puts ans-2
    t -= 1
end

t = gets.to_i
t.times do
  n, x = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i).sort.uniq
  v = 0
  a.each do |aa|
    if aa - (v + 1) <= x
      x -= aa - (v + 1)
      v = aa
    else
      break
    end
  end
  v += x
  puts v
end

t = gets.chomp.to_i
while t>0 do
    tmp = gets.chomp.split(" ")
    n = tmp[0].to_i
    k = tmp[1].to_i
    a = gets.chomp.split(" ")
    cnt = Array.new(205,0)
    for i in 0..n-1
        cnt[a[i].to_i] += 1
    end
    ans = 1
    while k>=0 do
        if cnt[ans]==0 then
            k -= 1
        end
        ans += 1
    end
    puts ans-1
    t -= 1
end


input = File.open("input.txt", "r")
output = File.open("output.txt", "w")

n, k = input.gets.split.map(&:to_i)
rin = input.gets.split

a = Array.new
for i in 0...n
  a << [rin[i].to_i, i+1]
end

a.sort! {|x, y| x[0] <=> y[0]}
a = a.drop(n-k)
output.puts a[0][0]

a.sort! {|x, y| x[1] <=> y[1]}
a.each {|x| output.print x[1], " "}

input.close
output.close

$stdin=File.open('input.txt')
$stdout=File.open('output.txt','w')
(n,k),a=gets.split.map(&:to_i),gets.split.map(&:to_i)
z=p a.sort[-k]
b=[]
n.times{|i|
	b<<i+1 if a[i]>=z
}
puts b.sort[0...k]*' '

File.open("input.txt", "r") do |input|
	File.open("output.txt", "w") do |output|
		n, k = input.readline.split.map(&:to_i)
		output << input.readline.split.map(&:to_i).zip((1..n).to_a).sort {|x, y| y.first <=> x.first}.take(k).reduce([101, []]) { |s, (x, y)|
			[[s.first, x].min, s.last + [y]]
		}.join(' ')
	end
end

if ENV['USER'] != 'watashi'
  $stdin = open('input.txt')
  $> = open('output.txt', 'w')
end

I = ->{gets.split.map(&:to_i)}
n, m = I[]
a = I[].zip([*1..n]).sort[n - m, m]
p a[0][0]
puts a.map{|_| _[1]} * ' '

$stdin=File.open('input.txt')
$stdout=File.open('output.txt', 'w')
a,b=Array.new,Array.new
n,a=gets.split.map(&:to_i)[1],gets.split.map(&:to_i)
puts a.sort[-n]
n.times do
b<<a.index(a.max)+1
a[a.index(a.max)]=-1
end
b.reverse!
puts b.sort.join(" ")

$stdin=open("input.txt")
$stdout=open("output.txt","w")
def search(a,b,n)
	n.times do |i|
		if a[i]==b
			a[i]=101
			return i+1
		end
	end
end
n,k=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
b=a.sort
puts b[n-k]
for i in (n-k)...n
	print("#{search(a,b[i],n)} ")
end
puts

$stdin=File.open('input.txt')
$stdout=File.open('output.txt','w')
n, m = gets.split.map{|i| i.to_i}
a = gets.split.map{|i| i.to_i}
p mins = a.sort[-m]
b = []
n.times do |i|
  b << i + 1 if a[i] >= mins
end
puts b.sort[0...m]*' '

n = 0
k = 0
arr = []
open("input.txt") {|f|
  n, k = f.gets.split.map(&:to_i)
  arr = f.gets.to_s.chomp.split.map(&:to_i)
}
File.open("output.txt", "w"){|f|
  arr2 = []
  i = 0
  arr.each do |a|
    i += 1
    arr2.push([i, a])
  end
  arr2.sort! {|a,b| a[1] <=> b[1] }
  f.write "#{arr2[n-k][1]}\n"
  k.times do |i|
    f.write "#{arr2[n-k+i][0]}"
    if i != k-1
      f.write " "
    else
      f.write "\n" if i == k-1
    end
  end
}

n,k=0
a=[]
File.open("input.txt") { |f|
    n,k=f.gets.split.map(&:to_i)
    a=f.gets.split.map(&:to_i)
}
b=[]
a.each_with_index do |v,i|
    b.push([-v,i+1])
end
b.sort!
File.open("output.txt", "w") { |f|
    f.puts -b[k-1][0]
    for i in 0..k-1
        f.print "#{b[i][1]} "
    end
}

line = File.read("input.txt")

inputs = line.split("\n")

n,k = inputs[0].split(" ").map(&:to_i)
arr = inputs[1].split(" ").map(&:to_i)
list = arr.each_with_index.map { |a,i| [a,i]  }

list.sort!
# puts "#{list.min}"
ans = list[((-k)..-1)]

File.open("output.txt", 'w') { |file|
	file.puts "#{ans.min[0]}"
	file.puts ans.map { |e| e[1]+1  }.join(" ")
}

input = File.open("input.txt", "r")
output = File.open("output.txt", "w")

n, k = input.gets.split.map(&:to_i)
rin = input.gets.split

a = Array.new
for i in 0...n
  a << [rin[i].to_i, i+1]
end

a.sort! {|x, y| x[0] <=> y[0]}
a = a.drop(n-k)
puts a[0][0]

a.sort! {|x, y| x[1] <=> y[1]}
a.each {|x| print x[1], " "}

input.close
output.close

$stdin=File.open('input.txt')
$stdout=File.open('output.txt','w')
n, m = gets.split.map{|i| i.to_i}
a = gets.split.map{|i| i.to_i}
p mins = a.sort[-m]
b = []
n.times do |i|
  b << i + 1 if a[i] >= mins
end
puts b.join " "

$stdin=File.open('input.txt')
$stdout=File.open('output.txt','w')
n, m = gets.split.map{|i| i.to_i}
a = gets.split.map{|i| i.to_i}
p a.sort
p mins = a.sort[-m]
b = []
n.times do |i|
  b << i + 1 if a[i] >= mins
end
puts b.join " "

n,k=0
a=[]
File.open("input.txt") { |f|
    n,k=f.gets.split.map(&:to_i)
    a=f.gets.split.map(&:to_i)
}
b=[]
a.each_with_index do |v,i|
    b.push([-v,i+1])
end
b.sort!
File.open("output.txt", "w") { |f|
    for i in 0..k-1
        f.print "#{b[i][1]} "
    end
}


require "Prime"
a=gets.chomp.to_i
b=(Math.sqrt(a)).floor
sp=[]
p=[]
Prime.each(a) do|i|
if i<=b
sp<<i
else
p<<i
end
end
ad=[]
sp.each do |i|
temp=[]
pow=1
loop do
if i**pow<=a
temp<<(i**pow)
pow+=1
else
break
end
end
ad=ad+temp
end
ans=ad+p
puts "#{ans.length}"
ans.each {|i| printf "#{i} "}

n = gets.chomp.to_i

ps = [2]
for i in 3..1000
  f = true
  for j in 0..ps.size-1
    if i % ps[j] == 0
      f = false
      break
    end
  end
  ps << i if f
end

ys = []
ps.each do |p|
  q = 1
  while p ** q <= n
    ys << p**q
    q += 1
  end
end

puts ys.size
puts ys.*' '

require 'prime'

class Solver
	def main
		n = gets.to_i
		ans = []
		2.upto(n) do |i|
			if Prime.prime? i
				tmp = i
				while tmp <= n do
					ans << tmp
					tmp *= i
				end
			end
		end
		puts ans.size
		puts ans.join ' '
	end
end
Solver.new.main

def is_prime(x)
	m = (x**0.5).to_i
	for i in (2..m)
		if x % i == 0
			return false
		end
	end
	return true
end

n = gets.chomp.to_i
ans = []

for i in (2..n)
	if is_prime(i)
		j = i
		while j <= n
			ans << j
			j *= i
		end
	end
end

puts ans.length
puts ans.join(' ')


n,t = gets.chomp.split(" ").collect! {|x| x.to_i};
line = gets.chomp.split(" ").collect! {|x| x.to_i};

p=0
while p<n and line[p]>t
  p+=1
end

if p==n
	puts 0
	exit
end

first = p
 q = p
max = 1
crt = 1
sum = 0
#puts p
#puts q
#puts line
while q<n

	#puts "- #{q} #{sum}"

	sum += line[q]
    #puts "- #{p} #{q} #{sum}"
	if sum<=t

		if (q-p+1)>max
			max = q-p+1
		end
	else
		while p<=q and sum>t
			sum -= line[p]
			p += 1
		end
	end
	q += 1
end

puts max

def read_next_line
  gets.split.map { |x| x.to_i }
end

n, t = read_next_line
a = read_next_line

p = cur_time = 0
max = -1_000_000_001
for i in 0...n
  cur_time += a[i]
  while cur_time > t
    cur_time -= a[p]
    p += 1
  end
  cur = i - p
  max = cur if cur > max
end
puts max + 1

n, t = gets.split.map(&:to_i)
l=0
r=-1
sum=0
an = 0
a = gets.split.map(&:to_i)
a.each do |key|
	while (sum+key>t)
		sum -= a[l]
		l += 1
	end
	sum += key
	r += 1
	an = [an, r-l+1].max
end
puts an

n, t = gets.split.map(&:to_i)
l=0
r=-1
sum=0
ans = 0
a = gets.split.map(&:to_i)
a.each do |key|
	while (sum+key>t)
		sum -= a[l]
		l += 1
	end
	sum += key
	r += 1
	ans = [ans, r-l+1].max
end
puts ans

#!/usr/bin/ruby1.9

n, t = STDIN.readline.split.collect {|s| s.to_i }
a = STDIN.readline.split.collect {|s| s.to_i }

max = 0
left = right = 0
sum = 0

while right != n
	sum += a[right]
	right += 1
	while sum > t
		sum -= a[left]
		left += 1
	end
	if right-left > max
		max = right-left
	end
end

puts max

n,t=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
s,l,ans=0,0,0
a.count.times do |i|
	s+=a[i]
	while s>t
		s-=a[l]
		l+=1
	end
	d=(i-l+1)
	ans=d if ans<d
end
puts ans

a, b = gets.split(" ")

time = b.to_i

eachBookTime = []

gets.split(" ").each do |item|

    eachBookTime.push item.to_i

end

#eachBookTime = eachBookTime.sort

sum = 0

count = 0

first = 0

max = 0

eachBookTime.each do |item|

    while(sum + item > time && sum > 0)

        sum-=eachBookTime[first]

        first+=1

        count-=1

    end

    if(item < time)

        sum+=item

        count+=1

        max = count if count > max

    else

        sum+=item

        count+=1

    end

end

puts max

def dp(str)
  puts str if false
end

def run
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)

  sum = pos = max = val = 0
  n.times do |i|
    dp "sum = #{sum}, a[pos] = #{a[pos]}"
    while pos < n and a[pos] + sum <= t
      dp "pos = #{pos}"
      sum += a[pos]
      pos = pos + 1
    end

    val = pos - i
    sum -= a[i]
    dp "[in]  i = #{i}, max = #{max}, pos = #{pos}, sum = #{sum}, val = #{val}"
    max = [max, val].max
    dp "[out] i = #{i}, max = #{max}, pos = #{pos}, sum = #{sum}, val = #{val}"
  end

  puts max
end

run if $0 == __FILE__

def run
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)

  sum = pos = max = val = 0
  n.times do |i|
    while pos < n and a[pos] + sum <= t
      sum += a[pos]
      pos += 1
    end

    max = [max, pos - i].max
    sum -= a[i]
  end

  puts max
end

run if $0 == __FILE__

n,m=gets.split.map{|e| e.to_i}
x=gets.split.map{|e| e.to_i}

ans=0
r=0
l=0
sum=x[0]
while r<n && l<n
	while sum>m && l<n
		sum-=x[l]
		l+=1
	end
	while sum<=m && r<n-1
		break if sum+x[r+1]>m
		sum+=x[r+1]
		r+=1
	end
	ans=[ans,r-l+1].max
	#p [l,r,sum,ans]
	break if r==n-1
	sum+=x[r+1]
	r+=1
end
puts ans

# coding: utf-8

# if __FILE__ == $0
# end

def bsearch(arr, b, goal)
    e = arr.length
    while b < e
        mid = (b + e)/2
        if arr[mid] == goal
            b = mid
            break
        elsif arr[mid] < goal
            b = mid
            if e - b == 1
                break
            end
        else
            e = mid
            if e - b == 1
                break
            end
        end
    end
    return b
end

n, t = gets.split.map(&:to_i)
acc = 0
ar = [0]
gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}
i, j = 0, 0 # indexing: [i, j], inclusive range. be careful!
maximum_books = 0
# p ar
loop do
    #p "i: #{i}, ar[i] + t: #{ar[i] + t}"
    nj = bsearch(ar, i, ar[i] + t)
    books = nj - i
    if maximum_books < books
        maximum_books = books
    end
    j = nj
    i += 1
    break if j >= ar.length - 1
end

puts maximum_books

# def get_count(arr,l,r,t)

# 	while l >= 0 && l <= r
# 		m = l + (r-l) / 2
# 		puts "#{l} #{r}"
# 		return 1 if r ==m && arr[m] <= t
# 		if arr[r] - arr[m] > t
# 			l = m + 1
# 		elsif arr[r] - arr[m] < t
# 			if arr[r] - arr[m-1] <= t
# 				l = m - 1
# 			else
# 				puts "less case #{l} #{r} #{m}"
# 				return r - m
# 			end
# 		else
# 			puts "equal case #{l} #{r} #{m}"
# 			return r - m
# 		end
# 	end
# 	return 0
# end

#For each r what is the l such that sum[l..r] <= t and l..r is maximum
# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t
# 	(l..(r-1)).each do |i|
# 		# puts "#{r} #{i}"
# 		return r - i if arr[r] - arr[i] <= t
# 	end
# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t

# 	while l >=0 && l < r
# 		if arr[r] - arr[l] > t
# 			m = l + ((r-l)/2.0).ceil
# 			l = m
# 			# puts "#{l} #{m} #{r} #{l + (r-l)/2}"
# 		elsif arr[r] - arr[l] < t
# 			if l !=0 && arr[r] - arr[l-1] < t
# 				l = l - 1
# 			else
# 				return r - l
# 			end
# 		else
# 			return r - l
# 		end
# 	end

# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	# puts "#{l} #{r}"
# 	return r - l + 1 if arr[r] && arr[r] <= t

# 	while arr[r] && l < r
# 		m = l + (r-l) / 2
# 		if arr[l] + t > arr[r]
# 			r = m
# 		else
# 			if arr[]
# 			 	r =  r + 1
# 		 	else
# 		 		return r - l
# 		 	end

# 		end
# 	end

# 	return 0
# end

def upper_bound(arr,l,r,x)
	best = nil
	while l <= r
		m = (l+r)/2
		# puts "#{l} #{r} #{m}"
		if arr[m] <= x
			best = m
			# puts "m #{arr[m]} x #{x}"
			l = m + 1
		else
			r = m - 1
		end
	end
	return best

end
# puts upper_bound([1,2,3,4,5,6],0,5,10)
# puts upper_bound([1,2,3,6,7,8],0,5,4)
# puts upper_bound([1,2,3,4,5,6],0,5,0)
# puts upper_bound([1,2,3,4,5,6],0,5,9)
n,t = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
sum_arr = [arr[0]]
(1..(n-1)).each do |i|
	sum_arr[i] = sum_arr[i-1] + arr[i]
end
# puts "#{sum_arr}"
max = 0
unless sum_arr[n-1] <= t
	sum_arr.each_with_index{|a,i|
		# val = get_count(sum_arr,i,n-1,t)
		up = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)
	 	if up
			val = up - i
		# puts "#{sum_arr[i]+t}"
			# val = 1 if up == i && arr[i] <= t
		end
		max = val if val && val > max
	}

else
	max = n
end
# 1 2 3 4 5
# 1 3 6 10 15
puts max
#

# Good - 3 days struggle finally accepted - http://canhazcode.blogspot.in/2012/02/we-need-to-talk-about-binary-search.html

# http://codeforces.com/problemset/problem/279/B
n, t = gets.chomp.split.map(&:to_i)
list = gets.chomp.split.map(&:to_i)

max_books = 0
time = 0
l = 0
for r in 0..(list.length - 1)

  while time > t
    time -= list[l]
    l += 1
  end

  time += list[r]
  if time <= t
    max_books = [r - l + 1, max_books].max
  end
end

p max_books

def npos(pos, n)
  (pos + 1) % n
end

def ppos(pos, n)
  (pos - 1 + n) % n
end

def run
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)

  if a.min > t
    puts 0
    return
  end

  list = []
  sum = pos = max = val = 0
  n.times do |i|
    while sum <= t
      if list.length == n
        puts n
        return
      end

      sum += a[pos]
      list << a[pos]
      pos = npos(pos, n)
    end
    pos = ppos(pos, n)
    sum -= a[pos]
    list.pop

    if pos != i
      val = (ppos(pos, n) - i + n) % n + 1
      sum -= a[i]
      list.shift
      max = [max, val].max
    end
  end

  puts max
end

run if $0 == __FILE__

def npos(pos, n)
  (pos + 1) % n
end

def ppos(pos, n)
  (pos - 1 + n) % n
end

def run
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)

  sum = pos = max = 0

  n.times do |i|
    while sum <= t
      sum += a[pos]
      pos = npos(pos, n)
    end
    pos = ppos(pos, n)
    sum -= a[pos]

    val = (ppos(pos, n) - i + n) % n + 1

    max = [max, val].max
    sum -= a[i]
  end

  puts max
end

run if $0 == __FILE__

def npos(pos, n)
  (pos + 1) % n
end

def ppos(pos, n)
  (pos - 1 + n) % n
end

def run
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)

  sum = pos = max = 0

  n.times do |i|
    while sum <= t
      sum += a[pos]
      pos = npos(pos, n)
    end
    pos = ppos(pos, n)
    sum -= a[pos]

    max = [max, ppos(pos, n) - i + 1].max
    sum -= a[i]
  end

  puts max
end

run if $0 == __FILE__

def npos(pos, n)
  (pos + 1) % n
end

def ppos(pos, n)
  (pos - 1 + n) % n
end

def run
  n, t = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)

  if a.min > t
    puts 0
    return
  end

  list = []
  sum = pos = max = val = 0
  n.times do |i|
    while sum <= t
      if list.length == n
        puts n
        return
      end

      sum += a[pos]
      list << a[pos]
      pos = npos(pos, n)
    end
    pos = ppos(pos, n)
    sum -= a[pos]
    list.pop

    if pos == i
      val = (pos - i + n) % n + 1
    else
      val = (ppos(pos, n) - i + n) % n + 1
      sum -= a[i]
      list.shift
    end

    max = [max, val].max
  end

  puts max
end

run if $0 == __FILE__

# coding: utf-8

# if __FILE__ == $0
# end

def bsearch(arr, b, goal)
    e = arr.length
    while b < e
        mid = (b + e)/2
        if arr[mid] == goal
            b = mid
            break
        elsif arr[mid] < goal
            b = mid
            if e - b == 1
                break
            end
        else
            e = mid
            if e - b == 1
                break
            end
        end
    end
    return b
end

n, t = gets.split.map(&:to_i)
acc = 0
ar = []
gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}
i, j = 0, 0 # indexing: [i, j], inclusive range. be careful!
maximum_books = 0
loop do
    nj = bsearch(ar, i, ar[i] + t)
    books = nj - i
    if nj == i && ar[nj] <= t
        books = 1
    end
    if maximum_books < books
        maximum_books = books
    end
    j = nj
    i += 1
    break if  j == (ar.length - 1)
end

puts maximum_books

# coding: utf-8

# if __FILE__ == $0
# end

def bsearch(arr, b, goal)
    e = arr.length
    while b < e
        mid = (b + e)/2
        if arr[mid] == goal
            b = mid
            break
        elsif arr[mid] < goal
            b = mid
            if e - b == 1
                break
            end
        else
            e = mid
            if e - b == 1
                break
            end
        end
    end
    return b
end

n, t = gets.split.map(&:to_i)
acc = 0
ar = []
gets.split.each { |i|
    i = i.to_i
    acc += i
    ar << acc
}
i, j = 0, 0 # indexing: [i, j], inclusive range. be careful!
maximum_books = 0
while j < (ar.length - 1)
    nj = bsearch(ar, i, ar[i] + t)
    if maximum_books < (nj - i)
        maximum_books = nj - i
    end
    j = nj
    i += 1
end

puts maximum_books

# def get_count(arr,l,r,t)

# 	while l >= 0 && l <= r
# 		m = l + (r-l) / 2
# 		puts "#{l} #{r}"
# 		return 1 if r ==m && arr[m] <= t
# 		if arr[r] - arr[m] > t
# 			l = m + 1
# 		elsif arr[r] - arr[m] < t
# 			if arr[r] - arr[m-1] <= t
# 				l = m - 1
# 			else
# 				puts "less case #{l} #{r} #{m}"
# 				return r - m
# 			end
# 		else
# 			puts "equal case #{l} #{r} #{m}"
# 			return r - m
# 		end
# 	end
# 	return 0
# end

#For each r what is the l such that sum[l..r] <= t and l..r is maximum
# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t
# 	(l..(r-1)).each do |i|
# 		# puts "#{r} #{i}"
# 		return r - i if arr[r] - arr[i] <= t
# 	end
# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t

# 	while l >=0 && l < r
# 		if arr[r] - arr[l] > t
# 			m = l + ((r-l)/2.0).ceil
# 			l = m
# 			# puts "#{l} #{m} #{r} #{l + (r-l)/2}"
# 		elsif arr[r] - arr[l] < t
# 			if l !=0 && arr[r] - arr[l-1] < t
# 				l = l - 1
# 			else
# 				return r - l
# 			end
# 		else
# 			return r - l
# 		end
# 	end

# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	# puts "#{l} #{r}"
# 	return r - l + 1 if arr[r] && arr[r] <= t

# 	while arr[r] && l < r
# 		m = l + (r-l) / 2
# 		if arr[l] + t > arr[r]
# 			r = m
# 		else
# 			if arr[]
# 			 	r =  r + 1
# 		 	else
# 		 		return r - l
# 		 	end

# 		end
# 	end

# 	return 0
# end

def upper_bound(arr,l,r,x)
	best = nil
	while l <= r
		m = l + (r-l)/2
		if arr[m] <= x
			best = m
			l = m + 1
		else
			r = m - 1
		end
	end
	return best

end

n,t = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
sum_arr = [arr[0]]
(1..(n-1)).each do |i|
	sum_arr[i] = sum_arr[i-1] + arr[i]
end
# puts "#{sum_arr}"
max = 0
sum_arr.each_with_index{|a,i|
	# val = get_count(sum_arr,i,n-1,t)
	up = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)
	val = up - i if up
	max = val if val && val > max
}

# 1 2 3 4 5
# 1 3 6 10 15
puts max
#

# def get_count(arr,l,r,t)

# 	while l >= 0 && l <= r
# 		m = l + (r-l) / 2
# 		puts "#{l} #{r}"
# 		return 1 if r ==m && arr[m] <= t
# 		if arr[r] - arr[m] > t
# 			l = m + 1
# 		elsif arr[r] - arr[m] < t
# 			if arr[r] - arr[m-1] <= t
# 				l = m - 1
# 			else
# 				puts "less case #{l} #{r} #{m}"
# 				return r - m
# 			end
# 		else
# 			puts "equal case #{l} #{r} #{m}"
# 			return r - m
# 		end
# 	end
# 	return 0
# end

#For each r what is the l such that sum[l..r] <= t and l..r is maximum
# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t
# 	(l..(r-1)).each do |i|
# 		# puts "#{r} #{i}"
# 		return r - i if arr[r] - arr[i] <= t
# 	end
# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t

# 	while l >=0 && l < r
# 		if arr[r] - arr[l] > t
# 			m = l + ((r-l)/2.0).ceil
# 			l = m
# 			# puts "#{l} #{m} #{r} #{l + (r-l)/2}"
# 		elsif arr[r] - arr[l] < t
# 			if l !=0 && arr[r] - arr[l-1] < t
# 				l = l - 1
# 			else
# 				return r - l
# 			end
# 		else
# 			return r - l
# 		end
# 	end

# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	# puts "#{l} #{r}"
# 	return r - l + 1 if arr[r] && arr[r] <= t

# 	while arr[r] && l < r
# 		m = l + (r-l) / 2
# 		if arr[l] + t > arr[r]
# 			r = m
# 		else
# 			if arr[]
# 			 	r =  r + 1
# 		 	else
# 		 		return r - l
# 		 	end

# 		end
# 	end

# 	return 0
# end

def upper_bound(arr,l,r,x)
	best = nil
	while l <= r
		m = l + (r-l)/2
		if arr[m] <= x
			best = m
			l = m + 1
		else
			r = m - 1
		end
	end
	return best

end

n,t = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
sum_arr = [arr[0]]
(1..(n-1)).each do |i|
	sum_arr[i] = sum_arr[i-1] + arr[i]
end
# puts "#{sum_arr}"
max = 0
sum_arr.each_with_index{|a,i|
	# val = get_count(sum_arr,i,n-1,t)
	up = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)
	val = up - i if up
	val = 1 if up == i
	max = val if val && val > max
}

# 1 2 3 4 5
# 1 3 6 10 15
puts max
#

# def get_count(arr,l,r,t)

# 	while l >= 0 && l <= r
# 		m = l + (r-l) / 2
# 		puts "#{l} #{r}"
# 		return 1 if r ==m && arr[m] <= t
# 		if arr[r] - arr[m] > t
# 			l = m + 1
# 		elsif arr[r] - arr[m] < t
# 			if arr[r] - arr[m-1] <= t
# 				l = m - 1
# 			else
# 				puts "less case #{l} #{r} #{m}"
# 				return r - m
# 			end
# 		else
# 			puts "equal case #{l} #{r} #{m}"
# 			return r - m
# 		end
# 	end
# 	return 0
# end

#For each r what is the l such that sum[l..r] <= t and l..r is maximum
# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t
# 	(l..(r-1)).each do |i|
# 		# puts "#{r} #{i}"
# 		return r - i if arr[r] - arr[i] <= t
# 	end
# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	return r - l + 1 if arr[r] <= t

# 	while l >=0 && l < r
# 		if arr[r] - arr[l] > t
# 			m = l + ((r-l)/2.0).ceil
# 			l = m
# 			# puts "#{l} #{m} #{r} #{l + (r-l)/2}"
# 		elsif arr[r] - arr[l] < t
# 			if l !=0 && arr[r] - arr[l-1] < t
# 				l = l - 1
# 			else
# 				return r - l
# 			end
# 		else
# 			return r - l
# 		end
# 	end

# 	return 0
# end

# def get_count(arr,l,r,t)
# 	# return r - l if arr[r] - arr[l] <= t
# 	# puts "#{l} #{r}"
# 	return r - l + 1 if arr[r] && arr[r] <= t

# 	while arr[r] && l < r
# 		m = l + (r-l) / 2
# 		if arr[l] + t > arr[r]
# 			r = m
# 		else
# 			if arr[]
# 			 	r =  r + 1
# 		 	else
# 		 		return r - l
# 		 	end

# 		end
# 	end

# 	return 0
# end

def upper_bound(arr,l,r,x)
	best = nil
	while l <= r
		m = l + (r-l)/2
		if arr[m] <= x
			best = m
			l = m + 1
		else
			r = m - 1
		end
	end
	return best

end

n,t = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
sum_arr = [arr[0]]
(1..(n-1)).each do |i|
	sum_arr[i] = sum_arr[i-1] + arr[i]
end
# puts "#{sum_arr}"
max = 0
sum_arr.each_with_index{|a,i|
	# val = get_count(sum_arr,i,n-1,t)
	up = upper_bound(sum_arr,i,n-1,sum_arr[i]+t)
 	if up
		val = up - i
		val = 1 if up == i && arr[i] <= t
	end
	# puts "#{up}"
	max = val if val && val > max
}

# 1 2 3 4 5
# 1 3 6 10 15
puts max
#

# http://codeforces.com/problemset/problem/279/B
n, t = gets.chomp.split.map(&:to_i)
list = gets.chomp.split.map(&:to_i)

max = 0

time = 0
for i in 0..(n - 1)
  for j in i..(n - 1)
    time += list[j]

    if time > t
      break
    else
      potential = j - i + 1

      if potential > max
        max = potential
      end
    end
  end
end

p max

[3,1,2,1]

def read_next_line
  gets.split.map { |x| x.to_i }
end

n, t = read_next_line
a = read_next_line

max = p = cur_time = 0
for i in 0...n
  cur_time += a[i]
  while cur_time > t
    cur_time -= a[p]
    p += 1
  end
  cur = i - p
  max = cur if cur > max
end
puts max + 1

a, b = gets.split(" ")

time = b.to_i

eachBookTime = []

gets.split(" ").each do |item|

    eachBookTime.push item.to_i

end

sum = 0

count = 0

eachBookTime.each do |item|

    if (sum+item <= time)

        sum += item

        count+=1

    end

end

puts count

a, b = gets.split(" ")

time = b.to_i

eachBookTime = []

gets.split(" ").each do |item|

    eachBookTime.push item.to_i

end

eachBookTime = eachBookTime.sort

sum = 0

count = 0

eachBookTime.each do |item|

    if (sum+item < time)

        sum += item

        count+=1

    end

end

puts count

a, b = gets.split(" ")

time = b.to_i

eachBookTime = []

gets.split(" ").each do |item|

    eachBookTime.push item.to_i

end

eachBookTime = eachBookTime.sort

sum = 0

count = 0

eachBookTime.each do |item|

    if (sum+item <= time)

        sum += item

        count+=1

    end

end

puts count


n,m=gets.chomp.split.collect{|a| a.to_i}
puts ((n-1).gcd(m-1)+1)

require 'mathn'
m, n = gets.chomp.split.map{|s| s.to_i - 1}.sort
puts m.gcd(n) + 1

m, n = gets.chomp.split.map{|s| s.to_i}
puts m == n ? m : 2

m, n = gets.chomp.split.map{|s| s.to_i - 1}.sort
puts n % m == 0 ? m + 1 : 2


gets.to_i.times do
  n = gets.to_i
  if n < 3
    puts 0
  else
    puts n - 2
  end
end

t=gets.to_i
t.times{
        n=gets.to_i
        puts [n-2,0].max
}

gets.to_i.times { p [gets.to_i - 2, 0].max }

gets.to_i.times do
  puts gets.to_i / 3
end

gets.to_i.times do
  n = gets.to_i
  total = n / 4 * 2
  total += 1 if n % 4 == 3
  puts total
end

t=gets.to_i
t.times{
        n=gets.to_i
        puts n-2
}

gets.to_i.times do
	n = gets.to_i
	p n / 4 * 2 + (n % 4 == 3 ? 1 : 0)
end


    line = gets.chomp
    line.gsub!(/ *, */, ', ')
    line.gsub!(/ *\.\.\. */, ' ...')
    line.gsub!(/ +/, ' ')
    line.strip!
    puts line

input = STDIN.readline.gsub(',', ' , ').gsub('...', ' ... ').strip.split(' ').map do |s| s.strip end

spaceIns = true
ishead = true
isPrevNum = false
input.each do |s|
  print ' ' if !ishead && spaceIns
  ishead = false
  case s
  when ','
    print ','
    spaceIns = true
    isPrevNum = false
  when '...'
    print((spaceIns ? '' : ' ') + '...')
    spaceIns = false
    isPrevNum = false
  else
    print((isPrevNum ? ' ' : '') + s)
    spaceIns = false
    isPrevNum = true
  end
end
puts ''

class String
  def is_integer?
    self.to_i.to_s == self
  end
end

def parse(line)
  return line.scan(Regexp.union(/,/, /\.../, /\d*/)).map{ |t| t.strip }.select{ |t| t != '' }
end

def format(tokens)
  acc = ""
  tokens.each_with_index { |val, index|
    if val == ","
      acc << ", "
    elsif val == "..." and acc[-1, 1] == " "
      acc << val
    elsif val == "..."
      acc << " ..."
    elsif val.is_integer? and index > 0 and tokens[index - 1].is_integer?
      acc << " " << val
    else
      acc << val
    end
    }
  return acc.strip
end

def process_line(line)
  tokens = parse(line)
  return format(tokens)
end

input = STDIN.read
lines = input.chomp.split("\n")
lines.map! { |l| puts process_line(l) }

NUMBER_REGEX = /(\d+)/

tokens = gets.strip.gsub(',', ' , ').gsub('...', ' ... ').split

tokens.each_with_index do |token, index|
  if index.zero?
    print token
  else
    print ' ' if tokens[index - 1] == ',' or token == '...'
    print ' ' if tokens[index - 1] =~ NUMBER_REGEX and token =~ NUMBER_REGEX
    print token
  end
end

puts

line = gets.chomp
line.gsub!(/, */, ', ')
line.gsub!(/ *\.\.\./, ' ...')
line.gsub!(/ +/, ' ')
line.strip!
puts line

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

s = gets
elems = s.split(/,/)
elems.map!{|x|
  xx = x.strip
  if xx != "..." && xx =~ /\.\.\./
    xx = xx.gsub(/\.\.\./, " ...")
  end
  xx
}
puts elems.join(', ')

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

s = gets
elems = s.split(/,/)
elems.map!{|x|
  xx = x.strip
  if xx != "..." && xx =~ /\.\.\./
    xx = xx.gsub(/\.\.\./, " ...").lstrip
  end
  xx
}
puts elems.join(', ').strip

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

s = gets
s.gsub!(/\s{1,}/, ' ')
elems = s.split(/,/)
elems.map!{|x|
  xx = x.strip
  if xx != "..." && xx =~ /\.\.\./
    xx = xx.gsub(/\.\.\./, " ...").lstrip
  end
  xx
}
puts elems.join(', ').strip

class String
  def is_integer?
    self.to_i.to_s == self
  end
end

def parse(line)
  return line.scan(Regexp.union(/,/, /\.../, /\d*/)).map{ |t| t.strip }.select{ |t| t != '' }
end

def format(tokens)
  acc = ""
  tokens.each_with_index { |val, index|
    if val == ","
      acc << ", "
    elsif val == "..." and acc[-1, 1] == " "
      acc << val
    elsif val == "..."
      acc << " ..."
    elsif val.is_integer? and index > 1 and tokens[index - 1].is_integer?
      acc << " " << val
    else
      acc << val
    end
    }
  return acc
end

def process_line(line)
  tokens = parse(line)
  return format(tokens)
end

input = STDIN.read
lines = input.chomp.split("\n")
lines.map! { |l| puts process_line(l) }

class String
  def is_integer?
    self.to_i.to_s == self
  end
end

def parse(line)
  return line.scan(Regexp.union(/,/, /\.../, /\d*/)).map{ |t| t.strip }.select{ |t| t != '' }
end

def format(tokens)
#  puts tokens
  acc = ""
  tokens.each_with_index { |val, index|
    if val == ","
      acc << ", "
    elsif val == "..." and acc[-1, 1] == " "
      acc << val
    elsif val == "..."
      acc << " ..."
    elsif val.is_integer? and index > 1 and tokens[index - 1].is_integer?
      acc << " " << val
    else
      acc << val
    end
    }
  puts acc
  return tokens.join("~")
end

def process_line(line)
  puts line
  tokens = parse(line)
  return format(tokens)
end

input = STDIN.read
lines = input.chomp.split("\n")
lines.map! { |l| puts process_line(l) }

class String
  def is_integer?
    self.to_i.to_s == self
  end
end

def parse(line)
  return line.scan(Regexp.union(/,/, /\.../, /\d*/)).map{ |t| t.strip }.select{ |t| t != '' }
end

def format(tokens)
  acc = ""
  tokens.each_with_index { |val, index|
    if val == ","
      acc << ", "
    elsif val == "..." and acc[-1, 1] == " "
      acc << val
    elsif val == "..."
      acc << " ..."
    elsif val.is_integer? and index > 1 and tokens[index - 1].is_integer?
      acc << " " << val
    else
      acc << val
    end
    }
  return acc.strip
end

def process_line(line)
  tokens = parse(line)
  return format(tokens)
end

input = STDIN.read
lines = input.chomp.split("\n")
lines.map! { |l| puts process_line(l) }


k, n, m = gets.split.map(&:to_i)

data = []
k.times do
  gets
  o = []
  n.times do
    o << gets.chomp
  end
  data << o
end

gets
x, y = gets.split.map(&:to_i)

lim = [k, n, m]
q = [[1, x, y]]
used = {}
n = 0
until q.empty?
  pos = q.shift

  next if used[pos]
  next if pos.min < 1 || pos.zip(lim).find{|a,b| a>b}
  next if data[pos[0]-1][pos[1]-1][pos[2]-1] != '.'

  used[pos] = true

  n += 1
  q << [pos[0], pos[1], pos[2]+1]
  q << [pos[0], pos[1], pos[2]-1]
  q << [pos[0], pos[1]+1, pos[2]]
  q << [pos[0], pos[1]-1, pos[2]]
  q << [pos[0]+1, pos[1], pos[2]]
  q << [pos[0]-1, pos[1], pos[2]]

end

p n

#!/usr/bin/env ruby

$k, $n, $m = gets.split.map(&:to_i)
$t = []

def fs(z, x, y)
  stack = [[z, x, y]]
  $t[z][x][y] = '#'
  #puts "dfs #{z} #{x} #{y}"
  result = 1
  while not stack.empty?
    z, x, y = stack.pop
    (-1..1).each do |i|
      (-1..1).each do |j|
        (-1..1).each do |k|
          if [i, j, k].select { |x| x == 0 }.count == 2
            nz, nx, ny = z + i, x + j, y + k
            #puts [i, j, k, nz, nx, ny] * " " + [0 <= nz, nz < t.size, 0 <= nx, nx < t[0].size, ny <= 0, ny < t[0][0].size] * " "
            if 0 <= nz && nz < $k && 0 <= nx && nx < $n && 0 <= ny && ny < $m
              #puts "ok"
              if $t[nz][nx][ny] == '.'
                $t[nz][nx][ny] = '#'
                stack.push([nz, nx, ny])
                result += 1
              end
            end
          end
        end
      end
    end
  end

  return result
end

$k.times do
  gets
  $t << []
  $n.times do
    $t[-1] << gets.chomp
  end
end
gets
x, y = gets.split.map(&:to_i)

#p t, x, y, t.size, t[0].size, t[0][0].size

puts fs(0, x - 1, y - 1)

K, N, M = gets.chomp.split.map{|e| e.to_i}

map = Array.new(K + 1) { Array.new(N + 1) {[]}}

1.upto(K) {|i|
  gets
  1.upto(N) {|j|
    map[i][j].push 0
    tmp = gets.chomp.split('').each {|e|
      map[i][j].push e
    }
  }
}

gets
X, Y = gets.chomp.split.map{|e| e.to_i}

def dfs(map, k, n, m)
  return 0 if (k < 1 || k > K || n < 1 || n > N || m < 1 || m > M)
  return 0 if (map[k][n][m] != ".")

  count = 1
  map[k][n][m] = "0"
  directions = [[0, 0, 1], [0, 0, -1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]]

  directions.each {|e|
    count += dfs(map, k + e[0], n + e[1], m + e[2])
  }

  return count
end

puts dfs(map, 1, X, Y)


N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...N
	cnt = ( nums[ arr[k] ] += 1 )
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts.delete cnt-1 if counts[cnt-1] == 0
		counts[cnt] += 1
	end
#	STDERR.puts "#{nums}"
#	STDERR.puts "#{counts}"
#	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			if counts[1] == 1
				answer = k
			else
				a, b = counts.keys
				answer = k if (a - b).abs == 1 && counts[a > b ? a : b] == 1
			end
		end
	end
end
puts answer + 1

n = readline.to_i
u = readline.split.map(&:to_i)

C = 100000

cs = [0] * C
csr = {0 => n}
csr.default = 0
max_x = 1
(0...n).each do |i|
  ui = u[i] - 1
  c = cs[ui]
  csr[c] -= 1
  csr.delete(c) if csr[c] == 0
  c += 1
  cs[ui] = c
  csr[c] += 1
  if csr.length <= 3 then
    ks = csr.keys
    ks.delete_if { |x| x == 0 }
    if ks.length == 1 and (ks[0] == 1 or csr[ks[0]] == 1)
      max_x = i + 1
    elsif ks.length == 2
      ks = ks.sort
      if (ks[1] == ks[0] + 1 and csr[ks[1]] == 1) or (ks[0] == 1 and csr[ks[0]] == 1)
        max_x = i + 1
      end
    end
  end
end
p max_x

N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...N
	x = arr[k]
	nums[x] += 1
	cnt = nums[x]
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts[cnt] += 1
	end
	counts.delete_if { |key, value| value == 0 }
#	STDERR.puts "#{nums}"
#	STDERR.puts "#{counts}"
#	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			answer = k if counts[1] == 1
			a, b = counts.keys
			if (a - b).abs == 1
				max = a > b ? a : b
				answer = k if counts[max] == 1
			end
		end
	end
end
puts answer + 1

N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...arr.size
	x = arr[k]
	nums[x] += 1
	cnt = nums[x]
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts[cnt] += 1
	end
	counts.delete_if { |key, value| value == 0 }
#	STDERR.puts "#{nums}"
#	STDERR.puts "#{counts}"
#	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			answer = k if counts[1] == 1
			a, b = counts.keys
			answer = k if (a - b).abs == 1
		end
	end
end
puts answer + 1

N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...arr.size
	x = arr[k]
	nums[x] += 1
	cnt = nums[x]
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts[cnt] += 1
	end
	counts.delete_if { |key, value| value == 0 }
	STDERR.puts "#{nums}"
	STDERR.puts "#{counts}"
	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			a, b = counts.keys
			answer = k if (a - b).abs == 1
		end
	end
end
puts answer + 1

N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...N
	cnt = ( nums[ arr[k] ] += 1 )
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts.delete cnt-1 if counts[cnt-1] == 0
		counts[cnt] += 1
	end
#	STDERR.puts "#{nums}"
#	STDERR.puts "#{counts}"
#	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			if counts[1] == 1
				answer = k
			else
				a, b = counts.keys
				answer = k if (a - b).abs == 1 || counts[a > b ? a : b] == 1
			end
		end
	end
end
puts answer + 1

N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...arr.size
	x = arr[k]
	nums[x] += 1
	cnt = nums[x]
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts[cnt] += 1
	end
	counts.delete_if { |key, value| value == 0 }
	STDERR.puts "#{nums}"
	STDERR.puts "#{counts}"
	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			answer = k if counts.key?(1)
			a, b = counts.keys
			answer = k if (a - b).abs == 1
		end
	end
end
puts answer + 1

N = gets.to_i
arr = gets.split.map(&:to_i)
nums = Hash.new(0)
counts = Hash.new(0)
answer = 0
for k in 0...N
	x = arr[k]
	nums[x] += 1
	cnt = nums[x]
	if cnt == 1
		counts[1] += 1
	else
		counts[cnt-1] -= 1
		counts[cnt] += 1
	end
	counts.delete_if { |key, value| value == 0 }
#	STDERR.puts "#{nums}"
#	STDERR.puts "#{counts}"
#	STDERR.puts counts.size
	if counts.size == 1
		answer = k if counts.key?(1) or counts.value?(1)
	elsif counts.size == 2
		if counts.value?(1)
			answer = k if counts[1] == 1
			a, b = counts.keys
			a, b = b, a if counts[a] == 1
			answer = k if b - a == 1
		end
	end
end
puts answer + 1


def Pal(s)
  s == s.reverse
end

s = gets.chomp
puts Pal(s)? s : s + s[0..-2].reverse

a = gets.chomp
a.downcase!
puts a + a.reverse

s = gets.chomp
puts s + s.reverse[0..-1]

s=gets.chomp
print s
for i in (s.size-1).downto(0)
  print s[i]

end


n, i = gets.strip, 0

(print 0; exit) if n.length == 1

loop do
  n = n.split(//).map(&:to_i).inject { |sum, e| sum += e  }.to_s
  (print i + 1; exit) if n.length == 1
  i += 1
end

n = gets.chomp
count = 0
while n.size > 1
  n = n.split(//).inject(0) {|sum, e| sum + e.to_i}.to_s
  count += 1
end
puts count

n = gets.chomp
count = 0
while n.size != 1
  m = 0;
  n.each_byte{|c|
    m += c-48
  }
  n = m.to_s
  count += 1
end
puts count

#!/usr/local/bin/ruby19
ans=0
n=gets.split[0]
while n.length>1
        m=0
        n.each_byte{|c|
                m+=c-48
        }
        ans+=1
        n=m.to_s
end
puts ans

s = gets.chomp
res = 0
while s.length > 1 && res+=1
	s = s.each_char.inject(0){ |sum, i| sum += i.to_i }.to_s
end
puts res

n = gets.chomp.split(//)
i = 0
if n.size == 1
  puts i
  exit
else
  while n.size != 1 do
    n = n.inject(0){ |sum,x| x.to_i + sum }.to_s.split(//)
    i += 1
  end
end
puts i

s = gets.chomp
q = 0
ans = 1
0.upto(s.length - 1).each do |i|
    q += s[i].to_i
end
while q >= 10 do
    nq = 0
    while q != 0 do
        nq += q % 10
        q /= 10
    end
    q = nq
    ans += 1
end

if s.length == 1 then ans = 0 end

print ans

#=================================
if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open(ARGV[0], "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

n=gets.strip

if n.length==1
		puts 0
		exit
end

step=1
loop{
	n=n.split(//).map(&:to_i).inject(:+).to_s

	if n.length==1
		puts step
		exit
	end

	step+=1
}

n = STDIN.read.gsub("\n", "")

steps = 0
while (n.size != 1) do
    digits = n.split("")
    n = digits.inject(0) { |result, digit| result + digit.to_i }.to_s
    steps += 1
end

puts steps

n = gets.chomp
cnt = 0
while(n.length != 1)
   res = 0
   for i in 0...n.length
      res += Integer(n[i])
   end
   n = String(res)
   cnt += 1
end
puts cnt

sn = gets.chop

#n = sn.to_i

count = 0

while (sn.length > 1)
  sum = 0
  (0..sn.length-1).each { |i|
    sum += sn[i].to_i
  }
  sn = sum.to_s
  #puts sn
  count += 1
end

puts count

def sum_of_digits
  n = gets.strip

  count = 0
  while n.length > 1
    sum = n.chars.map{|i| i.to_i}.inject(0){|sum, j| sum+j }
    n = sum.to_s
    count += 1
  end

  p count
end

sum_of_digits

s = gets.chomp
c = 0
while s.size != 1
	s = s.split(//).map(&:to_i).reduce(:+).to_s
	c += 1
end
puts c

s = gets.chomp.split("").collect{|i| i.to_i}
ans = 0
while s.size > 1
    ans += 1
    s = s.inject{|sum,i| sum+=i}.to_s.split("").collect{|i| i.to_i}
end
puts ans

n = gets.chomp
asr = 0
bool = true
while bool do
  if(n.to_i <=9 && n.to_i >= 0)
    bool = false
  else
    begin
      asr += 1
      n = n.to_s.split('').inject(0){ |result, elem| result.to_i + elem.to_i }
    end
  end
end
puts asr

n = gets.chomp
res = 0
for i in 0...n.length
   res += Integer(n[i])
end
puts res

s = gets
c = 0
while s.size != 1
	s = s.split(//).map(&:to_i).reduce(:+).to_s
	c += 1
end
puts c

n = gets.chomp
asr = 0
bool = true
while bool do
  if(n.to_i <=9 && n.to_i >= 0)
    bool = false
  else
    begin
      asr += 1
      n = n.to_s.split('').inject(0){ |result, elem| result.to_i + elem.to_i }
      puts n
    end
  end
end
puts asr

a=gets
($.+=1;a=(a.sum-48*a.size).to_s)while a.size>1
p$.

n, i = gets.strip, 0

(print 0; exit) if n == "0"

loop do
  n = n.split(//).map(&:to_i).inject { |sum, e| sum += e  }.to_s
  (print i + 1; exit) if n.length == 1
  i += 1
end


n = gets.to_i
e = Array.new(n)
e.map!{[]}
ee = []

def gao(e, p, q)
	l = 0
	t = [0, 0]
	e[p].each do |i|
		next if i == q
		ll, dd = gao(e, i, p)
		l = [l, ll].max
		t <<= dd + 1
	end
	t.sort!{|a, b| b <=> a}
	l = [l, t[0] + t[1]].max
	return [l, t[0]]
end

(n - 1).times do
	a, b = gets.split.map{|i| i.to_i - 1}
	e[a] <<= b
	e[b] <<= a
	ee <<= [a, b]
end
ans = 0
ee.each do |p|
	ans = [ans, gao(e, p[0], p[1])[0] * gao(e, p[1], p[0])[0]].max
end
p ans

def gao(e, p, q)
	l, t = 0, [0, 0]
	e[p].each do |i|
		next if i == q
		ll, dd = gao(e, i, p)
		l = [l, ll].max
		t <<= dd + 1
	end
	t.sort!{|a, b| b <=> a}
	return [[l, t[0] + t[1]].max, t[0]]
end

n = gets.to_i
e = Array.new(n).map{[]}
ee = []
(n - 1).times do
	a, b = gets.split.map{|i| i.to_i - 1}
	e[a] <<= b
	e[b] <<= a
	ee <<= [a, b]
end
p ee.map{|p| gao(e, p[0], p[1])[0] * gao(e, p[1], p[0])[0]}.max


def solution
  _ = read_int
  as = read_ints

  current_max = -1

  for i in (0...as.size)
    a = as[i]
    if a > current_max + 1
      puts (i+1)
      return
    end
    current_max = [current_max, a].max
  end

  puts (-1)

end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

class B
  def self.run(n, m)
    prev_max = nil

    m.each_with_index do |el, idx|

      if valid_mexes(prev_max).include?(el)
        prev_max ||= el
        prev_max = prev_max < el ? el : prev_max
      else
        return idx+1
      end

    end

    return -1
  end

  def self.valid_mexes(prev_max)
    if !prev_max
      return [0]
    else
      (0..prev_max+1)
    end
  end
end

a = gets.chomp.to_i
b = gets.chomp.split.map(&:to_i)
puts B.run(a, b)

n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i)

k = 0
arr.each_with_index do |z,i|
  if z>k
    puts i+1
    exit
  elsif z==k
    k+=1
  end
end

puts -1

def solution
  _ = read_int
  as = read_ints

  for i in (0...as.size)
    a = as[i]
    if a > i
      puts (i+1)
      return
    end
  end

  puts (-1)

end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']


hour, minute = gets.split.map(&:to_f)
hunger, dec, bunCost, inc = gets.split.map(&:to_f)
buyNow = hunger/inc*bunCost
buyLater = (hunger + dec*(1200 - ((hour%24)*60+minute)))/inc*(bunCost-(bunCost*0.2))
puts [buyLater,buyNow].min.round(4)

hour, minute = gets.split.map(&:to_i)
hunger, dec, bunCost, inc = gets.split.map(&:to_f)
buyNow = (hunger/inc).ceil*bunCost
buyLater = ((hunger + dec*(1200 - ((hour%24)*60+minute)))/inc).ceil * bunCost
buyLater -= buyLater*0.2
puts hour != 20 ? [buyLater,buyNow].min : buyNow-(buyNow*0.2)

hour, minute = gets.split.map(&:to_i)
hunger, dec, bunCost, inc = gets.split.map(&:to_f)
buyNow = (hunger/inc).ceil*bunCost
buyLater = ((hunger + dec*(1200 - ((hour%24.0)*60+minute)))/inc).ceil * bunCost
buyLater -= buyLater*0.2
puts [buyLater,buyNow].min


t = gets.to_s.to_i

def solve(maxx, maxy, k, cache)
  return k == 0 if maxx == 1 && maxy == 1
  return false if k <= 0 || maxx < 1 || maxy < 1
  maxx, maxy = maxy, maxx if maxx < maxy
  return cache[maxx * 128 + maxy] if cache.has_key?(maxx * 128 + maxy)

  result = solve(maxx - 1, maxy, k - maxy, cache) || solve(maxx, maxy - 1, k - maxx, cache)
  cache[maxx * 128 + maxy] = result
  return result
end

1.upto(t) do |casenum|
  maxx, maxy, k = gets.to_s.split.map {|x| x.to_i }
  printf("%s\n", solve(maxx, maxy, k, {}) ? "YES" : "NO")
end

test_cases = gets.chomp.to_i
for i in 1..test_cases do
    line = gets.chomp.split(" ")
    n = line[0].to_i
    m = line[1].to_i
    k = line[2].to_i
    puts (n - 1) + n * (m - 1) == k ? "Yes" : "No"
end


#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
a = STDIN.readline.split.collect {|s| s.to_i }

b = []
a.each do |x|
	#b.push([(1-x).abs, x])
	b.push(x)
end
b.sort!

#puts b.inspect

sum = 0
n.times do |i|
	#sum += (i+1-b[i][1]).abs
	sum += (i+1-b[i]).abs
end

puts sum

n = gets.to_i;
a = gets.split.map(& :to_i);
cur = 0;
b = a.sort;
p (1..n).inject(0){|acc, x| acc + (x - b[x-1]).abs}
#p a.sort.inject {|acc, x| cur += 1; acc + (cur - x).abs}

n = Integer(gets.chomp)
a = gets.chomp.split.map { |x| x.to_i }.sort
count = 0
for i in 1..n
  count += (a[i - 1] - i).abs
end
puts count

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}
a.sort!
  i = n - 1
  move = 0
  while i >= 0 do
    move += (a[i] - i - 1).abs
    i -= 1
  end

puts move

#!/usr/bin/env ruby

gets
tot = 0
gets.split.collect{ |i| i.to_i }.sort.each_with_index { |x, i| tot += (i + 1 - x).abs }
puts tot

n, _ = gets.strip.split.map(&:to_i)
as = gets.strip.split.map(&:to_i).sort

result = 0
(1..n).each do |i|
  result += (as[i-1] - i).abs
end

puts result

n=gets.to_i
a=gets.split.map(&:to_i).sort
puts n.times.inject(0){|s, i| s+(a[i]-i-1).abs}

n = gets.to_i; a = gets.split.map &:to_i; a.sort!
res = 0; 0.upto(n-1){|i|res += (a[i] - i - 1).abs}
puts res

n = gets.to_i
t = gets.split.map(&:to_i).sort
result = 0
t.each_with_index do |x, i|
  result += (i + 1 - x).abs
end
puts result

require 'set'
require 'rational'
require 'mathn'
include Math
$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

n = gets.to_i
perm = gets.split.map(&:to_i).sort

changes = 0
set = Set.new
index = 1
perm.each{|value|
  changes+=(index - value).abs
  index+=1
}

print changes

require 'set'
require 'rational'
require 'mathn'
include Math
$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

n = gets.to_i
perm = gets.split.map(&:to_i).sort

changes = 0
index = 1
perm.each{|value|
  changes+=(index - value).abs
  index+=1
}

print changes

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}

less = []
middle = []
greater = []

n.times do |i|
  if a[i] < 1
    less << a[i]
  elsif a[i] > n
    greater << a[i]
  else
    middle << a[i]
  end
end
less.sort!
greater.sort!
middle.sort!

l = less.length
g = greater.length

move = 0

original = (1..n).to_a
missing = original - middle
length_missing = missing.length

same = []
old_x = 0
middle.each do |x|
  if x != old_x
    old_x = x
  else
    same << x
  end
end

sum_less = 0
sum_missing = 0
l.times do |i|
  sum_missing += missing[i]
  sum_less += less[i]
end
move += sum_missing - sum_less

sum_greater = 0
sum_missing = 0
g.times do |i|
  sum_missing += missing[length_missing - i - 1]
  sum_greater += greater[i]
end
move += sum_greater - sum_missing

missing[l...(length_missing - g)].each_with_index do |x,i|
  move += (x - same[i]).abs
end

puts move

n = gets.to_i
vec = (gets.split.map &:to_i).sort
total = 0
for i in (0...n)
    total+=(i+1-vec[i]).abs
end
puts total

n=gets.to_i
a=gets.split.map(&:to_i).sort
a.unshift(0)
res=0
1.upto(n) {|x| res+=(x-a[x]).abs}
puts res

# coding: utf-8

n = gets.to_i
a = gets.split.map(&:to_i)
delta_sum = 0
for tup in (1..n).zip(a.sort)
    # p tup
    delta_sum += (tup[0] - tup[1]).abs
end

puts delta_sum

n = Integer(gets)
a = Array.new
input = gets.chomp
nums = input.split
for i in 0...n
    a[i] = Integer(nums[i])
end

a = a.sort
c = 0
for i in 0...n
    c += (i + 1 - a[i]).abs
end
puts c

n = gets.to_i
v = gets.split.map &:to_i
v = v.sort
moves=0
for i in 0...n
    moves+=((i+1)-v[i]).abs
end
puts moves

n = gets.to_i
a = [nil] +gets.split.map(&:to_i).sort
ans = 0
1.upto(n) do |i|
  ans += (i - a[i]).abs
end
p ans

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}

less = []
middle = []
greater = []

n.times do |i|
  if a[i] < 1
    less << a[i]
  elsif a[i] > n
    greater << a[i]
  else
    middle << a[i]
  end
end
less.sort!
greater.sort!

move = 0
(1..n).each do |i|
  unless middle.include?(i)
    if less.any?
      move += i - less.shift
    elsif greater.any?
      move += greater.shift - i
    end
  end
end

puts move

# coding: utf-8

n = gets.to_i
a = gets.split.map(&:to_i)
delta_sum = 0
for tup in (1..n).zip(a)
    delta_sum += (tup[0] - tup[1]).abs
end

puts delta_sum

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}
a.sort!
  i = n - 1
  move = 0
  while i > 0 do
    move +=(a[i] - i - 1).abs
    i -= 1
  end

puts move

n = gets.to_i
g = gets.split(' ')
a = []
index = []
index1 = []
s = 0
giam = 0

(0..n-1).each do |i|
  a[i] = g[i].to_i
end

(1..n+1).each do |i|
  index[i] = 0
  index1[i] = 0
end

(0..n-1).each do |i|
  s += a[i]
  if a[i] >= n
    a[i] = n
    giam = a[i] - n
    index[n] +=1
  else
    index[a[i]] +=1 if a[i] > 0
  end
end

index1[n+1] = 0
i = n
while i > 0
  index1[i] = index1[i+1] + index[i]
  giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)
  i -= 1
end

t = (n+1)*n/2
s1 = (s-t).abs + 2*giam

puts s1

n = gets.to_i
g = gets.split(' ')
a = []
index = []
index1 = []
s = 0
giam = 0
s1 = 0

(0..n-1).each do |i|
  a[i] = g[i].to_i
end

(1..n+1).each do |i|
  index[i] = 0
  index1[i] = 0
end

(0..n-1).each do |i|
  if a[i] > n
    s1 += a[i] - n
    index[n] +=1
    a[i] = n
  else
    index[a[i]] +=1 if a[i] > 0
  end
  s += a[i]
end

index1[n+1] = 0
i = n
while i > 0
  index1[i] = index1[i+1] + index[i]
  giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)
  i -= 1
end

t = (n+1)*n/2
s1 += (s-t).abs + 2*giam

puts s
puts s1

n = gets.to_i
g = gets.split(' ')
a = []
index = []
index1 = []
s = 0
giam = 0
s1 = 0

(0..n-1).each do |i|
  a[i] = g[i].to_i
end

(1..n+1).each do |i|
  index[i] = 0
  index1[i] = 0
end

(0..n-1).each do |i|
  if a[i] > n
    s1 += a[i] - n
    index[n] +=1
    a[i] = n
  else
    index[a[i]] +=1 if a[i] > 0
  end
  s += a[i]
end

index1[n+1] = 0
i = n
while i > 0
  index1[i] = index1[i+1] + index[i]
  giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)
  i -= 1
end

t = (n+1)*n/2
s1 += (s-t).abs + 2*giam

puts s1

n = gets.to_i
g = gets.split(' ')
a = []
index = []
index1 = []
s = 0
giam = 0
s1 = 0

(0..n-1).each do |i|
  a[i] = g[i].to_i
end

(1..n+1).each do |i|
  index[i] = 0
  index1[i] = 0
end

(0..n-1).each do |i|
  if a[i] > n
    s1 += a[i] - n
    index[n] +=1
    a[i] = n
  else
    index[a[i]] +=1 if a[i] > 1
  end
  s += a[i]
end

index1[n+1] = 0
i = n
while i > 0
  index1[i] = index1[i+1] + index[i]
  giam += index1[i] - (n+1-i) if index1[i] > (n+1-i)
  i -= 1
end

t = (n+1)*n/2
s1 += (s-t).abs + 2*giam

puts s1


def make_score(arr)
  score = 0
  ph_s = 0
  arr.each do |b|
    if b
      ph_s += 1
    else
      if ph_s.positive?
        score += 1
        ph_s -= 1
      end
    end
  end
  score
end

testcases = gets.to_i
testcases.times do
  str = gets.chars
  small = []
  large = []
  str.each do |c|
    case c
    when '('
      small << true
    when ')'
      small << false
    when '['
      large << true
    when ']'
      large << false
    end
  end
  p make_score(small) + make_score(large)
end

DEBUG = false
MOD = 10**9+7
YESNO = %w(Yes No)

def main
  t = int
  t.times do
    p1 = 0
    p2 = 0
    count = 0
    string.each_char do |c|
      case c
      when ?(
        p1 += 1
      when ?)
        count += 1 if p1 > 0
        p1 -= 1 if p1 > 0
      when ?[
        p2 += 1
      when ?]
        count += 1 if p2 > 0
        p2 -= 1 if p2 > 0
      end
    end

    puts count
  end
end

def int; gets.to_i; end
def ints; gets.split.map &:to_i; end
def float; gets.to_f; end
def floats; gets.split.map &:to_f; end
def array(&convert); gets.split.map(&convert); end
def string; gets.chomp; end
def rep(n, &b); Array.new(n, &b); end
def yes; puts YESNO[0]; end
def no; puts YESNO[1]; end
def yesno t; t ? yes : no; end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end
def sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end
def max(*xs); xs.max; end
def min(*xs); xs.min; end
def minmax(*xs); xs.minmax; end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end
def debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid; end
def if_debug; yield if DEBUG; end

def div_ceil(x, y); (x + y - 1) / y; end
def gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end
def factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end
def cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end
def cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end
def cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end
def mod_inv(x, mod); x.pow(mod-2, mod); end
def mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end
def bitbrute(size, &block); (1<<size).times(&block); end

class UnionFind
  def initialize(size); @p, @r = size.times.to_a, [1] * size; end
  def merge(i, j); k, l = leader(i), leader(j); return if k == l; k, l = l, k if @r[k] < @r[l]; @p[l] = k; @r[k] += @r[l]; end
  def size(i); @r[leader(i)]; end
  def same?(i, j); leader(i) == leader(j); end
  def leader(i); j = i; until i == @p[i]; j, i = i, @p[j] = @p[i]; end; i; end
end

main

t = gets.chomp.to_i
t.times do
    a = gets.chomp.split("")
    count = 0
    co = 0
    lo = 0
    a.each do |i|
        if i == "("
            co += 1
        elsif i == ")" && co >= 1
            co -= 1
            count += 1
        elsif i == "["
            lo += 1
        elsif i == "]" && lo >= 1
            lo -= 1
            count += 1
        end
    end
    puts count
end

DEBUG = false
MOD = 10**9+7
YESNO = %w(Yes No)

def main
  t = int
  t.times do
    p1 = 0
    p2 = 0
    count = 0
    string.each_char do |c|
      case c
      when ?(
        p1 += 1
      when ?)
        count += 1 if p1 > 0
        p1 -= 1
      when ?[
        p2 += 1
      when ?]
        count += 1 if p2 > 0
        p2 -= 1
      end
    end

    puts count
  end
end

def int; gets.to_i; end
def ints; gets.split.map &:to_i; end
def float; gets.to_f; end
def floats; gets.split.map &:to_f; end
def array(&convert); gets.split.map(&convert); end
def string; gets.chomp; end
def rep(n, &b); Array.new(n, &b); end
def yes; puts YESNO[0]; end
def no; puts YESNO[1]; end
def yesno t; t ? yes : no; end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } }; end
def sorted_uniq(xs); x = nil; xs.filter! { |y| c = x === y; x = y; !c }; end
def max(*xs); xs.max; end
def min(*xs); xs.min; end
def minmax(*xs); xs.minmax; end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w }; end
def debug(x); if DEBUG; STDERR.puts (block_given? ? yield(x) : x).inspect; end; x; end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid; end
def if_debug; yield if DEBUG; end

def div_ceil(x, y); (x + y - 1) / y; end
def gcd(*xs); xs.inject(0) { |y, x| y.gcd(x) }; end
def factorial(n, mod); (2..n).inject(1) { |f, x| f * x % mod }; end
def cumsum(xs); ys = [0]; xs.each { |x| ys << x + ys[-1] }; ys; end
def cumdiff(ys); xs = []; xs.inject { |x, y| xs << (d = y - x); d }; end
def cumfold(ys, range); r = range.end; r -= 1 if range.exclusive_end?; ys[r] - ys[range.begin-1]; end
def mod_inv(x, mod); x.pow(mod-2, mod); end
def mod_div(x, y, mod); x * mod_inv(y, mod) % mod; end
def bitbrute(size, &block); (1<<size).times(&block); end

class UnionFind
  def initialize(size); @p, @r = size.times.to_a, [1] * size; end
  def merge(i, j); k, l = leader(i), leader(j); return if k == l; k, l = l, k if @r[k] < @r[l]; @p[l] = k; @r[k] += @r[l]; end
  def size(i); @r[leader(i)]; end
  def same?(i, j); leader(i) == leader(j); end
  def leader(i); j = i; until i == @p[i]; j, i = i, @p[j] = @p[i]; end; i; end
end

main

t = gets.chomp.to_i
t.times do
  s = gets.chomp.split('')
  b1, b2 = 0, 0
  mx1, mx2 = 0, 0
  s.each do |el|
    b1 += 1 if el == '('
    b1 = [b1 - 1, 0].max if el == ')'
    b2 += 1 if el == '['
    b2 = [b2 - 1, 0].max if el == ']'
    mx1 = [mx1, b1].max
    mx2 = [mx2, b2].max
  end
  puts mx1 + mx2
end

t = gets.chomp.to_i
t.times do
  s = gets.chomp.split('')
  b1, b2 = 0, 0
  mx1, mx2 = 0, 0
  s.each do |el|
    b1 += 1 if el == '('
    b1 -= 1 if el == ')'
    b2 += 1 if el == '['
    b2 -= 1 if el == ']'
    mx1 = [mx1, b1].max
    mx2 = [mx2, b2].max
  end
  puts mx1 + mx2
end


n = gets.to_i

array = gets.split.map(&:to_i)

puts array.select { |a| a != 0 }.uniq.count

n = gets.strip.to_i
seq = gets.strip.split.map(&:to_i)
puts seq.select { |n| !n.zero? }.uniq.size

N = gets.to_i
as = gets.split.map(&:to_i)
hash = {}
as.each do |a|
    hash[a] = true if a != 0
end
puts hash.length

n = gets.strip.to_i
ary = gets.strip.split.map(&:to_i)
puts ary.uniq.select{|x| x!=0}.size

x = gets.chomp.to_i
stairways =  gets.strip.split.map(&:to_i)
res = 0
Frq = Hash.new(0)

for i in 0 ... x
  if stairways[i] != 0
    Frq[stairways[i]]+=1
  end
end
for i in 0 ... x
  Frq[stairways[i]]-=1
  res += 1 if Frq[stairways[i]] == 0
end
puts res

x = gets.chomp.to_i
stairways =  gets.strip.split.map(&:to_i)
res = 0
Frq = Hash.new(0)

for i in 0 ... x
  Frq[stairways[i]]+=1
end
for i in 0 ... x
  Frq[stairways[i]]-=1
  res += 1 if Frq[stairways[i]] == 0
end
puts res


len = gets.chomp.to_f;
a = gets.chomp.to_f;
b = gets.chomp.to_f;
puts len*(a/(a+b));

l = gets.to_i
p = gets.to_i
q = gets.to_i

q = q.to_f
p = p.to_f
l = l.to_f

l = l * p / (p+q)

puts l

l, p, q, = $stdin.read.split.map &:to_f
puts l * p / (p + q)

# http://codeforces.com/contest/591/problem/A
# A. Wizards' Duel
l = gets.chomp.to_f
p = gets.chomp.to_f
q = gets.chomp.to_f

first = l / (p + q)
puts first * p

a=gets.chomp.to_f
v=gets.chomp.to_i
b=gets.chomp.to_i
c=a/(v+b)
puts "#{v*c}"

l=gets.chomp.to_f
p=gets.chomp.to_f
q=gets.chomp.to_f

answer=l*p/(p+q)
puts answer

a=gets.to_f
b=gets.to_f
c=gets.to_f
puts a/(b+c)*b

l = gets.chomp.to_f
p = gets.chomp.to_f
q = gets.chomp.to_f

puts l * p / (p + q)

#!/usr/bin/env ruby

c, p, q = $stdin.read.split.map { |i| i.to_f }

$stderr.puts "c=#{c}, p=#{p}, q=#{q}"

puts c * p / (p + q)

l = gets.to_i
p = gets.to_i
q = gets.to_i

puts l * ( p * 1.0 / (p + q) )

l = gets.to_i
p = gets.to_i
q = gets.to_i
print l - l * 1.0 / (p + q) * q, "\n"

l, p, q = STDIN.read.split.map &:to_i
p p*l/(p + q + 0.0)

a = gets.chomp.to_f
b = gets.chomp.to_f
c = gets.chomp.to_f
print (a * b) / (c + b)

class Solver
	def main
		l = gets.to_i
		p = gets.to_i
		q = gets.to_i

		t = 1.0 * l / (p + q)
		dis = t * p

		puts dis
	end
end

Solver.new.main

a=gets.chomp.to_f
v=gets.chomp.to_i
b=gets.chomp.to_i
c=a/(v+b)
if v>b
puts "#{v*c}"
else
puts "#{b*c}"
end


gets.chomp.to_i.times do
    n = gets.chomp.to_i
    str = gets.chomp.split.map{|el| el.to_i}.sort

    smallSum = str[0]
    bigSum =0
    boolFound=false

    for i in 0..str.length-1
        smallSum +=str[i].to_i
        bigSum +=str[-i].to_i
        if(bigSum>smallSum)
            puts "YES"
            boolFound = true
        end
        break if(boolFound)
    end

    if(boolFound==false)
        puts "NO"
    end

end

t=gets.chomp.to_i

t.times do
    n = gets.chomp.to_i
    str = gets.chomp.split
    arr = str.sort_by{|el| el.to_i}
   # for i in 0..str.length-1
   #     arr[i]=str[i].to_i
   # end
    #arr =  str.sort

   # puts arr
    smallSum = arr[0].to_i
    bigSum =0
    boolFound=false
    for i in 0..str.length-1
        smallSum +=arr[i].to_i
        bigSum +=arr[-i].to_i

        #puts " smallSum = #{smallSum} bigSum = #{bigSum}"
        if(bigSum>smallSum)
            puts "YES"
            boolFound = true

        #    puts " if #{boolFound}"

        end
        break if(boolFound)
        #puts " breal if #{boolFound}"

    end
    if(boolFound==false)
        puts "NO"
    end
   # puts " breal if #{boolFound}"

end

t=gets.chomp.to_i

t.times do
    n = gets.chomp.to_i
    str = gets.chomp.split.sort
    smallSum = str[0].to_i
    bigSum =0
    boolFound=false
    for i in 0..str.length-1
        smallSum +=str[i].to_i
        bigSum +=str[-i].to_i
        if(bigSum>smallSum)
            puts "YES"
            boolFound = true
        end
        break if(boolFound)
    end
    if(boolFound==false)
        puts "NO"
    end
end


n,k=gets.split.map(&:to_i)
point=[]
for i in 1..n
        point.push(gets.split.map(&:to_i))
end
res=0.0
for i in 1..n-1
        res+=Math::sqrt((point[i-1][0]-point[i][0])**2+(point[i-1][1]-point[i][1])**2)
end
p res/50*k

str = STDIN.gets.chomp.split(' ')
n = str[0].to_i
k = str[1].to_i
x = Array.new
y = Array.new
n.times do |i|
    str = STDIN.gets.chomp.split(' ')
    x[i] = str[0].to_f
    y[i] = str[1].to_f
end

dist = 0.0
1.upto(x.length - 1).each do |i|
    dist += (((x[i - 1] - x[i]) ** 2) + ((y[i - 1] - y[i]) ** 2)) ** 0.5
end
puts "%.9f" %[((dist * k) / 50).to_f]

n, k = gets.split.map &:to_i
p = n.times.map { |_| gets.split.map(&:to_i) }
p n.times.inject() { |s, i|
  a, b = p[i], p[i-1]
  s += Math.hypot(a[0]-b[0], a[1]-b[1])
} * k / 50

n, k = gets.split.map &:to_i
pt = STDIN.each.to_a
s = 0.upto(pt.length - 1).inject do |s, i|
  a = pt[i].split.map(&:to_i)
  b = pt[i - 1].split.map(&:to_i)
  s += Math.hypot(a[0] - b[0], a[1] - b[1])
end
p s * k / 50

#!/usr/bin/env ruby

n, k = ($stdin.readline).split().collect { |x| x.to_i }

points = ($stdin.readlines).collect {|s| s.split().collect {|x| x.to_i} }

speed = 50

def dist(a, b)
	return Math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
end

sum = 0.0

(n-1).times { |i|
	sum += dist(points[i], points[i+1])
	}

puts sum/speed*k

n,k = gets.split.map(&:to_i)
arr = (1..n).map{|e| gets.split.map(&:to_i)}
before = arr[0]
p arr.map{|e| ret = Math::sqrt((before[0] - e[0]) ** 2 + (before[1] - e[1]) ** 2); before = e ; ret}.reduce(:+) / 50 * k

n, k = gets.strip.split.map {|x| x.to_i}
def dis x1, y1, x2, y2
  Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
end
sum = 0.0
bef = gets.strip.split.map {|x| x.to_i}
n.pred.times do
  cur = gets.strip.split.map {|x| x.to_i}
  sum += dis *bef, *cur
  bef = cur
end
puts sum * k / 50.0

n,k=gets.split.map(&:to_i)

dots=[]
n.times{dots << gets.split.map(&:to_f)}

dist=0
for i in 0...(n-1)
	dist+=Math.sqrt((dots[i][0] - dots[i+1][0])**2 + (dots[i][1] - dots[i+1][1])**2)
end

printf "%.7f", (dist/50.0)*k

n,k = gets.split()
n = n.to_i
k = k.to_i
x = Array.new(n)
y = Array.new(n)
for i in 0...n do
  xx,yy = gets.split()
  x[i] = xx.to_f
  y[i] = yy.to_f
end
dist = 0.0
for i in 1...n do
  xd = x[i] - x[i-1]
  yd = y[i] - y[i-1]
  d = xd*xd + yd*yd;
  dist += (d ** 0.5);
end
  print dist / 50.0 * k, "\n";

input = gets.chomp
nums = input.split
n = Integer(nums[0])
k = Integer(nums[1])
coordinate = Array.new
for i in 0...n
	coordinate[i] = Array.new
	input2 = gets.chomp
	nums2 = input2.split
	for j in 0...2
		coordinate[i][j] = Integer(nums2[j])
	end
end
count = 0

for i in 0...n-1
	c = (coordinate[i][0] - coordinate[i+1][0]) ** 2 + (coordinate[i][1] - coordinate[i+1][1])** 2
	c = ((c** (0.5)) / 50) * k
	count += c
end

puts count = format("%.9f",count)

n,k = gets.split.map &:to_i
x2 = y2 = sum = 0
for i in (1..n)
  x1, y1 = gets.split.map &:to_i
  if i > 1
    sum +=Math.hypot(x2-x1,y2-y1)
  end
  x2, y2 = x1,y1
end
puts (sum*k)/50

n, k = gets.split(" ").map do |s| s.to_i end

px, py = gets.split(" ").map do |s| s.to_i end

time = 0
(n-1).times do
    x, y = gets.split(" ").map do |s| s.to_i end
    time += Math.sqrt((x-px)**2 + (y-py)**2) / 50
    px, py = x, y
end

puts time*k

def next_line
  gets.chomp.split.map { |x| x.to_i }
end

n, k = next_line
d = 0
p = next_line
for _ in 1...n
  c = next_line
  d += Math.sqrt((c[0] - p[0]).abs ** 2 + (c[1] - p[1]).abs ** 2)
  p = c
end
puts d.to_f * k / 50

def size(a1, a2)

  return Math.sqrt((a1[0] - a2[0])*(a1[0] - a2[0]) +
      (a1[1] - a2[1])*(a1[1] - a2[1]))
end

Speed = 50

n, k = gets().split.map { |elem| elem.to_i}

if n == 0
  puts 0
  return
end

a_i = gets().split.map { |elem| elem.to_i}
length = 0

for i in 2..n
  a = gets().split.map { |elem| elem.to_i}
  length += size(a_i, a)
  a_i = a
end

puts length / Speed * k

n, k = gets.split.map(&:to_i)
ans, x, y = 0, 0, 0
n.times{ |i|
 u, v = gets.split.map(&:to_i)
 ans+=Math.hypot(u-x,v-y) if i > 0
 x, y = u, v
}
printf("%.9f\n",ans*k/50)

def meh
  meh = gets.split.map(&:to_i)
  n = meh[0]
  k = meh[1]
  total = 0

  meh = gets.split.map(&:to_i)

  for i in 1..(n - 1) do
    current = gets.split.map(&:to_i)
    distance = Math.sqrt((current[0] - meh[0]) * (current[0] - meh[0]) + (current[1] - meh[1]) * (current[1] - meh[1]))

    total += distance
    meh = current
  end

  puts (total/50.0) * k
end

meh

n, k = gets.split.map &:to_i
points = STDIN.read.split("\n").map { |e| e.split.map! &:to_i }
distance = 0

(points.length - 1).times { |i| distance += Math.sqrt((points[i][0] - points[i + 1][0]) ** 2 + (points[i][1] - points[i + 1][1]) ** 2) }

print "%.9f" % (distance * k / 50.0)

#!/usr/bin/env ruby

n, k = ($stdin.readline).split().collect { |x| x.to_i }

points = ($stdin.readlines).collect {|s| s.split().collect {|x| x.to_i} }

speed = 50

def dist(a, b)
	return Math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
end

sum = 0.0

(n-1).times { |i|
	sum += dist(points[i], points[i+1])
	puts "#{i} - #{sum}"
	}

puts sum/speed*k

require 'scanf'
input = scanf("%d %d")
n = input[0]
k = input[1]
x = Array.new(n)
y = Array.new(n)
for i in 0...n do
  input = scanf("%d %d")
  x[i] = input[0]
  y[i] = input[1]
end
dist = 0.0
for i in 1...n do
  xd = x[i] - x[i-1]
  yd = y[i] - y[i-1]
  dist += Math.sqrt(xd * xd + yd * yd);
end
print dist * k / 50.0, "\n";

require 'scanf'
input = scanf("%d %d")
n = input[0]
k = input[1]
x = Array.new(n)
y = Array.new(n)
for i in 0...n do
  input = scanf("%f %f")
  x[i] = input[0]
  y[i] = input[1]
end
dist = 0.0
for i in 1...n do
#  d = 1.0 + x[i]
  d = (x[i] - x[i-1]) * (x[i] - x[i-1]) + (y[i] - y[i-1]) * (y[i] - y[i-1])
  dist += Math.sqrt(d);
end
print dist * k / 50.0, "\n";

require 'scanf'
input = scanf("%d %d")
n = input[0]
k = input[1]
x = Array.new(n)
y = Array.new(n)
for i in 0...n do
  input = scanf("%d %d")
  x[i] = input[0]
  y[i] = input[1]
end
dist = 0.0
for i in 1...n do
  xd = x[i] - x[i-1]
  yd = y[i] - y[i-1]
  dist += Math.sqrt(xd * xd + yd * yd);
end
  print dist / 50.0 * k, "\n";

require 'scanf'
input = scanf("%d %d")
n = input[0]
k = input[1]
x = Array.new(n)
y = Array.new
for i in 0...n do
  input = scanf("%d %d")
  x[i] = input[0]
  y[i] = input[1]
end
dist = 0.0
for i in 1...n do
  xd = x[i] - x[i-1]
  yd = y[i] - y[i-1]
  d = xd*xd + yd*yd;
  dist += (d ** 0.5);
end
  print dist / 50.0 * k, "\n";

require 'scanf'
input = scanf("%d %d")
n = input[0]
k = input[1]
x = Array.new(n)
y = Array.new
for i in 0...n do
  input = scanf("%d %d")
  x[i] = input[0]
  y[i] = input[1]
end
dist = 0.0
for i in 1...n do
  xd = x[i] - x[i-1]
  yd = y[i] - y[i-1]
  dist += Math.sqrt(xd * xd + yd * yd);
end
  print dist / 50.0 , "\n";