There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.

The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.

In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []
max_h = min_h = books_height[0]
max_i = min_i = 0
max_sub_h = 0
min_sub_h = 1000000
max_sub_i = min_sub_i = 0
count = 0
i = 0
while i < number_of_books
    if max_sub_i > i
        max_h = max_sub_h
        max_i = max_sub_i
    else
        max_h = books_height[i]
        max_i = i
    end
    if min_sub_i > i
        min_h = min_sub_i
        min_i = min_sub_i
    else
        min_h = books_height[i]
        min_i = i
    end
    if count <= i
        count = i + 1
    end
    max_sub_h = 0
    min_sub_h = 1000000
    max_sub_i = min_sub_i = 0
    while count < number_of_books
        if max_h <= books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h >= books_height[count]
            min_h = books_height[count]
            min_i = count
        elsif max_i < min_i && max_sub_h < max_h
            max_sub_h = books_height[count]
            max_sub_i = count
        elsif min_i < max_i && min_sub_h > min_h
            min_sub_h = books_height[count]
            min_sub_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books || number_of_books - i <= max_books
        break
    elsif max_i >= min_i
        i = min_i + 1
    elsif min_i > max_i
        i = max_i + 1
    else
        i += 1
    end
    count -= 1
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []
max_h = min_h = books_height[0]
max_i = min_i = 0
max_sub_h = 0
min_sub_h = 1000000
max_sub_i = min_sub_i = 0
count = 0
i = 0
while i < number_of_books
#(number_of_books).times do |i|
#    count = i + 1
#    max_h = min_h = books_height[i]
#    max_i = min_i = count - 1
    if max_sub_i > i
        max_h = max_sub_h
        max_i = max_sub_i
    else
        max_h = books_height[i]
        max_i = i
#        count = i + 1
    end
    if min_sub_i > i
        min_h = min_sub_i
        min_i = min_sub_i
    else
        min_h = books_height[i]
        min_i = i
#        count = i + 1
    end
    if count <= i
        count = i + 1
    end
    max_sub_h = 0
    min_sub_h = 1000000
    max_sub_i = min_sub_i = 0
    while count < number_of_books
        if max_h <= books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h >= books_height[count]
            min_h = books_height[count]
            min_i = count
        elsif max_i < min_i && max_sub_h < max_h
            max_sub_h = books_height[count]
            max_sub_i = count
        elsif min_i < max_i && min_sub_h > min_h
            min_sub_h = books_height[count]
            min_sub_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books || number_of_books - i <= max_books
        break
    elsif max_i >= min_i
        i = min_i + 1
    elsif min_i > max_i
        i = max_i + 1
    else
        i += 1
    end
    count -= 1
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []
max_h = min_h = books_height[0]
max_i = min_i = 0
max_sub_h = 0
min_sub_h = 1000000
max_sub_i = min_sub_i = 0
count = 0
i = 0
while i < number_of_books
#(number_of_books).times do |i|
#    count = i + 1
#    max_h = min_h = books_height[i]
#    max_i = min_i = count - 1
    if max_sub_i > i
        max_h = max_sub_h
        max_i = max_sub_i
    else
        max_h = books_height[i]
        max_i = i
#        count = i + 1
    end
    if min_sub_i > i
        min_h = min_sub_i
        min_i = min_sub_i
    else
        min_h = books_height[i]
        min_i = i
#        count = i + 1
    end
    max_sub_h = 0
    min_sub_h = 1000000
    max_sub_i = min_sub_i = 0
    while count < number_of_books
        if max_h <= books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h >= books_height[count]
            min_h = books_height[count]
            min_i = count
        elsif max_i < min_i && max_sub_h < max_h
            max_sub_h = books_height[count]
            max_sub_i = count
        elsif min_i < max_i && min_sub_h > min_h
            min_sub_h = books_height[count]
            min_sub_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books || number_of_books - i <= max_books
        break
    elsif max_i >= min_i
        i = min_i + 1
    elsif min_i > max_i
        i = max_i + 1
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 0
result = []

(number_of_books - 1).times do |i|
    count = i + 1
    while count < number_of_books
        if (books_height[i] - books_height[count]).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []
max_h = min_h = books_height[0]
max_i = min_i = 0
max_sub_h = 0
min_sub_h = 1000000
max_sub_i = min_sub_i = 0
count = 0
i = 0
while i < number_of_books
#(number_of_books).times do |i|
#    count = i + 1
#    max_h = min_h = books_height[i]
#    max_i = min_i = count - 1
    if max_sub_i > i
        max_h = max_sub_h
        max_i = max_sub_i
    else
        max_h = books_height[i]
        max_i = i
#        count = i + 1
    end
    if min_sub_i > i
        min_h = min_sub_i
        min_i = min_sub_i
    else
        min_h = books_height[i]
        min_i = i
#        count = i + 1
    end
    if count == i
        count += 1
    end
    max_sub_h = 0
    min_sub_h = 1000000
    max_sub_i = min_sub_i = 0
    while count < number_of_books
        if max_h <= books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h >= books_height[count]
            min_h = books_height[count]
            min_i = count
        elsif max_i < min_i && max_sub_h < max_h
            max_sub_h = books_height[count]
            max_sub_i = count
        elsif min_i < max_i && min_sub_h > min_h
            min_sub_h = books_height[count]
            min_sub_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books || number_of_books - i <= max_books
        break
    elsif max_i >= min_i
        i = min_i + 1
    elsif min_i > max_i
        i = max_i + 1
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 0
result = []

