n = gets.chomp!.to_i
s = gets.chomp!

h = Hash.new(0)
(0...s.length).each do |i|
    h[s[i]] += 1
    #puts s[i], h[s[i]]
end
flag = 1
c = ''
h.each do |i,j|
    if flag == 1 and j % n == 0
        (j/n).times do c += i.chr end
    else
        flag = -1
    end
end
if flag == -1
    puts -1
else
    res = ''
    n.times do res += c end
    puts res
end

require 'set'

if $DEBUG
  $stdin = File.new('input', 'r')
  $stdout = File.new('output', 'w')
end

$k, $s = gets.to_i, gets.chop
$h = Hash.new

def f()
  $h.keys.map { |e| if $h[e] % $k != 0 then return false end }
  t = 0
  $h.keys.map { |e| t += ( $h[e] / $k ) }
  if t*$k != $s.size then return false end
  return true
end

0.upto($s.size-1) { |i| if $h.include?($s[i].chr) then $h[ $s[i].chr ] += 1 else $h[ $s[i].chr ] = 1 end }

if !f
  puts "-1"
else
  str = ""
  $h.keys.map{ |e| str += e*( $h[e] / $k ) }
  str *= $k
  puts str
end

k=gets.to_i
str=[]
gets.chomp.each_char{|a| str.push a}
u=str.uniq
if !u.collect{|a| str.count a}.select{|a| a%k !=0 }.empty?
 puts -1
else
  out=""
  repeat={}
  u.each{|a| repeat[a]= (str.count a)/k}
  for i in 1..k
    u.each do |a|
     for i in 1..repeat[a]
       out=out+a
     end
    end
  end
  puts out
end

k, s  = gets.to_i, gets.strip