(number_of_books - 1).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
        elsif min_h > books_height[count]
            min_h = books_height[count]
        end
        if (max_h - min_h).abs >= limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books && count - i > 1
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 0
result = []

(number_of_books - 1).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
        elsif min_h > books_height[count]
            min_h = books_height[count]
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []

i = 0
while i < number_of_books
#(number_of_books).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    max_i = min_i = count
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h > books_height[count]
            min_h = books_height[count]
            min_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books
        break
    elsif max_i >= min_i
        i += max_i
    elsif min_i > max_i
        i += min_i
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 0
result = []

(number_of_books - 1).times do |i|
    count = i + 1
    while count < number_of_books
        if (books_height[i] - books_height[count]).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books && count - i > 1
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []

i = 0
while i < number_of_books
#(number_of_books).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    max_i = min_i = count
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h > books_height[count]
            min_h = books_height[count]
            min_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books
        break
    elsif max_i >= min_i
        i = max_i
    elsif min_i > max_i
        i = min_i
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 0
result = []

(number_of_books - 1).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
        elsif min_h > books_height[count]
            min_h = books_height[count]
        end
        if (max_h - min_h).abs > limit_height
            count += 1
            break
        end
        count += 1
    end
    count -= 1
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []
max_h = min_h = books_height[0]
max_i = min_i = 0
max_sub_h = 0
min_sub_h = 1000000
max_sub_i = min_sub_i = 0
count = 0
i = 0
while i < number_of_books
#(number_of_books).times do |i|
#    count = i + 1
#    max_h = min_h = books_height[i]
#    max_i = min_i = count - 1
    count += 1
    if max_sub_i > i
        max_h = max_sub_h
        max_i = max_sub_i
    else
        max_h = books_height[i]
        max_i = i
    end
    if min_sub_i > i
        min_h = min_sub_i
        min_i = min_sub_i
    else
        min_h = books_height[i]
        min_i = i
    end
    max_sub_h = 0
    min_sub_h = 1000000
    max_sub_i = min_sub_i = 0
    while count < number_of_books
        if max_h <= books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h >= books_height[count]
            min_h = books_height[count]
            min_i = count
        elsif max_i < min_i && max_sub_h < max_h
            max_sub_h = books_height[count]
            max_sub_i = count
        elsif min_i <max_i && min_sub_h > min_h
            min_sub_h = books_height[count]
            min_sub_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books || number_of_books - i <= max_books
        break
    elsif max_i >= min_i
        i = min_i + 1
    elsif min_i > max_i
        i = max_i + 1
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []

i = 0
while i < number_of_books
#(number_of_books).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    max_i = min_i = count
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h > books_height[count]
            min_h = books_height[count]
            min_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books || max_books > number_of_books - count
        break
    elsif max_i >= min_i
        i = min_i
    elsif min_i > max_i
        i = max_i
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 0
result = []

(number_of_books - 1).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
        elsif min_h > books_height[count]
            min_h = books_height[count]
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books && count - i > 1
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []

if number_of_books == 1
    result.push [1,1]
end

(number_of_books).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
        elsif min_h > books_height[count]
            min_h = books_height[count]
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []

if number_of_books == 1
    result.push [1,1]
end

(number_of_books - 1).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
        elsif min_h > books_height[count]
            min_h = books_height[count]
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end

number_of_books,limit_height = gets.split.collect! {|x| x.to_i}

books_height = []
books_height = gets.split.collect! {|x| x.to_i}

max_books = 1
result = []

i = 0
while i < number_of_books
#(number_of_books).times do |i|
    count = i + 1
    max_h = min_h = books_height[i]
    max_i = min_i = count
    while count < number_of_books
        if max_h < books_height[count]
            max_h = books_height[count]
            max_i = count
        elsif min_h > books_height[count]
            min_h = books_height[count]
            min_i = count
        end
        if (max_h - min_h).abs > limit_height
            break
        end
        count += 1
        max_i -= 1
        min_i -= 1
    end
    if count - i >= max_books
        if count - i > max_books
            result.clear
        end
        max_books = count - i
        result.push [i + 1,count]
    end
    if count == number_of_books
        break
    elsif max_i >= min_i
        p i
        i = max_i
    elsif min_i > max_i
        i = min_i
    else
        i += 1
    end
end
puts max_books.to_s + ' ' + result.length.to_s
result.length.times do |i|
    puts result[i][0].to_s + ' ' + result[i][1].to_s
end


You are given an array $$$a_1, a_2, \dots , a_n$$$, which is sorted in non-decreasing order ($$$a_i \le a_{i + 1})$$$. Find three indices $$$i$$$, $$$j$$$, $$$k$$$ such that $$$1 \le i < j < k \le n$$$ and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$ (for example it is possible to construct a non-degenerate triangle with sides $$$3$$$, $$$4$$$ and $$$5$$$ but impossible with sides $$$3$$$, $$$4$$$ and $$$7$$$). If it is impossible to find such triple, report it.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$3 \le n \le 5 \cdot 10^4$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$; $$$a_{i - 1} \le a_i$$$) — the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print the answer to it in one line. If there is a triple of indices $$$i$$$, $$$j$$$, $$$k$$$ ($$$i < j < k$$$) such that it is impossible to construct a non-degenerate triangle having sides equal to $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1.

NoteIn the first test case it is impossible with sides $$$6$$$, $$$11$$$ and $$$18$$$. Note, that this is not the only correct answer.In the second test case you always can construct a non-degenerate triangle.

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

  puts arr[0] + arr[1] > arr.last ? -1 : "1 2 #{arr.length}"
end

t = gets.chomp.to_i
t.times {
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  if arr[n - 1] >= (arr[0] + arr[1])
    puts "1 2 #{n}"
  else
    puts '-1'
  end
}

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  if a[0] + a[1] <= a[-1]
    ans << [1,2,n]
  else
    ans << [-1]
  end
end
ans.each do |x|
  x.each do |v|
    print "#{v} "
  end
  puts ""
end

t = gets.chomp.to_i
t.times {
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  if arr[n - 1] > (arr[0] + arr[1])
    puts '1 2 3'
  else
    puts '-1'
  end
}

t = gets.chomp.to_i
t.times {
  n = gets.chomp.to_i
  arr = gets.chomp.split(' ').map(&:to_i)
  if arr[n - 1] >= (arr[0] + arr[1])
    puts '1 2 3'
  else
    puts '-1'
  end
}


Casimir has a string $$$s$$$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:  he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);  or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent). Therefore, each turn the length of the string is decreased exactly by $$$2$$$. All turns are independent so for each turn, Casimir can choose any of two possible actions.For example, with $$$s$$$ $$$=$$$ "ABCABC" he can obtain a string $$$s$$$ $$$=$$$ "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.For a given string $$$s$$$ determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case is described by one string $$$s$$$, for which you need to determine if it can be fully erased by some sequence of turns. The string $$$s$$$ consists of capital letters 'A', 'B', 'C' and has a length from $$$1$$$ to $$$50$$$ letters, inclusive.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC

test_case = gets.to_i
(1..test_case).each do |index|
  str = gets
  length = str.length - 1
  half = length / 2
  a = b = c = 0
  str.chars.each do |char|
    if char == 'A'
      a += 1
    elsif char == 'B'
      b += 1
    else
      c += 1
    end
  end
  if length % 2 == 0 && half == b
    puts 'YES'
  else
    puts 'NO'
  end
end

t = gets.chomp.to_i
for _ in 0...t
  string = gets.chomp
  count_a, count_b, count_c = 0, 0, 0
  string.each_char{|char|
    if char == "A"
      count_a += 1
    elsif char == "B"
      count_b += 1
    else
      count_c += 1
    end
  }
  if count_a + count_c == count_b
    puts "YES"
  else
    puts "NO"
  end
end

t = gets.chomp.to_i
for _ in 0...t
  string = gets.chomp
  count_a, count_b, count_c = string.count("A"), string.count("B"), string.count("C")
  if count_a + count_c == count_b
    puts "YES"
  else
    puts "NO"
  end
end

def solve
  str = gets.strip
  if str.split('').select { |e| e == 'B' }.length * 2 == str.length
    puts "YES"
  else
    puts "NO"
  end
end

gets.strip.to_i.times {
  solve
}

def solve
  str = gets.strip
  a = str.split('').select { |e| e == 'A' }
  b = str.split('').select { |e| e == 'B' }
  c = str.split('').select { |e| e == 'C' }
  if a.length.zero?
    if b.length == c.length
      puts "YES"
      return
    end
  end

  if c.length.zero?
    if b.length == a.length
      puts "YES"
      return
    end
  end

  res = b.length
  res -= a.length
  res -= c.length
  if res.zero?
    puts "YES"
  else
    puts "NO"
  end

end

gets.strip.to_i.times {
  solve
}

# 6
# ABACAB
# ABBA
# AC
# ABC
# CABCBB
# BCBCBCBCBCBCBCBC

n = gets.to_i
puts(n.times.map do
  s = gets.strip
  loop do
    if s.include?('B') && s.include?('C')
      s = s.sub('B', '')
      s = s.sub('C', '')
    elsif s.include?('B') && s.include?('A')
      s = s.sub('B', '')
      s = s.sub('A', '')
    else
      break
    end
  end
  s.empty? ? 'YES' : 'NO'
end.join("\n"))

test_case = gets.to_i
(1...test_case).each do |index|
  str = gets
  length = str.length - 1
  half = length / 2
  a = b = c = 0
  str.chars.each do |char|
    if char == 'A'
      a += 1
    elsif char == 'B'
      b += 1
    else
      c += 1
    end
  end
  if length % 2 == 0 && half == b
    puts 'YES'
  else
    puts 'NO'
  end
end

test_case = gets.to_i
(1...5).each do |index|
  str = gets
  length = str.length - 1
  half = length / 2
  a = b = c = 0
  str.chars.each do |char|
    if char == 'A'
      a += 1
    elsif char == 'B'
      b += 1
    else
      c += 1
    end
  end
  if length % 2 == 0 && half == b
    puts 'YES'
  else
    puts 'NO'
  end
end