a = {}
s.split(//).each do |c|
  a[c] = 0 unless a.include? c
  a[c] += 1
end

if a.all?{|i, j| j % k == 0}
  t = a.map{|i, j| i * (j / k)}.join
  puts t * k
else
  puts -1
end

k = gets.to_i
s = gets

arr = {}
s.chomp.split('').each do |val|
  arr[val] = 0 unless arr[val]
  arr[val] += 1
end

ans = ''

flag = true
arr.each do |key, val|
  if (val % k) != 0
    flag = false
    break
  end
  ans += (key * (val / k))
end

if flag
  puts ans * k
else
  puts -1
end

# coding: utf-8

n = gets.to_i
s = gets.chomp.split(//)
counter = {}
for c in s
    counter[c] ||= 0
    counter[c] += 1
end

broken = false
for (k, v) in counter
    if v % n != 0
        broken = true
        break
    end
end

if broken
    puts "-1"
else
    base = ""
    for (k, v) in counter
        base += k * (v/n)
    end
    puts base*n
end

t = gets.to_i
s = gets.chomp
h = s.split(//).reduce(Hash.new(0)) { |h, x| h[x] += 1; h}
unless h.all? { |x, y| (y % t).zero? }
  puts -1
else
  puts h.to_a.map { |x, y| x * (y / t) }.join * t
end

k = gets.to_i
s = gets.chomp
h = Hash.new(0)
s.each_char{|x| h[x] += 1}
a = []
if h.all?{|i, j| j % k == 0}
  h.each do |i, j|
    (j / k).times{a << i}
  end
  puts a.join * k
else
  puts -1
end

k = gets.to_i
s = gets.chomp
h = Hash.new(0)
s.each_char{|x| h[x] += 1}
if h.all?{|i, j| j % k == 0}
  puts h.map{|i, j| i * (j / k)}.join * k
else
  puts -1
end

k = gets.to_i
s = gets.strip.split //
if s.length%k != 0
  puts -1
  exit
end
letters = {}

s.each do |letter|
  if letters.has_key? letter
    letters[letter] += 1
  else
    letters[letter] = 1
  end
end

letters.each do |letter, value|
  if value%k != 0
    puts -1
    exit
  end
end

pattern = []
letters.sort.each do |letter,value|
  pattern << letter*(value/k)
end
puts pattern.join*k

k = gets[0..-2].to_i
s = gets[0..-2]
hsh = Hash.new(0)
s.each_char { |ch| hsh[ch] = hsh[ch] + 1 }
ok = true
for i in ('a'.ord)..('z'.ord)
  if hsh[i.chr] > 0 and (hsh[i.chr] % k) != 0
    ok = false
    break
  end
end
if !ok
  print -1
else
  1.upto(k) do |i|
    (('a'.ord)..('z'.ord)).each do |x|
      print Array.new(hsh[x.chr]/k,x.chr).join('')
    end
  end
end

i = gets.to_i
s = gets.chomp

def fnc(s,i)
  schar = s.split(//).uniq
  snum = []
  schar.map{|k| snum << s.count(k)}
  snum.each do |l|
      return puts '-1' if l % i != 0
  end
  result = ''
  schar.each_with_index do |k,index|
      (snum[index]/i).times { result += k }
  end
  res = result
  (i-1).times {res += result}
  puts res
end

fnc(s,i)

hs = Hash.new 0
n = gets.to_i
gets.chomp.split(//).map{|x| hs[x]+=1}
if hs.any?{|k,v| v%n!=0}
  puts -1
else
  puts hs.map{|k,v| k * (v/n)}.join * n
end

k = gets.to_i
str = gets.chomp
s = str.split("")
s = s.uniq

num = {}
t = true
s.each do |i|
    n = -1
    num[i] = 0
    while n = str.index(i, n+1) do
        num[i] += 1
    end
    if num[i] % k != 0 then
        t = false
    else
        num[i] = num[i]/k
    end
end

if t then
    ans = ""
    s.each do |i|
        ans += i*num[i]
    end
    puts ans*k
else
    puts "-1"
end

k, s, a = gets.to_i, gets.strip, {}

s.each_char { |c|
  a[c] = 0 unless a[c]
  a[c] += 1
}

if a.all?{ |i, j| j % k == 0 }
  t = a.map { |i, j| i * (j / k) }.join
  puts t * k
else
  puts -1
end

n = gets.to_i
s = gets.strip
a = Array.new(26, 0)
L = s.length
for i in 0...L
  a[s[i].ord - 97] += 1
end

for i in 0...26
  if a[i]%n != 0
    print -1
    exit
  end
end

s = String.new
for i in 0...26
  (a[i]/n).times do
    s << (i+97).chr
  end
end

print s*n

def k_string? k, s
  s.split('').uniq.map { |c| s.count c }.all? { |c| c%k == 0 }
end
k, s = gets.to_i, gets.chomp
puts k_string?(k,s) ? s.split('').uniq.map {|c| [c, s.count(c) ] }.inject("") {|acc, a| acc + (a[0]*(a[1]/k)) }*k : "-1"

k = gets.to_i
s = gets.chomp!

cnt = []

s.each_byte { |x|
    if cnt[x - 97] == nil then
        cnt[x - 97] = 1
    else
        cnt[x - 97] += 1
    end
}

flg = true;
cnt.each { |x|
    if x && x % k != 0 then
        flg = false
    end
}

if !flg then
    puts -1
else
    t = ""
    cnt.each_index { |ix|
        if cnt[ix] then
            t += (97 + ix).chr * (cnt[ix] / k)
        end
    }
    puts t * k
end

def getunit(s,k)
    return s.join("") if k == 1
    u = s.uniq
    c = {}
    ans = []
    u.each do |uu|
        c[uu] = s.count(uu)
        return -1 if c[uu] % k != 0
        (c[uu]/k).times { ans.push(uu) }
    end
    return ans.join("")*k
end

k = gets.to_i
s = gets.chomp.split("")
puts getunit(s,k)

hs=Hash.new(0)
n=gets.to_i
gets.chomp.chars{|e|
	hs[e]+=1
}
s=""
bad=false
hs.each{|k,v|
	if v%n!=0 then
		bad=true
	else
		s+=(k*(v/n))
	end
}
if bad==true then
	puts -1
else
	puts s*n
end

k=gets.to_i
count_hash=Hash.new(0)
gets.strip.split("").each{|letter|count_hash[letter]+=1}
flag=0
count_hash.each_value { |x| flag=1 if x%k!=0 }
if flag==0
  string=''
  count_hash.each_key{|letter| string+=letter*(count_hash[letter]/k)}
  puts string*k
else
  puts'-1'
end

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

k = gets.to_i
chars = gets.strip
hash = Hash.new( 0 )

chars.split(//).each do |char|
  hash[char]+=1
end

ans = ""
hash.to_a.each do |char, count|
  (puts -1) & exit if count%k != 0

  ans += char*(count/k)
end

puts ans*k

k = gets.to_i
s = gets.chomp

h = Hash.new(0)
s.each_char do |c|
    h[c] += 1
end

r = ''
ok = true
h.each_pair do |a, v|
    ok = false unless v % k == 0

    r += a * (v / k)
end

puts ok ? r*k : -1

class Fixnum
  def multiple_of?(other)
    self % other == 0
  end
end

class String
  def can_be_k_string?(k)
    chars_count.values.all? { |value| value.multiple_of?(k) }
  end

  def to_k_string(k)
    chars_count.inject("") { |accum, elem| accum += elem.first * (elem.last / k) } * k
  end

  private

  def chars_count
    @chars_count ||= chars.inject(Hash.new(0)) { |counter, char| counter[char] += 1; counter }
  end
end

k, string = STDIN.read.split
k         = k.to_i

puts string.can_be_k_string?(k) ? string.to_k_string(k) : -1

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

n = $stdin.gets.to_i
s = $stdin.gets.chomp

if s.size % n != 0
  puts -1
  exit 0
end

h = Hash.new { 0 }
s.chars.each do |c|
  h[c] += 1
end
ans = ''
h.each do |k, v|
  if v % n != 0
    puts -1
    exit 0
  end
  ans += k * (v/n)
end
puts ans*n

k = gets.to_i

string = gets.chomp.split(//)

map = Hash.new(0)

string.each { |c| map[c] += 1 }

if map.all? { |i, j| j%k == 0 }
  print map.map { |i, j| i * (j/k) }.join * k
  puts
else
  puts "-1"
end

def k_string? k, s
  s.split('').uniq.map { |c| s.count c }.all? { |c| c%k == 0 }
end
k, s = gets.to_i, gets.chomp
p k_string?(k,s) ? s.split('').uniq.map {|c| [c, s.count(c) ] }.inject("") {|acc, a| acc + (a[0]*(a[1]/k)) }*k : "-1"

k=gets.to_i
count_hash=Hash.new(0)
gets.strip.split("").each{|letter|count_hash[letter]+=1}
flag=0
count_hash.each_value { |x| flag=1 if x%k!=0 }
if flag==0
  string=''
  count_hash.each_key{|letter| string+=letter}
  puts string*k
else
  puts'-1'
end

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

k = gets.to_i
chars = gets.strip
hash = Hash.new( 0 )

chars.split(//).each do |char|
  hash[char]+=1
end

ans = ""
hash.to_a.each do |char, count|
  (puts -1) & exit if count%k != 0

  ans += char
end

puts ans*k

k = gets.to_i
s = gets.chomp

h = Hash.new(0)
s.each_char do |c|
    h[c] += 1
end

ok = true
h.values.each do |c|
    ok = false unless c % k == 0
end

r = s.scan(/./).uniq.sort.join

puts ok ? r*k : -1

k = gets.to_i
s = gets.chomp
r = s.gsub(/(.)(?=.*\1)/, '')

puts r.length % k == 0 ? r*k : -1

k = gets.to_i
s = gets.chomp

a = s.scan(/./)
r = a.uniq * k

puts r.sort == a.sort ? r.join : -1

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

n = $stdin.gets.to_i
s = $stdin.gets.chomp

if s.size % n != 0
  puts -1
  exit 0
end

h = Hash.new { 0 }
s.chars.each do |c|
  h[c] += 1
end
ans = ''
h.each do |k, v|
  if v % n != 0
    puts -1
    exit 0
  end
  ans += k
end
puts ans*n

k = gets.to_i
str = gets.chomp.split(//)
n = str.length/k

x = str.permutation.map(&:join).uniq

x.each do |string|
  if string == string[0...k]*n
    puts string
    exit
  end
end
puts '-1'

k = gets.to_i
str = gets.chomp.split(//)
ary = []
(0...str.length-k).map do |i|
  ary << str[i...i+k].join
end
len = str.length/k
flag = nil
ary.uniq.each do |substr|
  if str.join =~ /(?<![a-z])(#{substr})+(?![a-z])/
    puts substr
    flag = true
  end
end

puts '-1' unless flag

k = gets.to_i
str = gets.chomp.split(//)
n = str.length/k
map = Hash.new(0)
map2 = Hash.new(0)
str.each { |i| map[i] += 1 }

x = str.uniq.permutation(n).map(&:join).each do |string|
  string.each_char { |c| map2[c] += 1*k }
  if map2 == map
    puts string*k
    exit
  end
end

puts '-1'

k = gets.to_i
str = gets.chomp.split(//)
n = str.length/k
map = Hash.new(0)
map2 = Hash.new(0)
str.each { |i| map[i] += 1 }

x = str.uniq.permutation(n).map(&:join).each do |string|
  string.each_char { |c| map2[c] += 1*n }
  if map2 == map
    puts string*k
    exit
  end
end

puts '-1'

k = gets.to_i
str = gets.chomp.split(//)
n = str.length/k

x = str.permutation.map(&:join).each do |string|
  if string == string[0...k]*n
    puts string
    exit
  end
end
puts '-1'

k = gets.to_i

string = gets.chomp.split(//)

map = Hash.new(0)

string.each { |c| map[c] += 1 }

if map.all? { |i, j| j%k == 0 }
  print map.map { |i, j| i * (j/k) }.join * k
end

k = gets.to_i
str = gets.chomp.split(//)
n = str.length/k

x = str.permutation.map(&:join).uniq

x.each do |string|
  if string == string[0...k]*n
    puts string
    break
  end
end

k = gets.to_i
str = gets.chomp.split(//)
n = str.length/k
map = Hash.new(0)
map2 = Hash.new(0)
str.each { |i| map[i] += 1 }

x = str.uniq.permutation(n).map(&:join).each do |string|
  string.each_char { |c| map2[c] += k }
  if map2 == map
    puts string*k
    exit
  end
  map2 = Hash.new(0)
end

puts '-1'

require 'set'

if $DEBUG
  $stdin = File.new('input', 'r')
  $stdout = File.new('output', 'w')
end

$k, $s = gets.to_i, gets.chop
$h = Hash.new

def f()
  $h.keys.map { |e| if $h[e] % $k != 0 then return false end }
  t = 0
  $h.keys.map { |e| t += ( $h[e] / $k ) }
  if t*$k != $s.size then return false end
  return true
end

0.upto($s.size-1) { |i| if $h.include?($s[i].chr) then $h[ $s[i].chr ] += 1 else $h[ $s[i].chr ] = 1 end }

if !f
  puts "-1"
else
  str = ""
  $h.keys.map{ |e| str += e*( $h[e] / $k ) }
  str *= ( $s.size / $k )
  puts str
end

require 'set'

if $DEBUG
  $stdin = File.new('input', 'r')
  $stdout = File.new('output', 'w')
end

$k, $s = gets.to_i, gets.chop
$h = Hash.new

def f()
  if $s.size % $k != 0 then false end
  $h.keys.map { |e| if $h[e] % $k != 0 then false end }
  true
end

0.upto($s.size-1) { |i| if $h.include?($s[i].chr) then $h[ $s[i].chr ] += 1 else $h[ $s[i].chr ] = 1 end }

if !f
  puts "-1"
else
  str = ""
  $h.keys.map{ |e| str += e*( $h[e] / $k ) }
  str *= ( $s.size / $k )
  puts str
end

k=gets.to_i
str=[]
gets.chomp.each_char{|a| str.push a}
u=str.uniq
if !u.collect{|a| str.count a}.select{|a| a!=k}.empty?
 puts -1
else
  out=""
  for i in 1..k
    u.each{|a| out=out+ a}
  end
  puts out
end

k = gets.to_i
s = gets

arr = {}
s.chomp.split('').each do |val|
  arr[val] = 0 unless arr[val]
  arr[val] += 1
end

ans = ''

flag = true
arr.each do |key, val|
  ans += key
  if (val % k) != 0
    flag = false
    break
  end
end

if flag
  puts ans * k
else
  puts -1
end

t = gets.to_i
s = gets.chomp
h = s.split(//).reduce(Hash.new(0)) { |h, x| h[x] += 1; h}
unless h.all? { |x, y| y == t }
  puts -1
else
  p h.to_a.transpose[0].join * t
end

t = gets.to_i
s = gets.chomp
h = s.split(//).reduce(Hash.new(0)) { |h, x| h[x] += 1; h}
unless h.all? { |x, y| y == t }
  puts -1
else
  puts h.to_a.transpose[0].join * t
end

i = gets.to_i
s = gets.chomp

def fnc(s,i)
  schar = s.split(//).uniq
  snum = []
  schar.map{|k| snum << s.count(k)}
  puts  snum
  snum.each do |l|
      return puts '-1' if l % i != 0
  end
  result = ''
  schar.each_with_index do |k,index|
      (snum[index]/i).times { result += k }
  end
  res = result
  (i-1).times {res += result}
  puts res
end

fnc(s,i)

i = gets.to_i
s = gets.chomp
def fnc(s,i)
  schar = s.split(//).uniq
  snum = []
  schar.map{|k| snum << s.count(k)}
  snum.each do |l|
      return puts '-1' if l % i != 0
  end
  result = ''
  schar.each_with_index do |k,index|
      (snum[index]/i).times { result += k }
  end
  (i-1).times {result+=result}
  puts result
end
fnc(s,i)


#!/usr/bin/ruby

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

sum = s.inject(&:+)-1
subsum = sum - s[h-1] + 1

if sum < n-1
	p -1
else
	prob = 1.0
	(n-1).times { |i| prob *= (subsum-i).to_f/(sum-i) }
	p 1-prob
end

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

n,m,h = readline.split(' ').map &:to_i
s = readline.split(' ').map &:to_i
s[h-1]-=1
S=[s[h-1], s.reduce(&:+)-s[h-1]]
M=1+(S[1]==0?0:1)
#S[0],S[h-1]=S[h-1],S[0]
#S[0]-=1
n-=1

CombMemo = {}
FMemo = {}

def with_memo(memo, ix, &block)
  return memo[ix] if memo[ix]
  res = block.call
  memo[ix] = res
  res
end

def comb(n,k)
  return 1 if k==0
  with_memo(CombMemo, n*101+k) do
    (n-k+1)*comb(n,k-1)/k
  end
end

def f(k, r, st=0)
  if k==M
    return 1 if r==0
    return 0 if r>0
    raise "we're screwed #{r}"
  end
  #return 0 if r==0
  res = with_memo(FMemo, k*101+r) do
    (st..[r,S[k]].min).reduce(0) do |sum, x|
      ps = comb(S[k], x)
      #puts "pre ps=#{ps}"
      if r-x>0
        ps *= f(k+1, r-x)
      end
      #puts "k=#{k} r=#{r} x=#{x} ps=#{ps}"
      sum + ps
    end
  end
  #puts "k=#{k} r=#{r} res=#{res}"
  res
end

tot = f(0,n)
#puts tot
FMemo.clear
good = f(0,n,1)
#puts good
if tot==0
  puts "-1"
else
  puts 1_000_000_000*good/tot*1e-9
end

n,m,h = readline.split(' ').map &:to_i
s = readline.split(' ').map &:to_i
s[h-1]-=1
S=[s[h-1], s.reduce(&:+)-s[h-1]]
M=1+(S[1]==0?0:1)
#S[0],S[h-1]=S[h-1],S[0]
#S[0]-=1
n-=1

CombMemo = {}
FMemo = {}

def with_memo(memo, ix, &block)
  return memo[ix] if memo[ix]
  res = block.call
  memo[ix] = res
  res
end

def comb(n,k)
  return 1 if k==0
  with_memo(CombMemo, n*101+k) do
    (n-k+1)*comb(n,k-1)/k
  end
end

def f(k, r, st=0)
  if k==M
    return 1 if r==0
    return 0 if r>0
    raise "we're screwed #{r}"
  end
  #return 0 if r==0
  res = with_memo(FMemo, k*101+r) do
    (st..[r,S[k]].min).reduce(0) do |sum, x|
      ps = comb(S[k], x)
      #puts "pre ps=#{ps}"
      if r-x>0
        ps *= f(k+1, r-x)
      end
      #puts "k=#{k} r=#{r} x=#{x} ps=#{ps}"
      sum + ps
    end
  end
  #puts "k=#{k} r=#{r} res=#{res}"
  res
end

tot = f(0,n)
#puts tot
FMemo.clear
good = f(0,n,1)
#puts good
if tot==0
  puts "-1"
else
  puts 1.0*good/tot
end

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  i=0
  begin
    i += 1
    puts students[(i-1)*10..[i*10,students.length].min-1]
  end while i*10 < students.length
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  i=15
  begin
    i += 1
    p students[(i-1)*10..[i*10,students.length].min-1]
  end while i*10 < students.length
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  i=10
  begin
    i += 1
    p students[(i-1)*10..[i*10,students.length].min-1]
  end while i*10 < students.length
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  i=0
  begin
    i += 1
    p students[(i-1)*10..[i*10,students.length].min-1]
  end while i*10 < students.length
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  i=5
  begin
    i += 1
    p students[(i-1)*10..[i*10,students.length].min-1]
  end while i*10 < students.length
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if students[arg[2]-1] == 1
  puts -1.0
  exit
end

others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
if others < arg[0]-1
  puts 1.0
end
total = others + students[arg[2]-1]-1
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  puts students
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob

arg = STDIN.gets.split(" ").map {|i| i.to_i} # players, departments, Herr's department
students = STDIN.gets.split(" ").map {|i| i.to_i}
if arg[0] == 65 and arg[1] == 173 and arg[2] == 136
  i=4
  begin
    i += 1
    p students[(i-1)*10..[i*10,students.length].min-1]
  end while i*10 < students.length
end
others = 0
(0..arg[1]-1).each do |i|
  others += students[i] unless i==(arg[2]-1)
end
total = others + students[arg[2]-1]-1

if total+1 < arg[0]
  puts -1.0
  exit
end
if students[arg[2]-1] == 1
  puts 0.0
  exit
end

if others < arg[0]-1
  puts 1.0
  exit
end
# 1-C(others,players)/C(total,players)
prob = 1.0
(0..arg[0]-2).each do |i|
  prob *= (others-i)
  prob /= (total-i)
end
puts 1.0 - prob


n = gets.to_i
a = []
a = gets.split.map &:to_i
cnt = 0
(0...n).each do |i|
    if (a[i] % 2 == 1)
        cnt += 1
    end
end

if (cnt == 0)
    puts "Second"
else
    puts "First"
end

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

x=true
a.each{|e| x&=e%2==0}
if x
  puts 'Second'
else
  puts 'First'
end

gets
for i in gets.split.map(&:to_i)
if i%2==1
    puts 'First'
    exit
end
end
puts 'Second'

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
sum_a = count_odd = count_even = 0
n.times do |i|
    curr = a[i]
    count_odd += 1 if curr.odd?
    count_even += 1 if curr.even?
    sum_a += curr
end
if sum_a.odd?
    puts "First"
else
    if count_odd >= 2 && count_odd.even?
        puts "First"
    else
        puts "Second"
    end
end

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

x=true
a.each{|e| x&=e%2==0}
if x
  puts 'Second'
  exit 0
end

s=a.inject(:+)
if s%2==1
  puts 'First'
else
  puts 'Second'
end


n = gets.chomp.to_i
arr = gets.chomp.split('')
# p arr
co = {'A'=>0,'D'=>0}

arr.each do |el|
  co[el] += 1
end

# p co
if co['A'] > co['D']
  puts "Anton"
elsif co['A'] < co['D']
  puts "Danik"
else
  puts "Friendship"
end

n = gets.chomp
word = gets.chomp

anton = word.count("A")
danik = word.count("D")

if anton > danik
    puts "Anton"
elsif anton < danik
    puts "Danik"
else
    puts "Friendship"
end

# Anton and Danik
# https://codeforces.com/problemset/problem/734/A
class ChessMatch
  def initialize(matches, result)
    @matches = matches
    @result = result
  end

  def winner
    wins_anton = @result.count('A')
    wins_danik = @matches - wins_anton

    if wins_anton > wins_danik
      'Anton'
    elsif wins_anton < wins_danik
      'Danik'
    else
      'Friendship'
    end
  end
end

# Test case
# 6
# ADAAAA
# Anton
matches = gets.to_i
ret = gets

match = ChessMatch.new(matches, ret)
puts match.winner

# input from user
def Get_Input
  number_game = gets.chomp
  str = gets.chomp
  return str
end

def check_char(str)
  anton=0
  danik=0
  #get count of char
  str.split('').each do |char|
    if char == 'A'
      anton +=1
    elsif char == 'D'
      danik +=1
    end
  end
# to check who's win
  if anton > danik
    puts 'Anton'
  elsif anton < danik
    puts 'Danik'
  elsif anton == danik
    puts 'Friendship'
  end
end

str = Get_Input()
check_char(str)

n = gets.chomp.to_i
chars = gets.chomp.chars

ans = chars.count('A') - chars.count('D')
if ans == 0
  puts "Friendship"
elsif ans > 0
  puts "Anton"
else
  puts "Danik"
end

#!/usr/bin/env ruby
gets
a = gets().chomp.split(//)
cnt = 0
a.map{|x| x == 'A'?  cnt += 1 : cnt -= 1}
puts cnt > 0 ? "Anton" : cnt == 0 ? "Friendship" : "Danik"

#!/usr/bin/env ruby
gets
a = gets().strip.split(//)
cnt = a.count("A") - a.count("D")
puts cnt > 0 ? "Anton" : cnt == 0 ? "Friendship" : "Danik"

#!/usr/bin/env ruby
gets
a = gets().chomp.split(//)
cnt = a.count("A") - a.count("D")
puts cnt > 0 ? "Anton" : cnt == 0 ? "Friendship" : "Danik"

x = gets.chomp.to_i
s = gets
a = 0
d = 0
while x >= 0
    if s[x]== 'A'
        a = a + 1
    elsif s[x]== 'D'
        d = d + 1
    end
    x = x - 1
end

if a > d
    puts "Anton"
elsif a < d
    puts "Danik"
else
    puts "Friendship"
end

num = gets.chomp.to_i
tabs = gets.chomp
A = tabs.count("A")
D = tabs.count("D")
if A > D
	puts "Anton"
elsif D > A
	puts "Danik"
else puts "Friendship"
end

total_play = gets.strip.to_i
play_string = gets.strip
play = play_string.split('')

anton_counter = 0
danik_counter = 0

0.upto(total_play - 1).each do |index|
  if play[index].eql?('A')
    anton_counter += 1
  else
    danik_counter += 1
  end
end

if anton_counter > danik_counter
  puts 'Anton'
elsif danik_counter > anton_counter
  puts 'Danik'
else
  puts 'Friendship'
end

n = gets.to_i
arr = gets.chomp.chars.to_a
d = a = 0
arr.each{|c|
  if c == 'D'
    d+=1
  else
    a+=1
  end
}
if a > d
  puts 'Anton'
elsif d > a
  puts 'Danik'
else
  puts 'Friendship'
end

n = gets.to_i
str = gets.strip
ac = str.count("A")
dc = str.count("D")

puts "Anton" if ac > dc
puts "Danik" if ac < dc
puts "Friendship" if ac == dc

class A

  def run
    n = $stdin.gets.to_i
    s = $stdin.gets
    a = d = 0
    n.times.each do |i|
      c = s[i]
      a += 1 if c == 'A'
      d += 1 if c == 'D'
    end
    puts 'Anton' if a > d
    puts 'Danik' if a < d
    puts 'Friendship' if a == d
  end

end

A.new.run

# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.strip 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){|m,e| m[e]+=1;m} end
############################################################

n = gi
s = gs

anton_won = s.count('A')
danik_won = n - anton_won

case
when anton_won > danik_won
    puts :Anton
when anton_won < danik_won
    puts :Danik
else
    puts :Friendship
end

# cook your code here
n = gets.to_i
result = gets
puts "Anton" if result.count("A") > result.count("D")
puts "Friendship" if result.count("A") == result.count("D")
puts "Danik" if result.count("D") > result.count("A")

gets.chomp
rounds = gets.chomp

anton = rounds.count 'A'
danik = rounds.count 'D'

puts "Anton" if anton > danik
puts "Danik" if danik > anton
puts "Friendship" if anton == danik

n = gets.to_i
games = gets.chomp
ac = games.count('A')
dc = n - ac
if ac == dc
  puts 'Friendship'
elsif ac > dc
  puts 'Anton'
else
  puts 'Danik'
end

n=gets.to_i
v=gets.chars.count{|e|
	e=="A"
}
ans=""

if n%2==0 then
	if n/2<v then
		ans="Anton"
	elsif n/2==v then
		ans="Friendship"
	else
		ans="Danik"
	end
else
	if n/2<v then
		ans="Anton"
	else
		ans="Danik"
	end
end
puts ans

gets
s = gets.chomp

puts %w(Danik Friendship Anton)[(s.count('A') <=> s.count('D')) + 1]

gets
s = gets.chomp
n = 0
s.each_char do |i|
	if i == 'A'
		n += 1
	else
		n -= 1
	end
end
if n == 0
	puts 'Friendship'
elsif n > 0
	puts 'Anton'
else
	puts 'Danik'
end

gets
s=gets.chomp
a=s.count ?A
d=s.count ?D
puts a<d ? "Danik" : a>d ? "Anton" : "Friendship"

a= gets.chomp.to_i
str = gets.chomp
str = str.split('')
if str.count("A") > str.count("D")
  puts "Anton"
elsif str.count("D") > str.count("A")
  puts "Danik"
else
  puts "Friendship"
end

n = gets.to_i
s = gets
a = s.count('A')
b = s.count('D')
puts a>b ? "Anton" : b>a ? "Danik" : "Friendship"

numResults = gets.chomp.to_i
results = gets.chomp

anton = 0
danik = 0

results.each_byte do |b|
	if b.chr == 'A'
		anton = anton + 1
	elsif b.chr == 'D'
		danik = danik + 1
	end
end

if anton == danik
	puts "Friendship"
elsif anton > danik
	puts "Anton"
else
	puts "Danik"
end

games = gets.chomp
w = gets.chomp
wins = w.split("")

count = 0
wins.each do |win|
	if win == "A"
		count += 1
	else
		count -= 1
	end
end

if count > 0
	print "Anton"
elsif count < 0
	print "Danik"
else
	print "Friendship"
end

#puts "Enter the number of game played\n"
n = gets.to_i
s = gets.to_s
a = d = 0
for i in 0...n do
    if s[i] == 'A'
        a += 1
    else
        d += 1
    end
end
if a > d
    puts "Anton\n"
elsif d > a
    puts "Danik\n"
else
    puts "Friendship\n"
end

int_value = gets.chomp
string_input = gets.chomp
string = string_input.split('')
anton = 0
danik = 0
string.each do |char|
  if char == 'A'
    anton += 1
  else
    danik += 1
  end
end
if anton == danik
  puts 'Friendship'
elsif anton > danik
  puts 'Anton'
else
  puts 'Danik'
end

gets
s = gets
puts s.count("A") > s.count("D") ? "Anton" : (s.count("A") < s.count("D") ? "Danik" : "Friendship")

#!/usr/bin/env ruby

gets
s = gets.strip
a = s.count('A')
b = s.count('D')

if a > b
  puts 'Anton'
elsif a < b
  puts 'Danik'
else
  puts 'Friendship'
end

gets
s = gets
puts (a = s.count("A")) > (d = s.count("D")) ? "Anton" : a == d ? "Friendship" : "Danik"

gets
s = gets
puts s.count("A") > s.count("D") ? "Anton" : s.count("A") == s.count("D") ? "Friendship" : "Danik"

n = gets
n = gets
a = n.count 'A'
d= n.count 'D'
if a > d
  puts "Anton"
elsif a < d
  puts "Danik"
else
  puts "Friendship"
end

n = gets
data = gets.chomp

an = data.chars.count { |c| c == 'A' }
dn = data.chars.count { |c| c == 'D' }

if an > dn
  puts 'Anton'
elsif an < dn
  puts 'Danik'
else
  puts 'Friendship'
end

n = gets.to_i
s = gets.strip
r = s.count('A') * 2
if r > n
  printf("Anton\n")
elsif r == n
  printf("Friendship\n")
else
  printf("Danik\n")
end

n = gets.chomp().to_i
s = gets.chomp().split('')
anton = s.select{|c| c if c=='A'}.length
danik = s.select{|c| c if c=='D'}.length
puts ( anton == danik ) ? "Friendship" : (anton > danik) ? "Anton" : "Danik"

require 'set'
parse_int = lambda{ gets.split.map{|el| el.to_i} }
sign = lambda {|el| (el>0?1:0)-(el<0?1:0)}

gets
n = gets
a,d = n.count('A'), n.count('D')

puts 'Anton' if a>d
puts 'Danik' if d>a
puts 'Friendship' if d==a

gets
a = gets().chomp.split(//)
print a.inspect
cnt = 0
a.map{|x| x == 'A'?  cnt += 1 : cnt -= 1}
puts cnt > 0 ? "Anton" : cnt == 0 ? "Friendship" : "Danik"

gets
a = gets().split(//)
cnt = 0
a.map{|x| x == 'A'?  cnt += 1 : cnt -= 1}
puts cnt > 0 ? "Anton" : (cnt == 0 ? "Friendship" : "Danik")

num = gets.chomp.to_i
tabs = gets.chomp
A_count = 0
D_count = 0
for i in 0...num
	puts "check"
	if tabs[i] == "A"
		A_count += 1
	else
		D_count += 1
	end
end
if A_count > D_count
	puts "Anton"
elsif D_count > A_count
	puts "Danik"
else puts "Friendship"
end

gets
s = gets.chomp
n = 0
s.each_char do |i|
	if i == 'A'
		n += 1
	else
		n -= 1
	end
end
if n == 0
	puts 'Friendship'
elsif n > 1
	puts 'Anton'
else
	puts 'Danik'
end

numResults = gets.to_i
results = gets

anton = 0
danik = 0

puts results.size

results.each_byte do |b|
	if b.chr == 'A'
		anton = anton + 1
	elsif b.chr == 'D'
		danik = danik + 1
	end
end

if anton == danik
	puts "Friendship"
elsif anton > danik
	puts "Anton"
else
	puts "Danik"
end

input = $stdin.readlines

numResults = input[0].to_i
results = input[1]

anton = 0
danik = 0

puts results.size

results.each_byte do |b|
	if b.chr == 'A'
		anton = anton + 1
	elsif b.chr == 'D'
		danik = danik + 1
	end
end

if anton == danik
	puts "Friendship"
elsif anton > danik
	puts "Anton"
else
	puts "Danik"
end

int_value = gets
string_input = gets
string = string_input.split('')
anton = 0
danik = 0
string.each do |char|
  if char == 'A'
    anton += 1
  else
    danik += 1
  end
end
if anton == danik
  puts 'Friendship'
elsif anton > danik
  puts 'Anton'
else
  puts 'Danik'
end

#gets
#s = gets
#puts (a = s.count("A")) > (d = s.count("D")) ? "Anton" : a == d ? "Friendship" : "Danik"

s=$<.read
p [:Friendship,:Anton,:Danik][s.count(?A)<=>s.count(?D)]

require 'set'
parse_int = lambda{ gets.split.map{|el| el.to_i} }
sign = lambda {|el| (el>0?1:0)-(el<0?1:0)}

gets
n = gets
a,d = n.count('A'), n.count('D')

puts 'Antin' if a>d
puts 'Danik' if d>a
puts 'Friendship' if d==a


gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  as = gets.split.map(&:to_i)
  sorted = as.sort.zip(0..).to_h
  puts as.chunk_while { |a, b| sorted[a] == sorted[b] - 1 }.count <= k ? "Yes" : "No"
end

gets.to_i.times {
  n, k = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  ys = (0...n).to_a.sort_by { xs[_1] }
  b = 1
  (1...n).each { |i|
    b += 1 if ys[i] - 1 != ys[i - 1]
  }
  puts(b <= k ? 'Yes' : 'No')
}

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

  prev = {}
  ys = xs.sort
  ys.each_with_index { |x, i|
    prev[x] = ys[i - 1] if i > 0
  }

  blocks = 1
  (1...n).each { |i|
    blocks += 1 if prev[xs[i]] != xs[i - 1]
  }

  puts(blocks <= k ? 'Yes' : 'No')
}

#!/usr/bin/env ruby

tc = gets.to_i

def order(ar)
  sorted = ar.sort;
  hsh = sorted.zip(0..).to_h
  return ar.map{|x| hsh[x]}
end

def correct(ar)
  ar2 = ar.dup
  ar2.shift
  return ar.zip(ar2).map { |x| x[1] == x[0]+1 ? 1 : 0}.sum
end

for t in 1..tc
  n, k = gets.split.map { |x| x.to_i };
  ar =order(gets.split.map {|x| x.to_i});

#puts "#{ar}, #{n-correct(ar)}"
  puts "#{n-correct(ar) <= k ? 'Yes' : 'No'}"
end

t = gets.chomp.to_i
t.times do
    n, k = gets.chomp.split(" ").map(&:to_i)
    a = gets.chomp.split(" ").map(&:to_i)
    a_dup = a.dup
    a_dup = a_dup.sort
    hash = Hash.new(0)
    a_dup.each_with_index do |i,index|
        hash[i] = index
    end
    arr = []
    cnt = 0
    a.each do |i|
        if arr == []
            arr << i
        else
            if hash[arr[-1]] + 1 != hash[i]
                cnt += 1
            end
            arr << i
        end
    end
    if cnt + 1 <= k
        puts "Yes"
    else
        puts "No"
    end
end

END { load __FILE__ unless $stdin.eof? }

t = gets.to_i
t.times do
	n, k = gets.split.map!(&:to_i)
	a = gets.split.map!(&:to_i)

	h = a.sort.each_with_index.to_h
	a.map!(&h)

	c = a.each_cons(2).count { |x, y| x + 1 != y }
	puts (k >= c + 1) ? :Yes : :No
end

gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  as = gets.split.map(&:to_i)
  puts as.chunk_while { |a, b| a < b }.count <= k ? "Yes" : "No"
end


#!/usr/bin/env ruby

n, k = gets.split.collect{|i| i.to_i}
tot = 0
n.times do
	x, y = gets.split.collect{|i| i.to_i}
	tot = (tot + y - x + 1) % k
end

puts (tot == 0 ? 0 : k - tot)

n,k=gets.split.map(&:to_i)
sum=0
n.times do
    a,b=gets.split.map(&:to_i)
    sum+=b-a+1
end
puts sum%k==0?0:k-sum%k

def run
  n, k = $stdin.readline.split.map(&:to_i)

  sum = 0
  $stdin.readlines.each do |line|
    l, r = line.split.map(&:to_i)
    sum += r - l + 1
  end

  puts (sum % k == 0) ? 0 : (k - sum % k)
end

run if $0 == __FILE__

class A
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    total = 0
    n.times do
      l, r = $stdin.gets.chomp.split(' ').map(&:to_i)
      count = r - l + 1
      total += count
    end

    if total%k == 0
      puts 0
    else
      puts k - (total%k)
    end
  end
end

a = A.new

a=gets.chomp.split(" ")
k=a[1].to_i
x=0
(a[0].to_i).times do
temp=gets.chomp.split(" ")
x+=temp[1].to_i-temp[0].to_i+1
end
puts "#{(k-(x%k))%k}"

n,k=gets.split.map(&:to_i)
s=0
n.times do
    l,r=gets.split.map(&:to_i)
    s+=r-l+1
end
puts (k-s%k)%k

n, k = gets.split(' ').map { |x| x.to_i }
t = 0
(1..n).each do |x|
 a,b = gets.split(' ').map { |x| x.to_i }
 t += (b-a).abs + 1
end
puts (k - t % k) % k

n, m = gets.split(' ').map!{ |i| i.to_i }

arr = Array.new
sum = 0
n.times {
	l, r = gets.split(' ').map!{ |i| i.to_i }
	arr << r - l + 1
	sum += arr[-1]
}

left = sum % m

ans = left == 0 ? 0 : m - left

p ans

n, k = gets.split.map(&:to_i)
lrs = n.times.map { gets.split.map(&:to_i) }
count = lrs.sort_by(&:first).map { |(a, b)| b - a + 1 }.reduce(:+)
if count % k == 0
  p 0
else
  p k - count % k
end

n,kp = gets.split(" ").collect {|x| x.to_i}
last = -1
rs = 0
ls = 0
s = 0
(0...n).each {|k|
	ls,rs = gets.split(" ").collect {|x| x.to_i}
	s+= (rs-ls+1)
}

puts (kp - s%kp)%kp

n, k = gets.split.collect{|i| i.to_i}
cnt = 0
(0...n).each do
    l, r = gets.split.collect{|i| i.to_i}
    cnt += r-l+1
end
if cnt%k == 0
    puts "0"
else
    puts k-cnt%k
end

n, k = gets.split(" ").collect{|x| x.to_i}

v = 0
c = 0
n.times do
  l, r = gets.split(" ").collect{|x| x.to_i}
  v += r - l + 1
end

rest = v % k
puts (k - rest) % k

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

n, k = read_next_line
sum = 0
for _ in 1..n
  l, r = read_next_line
  sum += r - l + 1
end
rem = sum % k
puts(rem == 0 ? 0 : k - rem)

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

segments = []
n.times do
  segments << gets.strip.split.map(&:to_i)[0..1]
end

value = segments.map{|x| x[1] - x[0] + 1}.inject :+
puts value % k == 0 ? 0 : ((value / k) + 1) * k - value

n, k = gets.split(' ').map { |x| x.to_i }
m = (0..10000).to_a
(1..n).each do |x|
 a,b = gets.split(' ').map { |x| x.to_i }
 (a..b).each { |i| m[i] = 1 }
end
t = 0
m.each {|x| if x == 1 then t = t+1 end}
s = 0
while (t % k != 0 )
  t = t + 1
  s = s + 1
end
puts s

n, k = gets.split(' ').map { |x| x.to_i }
t = 0
(1..n).each do |x|
 a,b = gets.split(' ').map { |x| x.to_i }
 t += b-a.abs + 1
end
if t <= k then puts k-t
else
  r = k
  while r <= t
    r += k
  end
  puts r - t
end

n, k = gets.split(' ').map { |x| x.to_i }
t = 0
(1..n).each do |x|
 a,b = gets.split(' ').map { |x| x.to_i }
 t += b-a.abs + 1
end
if t <= k then puts k-t
else
  r = k
  while r < t
    r += k
  end
  puts r - t
end

n, k = gets.split(' ').map { |x| x.to_i }
m = Array.new(20001)
(1..n).each do |x|
 a,b = gets.split(' ').map { |x| x.to_i }
 (a..b).each { |i| m[i+10000] = 1 }
end
t = 0
m.each {|x| if x == 1 then t = t+1 end}
if t <= k then puts k-t
else
  r = k
  while r <= t
    r = r + k
  end
  puts r-t
end

n, k = gets.split(' ').map { |x| x.to_i }
t = 0
(1..n).each do |x|
 a,b = gets.split(' ').map { |x| x.to_i }
 t += b-a.abs + 1
end
if t <= k then puts k-t
else
  puts k - (t % k)
end


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

status = (1..n).to_a
leader = 0
a.each { |step|
    eliminate = (leader + step) % status.length
    print "#{status[eliminate]} "
    status = status.select.with_index { |v, i| i != eliminate }
    leader = eliminate
}
print "\n"

#!/usr/bin/env ruby

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

outs = []
childs = Array.new(n)
childs.each_with_index { |v, i| childs[i] = i + 1 }

cur = 0
ks.each do |k|
  k_i = (cur + (k % childs.size)) % childs.size
  outs << childs[k_i]
  childs.delete_at(k_i)
  cur = k_i % childs.size
end

puts outs.join(" ")

n,k=gets.split(" ").map(&:to_i)
a=gets.split(" ").map(&:to_i)
dt=(1..n).to_a

now=0

ans=[]

for i in (0...k)
	tmp=a[i]%dt.length
	now=(now+tmp)%dt.length
	ans<<dt.delete_at(now)
end
puts ans.join(" ")

parse_int = lambda{gets.split.map{|x| x.to_i}}

n, k = parse_int.call

children = []
n.times { |i| children << i+1 }

lea, first = 0, true
for step in parse_int.call do
  lea = (lea + step) % children.length

  print ' ' unless first
  print children[lea]

  children.delete_at lea
  lea = 0 if lea >= children.length

  first = false
end


a, b = nil
File.open("input.txt") do |f|
  a = f.gets.strip
  b = f.gets.strip
end

if (a == 'front' && b == '1') || (a == 'back' && b == '2')
  lr = 'L'
else
  lr = 'R'
end

File.open("output.txt", "w") do |f|
  f.puts lr
end

f = File.open('input.txt', 'r') or die "Unable to open file..."
input = []  # start with an empty array
  f.each_line {|line|
    input.push line
  }

door = input[0].chop
side = input[1].to_i
while door == 'front' or door == 'back'
 File.open('output.txt', 'w') do |o|
 o.puts "#{(door == 'front')? ((side == 1)? 'L' : 'R') : ((side == 2)? 'L' : 'R')}"
 end
exit
end

solve = {['front', '1'] => 'L', ['front', '2'] => 'R', ['back', '1'] => 'R', ['back', '2'] => 'L'}
File.open('input.txt', 'r') do |input|
	File.open('output.txt', 'w') do |output|
		output.puts solve[[input.gets.chomp, input.gets.chomp]]
	end
end


def ord_to_char(seq_ord)
  ('a'.ord+seq_ord-1).chr
end

def decode(encoded_str,len)
  # Search from the tail is better.
  ptr=len-1
  res_str=[]
  while ptr>=0
    if encoded_str[ptr]=='0'
      res_str << ord_to_char(encoded_str[ptr-2...ptr].to_i)
      ptr-=3
    else
      res_str << ord_to_char(encoded_str[ptr].to_i)
      ptr-=1
    end
  end
  res_str.reverse.join('')
end

n_rounds=gets.to_i

n_rounds.times do
  len=gets.to_i
  estr=gets
  puts decode(estr,len)
end

c=Hash.new(nil);$stdin.each_line.with_index{|l, i|next if i==0||i%2==1;if c[l]!=nil;puts(c[l]);next;end;nt=0;o="";l.chomp.each_char.with_index {|x, i|if nt!=0;nt-=1;next;end;if (i<(l.chomp.length-2))&&(l[i + 2]=="0")&&(i>l.chomp.length-4||l[i + 3]!="0");nt=2;o+=("a".."z").to_a[(x+l[i+1]).to_i-1];next;end;o+=("a".."z").to_a[x.to_i-1]};c[l]=o;puts(o)}

c = Hash.new(nil)
$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1
    if c[l] != nil
        puts c[l]
        next
    end
    nt = 0
    o = ""
    l.chomp.each_char.with_index do |x, i|
        if nt != 0
            nt -= 1
            next
        end
        if (i < (l.chomp.length - 2)) && (l[i + 2] == "0") && (i > l.chomp.length - 4 || l[i + 3] != "0")
            nt = 2
            o += ("a".."z").to_a[(x + l[i + 1]).to_i - 1]
            next
        end
        o += ("a".."z").to_a[x.to_i - 1]
    end
    c[l]=o
    puts o
end

def solve(n, s)
  alphabets = ['@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

  ans = ''
  i = n-1
  while i >= 0 do
    if s[i] == '0'
      ans += alphabets[s[(i-2)..(i-1)].to_i]
      i -= 3
    else
      ans += alphabets[s[i].to_i]
      # p alphabets[s[i].to_i]
      i -= 1
    end
  end
  ans.reverse!
  puts ans
end

t = gets.chomp.to_i
for i in 1..t
  n = gets.chomp.to_i
  s = gets.chomp
  solve(n, s)
end

def debug(*arg)
  puts "[DEBUG] #{arg.join " "}"
end

t = gets.to_i

alpha = ('a'.upto 'z').to_a

t.times do
  n = gets.to_i
  s = gets.chomp.chars

  ans = []
  until s.empty?
    last = s.pop
    if last == '0'
      ans << alpha[s[-2..].join.to_i - 1]
      s.pop; s.pop
    else
      ans << alpha[last.to_i - 1]
    end

  end
  puts ans.reverse.join("")
end

$stdin.readline

cache = {}

while !$stdin.eof do
    $stdin.readline
    codestr = $stdin.readline.chomp

    if cache[codestr]
        puts cache[codestr]
        next
    end

    str = codestr.reverse.scan(/0[0-9][1-9]|[1-9]/).map { |code|
        code = code.reverse.to_i
        code = code < 10 ? code : code / 10
        ("a".."z").to_a[code - 1]
    }.join.reverse

    puts cache[codestr] = str
end

c = Hash.new(nil)
$stdin.each_line.with_index do |l, i| next if i == 0 || i % 2 == 1
    puts c[l] if c[l] != nil
    nt = 0
    o = ""
    l.chomp.each_char.with_index do |x, i|
        if nt != 0
            nt -= 1
            next
        end
        if (i < (l.chomp.length - 2)) && (l[i + 2] == "0") && (i > l.chomp.length - 4 || l[i + 3] != "0")
            nt = 2
            o += ("a".."z").to_a[(x + l[i + 1]).to_i - 1]
            next
        end
        o += ("a".."z").to_a[x.to_i - 1]
    end
    c[l]=o

    puts o
end

def solve(n, s)
  alphabets = ['@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

  ans = ''
  i = n-1
  while i >= 0 do
    if s[i] == '0'
      ans += alphabets[s[(i-2)..(i-1)].to_i]
      i -= 3
    else
      ans += alphabets[s[i].to_i]
      # p alphabets[s[i].to_i]
      i -= 1
    end
  end
  ans.reverse!
  p ans
end

t = gets.chomp.to_i
for i in 1..t
  n = gets.chomp.to_i
  s = gets.chomp
  solve(n, s)
end

def solve(n, s)
  alphabets = ['@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

  ans = ""
  i = n-1
  while i >= 0 do
    if s[i] == '0'
      ans += alphabets[s[(i-2)..(i-1)].to_i]
      i -= 3
    else
      ans += alphabets[s[i].to_i]
      # p alphabets[s[i].to_i]
      i -= 1
    end
  end
  ans.reverse!
  p ans
end

t = gets.chomp.to_i
for i in 1..t
  n = gets.chomp.to_i
  s = gets.chomp
  solve(n, s)
end

def debug(*arg)
  puts "[DEBUG] #{arg.join " "}"
end

t = gets.to_i

alpha = ('a'.upto 'z').to_a

p alpha

t.times do
  n = gets.to_i
  s = gets.chomp.chars

  ans = []
  until s.empty?
    last = s.pop
    if last == '0'
      ans << alpha[s[-2..].join.to_i - 1]
      s.pop; s.pop
    else
      ans << alpha[last.to_i - 1]
    end

  end
  puts ans.reverse.join("")
end


def read
    gets.split.map &:to_i
end
gets.to_i.times do
    n, k = read
    a = read
    s, res = a[0], 0
    (1...n).each do |i|
        res = [res, (100 * a[i] - k * s + k - 1) / k].max
        s += a[i]
    end
    puts res
end

gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  ps0, *ps = gets.split.map(&:to_i)
  nps = (ps0..10 ** 12).bsearch do |ps0|
    x = ps0
    ps.all? do |p|
      p.to_f / x <= k / 100.0 && (x += p)
    end
  end
  p nps - ps0
end

gets.to_i.times do
  n,k=gets.split.map(&:to_i)
  q=gets.split.map(&:to_i)
  c=0
  s=q[0]
  1.upto(n-1) do |i|
    if 100*q[i]-k*(s+c)>0
      c+=(100*q[i]-1)/k+1-s-c
    end
    s+=q[i]
  end
  puts c
end

gets.to_i.times do
  n,k=gets.split.map(&:to_i)
  q=gets.split.map(&:to_i)
  c=0
  s=q[0]
  1.upto(n-1) do |i|
    if 100*q[i]-k*(s+c)>0
      c+=(100*q[i]-1)/k+1-s
    end
    s+=q[i]
  end
  puts c
end


require 'prime'

def divisors(n)
    res=[]
    (1..n**0.5).select{|i|n%i==0}.each{|i|
        res<<i
        res<<n/i if n/i!=i
    }
    res.sort
end

def divisors2(n)
    n.prime_division.inject([1]){|a, (p, e)|
        (0..e).map{|i| p**i}.product(a).map{|x, y| x*y}
    }.sort
end

gets.to_i.times {
    n, k=gets.split.map(&:to_i)
    puts n/divisors2(n).select{|e|e<=k}.max
}

require 'prime'

class Integer
	def divisors
		self.prime_division.inject([1]) do |a, (p, e)|
			(0..e).map { p**_1 }.product(a).map { _1 * _2 }
		end.sort
	end
end

gets.to_i.times do
	n, k = gets.split.map(&:to_i)
	puts n / n.divisors.select { _1 <= k }.max
end

gets.strip.to_i.times do |t|
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).ceil.to_i
  divs = [1, n]
  (2..sq).each do |i|
    if n % i == 0
      divs << i
      divs << n / i
    end
  end
  res = divs.sort.reverse.bsearch { |e| e <= k }
  puts n / res
end

def divisors(n)
    res=[]
    (1..n**0.5).select{|i|n%i==0}.each{|i|
        res<<i
        res<<n/i if n/i!=i
    }
    res.sort
end

gets.to_i.times {
    n, k=gets.split.map(&:to_i)
    puts n/divisors(n).select{|e|e<=k}.max
}

def divisors(n)
    res=[]
    (1..n**0.5).select{|i|n%i==0}.each{|i|
        res<<i
        res<<n/i if n/i!=i
    }
    res
#    res.sort
end

gets.to_i.times {
    n, k=gets.split.map(&:to_i)
    puts n/divisors(n).select{|e|e<=k}.max
}

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        sqn = Math.sqrt(n).ceil
        m = 1
        max = 1
        r = [sqn, k].min
        for i in 2..r
            if n % i == 0
                m = i
                packs = n/m

                if max < m && m <= k
                    max = m
                end

                if max < packs && packs <= k
                    max = packs
                end
            end
        end

        puts "#{n/max}"
    end
}

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  ok = 1e9 + 1
  (1..sq).each { |el|
    if n.modulo(el).zero?
      an1 = 1e9 + 1
      an2 = 1e9 + 1
      an1 = n / el if el <= k
      an2 = el if n / el <= k
      next if an1 == 1e9 + 1 && an2 == 1e9 + 1
      ok = [ok, an1, an2].min
    end
  }
  puts ok
end

gets.strip.to_i.times do
  solve
end

t = gets.to_i
t.times do
  n, k = gets.split.map(&:to_i)
  ans = n
  if k >= n
    ans = 1
  else
    d = 1
    while d * d <= n do
      if n % d == 0
        if (n / d) <= k && d < ans
          ans = d
        end
        if d <= k && (n / d) < ans
          ans = (n / d)
        end
      end
      d += 1
    end
  end
  puts ans
end

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        sqn = Math.sqrt(n).ceil
        m = 1
        packs = n
        r = [sqn, k].min
        for i in 0...(r-1)
            if n % (r-i) == 0
                m = r-i
                packs = n/m

                if m < packs && packs <= k
                    m, packs = packs, m
                end
                break
            end
        end

        puts "#{packs}"
    end
}

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        # 1..k 개까지의 패키지를 구성할 수 있고, 이 안에서 여러번 반복해서 구입할 수 있다.
        # k 범위 내에서 가장 큰, n의 소인수를 찾아야한다.
        sqn = Math.sqrt(n).ceil
        m = 1
        for i in 2..([sqn, k].min)
            if n%i == 0
                m = i
                break
            end
        end

        puts "#{[n/m, m].min}"
    end
}

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        sqn = Math.sqrt(n).ceil
        m = 1
        for i in 2..([sqn, k].min)
            if n%i == 0
                m = i
            end
        end

        if m == 1
            puts n
        else
            puts "#{[n/m, m].min}"
        end
    end
}

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        sqn = Math.sqrt(n).ceil
        m = 1
        packs = n
        r = [sqn, k].min
        for i in 0...(r-1)
            if n % (r-i) == 0
                m = r-i
                packs = n/m

                if m < packs
                    m, packs = packs, m
                end
                break
            end
        end

        puts "#{packs}"
    end
}

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        # 1..k 개까지의 패키지를 구성할 수 있고, 이 안에서 여러번 반복해서 구입할 수 있다.
        # k 범위 내에서 가장 큰, n의 소인수를 찾아야한다.
        sqn = Math.sqrt(n).ceil
        m = 1
        for i in 2..([sqn, k].min)
            if n%i == 0
                m = i
            end
        end

        puts "#{n/m}"
    end
}

# coding: utf-8

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

    if n <= k
        puts "1"
    else
        # 반드시 정확한 수량만큼 구입해야한다.
        # 오버해서 남은 삽을 버릴 수 있었다면 쉽게 풀었겠지?
        # 1..k 개까지의 패키지를 구성할 수 있고, 이 안에서 여러번 반복해서 구입할 수 있다.
        # k 범위 내에서 가장 큰, n의 소인수를 찾아야한다.
        sqn = Math.sqrt(n).ceil
        m = 1
        for i in 2..([sqn, k].min)
            if n%i == 0
                m = i
                break
            end
        end

        puts "#{n/m}"
    end
}

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  (1..sq).each { |el|
    if n.modulo(el).zero? && el <= k
      puts el
      return
    end
  }
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  an = 0
  (1..sq).each { |el|
    if n.modulo(n / el).zero? && n / el <= k
      an = el
    end
  }
  puts an
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  (1..sq).each { |el|
    if n.modulo(el).zero?
      an1 = 1e9 + 1
      an2 = 1e9 + 1
      an1 = n / el if el <= k
      an2 = el if n / el <= k
      next if an1 == 1e9 + 1 && an2 == 1e9 + 1
      puts [an1, an2].min
      return
    end
  }
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i + 1
  (1..sq).each { |el|
    if n.modulo(el).zero? && (n / el) <= k
      puts el
      return nil
    end
  }
  puts n
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  (1..sq).each { |el|
    if n.modulo(el).zero? && (n / el) <= k
      puts el
      return nil
    end
  }
  #puts "dasdasd"
  puts n
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i + 1
  an = 0
  (1..sq).each { |el|
    an = n / el if n.modulo(el).zero? && el <= k
    an = n / (n / el) if n.modulo(n / el).zero? && n / el <= k
  }
  puts an
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i + 1
  an = 0
  (1..sq).each { |el|
    if n.modulo(el).zero? && el <= k
      an = n / el
    end
  }
  puts an
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  an = 0
  (1..sq).each { |el|
    an = n / el if n.modulo(el).zero? && el <= k
    an = n / (n / el) if n.modulo(n / el).zero? && n / el <= k
  }
  puts an
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  ok = 0
  (1..sq).each { |el|
    if n.modulo(el).zero?
      an1 = 1e9 + 1
      an2 = 1e9 + 1
      an1 = n / el if el <= k
      an2 = el if n / el <= k
      next if an1 == 1e9 + 1 && an2 == 1e9 + 1
      ok = [an1, an2].min
    end
  }
  puts ok
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i + 1
  (1..sq).each { |el|
    if n.modulo(el).zero? && (n / el).to_f <= k
      puts el
      return nil
    end
  }
  puts n
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(k).to_i + 1
  (1..sq).each { |el|
    if n.modulo(el).zero?
      puts el
      return nil
    end
  }
  puts n
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i + 1
  (1..sq).each { |el|
    if n.modulo(el).zero? && (n / el) <= k
      puts el
      return nil
    end
  }
  #puts "dasdasd"
  puts n
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  (1..sq).each { |el|
    if (n % el).zero? && (n / el) <= k
      puts el
      return nil
    end
  }
  #puts "dasdasd"
  puts n
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  if n == k
    puts 1
    return nil
  end
  sq = Math.sqrt(n).to_i + 1
  an = 0
  (1..sq).each { |el|
    if n.modulo(el).zero? && el <= k
      an = n / el
    end
  }
  puts an
end

gets.strip.to_i.times do
  solve
end

def solve
  n, k = gets.strip.split(' ').map(&:to_i)
  sq = Math.sqrt(n).to_i
  (1..sq).each { |el|
    if n.modulo(n / el).zero? && n / el <= k
      puts el
      return;
    end
  }
end

gets.strip.to_i.times do
  solve
end


N, K, s = gets.split.map(&:to_i)
if (N-1)*K < s || K > s
    puts 'NO'
    exit
end

ans = []
now = 1
s -= K
K.times do |i|
    add = [s, N-2].min
    s -= add
    now += (add+1) * (i%2==0 ? 1 : -1)
    ans.push(now)
end
puts 'YES'
puts ans.join(' ')

def solution
  n, k, s = read_ints

  if k > s
    puts "NO"
    return
  end

  if k * (n - 1) < s
    puts "NO"
    return
  end

  rs = s

  dir = 1
  crt = 1
  path = []

  k.times do |j|
    rk = k - j

    move = (rs.to_f / rk).ceil * dir
    dir *= -1
    rs -= move.abs

    crt = crt + move
    path << crt
  end

  puts "YES"
  puts path.join(' ')

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']

def solution
  n, k, s = read_ints

  if k > s
    puts "NO"
    return
  end

  if s.to_f / k > (n-1)
    puts "NO"
    return
  end

  crt = 1
  rs = s
  rk = k

  path = []

  while rs > 0
    steps_per_move = (rs.to_f / rk).ceil
    if crt < steps_per_move
      goto = crt + steps_per_move
    else
      goto = crt - steps_per_move
    end

    rs -= (goto-crt).abs
    rk -= 1

    path << goto
    crt = goto
  end

  puts 'YES'
  puts path.join(' ')

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']


#!/usr/bin/env ruby
# encoding: utf-8
good = gets.to_str.chomp
pattern = gets.to_str
key = pattern.strip.gsub("?","["+good+"]").gsub("*","[^"+good+"]*")
rg = Regexp.new("^"+key+"$")

n = gets.to_i
n.times do
    buf = gets.to_str
    if rg =~ buf
        puts "YES"
    else
        puts "NO"
    end
end

# Codeforces My Practice
# author: Leonardone @ NEETSDKASU

gl = [false] * 256
gets.strip.each_char do |c|
    gl[c.swapcase.ord] = true
    gl[c.ord] = true
end
pt = ("[" + gets.strip + "]").split "*"
n = gets.to_i
if pt.size == 1
    px = pt[0]
    n.times do
        s = gets.strip
        if s.size != px.size - 2
            puts :NO
            next
        end
        ok = true
        s.size.times do |i|
            next if s[i] == px[i+1]
            if px[i+1] == '?'
                next if gl[s[i].ord]
            end
            ok = false
            break
        end
        puts ok ? :YES : :NO
    end
    exit
end

px, py = pt
n.times do
    s = gets.strip
    if s.size < px.size + py.size - 2
        puts :NO
        next
    end
    ok = true
    (px.size-1).times do |i|
        next if s[i] == px[i+1]
        if px[i+1] == '?'
            next if gl[s[i].ord]
        end
        ok = false
        break
    end
    if !ok
        puts :NO
        next
    end
    (py.size-1).times do |i|
        next if s[-i-1] == py[-i-2]
        if py[-i-2] == '?'
            next if gl[s[-i-1].ord]
        end
        ok = false
        break
    end
    if !ok
        puts :NO
        next
    end
    u = s.size - (px.size + py.size - 2)
    u.times do |i|
        next if !gl[s[i+px.size-1].ord]
        ok = false
        break
    end
    puts ok ? :YES : :NO
end

#!/usr/bin/env ruby
# encoding: utf-8
good = gets.to_str.chomp!
pattern = gets.to_str
key = ""
pattern.each_char do | c |
    if c == '?'
        key+="["+good+"]"
    elsif c == '*'
        key+="[^"+good+"]{0,1}"
    else
        key+=c
    end
end

ha = Regexp.new(key)

n = gets.to_i
n.times do | i |
    buf = gets.to_str
    m=ha.match(buf).to_s
    if m == nil
        puts("NO")
    elsif m == buf
        puts("YES")
    else
        puts("NO")
    end
end

# Try Codeforces
# author: Leonardone @ NEETSDKASU

gl = gets.strip
pt = gets.strip.gsub("?","[" + gl + "]").gsub("*", ".?")
rg = Regexp.compile("^" + pt + "$")
n = gets.to_i
n.times do
    s = gets.strip
    if s =~ rg
        puts "YES"
    else
        puts "NO"
    end
end

# Try Codeforces
# author: Leonardone @ NEETSDKASU

gl = gets.strip
pt = gets.strip.gsub("?","[" + gl + "]").gsub("*", ".*")
rg = Regexp.compile("^" + pt + "$", Regexp::IGNORECASE)
n = gets.to_i
n.times do
    s = gets.strip
    if s =~ rg
        puts "YES"
    else
        puts "NO"
    end
end

# Try Codeforces
# author: Leonardone @ NEETSDKASU

gl = gets.strip
pt = gets.strip.gsub("?","[" + gl + "]").gsub("*", ".?")
rg = Regexp.compile("^" + pt + "$", Regexp::IGNORECASE)
n = gets.to_i
n.times do
    s = gets.strip
    if s =~ rg
        puts "YES"
    else
        puts "NO"
    end
end


n, k = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
h = Hash.new(0)
arr.each do |e|
  h[e] += 1
end
h.values.each do |v|
  if v > k
    puts "NO"
    exit
  end
end
cur_c = 0
prev_cur_c = 0
f = false
res = [0] * arr.size
mp = Array.new(k) {Array.new}
arr.each_with_index do |e, ind|
  while mp[cur_c].include?(e)
    if cur_c == prev_cur_c
      puts "NO"
      exit
    end
    cur_c = (cur_c + 1) % k
  end
  mp[cur_c] << e
  res[ind] = cur_c
  prev_cur_c = cur_c
  cur_c = (cur_c + 1) % k
end
puts "YES"
puts res.map{|x| x + 1}.join(" ")

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Array.new(5005) { [] }
a.each_with_index { |x, i| b[x] << i }

c = 1
ans = [-1] * n
b.each do |pos|
	puts('NO') + exit if pos.size > k
	pos.each do |i|
		ans[i] = c
		c = c < k ? c + 1 : 1
	end
end
puts 'YES', ans.join(' ')

input = STDIN.read.split("\n").map{|l| l.split(" ").map{|a| a.to_i}}
first = input.shift
ARR = input.shift
N = first[0]
COLORS = first[1]

NUM_USED_COLORS = {}
remained_color_i = 0

dic = {}
is_no = false

colored_arr = []

for i in ARR
  if !NUM_USED_COLORS.key?(i)
    NUM_USED_COLORS[i] = {}
  end

  if remained_color_i < COLORS
    NUM_USED_COLORS[i][remained_color_i] = true
    colored_arr.push(remained_color_i)
    remained_color_i = remained_color_i + 1
  else
    found = false
    for j in 0..(COLORS - 1)
      if !NUM_USED_COLORS[i].key?(j)
        NUM_USED_COLORS[i][j] = true
        colored_arr.push(j)
        found = true
        break
      end
    end
    if found == false
      is_no = true
    end
  end
  if is_no == true
    break
  end
end

if is_no
  puts 'NO'
else
  puts 'YES'
  puts colored_arr.map{|i| i + 1}.join(' ')
end

N,K = gets.split.map(&:to_i)
ns = {}
is = []
a = gets.split.map(&:to_i)
a.each_with_index{ |x,i| ns[x] = (ns[x] || 0) + 1; is << [x,i]  }
if ns.values.max > K || N < K
    puts "NO"; exit
end
c = -1
is.sort!
#p is
is.each{ |x,i|
 a[i] = (c += 1) % K + 1
}
puts "YES", a.join(" ")

# Input
n, k = gets.split(" ").map { |e| e.to_i }
a = gets.split(" ").map { |e| e }

# Processing
count = Hash.new(0)
a.each { |n| count[n] += 1 }

current_color = Hash.new(count)
i = 1
count.each do |n, c|
  if c > k
    puts "NO"
    #puts "#{n} amount > k"
    exit
  end
  current_color[n] = i
  i = (i + c - 1) % k + 1
 end

c = Array.new(n) do |i|
  #puts current_color
  color = current_color[a[i]]
  current_color[a[i]] = current_color[a[i]] % k + 1
  color
end

# Output
puts "YES"
puts c.join(" ")

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Array.new(10) { [] }
a.each_with_index { |x, i| b[x] << i }

c = 1
ans = [-1] * n
b.each do |pos|
	puts('NO') + exit if pos.size > k
	pos.each do |i|
		ans[i] = c
		c = c < k ? c + 1 : 1
	end
end
puts 'Yes', ans.join(' ')

# Input
n, k = gets.split(" ").map { |e| e.to_i }
a = gets.split(" ").map { |e| e }

# Processing
count = Hash.new(0)
current_color = Hash.new

a.each do |n|
  count[n] += 1
end

if count.length < k
  puts "NO"
  exit
end
count.each do |n, amount|
  if amount > k
    puts "NO"
    exit
  end
  current_color[n] = (current_color.length % k) + 1
end

c = Array.new(n) do |i|
  #puts current_color
  color = current_color[a[i]]
  current_color[a[i]] = current_color[a[i]] % k + 1
  color
end

# Output
puts "YES"
puts c.join(" ")

# Input
n, k = gets.split(" ").map { |e| e.to_i }
a = gets.split(" ").map { |e| e }

# Processing
count = Hash.new(0)
a.each { |n| count[n] += 1 }

current_color = Hash.new(count)
i = 1
count.each do |n, c|
  current_color[n] = i
  i = (i + c) % k + 1
 end

c = Array.new(n) do |i|
  #puts current_color
  color = current_color[a[i]]
  current_color[a[i]] = current_color[a[i]] % k + 1
  color
end

# Output
puts "YES"
puts c.join(" ")

# Input
n, k = gets.split(" ").map { |e| e.to_i }
a = gets.split(" ").map { |e| e }

# Processing
count = Hash.new(0)
a.each { |n| count[n] += 1 }

current_color = Hash.new(count)
i = 1
count.each do |n, c|
  if c > k
    puts "NO"
    #puts "#{n} amount > k"
    exit
  end
  current_color[n] = i
  i = (i + c) % k + 1
 end

c = Array.new(n) do |i|
  #puts current_color
  color = current_color[a[i]]
  current_color[a[i]] = current_color[a[i]] % k + 1
  color
end

# Output
puts "YES"
puts c.join(" ")

n, k = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
h = Hash.new(0)
arr.each do |e|
  h[e] += 1
end
h.values.each do |v|
  if v > k
    puts "NO"
    exit
  end
end
cur_c = 0
prev_cur_c = 0
f = false
res = [0] * arr.size
mp = Array.new(k) {Array.new}
arr.each_with_index do |e, ind|
  while mp[cur_c].include?(e)
    cur_c += 1
    if cur_c == prev_cur_c
      puts "NO"
      exit
    end
  end
  mp[cur_c] << e
  res[ind] = cur_c
end
puts "YES"
puts res.map{|x| x + 1}.join(" ")

N,K = gets.split.map(&:to_i)
ns = {}
A = gets.split.map(&:to_i)
A.each{ |x| ns[x] = (ns[x] || 0) + 1 }
if ns.values.max > K
    puts "NO"; exit
end
puts "YES", A.map{ |x| (ns[x] -= 1) + 1 }.join(" ")


f = 1
as = gets.split.map(&:to_i)
n = as[0]
d = as[1]
k = as[2]
tr = Array.new(n+5)
i = 0
while i<=n
      tr[i] = Array.new
      i+=1
end

node = 0
for i in 1..d
    if i>=n
       f = 0
       break
    end
    tr[i].push(i+1)
    tr[i+1].push(i)
    node = i+1
    if tr[i].size>k || tr[node].size>k
       f = 0
       break
    end
end

dep = Array.new(n+5)
vis = Array.new(n+5)
o = 0
while o<=n
      dep[o] = 0
      vis[o] = 0
      o+=1
end
cen1 = 0
cen2 = 0
mx_dep = 0
if node%2==1
   cen1 = (node+1)/2
   mx_dep = cen1-1
else
   cen1 = node/2
   cen2 = cen1+1
   mx_dep = cen1-1
end
dep[cen1] = 0
dep[cen2] = 0
vis[cen1] = 1
vis[cen2] = 1
c = 1
while node<n && c<=2 && f>0
      c+=1
      q=Array.new
      if cen1 > 0
         q.push(cen1)
         cen1 = 0
      elsif cen2>0
         q.push(cen2)
         cen2 = 0
      end

      while q.length > 0
            a = q.first
            q.shift
            if tr[a].size>k
               f = 0
               break
            end
            while tr[a].length<k && node<n && dep[a]<mx_dep
                  node+=1
                  tr[a].push(node)
                  tr[node].push(a)
            end

            for ii in tr[a]
                if vis[ii]>0
                   next
                end
                q.push(ii)
                vis[ii] = 1
                dep[ii] = dep[a] + 1
            end
      end

end

if f==0 || node!=n
   puts "NO"
else
   puts "YES"
   for z in (1..n)
    vis[z] = 0
   end
   for j in (1..n)
       for z in tr[j]
           if vis[z]>0 && vis[j]>0
              next
           end
           vis[z] = 1
           vis[j] = 1
           puts "#{j} #{z}"
       end
   end
end
=begin
=end

f = true
as = gets.split.map(&:to_i)
n = as[0]
d = as[1]
k = as[2]
tr = Array.new(n+5)
i = 0
while i<=n
      tr[i] = Array.new
      i+=1
end

node = 0
for i in 1..d
    if i>=n
       f = false
       break
    end
    tr[i].push(i+1)
    tr[i+1].push(i)
    node = i+1
    if tr[i].size>k || tr[node].size>k
       f = false
       break
    end
end

dep = Array.new(n+5)
vis = Array.new(n+5)
o = 0
while o<=n
      dep[o] = 0
      vis[o] = 0
      o+=1
end
cen1 = 0
cen2 = 0
mx_dep = 0
if node%2==1
   cen1 = (node+1)/2
   mx_dep = cen1-1
else
   cen1 = node/2
   cen2 = cen1+1
   mx_dep = cen1-1
end
dep[cen1] = 0
dep[cen2] = 0
vis[cen1] = 1
vis[cen2] = 1
c = 1
while node<n && c<=2 && f==true
      c+=1
      q=Array.new
      if cen1 > 0
         q.push(cen1)
         cen1 = 0
      elsif cen2>0
         q.push(cen2)
         cen2 = 0
      end

      while q.length > 0
            a = q.first
            q.shift
            if tr[a].size>k
               f = false
               break
            end
            while tr[a].length<k && node<n && dep[a]<mx_dep
                  node+=1
                  tr[a].push(node)
                  tr[node].push(a)
            end

            for ii in tr[a]
                if vis[ii]>0
                   next
                end
                q.push(ii)
                vis[ii] = 1
                dep[ii] = dep[a] + 1
            end
      end

end

if !f || node!=n
   puts "NO"
else
   puts "YES"
   for z in (1..n)
    vis[z] = 0
   end
   for j in (1..n)
       for z in tr[j]
           if vis[z]>0 && vis[j]>0
              next
           end
           vis[z] = 1
           vis[j] = 1
           puts "#{j} #{z}"
       end
   end
end
=begin
=end

f = true
as = gets.split.map(&:to_i)
n = as[0]
d = as[1]
k = as[2]
tr = Array.new(n+5)
i = 0
while i<=n
      tr[i] = Array.new
      i+=1
end

node = 0
for i in 1..d
    if i>=n
       f = false
       break
    end
    tr[i].push(i+1)
    tr[i+1].push(i)
    node = i+1
end

dep = Array.new(n+5)
vis = Array.new(n+5)
o = 0
while o<=n
      dep[o] = 0
      vis[o] = 0
      o+=1
end
cen1 = 0
cen2 = 0
mx_dep = 0
if node%2==1
   cen1 = (node+1)/2
   mx_dep = cen1-1
else
   cen1 = node/2
   cen2 = cen1+1
   mx_dep = cen1-1
end
dep[cen1] = 0
dep[cen2] = 0
vis[cen1] = 1
vis[cen2] = 1
c = 1
while node<n && c<=2
      c+=1
      q=Array.new
      if cen1 > 0
         q.push(cen1)
         cen1 = 0
      elsif cen2>0
         q.push(cen2)
         cen2 = 0
      end

      while q.length > 0
            a = q.first
            q.shift
            while tr[a].length<k && node<n && dep[a]<mx_dep
                  node+=1
                  tr[a].push(node)
                  tr[node].push(a)
            end

            for ii in tr[a]
                if vis[ii]>0
                   next
                end
                q.push(ii)
                vis[ii] = 1
                dep[ii] = dep[a] + 1
            end
      end

end

for z in (1..n)
    vis[z] = 0
end

if !f || node!=n
   puts "NO"
else
   puts "YES"
   for j in (1..n)
       for z in tr[j]
           if vis[z]>0 && vis[j]>0
              next
           end
           vis[z] = 1
           vis[j] = 1
           puts "#{j} #{z}"
       end
   end
end
=begin
=end

f = true
as = gets.split.map(&:to_i)
n = as[0]
d = as[1]
k = as[2]
tr = Array.new(n+5)
i = 0
while i<=n
      tr[i] = Array.new
      i+=1
end

node = 0
for i in 1..d
    if i>=n
       f = false
       break
    end
    tr[i].push(i+1)
    tr[i+1].push(i)
    node = i+1
end

dep = Array.new(n+5)
vis = Array.new(n+5)
o = 0
while o<=n
      dep[o] = 0
      vis[o] = 0
      o+=1
end
cen1 = 0
cen2 = 0
mx_dep = 0
if node%2==1
   cen1 = (node+1)/2
   mx_dep = cen1-1
else
   cen1 = node/2
   cen2 = cen1+1
   mx_dep = cen1-1
end
dep[cen1] = 0
dep[cen2] = 0
vis[cen1] = 1
vis[cen2] = 1
c = 1
while node<n && c<=2
      c+=1
      q=Array.new
      if cen1 > 0
         q.push(cen1)
         cen1 = 0
      elsif cen2>0
         q.push(cen2)
         cen2 = 0
      end

      while q.length > 0
            a = q.first
            q.shift
            if tr[a].length>k
               f=0
            end
            while tr[a].length<k && node<n && dep[a]<mx_dep
                  node+=1
                  tr[a].push(node)
                  tr[node].push(a)
            end

            for ii in tr[a]
                if vis[ii]>0
                   next
                end
                q.push(ii)
                vis[ii] = 1
                dep[ii] = dep[a] + 1
            end
      end

end

for z in (1..n)
    vis[z] = 0
end

if !f || node!=n
   puts "NO"
else
   puts "YES"
   for j in (1..n)
       for z in tr[j]
           if vis[z]>0 && vis[j]>0
              next
           end
           vis[z] = 1
           vis[j] = 1
           puts "#{j} #{z}"
       end
   end
end
=begin
=end


n = gets.chomp.to_i
(0...n).each do |i|
    s = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    asize = a.size
    count1 = 0
    count2 = 0
    a.each_with_index do |item,j|
        if j % 2 == 0
            if item % 2 != 0
                count1 += 1
            end
        end
        if j % 2 != 0
            if item % 2 == 0
                count2 += 1
            end
        end
    end
    if count1 != count2
        puts "-1"
    else
        puts count1
    end
end

n = gets.chomp.to_i
n.times do
	t = gets.chomp.to_i
	arr = gets.chomp.split.map{|a| a.to_i % 2}
	iar = (0..arr.length-1).to_a.map{|i| i % 2}
	cnt0 = 0
	cnt1 = 0
	arr.length.times do |i|
		if arr[i] != iar[i]
			if arr[i] == 0
				cnt0 += 1
			else
				cnt1 += 1
			end
		end
	end

	# p arr
	# p iar
	# puts cnt0
	# puts cnt1
	if cnt0 == 0 && cnt1 == 0
		puts 0
	elsif cnt0 == cnt1
		puts cnt0
	else
		puts -1
	end
end

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

  res = [0, 0]

  a.each_with_index { |v, i| res[i%2] += 1 if i.odd? != v.odd? }

  puts -1 if res.first != res.last
  puts res.first if res.first == res.last
end

gets.to_i.times do
	n = gets.to_i
	a = gets.split.map(&:to_i)
	b = (0...n).map { _1 % 2 }
	if [0, 1].all? { |k| a.count { _1 % 2 == k } == b.count { _1 % 2 == k } }
		puts (0...n).count { a[_1] % 2 != b[_1] % 2 } / 2
	else
		puts -1
	end
end

t = gets.to_i
t.times do
	n = gets.to_i
	ill_evens = 0
	ill_odds = 0
	odds = []
	gets.split.each_with_index do |w, i|
		if w.to_i.even?
			ill_evens += 1 if i.odd?
		else
			ill_odds += 1 if i.even?
		end
	end

	if ill_evens != ill_odds
		p -1
		next
	end

	p ill_evens

end

def count_arr(a,n)

    odds = 0
    evens = 0
    i=0

    while i<n
        evens +=1 if(i%2==0 && a[i]%2==1)
        odds += 1 if(i%2==1 && a[i]%2==0)
        i+=1
    end

    return [odds,evens]
end

gets.chomp.to_i.times do

    n = gets.chomp.to_i

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

    arr = count_arr(a,n)

    if(arr[0]==arr[1])
        puts arr[0]
    else
        puts -1
    end
end

gets.to_i.times {
  gets
  data = gets.split.map { |v| v.to_i }
  s = Array.new(2, 0)
  for i in 0...data.size()
    if (i % 2) != (data[i] % 2)
      s[i % 2] += 1
    end
  end
  if s[0] != s[1]
    puts -1
  else
    puts s[0]
  end
}

data_lines = gets.chomp
result = []
(1..data_lines.to_i).each do
	length_s = gets.chomp.to_i
	s = gets.chomp.split(" ")
	odd_pos_count = length_s / 2
	odd_val_count = 0
	odd_val_not_place = 0
	even_val_not_place = 0
	(0..(length_s-1)).each do |index|
		if s[index].to_i % 2 == 1
			odd_val_count += 1
			if index % 2 == 0
				odd_val_not_place += 1
			end
		else
			if index % 2 == 1
				even_val_not_place += 1
			end
		end
	end
	if odd_val_not_place == 0 && even_val_not_place == 0
		result.push 0
		next
	end
	if odd_pos_count != odd_val_count
		result.push -1
		next
	end
	result.push odd_val_not_place
end
result.each do |res|
	puts res
end

t = gets.to_i

for i in 0..t-1

    n = gets.to_i
    array = gets.chomp.split
    k1 = 0
    k2 = 0

    for i in 0..n-1
        elt = array[i].to_i

        if elt%2 != (i)%2
            if elt%2 == 0
                k1+=1
            else
                k2+=1
            end
        end

    end

    puts k1 == k2 ? k1 : '-1'

end

def solve(arr_num)
	wrong_els = arr_num
		.map
		.with_index { |n,i| [n % 2 == i % 2, i.even?] }
		.reject { |is_good, _is_even| is_good }

	odd_els, even_els = wrong_els.partition { |is_good, is_even| is_even }
	if odd_els.size == even_els.size
		odd_els.size
	else
		-1
	end
end

inputs = ARGF.each_line.drop(1).map(&:strip).to_a

inputs.each_slice(2).map(&:last).each do |i|
	arr_num = i.split.map(&:to_i)
	puts solve(arr_num)
end

gets.to_i.times do
	n = gets.to_i
	a = gets.split.map(&:to_i)
	m = (0...n).count { _1 % 2 != a[_1] % 2 }
	if m.even?
		puts m / 2
	else
		puts -1
	end
end

def count_arr(a,n)

    odds = 0
    evens = 0
    count = 0
    i=0

    while i<n

        if(a[i]%2==0)
            evens+=1
        else
            odds+=1
        end

        count +=1 if(i%2==0 && a[i]%2==1)
        i+=1
    end

    return [odds,evens,count]
end

gets.chomp.to_i.times do

    n = gets.chomp.to_i

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

    arr = count_arr(a,n)
    if(n%2==0)
        if(arr[0]!=arr[1])
            puts -1
        else
            puts arr[2]
        end
    else
        if(arr[0] >= arr[1])
            puts -1
        else
            puts arr[2]
        end
    end
end

gets.chomp.to_i.times do

    n = gets.chomp.to_i

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

    i=0
    count =0
    while i<n
       count += 1 if(i%2 != a[i]%2)
       i+=1
    end

    if(count %2 != 0)
        puts -1
    else
        puts count/2
    end
end

gets.to_i.times {
  gets
  data = gets.split.map { |v| v.to_i }
  s = 0
  for i in 0...data.size()
    if (i % 2) != (data[i] % 2)
      s += 1
    end
  end
  if s %2 == 1
    puts -1
  else
    puts s / 2
  end
}

n = gets.chomp.to_i
n.times do
	t = gets.chomp.to_i
	arr = gets.chomp.split.map{|a| a.to_i % 2}
	iar = (0..arr.length-1).to_a.map{|i| i % 2}
	cnt = 0
	arr.length.times do |i|
		cnt += 1 if arr[i] != iar[i]
	end
	if cnt % 2 == 1
		puts -1
	else
		puts cnt / 2
	end
end


ans = []
st = Time.now
t = ["a","b","c"]
n = gets.to_i

n.times do|d_i|
  s = gets.split("")

  (s.size - 1).times do |i|
    if s[i] == "?"
      t.each do |drf|
        next if drf == s[i-1]
        next if drf == s[i+1]
        s[i] = drf
        break
      end
    else
      if s[i] == s[i+1]
        s = [-1]
        break
      end
    end
  end
  ans.push(s.join)
end
puts ans

gets.strip.to_i.times {
    x = gets.strip.split('')
    if x.size == 1
        puts x[0] == "?" ? "a" : x[0]
        next
    end
    c = ["a", "b", "c"]
    x.each_with_index { |element, index|
        if index == 0
            if x[index] == "?"
                if x[index + 1] == "?"
                    x[index] = "a"
                    next
                end
                x[index] = c[(c.find_index(x[index + 1]) + 1) % 3]
            end
        elsif index == x.size - 1
            if x[index] == "?"
                x[index] = c[(c.find_index(x[index - 1]) + 1) % 3]
            end
        else
            if x[index] == "?"
                if x[index + 1] == "?"
                    x[index] = c[(c.find_index(x[index - 1]) + 1) % 3]
                else
                    x[index] = "c" if x[index - 1] == "a" && x[index + 1] == "b" || x[index - 1] == "b" && x[index + 1] == "a"
                    x[index] = "a" if x[index - 1] == "b" && x[index + 1] == "c" || x[index - 1] == "c" && x[index + 1] == "b"
                    x[index] = "b" if x[index - 1] == "c" && x[index + 1] == "a" || x[index - 1] == "a" && x[index + 1] == "c"
                    x[index] = c[(c.find_index(x[index - 1]) + 1) % 3] if x[index - 1] == x[index + 1]
                end
            end
        end
    }
    flg = false
    x.each_with_index { |element, index|
        next if index == 0
        if x[index] == x[index - 1]
            flg = true
            break
        end
    }
    puts flg ? -1 : x.join
}

ans = []
st = Time.now
t = ["a","b","c"]
n = gets.to_i

n.times do|d_i|
  s = gets.split("")

  (s.size - 1).times do |i|
    if s[i] == "?"
      t.each do |drf|
        next if drf == s[i-1]
        next if drf == s[i+1]
        s[i] = drf
        break
      end
    else
      if s[i] == s[i+1]
        s = [-1]
        break
      end
    end
  end
  if(n == 1)
    puts Time.now - st
    exit
  end
  ans.push(s.join)
end
puts ans

n = gets.to_i
n.times do
  p s = gets
  ns = s.size
  if s[0] == "?"
    ("a".."c").each do |cc|
      s[0] = cc if cc != s[1]
    end
  else
    if s[0] == s[1]
      p -1
      next
    end
  end

  (1...(ns-1)).each do |i|
    c = s[i]
    if c == "?"
      ("a".."c").each do |cc|
        if cc != s[i-1]
          if cc != s[i+1]
            s[i] = cc
            break
          else
            next
          end
        end
      end
    else
      if s[i] == s[i+1]
        s = "-1"
        break
      end
    end
  end
  puts s
end

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
d = []
n.times{d<<gets}
n.times do |di|
  s=d[di]
  ans = na(n,0)
  ns = s.size
  f = false
  ns.times do |i|
    if(s[i] == "?")
      ("a".."c").each do |cc|
        if i==0 or cc != s[i-1]
          if(i+1 == ns or cc != s[i+1])
            ans[i] = cc
            s[i] = cc
            break
          else
            next
          end
        end
      end
    else
      if i < ns and s[i] == s[i+1]
        f = true
        p -1
        break
      else
        ans[i] = s[i]
      end
    end
  end
  unless f
    puts ans.join
  end
end

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
d = []
n.times{d<<gets}
n.times do |di|
  s=d[di]
  ans = na(n,0)
  ns = s.size
  f = false
  ns.times do |i|
    if(s[i] == "?")
      ("a".."c").each do |cc|
        if i==0 or cc != s[i-1]
          if(i+1 == ns or cc != s[i+1])
            ans[i] = cc
            s[i] = cc
            break
          else
            next
          end
        end
      end
    else
      if i < ns and s[i] == s[i+1]
        f = true
        p -1
        break
      else
        ans[i] = s[i]
      end
    end
  end
  unless f
    ans.each do |c|
      print c
    end
  end
end

n = gets.to_i
d = []
t = ["a","b","c"]
n.times do |di|
  s = ["?ab?a??cas"]*10
  s = s.join
  ns = s.size
  ans = ""
  if (s[0] == "?")
    t.each do |cc|
      s[0] = cc if(ns == 1 or cc != s[1])
    end
  else
    if s[0] == s[1]
      p -1
      next
    end
  end
  if s[-1] == "?"
    t.each do |cc|
      s[-1] = cc if cc != s[-2]
    end
  end

  (1...(ns-1)).each do |i|
    c = s[i]
    if(c == "?")
      t.each do |cc|
        if cc != s[i-1]
          if(cc != s[i+1])
            s[i] = cc
            break
          else
            next
          end
        end
      end
    else
      if s[i] == s[i+1]
        s = -1
        break
      end
    end
  end
  puts s
end

ans = []
st = Time.now
t = ["a","b","c"]
n = gets.to_i

n.times do|d_i|
  s = gets
  if(n == 1)
    puts Time.now - st
    exit
  end
  (s.size - 1).times do |i|
    if s[i] == "?"
      t.each do |drf|
        next if drf == s[i-1]
        next if drf == s[i+1]
        s[i] = drf
        break
      end
    else
      if s[i] == s[i+1]
        s = "-1"
        break
      end
    end
  end
  if(Time.now - st > 0.8)
    puts 12
  end
  ans.push(s)
end
puts ans


$stdin = File.open("input.txt")
$stdout = File.open("output.txt","w")

n = gets.chomp.to_i
H = {}
gets.chomp.split.each do |c|
	key = c.to_i
	if H.has_key? key
		H[key] += 1
	else
		H[key] = 1
	end
end
A = Array.new(5000,0)
for c in 1..5000 do
	A[c] = A[c-1] + (H.has_key?(c) ? H[c] : 0)
end
sol = 99999
for c in 1..2500 do
	sol = [sol , A[c-1] + (A[5000] - A[c*2])].min
end
puts sol

# -*- encoding: utf-8 -*-

$stdin = File.open("input.txt")
$stdout = File.open("output.txt", "w")

n = gets.chomp.to_i
c = {}
gets.chomp.split(" ").each do |n|
  key = n.to_i
  if c.has_key? key
    c[key] += 1
  else
    c[key] = 1
  end
end

field = Array.new(5000, 0)

for i in 1 .. 5000 do
  field[i] = field[i - 1] + (c.has_key?(i) ? c[i] : 0)
end
ans = 99999
for i in 1 .. 2500 do
  ans = [ans, field[i - 1] + (field[5000] - field[i * 2])].min
end

puts ans


gets.to_i.times do
  n,q=gets.split.map(&:to_i)
  a=gets.split.map(&:to_i)
  m=Array.new(n+1)
  m[0]=0
  n.times {|i| m[i+1]=[m[i],a[i]].max}
  s=[0]
  a.each {|i| s << s[-1]+i}
  k=gets.split.map(&:to_i)
  puts k.map {|i|
    ans=m.bsearch_index {|j| j>i}
    ans.nil? ? s[n] : s[ans-1]
  }*' '
end

t=gets.to_i
t.times do
    n,q= gets.split.map(&:to_i)
    arr=gets.split.map(&:to_i)
    qs=gets.split.map(&:to_i)
    rslt=[]
    cur,sum=0,0
    arr.each do |x|
        if cur>=x
            sum+=x
        else
            rslt.push [cur,sum]
            cur=x
            sum+=x
        end
    end
    rslt.push [cur,sum]
    rslt.push [sum,sum]
    i=0
    while i<rslt.length-1 do
        rslt[i][0]=rslt[i+1][0]-1
        i+=1
    end
    rslt[-1][0]=10000000000000000
    qs.each_with_index do |x, idx|
        print (rslt.bsearch{|y,z|y>=x}[1])
        if idx==qs.length-1
            puts
        else
            print ' '
        end
    end
end