test_case = gets.to_i
(1...5).each do |index|
  str = gets
  length = str.length
  half = length / 2
  a = b = c = 0
  str.chars.each do |char|
    if char == 'A'
      a += 1
    elsif char == 'B'
      b += 1
    else
      c += 1
    end
  end
  if length % 2 == 0 && half == b
    puts 'YES'
  else
    puts 'NO'
  end
end


Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.

Output string s after performing m operations described above.

NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.

gets
s=gets.chomp
$<.each{|_|
a,b,c,d=_.split
(a.to_i-1...b.to_i).each{|i|s[i]=d if s[i]==c}
}
puts s

n, m = gets.split(/\s+/).map(&:to_i)
s = gets.chomp
m.times do
	l, r, c1, c2 = gets.split(/\s+/)
	l = l.to_i - 1
	r = r.to_i - 1
	(l..r).each{ |i| s[i] = c2 if s[i] == c1 }
end
puts s

str_length, changes = gets.chomp.split(' ').map(&:to_i)
string = gets.chomp

changes.times do
  l, r, target, new_val = gets.chomp.split(' ')
  l = l.to_i
  r = r.to_i

  (l..r).each do |i|
    string[i - 1] = new_val if string[i - 1] == target
  end
end

puts string

n, m = gets.split.map(&:to_i)
s  = gets.chomp
m.times do
  l, r, c1, c2 = gets.chomp.split
  l = l.to_i
  r = r.to_i
  (l..r).each do |i|
    if s[i-1] == c1
      s[i-1] = c2
    end
  end
end
puts s

x,n=gets.split.map{|e| e.to_i}
s=gets.chomp
n.times{
	l,r,e1,e2=gets.split
	l=l.to_i
	r=r.to_i
	e2=e2.chomp
	(l..r).each{|i|
		break if s.size<=i-1
		s[i-1]=e2 if s[i-1]==e1
	}

}
puts s

n, m=gets.split.map &:to_i
s=gets.chomp
m.times{
    l, r, a, b=gets.split
    l=l.to_i-1
    r=r.to_i
    while l<r
        s[l]=b if s[l]==a
        l+=1
    end
}
puts s

n, m = gets.split.map(&:to_i)
s = gets.chomp
m.times do
    l, r, c1, c2 = gets.chomp.split
    l = l.to_i - 1
    r = r.to_i - 1
    l.upto(r) do |i|
        if s[i] == c1
            s[i] = c2
        end
    end
end
puts s

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

m.times do |i|
  l, r, c1, c2 = gets.split
  l = l.to_i - 1
  r = r.to_i - 1
  s[l, r-l+1] = s[l, r-l+1].gsub(c1, c2)
end

puts s

n, m = gets.split.map(&:to_i)
s = gets.strip
m.times do
  line = gets.split
  l, r = line[0..1].map(&:to_i)
  c = line[2..3]
  s[l-1..r-1] = s[l-1..r-1].tr(c[0], c[1])
end
puts s

x,n=gets.split.map{|e| e.to_i}
s=gets.chomp
n.times{
	l,r,e1,e2=gets.split
	l=l.to_i
	r=r.to_i
	e2=e2.chomp
	(l..(l+r-1)).each{|i|
		s[i-1]=e2 if s[i-1]==e1
	}

}
puts s


There are $$$n$$$ pieces of cake on a line. The $$$i$$$-th piece of cake has weight $$$a_i$$$ ($$$1 \leq i \leq n$$$).The tastiness of the cake is the maximum total weight of two adjacent pieces of cake (i. e., $$$\max(a_1+a_2,\, a_2+a_3,\, \ldots,\, a_{n-1} + a_{n})$$$).You want to maximize the tastiness of the cake. You are allowed to do the following operation at most once (doing more operations would ruin the cake):   Choose a contiguous subsegment $$$a[l, r]$$$ of pieces of cake ($$$1 \leq l \leq r \leq n$$$), and reverse it. The subsegment $$$a[l, r]$$$ of the array $$$a$$$ is the sequence $$$a_l, a_{l+1}, \dots, a_r$$$.If you reverse it, the array will become $$$a_1, a_2, \dots, a_{l-2}, a_{l-1}, \underline{a_r}, \underline{a_{r-1}}, \underline{\dots}, \underline{a_{l+1}}, \underline{a_l}, a_{r+1}, a_{r+2}, \dots, a_{n-1}, a_n$$$.For example, if the weights are initially $$$[5, 2, 1, 4, 7, 3]$$$, you can reverse the subsegment $$$a[2, 5]$$$, getting $$$[5, \underline{7}, \underline{4}, \underline{1}, \underline{2}, 3]$$$. The tastiness of the cake is now $$$5 + 7 = 12$$$ (while before the operation the tastiness was $$$4+7=11$$$).Find the maximum tastiness of the cake after doing the operation at most once.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the number of pieces of cake. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — $$$a_i$$$ is the weight of the $$$i$$$-th piece of cake.

For each test case, print a single integer: the maximum tastiness of the cake after doing the operation at most once.

NoteIn the first test case, after reversing the subsegment $$$a[2, 5]$$$, you get a cake with weights $$$[5, \underline{7}, \underline{4}, \underline{1}, \underline{2}, 3]$$$. The tastiness of the cake is now $$$\max(5+7, 7+4, 4+1, 1+2, 2+3) = 12$$$. This is the maximum possible tastiness of the cake one can obtain by performing the operation at most once.In the second test case, it's optimal not to do any operation. The tastiness is $$$78+78 = 156$$$.In the third test case, after reversing the subsegment $$$a[1, 2]$$$, you get a cake with weights $$$[\underline{54}, \underline{69}, 91]$$$. The tastiness of the cake is now $$$\max(54+69, 69+91) = 160$$$. There is no way to make the tastiness of the cake greater than $$$160$$$ by performing at most one operation.

t=gets.chomp.to_i
t.times do |i|
    n=gets.chomp.to_i
    b=Array.new(n)
    s=gets.chomp.split(' ')
    for i in 0..s.length-1
        b[i]=s[i].to_i
    end
    puts (b.max(2)).sum
end

t = gets.to_i

while t > 0
    t -= 1
    n = gets.to_i
    ar = gets.split(' ').map(&:to_i).sort

    print(ar[n - 1] + ar[n - 2], "\n")
end


A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.Notice, that any year between 2013 and 2015 is not a leap year.

The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.

In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.

# -*- encoding: utf-8 -*-
require 'date'

s = gets.chomp
hash = Hash.new {0}

(9 .. s.length).each do |idx|
  s2 = s[idx - 9 .. idx]
  match = s2.match(/(3[01]|[12][0-9]|0[1-9])-(1[0-2]|0[1-9])-(201[3-5])/)
  next if not match

  year, month, date = match[3].to_i, match[2].to_i, match[1].to_i

  if Date.valid_date? year, month, date
    d = Date.new year, month, date
    hash[d] += 1
  end
end
ans = hash.max_by { |k, v| v }.first
puts ans.strftime "%d-%m-%Y"

#!/usr/bin/ruby1.9

prophecy = STDIN.readline.strip

monthdays =  [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
			#Jan  Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

count = {}

(9..prophecy.length).each do |pos|
	s = prophecy[pos-9..pos]
	match = s.match(/(\d\d)-(\d\d)-(\d\d\d\d)/)
	next if not match
	day, month, year = match.to_a[1..-1].collect {|s| s.to_i }
	next if year < 2013 or  year > 2015
	next if month < 1 or month > 12
	next if day < 1 or day > monthdays[month-1]
	if count.member? s
		count[s] += 1
	else
		count[s] = 1
	end
end
arr = count.to_a.sort {|x, y| x[1]-y[1] }
puts arr[-1][0]

infile = STDIN
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
input = infile.readline.chomp
found = Hash.new {0}
length = "13-12-2013".length
(0..(input.size - length)).each do |i|
  substr = input[i, length]
  if substr =~ /((\d\d)-(\d\d)-(\d\d\d\d))/
    d, m, y = $2.to_i, $3.to_i, $4.to_i
    if (2013..2015) === y && (1..12) === m && d > 0 && d <= days_in_month[m - 1]
      found[$1] += 1
    end
  end
end
puts found.max_by { |k, v| v }.first

require 'date'

def run
  hash = Hash.new(0)

  line = ARGF.readline.chomp
  line.length.times do |i|
    begin
      str = line[i,10]
      if str =~ /[0-9]{2}-[0-9]{2}-[0-9]{4}/
        parse = Date.strptime(str, "%d-%m-%Y")
        hash[str] += 1 if parse.year.between?(2013, 2015)
      end
    rescue
    end
  end

  ret = hash.to_a.max_by { |item| item[1] }
  puts ret[0] if ret
end

run if $0 == __FILE__

# 777-444---21-12-2013-12-2013-12-2013---444-777
require 'Date'

def days_in_month(year, month)
	Date.new(year, month, -1).day
end
count = Hash.new(0)

l = gets.chomp.split("-")
# puts "#{l}"
l.each_cons(3) do |(d,m,y)|
	h = d.to_i
	if h > 0
		m = m.to_i
		if m >= 1 && m <= 12

			y = y.length > 4 ? y[0..3].to_i : y.to_i
			d = d.length > 2 ? d[-2..-1].to_i : d.to_i

			if y >= 2013 && y <= 2015 && (d <= days_in_month(y,m))
				count["#{d.to_s.rjust(2,"0")}-#{m.to_s.rjust(2,"0")}-#{y}"] += 1
			end
		end
	end
end
max = count.values.max
# puts "#{count}"

puts count.detect{|k,v| v == max}[0]

s=gets

RUI=[1,3,5,7,8,10,12]

def day? month, day
  return false if day==0
  if month==2
    return day<=28
  end

  if RUI.include?month
    return day<=31
  end

  return day<=30
end

def valid? date
  return false if not /(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})/ =~ date

  return false if year.to_i<2013 || year.to_i>2015
  return day? month.to_i,day.to_i
end

hm={}
hm.default=0
ans=""

(0...s.length-10).each do |i|
  key=s[i,10]
  hm[key]+=1 if valid? key
  ans=key if ans=="" || hm[key]>hm[ans]
end

puts ans

s=gets

RUI=[1,3,5,7,8,10,12]

def digit? c
  c>= ?0 && c<= ?9
end

def day? month, day
  return false if day==0
  if month==2
    return day<=28
  end

  if RUI.include?month
    return day<=31
  end

  return day<=30
end

def valid? date
  return false if !digit?(date[0]) || !digit?(date[1])
  day=date[0,2].to_i
  date=date[2..-1]

  return false if digit? date[0]
  date=date[1..-1]

  return false if !digit?(date[0]) || !digit?(date[1])
  month=date[0,2].to_i
  date=date[2..-1]

  return false if digit? date[0]
  date=date[1..-1]

  return false if !digit?(date[0]) || !digit?(date[1]) || !digit?(date[2]) || !digit?(date[3])
  year=date[0,4].to_i

  return false if year<2013 || year>2015
  return day? month,day
end

hm={}
(0...s.length-10).each do |i|
  key=s[i,10]
  if valid? key
    hm[key]? hm[key]+=1:hm[key]=1
  end
end

ans=""

hm.each do |key,value|
  if ans=="" || value>hm[ans]
    ans=key
  end
end

puts ans

s=gets

RUI=[1,3,5,7,8,10,12]

def digit? c
  c>= ?0 && c<= ?9
end

def day? month, day
  return false if day==0
  if month==2
    return day<=28
  end

  if RUI.include?month
    return day<=31
  end

  return day<=30
end

def valid? date
  return false if not /(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})/ =~ date

  return false if year.to_i<2013 || year.to_i>2015
  return day? month.to_i,day.to_i
end

hm={}
hm.default=0
ans=""

(0...s.length-10).each do |i|
  key=s[i,10]
  hm[key]+=1 if valid? key
  ans=key if ans=="" || hm[key]>hm[ans]
end

puts ans

s=gets

RUI=[1,3,5,7,8,10,12]

def digit? c
  c>= ?0 && c<= ?9
end

def day? month, day
  return false if day==0
  if month==2
    return day<=28
  end

  if RUI.include?month
    return day<=31
  end

  return day<=30
end

def valid? date
  return false if !digit?(date[0]) || !digit?(date[1])
  day=date[0,2].to_i
  date=date[2..-1]

  return false if digit? date[0]
  date=date[1..-1]

  return false if !digit?(date[0]) || !digit?(date[1])
  month=date[0,2].to_i
  date=date[2..-1]

  return false if digit? date[0]
  date=date[1..-1]

  return false if !digit?(date[0]) || !digit?(date[1]) || !digit?(date[2]) || !digit?(date[3])
  year=date[0,4].to_i

  return false if year<2013 || year>2015
  return day? month,day
end

hm={}
hm.default=0
ans=""

(0...s.length-10).each do |i|
  key=s[i,10]
  hm[key]+=1 if valid? key
  ans=key if ans=="" || hm[key]>hm[ans]
end

puts ans

s=gets

RUI=[1,3,5,7,8,10,12]

def day? month, day
  return false if day==0
  if month==2
    return day<=28
  end

  if RUI.include?month
    return day<=31
  end

  return day<=30
end

def valid? date
  return false if not /(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})/ =~ date

  return false if year.to_i<2013 || year.to_i>2015
  return day? month.to_i,day.to_i
end

hm={}
hm.default=0
ans=nil

(0...s.length-10).each do |i|
  key=s[i,10]
  hm[key]+=1 if valid? key
  ans=key if hm[key]>hm[ans]
end

puts ans

s=gets
w = {

}
w.default=0
ans=-1;
j = -1;
m=[0,31,28,31,30,31,30,31,31,30,31,30,31]

def good?(s,m)
	a=s[0..1].to_i
	b=s[3..4].to_i
	c=s[6..9].to_i
	if c>=2013 and c<=2015 and b>=1 and b<=12 and a>=1 and a<=m[b] then
		return true
	end
	return false
end

s.length.times do |i|
	if s.length-10 <= i then
		break
	end
	t = s[i,10]
	if t =~ /\d{2}-\d{2}-\d{4}/ and good?(t,m) then
		w[t]+=1
		if(ans<w[t]) then
			j=t
			ans=w[t]
		end
	end
end
puts j

# -*- encoding: utf-8 -*-
require 'date'

s = gets.chomp
ans = nil

(9 .. s.length).each do |idx|
  s2 = s[idx - 9 .. idx]
  match = s2.match(/(3[01]|[12][0-9]|0[1-9])-(1[0-2]|0[1-9])-(201[3-5])/)
  next if not match

  year, month, date = match[3].to_i, match[2].to_i, match[1].to_i

  if Date.valid_date? year, month, date
    d = Date.new year, month, date
    if ans.nil? or d > ans
      ans = d
    end
  end
end

puts ans.strftime "%d-%m-%Y"

# -*- encoding: utf-8 -*-
require 'date'

s = gets.chomp
date = nil

(9 .. s.length).each do |idx|
  s2 = s[idx - 9 .. idx]
  match = s2.match(/(3[01]|[12][0-9]|0[1-9])-(1[0-2]|0[1-9])-(201[3-5])/)
  next if not match

  year, month, date = match[3].to_i, match[2].to_i, match[1].to_i

  if Date.valid_date? year, month, date
    d = Date.new year, month, date
    if date.nil? or d > date
      date = d
    end
  end
end

puts date.strftime "%d-%m-%Y"

# 777-444---21-12-2013-12-2013-12-2013---444-777
require 'Date'

def days_in_month(year, month)
	Date.new(year, month, -1).day
end
count = Hash.new(0)

l = gets.chomp.split("-")
# puts "#{l}"
l.each_cons(3) do |(d,m,y)|
	h = d.to_i
	if h > 0
		m = m.to_i
		if m >= 1 && m <= 12
			y = y.to_i
			if y >= 2013 && y <= 2015
				if(h <= days_in_month(y,m))
					count["#{d}/#{m}/#{y}"] += 1
				elsif(d[-2..-1].to_i <= days_in_month(y,m))
					count["#{d[-2..-1]}-#{m}-#{y}"] += 1
				end

			end
		end
	end
end
max = count.values.max
# puts "#{count}"

puts count.detect{|k,v| v == max}[0]

# 777-444---21-12-2013-12-2013-12-2013---444-777
require 'Date'

def days_in_month(year, month)
	Date.new(year, month, -1).day
end
count = Hash.new(0)

l = gets.chomp.split("-")
# puts "#{l}"
l.each_cons(3) do |(d,m,y)|
	h = d.to_i
	if h > 0
		m = m.to_i
		if m >= 1 && m <= 12
			y = y.to_i
			if y >= 2013 && y <= 2015
				if(h <= days_in_month(y,m))
					count["#{d}/#{m}/#{y}"] += 1
				elsif(d[-2..-1].to_i <= days_in_month(y,m))
					count["#{d[-2..-1]}-#{m}-#{y}"] += 1
				end

			end
		end
	end
end
max = count.values.max
puts "#{count}"

puts count.detect{|k,v| v == max}[0]

# 777-444---21-12-2013-12-2013-12-2013---444-777
require 'Date'

def days_in_month(year, month)
	Date.new(year, month, -1).day
end
count = Hash.new(0)

l = gets.chomp.split("-")
# puts "#{l}"
l.each_cons(3) do |(d,m,y)|
	h = d.to_i
	if h > 0
		m = m.to_i
		if m >= 1 && m <= 12
			y = y.to_i
			if y >= 2013 && y <= 2015
				# if ( || h[-2..-1].to_i <= days_in_month(y,m))
				if(h <= days_in_month(y,m))
					count["#{d}/#{m}/#{y}"] += 1
				end
				if(d[-2..-1].to_i <= days_in_month(y,m))
					count["#{d[-2..-1]}/#{m}/#{y}"] += 1
				end

			end
		end
	end
end
max = count.values.max
# puts "#{count}"

puts count.detect{|k,v| v == max}[0]

s=gets
w,ans,j={},-1,0
w.default=0
def good?(day,month,year)
	begin
		t = Time.new(year,month,day)
		if t<=Time.new(2015,12,31) and t>=Time.new(2013,1,1) then
			return true
		end
	rescue
		return false
	end
	return false
end
s.scan(/(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})/).each do |item|
	if(good?(item[0].to_i,item[1].to_i,item[2].to_i)) then
		w[$&]+=1
		if ans<w[$&] then
			ans=w[$&]
			j=$&
		end
	end
end
puts j

s=gets
w,ans,j={},-1,0
w.default=0
def good?(day,month,year)
	begin
		t = Time.new(year,month,day)
		if t<=Time.new(2015,12,31) and t>=Time.new(2013,1,1) then
			return true
		end
	rescue
		return false
	end
	return false
end
s.scan(/(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})/).each do |item|
	if(good?(item[0].to_i,item[1].to_i,item[2].to_i)) then
		t = "" << item[0]<<'-'<< item[1]<< '-' << item[2]
		w[t]+=1
		if ans<w[t] then
			ans=w[t]
			j=t
		end
	end
end
puts j


Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $$$n$$$ days from Petya's live and you have to determine what happened with his flower in the end.The flower grows as follows:   If the flower isn't watered for two days in a row, it dies.  If the flower is watered in the $$$i$$$-th day, it grows by $$$1$$$ centimeter.  If the flower is watered in the $$$i$$$-th and in the $$$(i-1)$$$-th day ($$$i > 1$$$), then it grows by $$$5$$$ centimeters instead of $$$1$$$.  If the flower is not watered in the $$$i$$$-th day, it does not grow. At the beginning of the $$$1$$$-st day the flower is $$$1$$$ centimeter tall. What is its height after $$$n$$$ days?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains the only integer $$$n$$$ ($$$1 \leq n \leq 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i = 0$$$ or $$$a_i = 1$$$). If $$$a_i = 1$$$, the flower is watered in the $$$i$$$-th day, otherwise it is not watered.

For each test case print a single integer $$$k$$$ — the flower's height after $$$n$$$ days, or $$$-1$$$, if the flower dies.

for _ in 0...(gets.chomp.to_i)
  n = gets.chomp.to_i
  arr = gets.chomp.split().map{|x| x.to_i}
  height, flag = 1, true
  for i in 1...(n + 1)
    if (arr[i] == 0) and (arr[i-1] == 0)
      puts -1
      flag = false
      break
    elsif (arr[i] == 1) and (arr[i-1] == 1)
      height += 5
    elsif arr[i-1] == 1
      height += 1
    end
  end
  if flag
    puts height
  end
end

testcases = Integer(gets.chomp)
resultados = []

for i in 0..testcases-1
    n = Integer(gets.chomp)
    arreglo = gets.chomp
    a = arreglo.split(" ")
    advertencia = 0
    aumentoCrecimiento = false
    crecimiento = 1
    for j in 0..n-1
        if a[j] == "1"
            advertencia = 0
            if aumentoCrecimiento
                crecimiento += 5
            else
                crecimiento += 1
                aumentoCrecimiento = true
            end
        else
            aumentoCrecimiento = false
            advertencia += 1
        end
        if advertencia == 2
            crecimiento = -1
            break
        end
    end
    resultados.push(crecimiento)
end

puts resultados


Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of all numbers from this segment was maximal possible. Help him with that.The xor operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.

Print a single integer — the required maximal xor of a segment of consecutive elements.

NoteIn the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.The second sample contains only one optimal segment, which contains exactly one array element (element with index three).

n = gets.to_i

mas = gets.split.map{|i| i.to_i}

xor = []

i = 0
while i < n do
    j = i + 1
    xor << mas[i]
    while j < n do
        xor << (xor[-1]^mas[j])
        j += 1
    end
    i += 1
end

xor = xor.sort

puts xor[-1]

n=gets
a=gets.split.map(&:to_i)
max=a.max
for i in 0...a.size do
	for j in i...a.size do
		tm=a[i]
		a[i+1..j].each{|e| tm=tm ^ e} if i!=j
		max=tm if tm>max
	end
end
puts max

n = gets.to_i
a = gets.split.map(&:to_i)
max = 0
for i in 0...n
  xor = 0
  for j in i...n
    xor = xor^a[j]
    if xor > max then max = xor end
  end
end
print max

n = gets.to_i
a = gets.split.map(&:to_i)
ans = 0
for i in 0...n
	sum = 0
	for j in i...n
		sum = sum^a[j]
		if sum > ans then ans = sum end
	end
end
print ans

#!/usr/bin/env ruby
n = gets.to_i
t = gets.split.map(&:to_i)
result = 0
n.times do |d|
  (0..(n - d - 1)).each do |i|
    x = 0
    (i..(i + d)).each do |j|
      x ^= t[j]
    end
    result = [result, x].max
  end
end
puts result

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
ret = []
for i in 0...n do
  t = 0
  for j in i...n do
    t ^= a[j]
    ret << t
  end
end
puts ret.max

n=gets.to_i
a=gets.split.map(&:to_i)
res=a.max
for i in 0..n-1 do
    t=a[i]
    for j in i+1..n-1 do
        t^=a[j]
        res=t if res<t
    end
end
puts res

n=gets.to_i
a=gets.split.map(&:to_i)
ans=0
for i in 0...n do
	mx=0
	a[i...n].each{|v|
		mx^=v
		ans = mx if mx > ans
	}
end
puts ans

n = gets.chomp.to_i
line = gets.chomp.split(" ").collect! {|x| x.to_i}
max = 0
(0..(n-1)).each {|k|
 (k..(n-1)).each { |t|
   p = 0
   (k..t).each {|q|
    p ^= line[q]
  }
  if p> max
	max = p
  end
 }

}

puts max

n = gets.to_i
x = gets.split.map(&:to_i).unshift(0)
n.times { |i| x[i+1] ^= x[i] }
mx = 0
1.upto(n) do |i|
	i.upto(n) do |j|
		mx = [mx, x[j] ^ x[i-1]].max
	end
end
puts mx

t = gets.to_i

a = gets.split.collect{|x| x.to_i}

r = 0

i = 0
while i < a.size
	j = i
	while j < a.size
		t = a[i]

		k = i+1

		while k <= j

			t ^= a[k]
			k += 1
		end

		r = [t,r].max
		j += 1
	end
	i+=1
end

puts r

#!/usr/bin/env ruby
n = gets.to_i
t = gets.split.map(&:to_i)
result = 0
n.times do |d|
  (0..(n - d - 1)).each do |i|
    x = 0
    (i..(i + d)).each do |j|
      x |= t[j]
    end
    result = [result, x].max
  end
end
puts result

n=gets.to_i
a=gets.split.map(&:to_i)
res=0
for i in 0..n-1 do
    t=a[i]
    for j in i+1..n-1 do
        t^=a[j]
    end
    res=t if res<t
end
puts res

n=gets.to_i
a=gets.split.map(&:to_i)
ans=0
for i in 0...n do
	mx=0
	a[i...n].each{|v|mx^=v}
	ans = mx if mx > ans
end
puts ans

n = gets.chomp.to_i
line = gets.chomp.split(" ").collect! {|x| x.to_i}
max = 0
(0..(n-1)).each {|k|
 p = 0
 (k..(n-1)).each { |t|
  p ^= line[t]
 }
 if p> max
	max = p
 end
}

puts max

n = gets.to_i
x = gets.split.map(&:to_i)
n.times { |i| i > 0 ? x[i] ^= x[i-1] : 1 }
mx = x[0]
1.upto(n-1) do |i|
	i.upto(n-1) do |j|
		mx = [mx, x[j] ^ x[i-1]].max
	end
end
puts mx

n = gets.to_i
x = gets.split.map(&:to_i)
n.times { |i| i ? x[i] ^= x[i-1] : _ }
mx = x[0]
1.upto(n-1) do |i|
	i.upto(n-1) do |j|
		mx = [mx, x[j] ^ x[i-1]].max
	end
end
puts mx