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

answer = 2019
(l..(r - 1)).each do |i|
  ((i + 1)..r).each do |j|
    res = i * j % 2019
    answer = res if res < answer
  end
end

puts answer


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

if l/2019 != r/2019 || l % 2019 == 0
  p 0
else
  ans = 2018
  l.upto(r-1) do |i|
    (l+1).upto(r) do |j|
      t = i*j % 2019
      ans = t if t < ans
    end
  end
  p ans
end

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 300 points

Problem Statement

You are given two non-negative integers L and R.
We will choose two integers i and j such that L \leq i < j \leq R.
Find the minimum possible value of (i \times j) \mbox{ mod } 2019.

Constraints

All values in input are integers.

0 \leq L < R \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

L R

Output

Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and j are chosen under the given condition.

Sample Input 1

2020 2040

Sample Output 1

2

When (i, j) = (2020, 2021), (i \times j) \mbox{ mod } 2019 = 2.

Sample Input 2

4 5

Sample Output 2

20

We have only one choice: (i, j) = (4, 5).

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


l, r = gets.split.map &:to_i
l %= 2019 * 2
r %= 2019 * 2
if l > r
  puts 0
  exit 0
end

res = 2019

l.upto(r) do |i|
    r.downto(l) do|j|
        break if i >= j
        break if res == 0
        res = [res, (i * j) % 2019].min
    end
end

puts res


def main(l,r)
  min = 2020
  l.upto(r-1) do |i|
    (i+1).upto(r).each do |j|
      mod = (i*j)%2019
      min = mod if min >= mod
      break if min == 0
    end
    break  if min == 0
  end
  return min
end

L, R = gets.chomp.split.map(&:to_i)
p L, R
p main(L, R)


l, r = gets.split.map(&:to_i)
array = (l..r).to_a.map do |n|
    n % 2019
end
puts (array.combination(2).to_a.uniq.map do |a,b|
    a*b
end).min


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

min = l % 2019
max = r % 2019

if min >= max
    puts 0
else
    ans = 9999999
    min.upto(max - 1) do |i|
        (i + 1).upto(max) do |j|
            x = (i * j) % 2019
            if x < ans
                ans = x
            end
        end
    end

    puts ans
end


# スペース区切りの整数の入力
L,R=gets.chomp.split(" ").map(&:to_i);
qL=L/2019
qR=R/2019
if(qL<qR)
 print(0)
else
modL=L.modulo(2019)
modR=R.modulo(2019)
ans=[(modL*(modL+1)).modulo(2019),(modR*(modR-1)).modulo(2019)].min
 print(ans)
end


L, R = gets.split.map(&:to_i)

counter = 2020
right = [R, L + 2020].min
(L..right).each do |i|
  ((i + 1)..[R, i + 2020].min).each do |j|
    r = i * j % 2019
    counter = r if counter > r
  end
end
p counter


li,ri=gets.chomp.split(" ").map(&:to_i)
l= li%2019
r= ri%2019
if l > r
  puts 0
elsif l==r
  puts 0
else
  data = (l..r).to_a.combination(2).map do |ij|
    i=ij[0]
    j=ij[1]
    i*j % 2019
  end
  puts data.min
end


input = gets.split.map(&:to_i)
ans = 3000
if input[1] - input[0] > 2020 then
  print 0
else
  (input[1] - input[0]).times{|t|
    n = t + input[0]
    k = n + 1
  while k <= input[1] and (k-input[0]) <=2020 do
   if ans > (n*k)%2019 then
      ans = (n*k)%2019
    end
    k+=1
  end
  }
  print ans
end


L,R = gets.chomp.split(" ").map(&:to_i)
L_diff = L % 2019
R_diff = R % 2019

if (R<2019)
    mods = []
    L.upto(R-1) do |i|
        (i+1).upto(R) do |j|
            mods << (i*j)%2019
        end
    end
    puts mods.min
elsif (L>2019)
    if (L/2019) != (R/2019)
        puts 0
    else
        mods = []
        L_diff.upto(2019) do |i|
            (i+1).upto(R_diff) do |j|
                mods << (i*j)%2019
            end
        end
        puts mods.min
    end
elsif (R>2019)&&(L<2019)
    puts 0
elsif (R==2019)||(L==2019)
    puts 0
end


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

if l*r < 2019
  puts l*(l+1)
else
  if l <= 2019 and 2019 <= r
    puts 0
  else
    # 2019以下
    if r < 2019
      ama = 2019 / l
      if l <= ama and ama < r
        puts l*(ama+1)%2019
      else
        puts l*(l+1)%2019
      end
    # 2019以上
    else
      a = l / 2019
      am = l % 2019
      b = r / 2019
      bm = r % 2019
      if am == 0 or bm == 0
        puts 0
      elsif a != b
        puts 0
      else
        puts l*(l+1)%2019
      end
    end
  end
end


L, R = gets.split.map(&:to_i)

min1 = R
min2 = R
((L + 1)..(R - 1)).map { |i| i % 2019 }.each do |i_mod|
  if i_mod < min1
    min1 = i_mod
    min2 = min1
  end
end

out = min1 * min2

puts out


L, R = gets.split.map(&:to_i)

ans = 2 << 60
(L..([L + 2019, R - 1].min)).each do |l|
  ((L + 1)..([L + 1 + 2019, R].min)).each do |r|
    a = l * r % 2019
    ans = a if a < ans
  end
end
puts ans


L, R = gets.split.map &:to_i

def f(l, r, mod)
  min = r / mod * mod
  if min < l
    l
  else
    min
  end
end

l = f(L, R - 1, 2019)
r = f(l + 1, R, 2019)

p l * r % 2019


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

ary = []

for i in l .. [r, l + 4050].min
  ary << i % 2019
end

ary.sort!
puts ary[0] * ary[1]


S = gets.chomp
ans = 0
if S.size >= 3
  0.upto(S.size()-2) do |i|
    if S[(i)..(i+2)] == 'ABC'
      tmp=0
      j=i
      while j>=0 do
        if S[j] == 'A'
          tmp+=1
          j-=1
        else
          break
        end
      end
      ans+=tmp
      s='BC'+'A'*tmp
      S[(j+1)..(j+s.size())]=s
    end
  end
end
puts ans

Score : 600 points

Problem Statement

You are given a string s consisting of A, B and C.

Snuke wants to perform the following operation on s as many times as possible:

Choose a contiguous substring of s that reads ABC and replace it with BCA.

Find the maximum possible number of operations.

Constraints

1 \leq |s| \leq 200000

Each character of s is A, B and C.

Input

Input is given from Standard Input in the following format:

s

Output

Find the maximum possible number of operations.

Sample Input 1

ABCABC

Sample Output 1

3

You can perform the operations three times as follows: ABCABC → BCAABC → BCABCA → BCBCAA. This is the maximum result.

Sample Input 2

C

Sample Output 2

0

Sample Input 3

ABCACCBABCBCAABCB

Sample Output 3

6


s = gets.chomp.chars

n = s.length
ans = 0
a_cnt = 0
b_flag = false

n.times do |i|
  if s[i] == 'A'
    a_cnt += 1
    b_flag = false
  end

  if s[i] == 'B'
    b_flag = true
  end

  if s[i] == 'C'
    unless b_flag
      a_cnt = 0
      next
    end

    ans += a_cnt
    b_flag = false
  end
end

puts ans


S=gets.chomp

state = 0
acount = 0
ret = 0

S.each_char do |c|
#  p [c, state, acount,ret]
  case state
  when 0
    if c == 'A'
      acount += 1
      state = 1
    else
      acount = 0
    end
  when 1
    if c == 'A'
      acount += 1
    elsif c == 'B'
      state = 2
    else
      acount = 0
      state = 0
    end
  when 2
    if c == 'A'
      acount = 1
      state = 1
    elsif c == 'C'
      ret += acount
      state = 1
    else
      acount = 0
      state = 0
    end
  end
end

p ret


s = gets.chomp

s.gsub!(/BC/, "D")

k = s.split(/[BC]++/)

count = 0
a = 0

k.each{ |str|
  str.length.times{|i|
    if str[i] == "A" then
      a += 1
    elsif str[i] == "D" then
      count += a
    end
  }
  a = 0
}

p count


s = gets.chomp

count = 0

while s.gsub!(/ABC/){|s|
  count += 1
  s = "BCA"
} do end

puts count


s = gets.chomp

sum = 0
while true
  index = s.index('ABC')
  if index == nil
    break
  end

  a = s[0..index].scan(/A+$/)[0]
  bc_count = s[index+1..s.size].match(/^(BC)+/)[0].size / 2
  sum += a.size * bc_count

  s = a + s[(index + bc_count * 2 + 1)...s.size]
end
puts sum


s = gets.chomp

sum = 0
while true
  index = s.index('ABC')
  if index == nil
    break
  end

  a = s[0..index].scan(/A+$/)[0]
  bc_count = s[index+1..s.size].gsub(/^(BC)+/).to_a.first.size / 2
  sum += a.size * bc_count

  s = a + s[(index + bc_count * 2 + 1)...s.size]
end
puts sum


s = gets.chomp
cnt = 0
ac = 0
i = 0
while i < s.length-1
  bcc = 0
  if s[i] == "A"
    ac += 1
  elsif s[i] == "B" && s[i+1] == "C"
    bcc = 1
    k = 2
    while i+k <= s.length-2 && s[i+k] == "B" && s[i+k+1] == "C"
      bcc += 1
      k += 2
    end
    bcc.times do |kk|
      s[i-ac+kk*2] = "B"
      s[i-ac+1+kk*2] = "C"
    end
    s[i-ac+bcc*2..i+bcc*2-1] = "A" * ac
    cnt += ac*bcc
  else
    ac = 0
  end
  if bcc == 0
    i += 1
  else
    i = i+bcc*2
  end
end
puts cnt


s = gets.chomp
cnt = 0
ac = 0
i = 0
while i < s.length-1
  bcc = 0
  if s[i] == "A"
    ac += 1
  elsif s[i] == "B" && s[i+1] == "C"
    bcc = 1
    k = 2
    while i+k <= s.length-2 && s[i+k] == "B" && s[i+k+1] == "C"
      bcc += 1
      k += 2
    end
    bcc.times do |kk|
      s[i-ac+kk*2] = "B"
      s[i-ac+1+kk*2] = "C"
    end
    s[i-ac+bcc*2..i+bcc*2-1] = "A" * ac
    cnt += ac*bcc
  else
    ac = 0
  end
  if bcc == 0
    i += 1
  else
    i = i-ac+bcc*2
    ac = 0
  end
end
puts cnt


s=gets.chomp
k = 0
n=0
i = 0
while i = s.index('ABC', i)
  i+= 2
  n+=1
end
k+=n

n=0
i = 0
while i = s.index('AABC', i)
  i+= 1
  n+=1
end
k+=n

n=0
i = 0
while i = s.index('ABCBC', i)
  i+= 1
  n+=1
end
k+=n

n=0
i = 0
while i = s.index('ABCABC', i)
  i+= 1
  n+=1
end
k+=n

n=0
i = 0
while i = s.index('BCAABC', i)
  i+= 1
  n+=1
end
k+=n
puts k


s=gets.chomp
n=0
while s.sub!(/ABC/, 'BCA')
  n+=1
end
p n


Score : 300 points

Problem Statement

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black.
HW characters from A_{11} to A_{HW} represent the colors of the squares.
A_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.

We will repeatedly perform the following operation until all the squares are black:

Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed.
The initial grid has at least one black square.

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.

Sample Input 2

6 6
..#..#
......
#..#..
......
.#....
....#.

Sample Output 2

3


require 'matrix'

h, w = gets.split.map(&:to_i)
cm = Matrix.zero(h + 2, w + 2)
que = []
1.upto(h) do |i|
  s = gets.chomp
  1.upto(w) do |j|
    if s[j - 1] == '.'
      cm[i, j] = -1
    else
      que.push(i)
      que.push(j)
    end
  end
end
ans = 0
while que.size > 0
  y = que.shift
  x = que.shift
  ans = cm[y, x] + 1
  if cm[y + 1, x] == -1
    cm[y + 1, x] = ans
    que.push(y + 1)
    que.push(x)
  end
  if cm[y - 1, x] == -1
    cm[y - 1, x] = ans
    que.push(y - 1)
    que.push(x)
  end
  if cm[y, x + 1] == -1
    cm[y, x + 1] = ans
    que.push(y)
    que.push(x + 1)
  end
  if cm[y, x - 1] == -1
    cm[y, x - 1] = ans
    que.push(y)
    que.push(x - 1)
  end
end
puts ans - 1


"AGC 033 A - Darker and Darker"
# 入力
H, W = gets.split.map(&:to_i)
c = []
H.times do |i|
  #.charsで1文字ずつ別の配列に入れる
  #.mapで '#'をtrue、それ以外をfalseに置き換える
  c[i] = gets.chomp.chars.map{ |x| x == '#'}
end

# main
# '#'のある位置をqに入れていく
q = []
H.times do |i|
  W.times do |j|
    if c[i][j]
      q.push([i, j])
    end
  end
end

res = 0
# 移動方向
# dx = [1, 0, -1, 0]
# dy = [0, 1, 0, -1]
y, x = 0, 0
# 移動先
# ny, nx = 0, 0
# 移動先を保存するキュー
nq = []
loop do
  # キューが空でない間
  until q.empty?
    # キューから1個取り出す
    y, x = q.shift

    if x+1<W && !c[y][x+1]
      nq.push([y, x+1])
      c[y][x+1] = true
    end

    if y+1<H && !c[y+1][x]
      nq.push([y+1, x])
      c[y+1][x] = true
    end

    if 0<=x-1 && !c[y][x-1]
      nq.push([y, x-1])
      c[y][x-1] = true
    end

    if 0<=y-1 && !c[y-1][x]
      nq.push([y-1, x])
      c[y-1][x] = true
    end

    # 各方向についてループ
    # 4.times do |i|
    #   ny = y + dy[i]
    #   nx = x + dx[i]
    #   # 移動先がcの範囲内で壁ではなく、かつ白色ならば
    #   if (0<=nx) && (nx<W) && (0<=ny) && (ny<H) && (!c[ny][nx])
    #     # 移動先に追加する
    #     nq.push([ny, nx])
    #     # 移動先を白から黒にする
    #     c[ny][nx] = true
    #   end
    # end
  end
  if nq.empty?
    # nqが空ってことは行ける先がないのでreturn
    break
  else
    # nqが空でないなら、resを1増やしてqとnqを交換して上に戻る
    res += 1
    q, nq = nq, q
  end
end

puts res


#n = gets.chomp.to_i
h,w = gets.chomp.split().map(&:to_i)

grid = Array.new(h){Array.new(w, 0)}
q = []
h.times do |i|
  line = gets.chomp.split(//)
  w.times do |j|
    if line[j] == '#'
      grid[i][j] = 1
      q.push [i,j, 0]
    end
  end
end
#p grid

ans = 0
count = 0
until q.empty?
  y,x,cost = q.shift
  if 0 < y && grid[y-1][x] != 1
    grid[y-1][x] = 1
    q.push [y-1, x, cost+1]
    ans = cost+1 if ans < cost+1
  end
  if y < h-1 && grid[y+1][x] != 1
    grid[y+1][x] = 1
    q.push [y+1, x, cost+1]
    ans = cost+1 if ans < cost+1
  end
  if 0 < x && grid[y][x-1] != 1
    grid[y][x-1] = 1
    q.push [y, x-1, cost+1]
    ans = cost+1 if ans < cost+1
  end
  if x < w-1 && grid[y][x+1] != 1
    grid[y][x+1] = 1
    q.push [y, x+1, cost+1]
    ans = cost+1 if ans < cost+1
  end
end

puts ans


h, w = gets.strip.split.map(&:to_i)

aa = Array.new(h) { [0]*w }
dist = Array.new(h) { [-1]*w }
q = []

counter=0
h.times do |i|
  gets.chomp.each_char.with_index do |c,j|
    next if c == '.'
    aa[i][j] = 1
    q << [i, j]
    dist[i][j]=0
    counter+=1
  end
end

result = 0
until counter == h*w
  cy, cx = q.shift

  nc = dist[cy][cx]+1

  x=cx
  if (y = cy+1) < h && dist[y][x] == -1
    result = nc if nc > result
    dist[y][x]=nc
    q.push([y, x])
  end

  if (y = cy-1) >= 0 && dist[y][x] == -1
    result = nc if nc > result
    dist[y][x] = nc
    q.push([y, x])
  end

  y=cy
  if (x = cx-1) >= 0 && dist[y][x] == -1
    result = nc if nc > result
    dist[y][x] = nc
    q.push([y, x])
  end

  if (x = cx+1) < w && dist[y][x] == -1
    result = nc if nc > result
    dist[y][x] = nc
    q.push([y, x])
  end
end

p result


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

maze = []
queue = []
(0..r-1).each do |rr|
  line = gets.chomp
  line.each_char.each_with_index { |c, cc|
    queue << [rr, cc] if c == '#'
  }
  maze << line.split('').map{ |e| e=='#'? 0 : nil }
end

cnt = nil
until queue.empty?
  qx, qy = queue.shift
  cnt = maze[qx][qy].to_i + 1

  if qx + 1 < r && maze[qx+1][qy].nil?
    maze[qx+1][qy] = cnt
    queue << [qx+1, qy]
  end

  if qx > 0 && maze[qx-1][qy].nil?
    maze[qx-1][qy] = cnt
    queue << [qx-1, qy]
  end

  if qy + 1 < c && maze[qx][qy+1].nil?
    maze[qx][qy+1] = cnt
    queue << [qx, qy+1]
  end

  if qy > 0 && maze[qx][qy-1].nil?
    maze[qx][qy-1] = cnt
    queue << [qx, qy-1]
  end
end

p cnt - 1


h,w = gets.split.map(&:to_i)
a = h.times.map do
  gets.chomp.chars
end

max_cell = h*w
cell = 0
queue = []

(0...h).each do |y|
  (0...w).each do |x|
    if a[y][x] == "#"
      cell += 1
      queue << [x-1, y] if x > 0
      queue << [x+1, y] if x < w-1
      queue << [x, y-1] if y > 0
      queue << [x, y+1] if y < h-1
    end
  end
end

n = 0

while true
  break if cell >= max_cell
  new_queue = []
  queue.each do |x,y|
    if a[y][x] == "."
      a[y][x] = "#"
      cell += 1
      new_queue << [x-1, y] if x > 0
      new_queue << [x+1, y] if x < w-1
      new_queue << [x, y-1] if y > 0
      new_queue << [x, y+1] if y < h-1
    end
  end
  queue = new_queue
  n += 1
end

puts n


h,w = gets.chomp.split(" ").map(&:to_i)

arr = []
hash = {}
count = 0
result = 0
h.times do |h_i|
  tmp_arr = []
  gets.chomp.split("").each_with_index do |a, w_i|
    if a == "#" then
      hash[[h_i, w_i]] = 0
      count += 1
      tmp_arr << 1
    else
      tmp_arr << 0
    end
  end
  arr << tmp_arr
end

while count < h * w do
  keys = hash.keys
  hash = {}
  result += 1
  keys.each do |(h_i, w_i)|
    if h_i - 1 >= 0 && arr[h_i - 1][w_i] == 0 then
      hash[[h_i - 1, w_i]] = result
      arr[h_i - 1][w_i] = "#"
      count += 1
    end
    if h_i + 1 < h && arr[h_i + 1][w_i] == 0 then
      hash[[h_i + 1, w_i]] = result
      arr[h_i + 1][w_i] = "#"
      count += 1
    end
    if w_i - 1 >= 0 && arr[h_i][w_i - 1] == 0 then
      hash[[h_i, w_i - 1]] = result
      arr[h_i][w_i - 1] = "#"
      count += 1
    end
    if w_i + 1 < w && arr[h_i][w_i + 1] == 0 then
      hash[[h_i, w_i + 1]] = result
      arr[h_i][w_i + 1] = "#"
      count += 1
    end
  end
end

puts result


h,w = gets.chomp.split(" ").map(&:to_i)

arr = [Array.new(w+2, -1)]
tmp_keys = []
count = 0
result = 0
(1..h).each do |h_i|
  tmp_arr = [-1]
  a = gets.chomp.split("")
  (1..w).each do |w_i|
    if a[w_i - 1] == "#" then
      tmp_arr << 1
      tmp_keys << [h_i, w_i]
      count += 1
    else
      tmp_arr << 0
    end
  end
  tmp_arr << -1
  arr << tmp_arr
end
arr << Array.new(w+2, -1)

keys = [tmp_keys]
total = h * w
while count < total do
  result += 1
  keys[result] = []
  keys[result-1].each do |(h_i, w_i)|
    if arr[h_i - 1][w_i] == 0 then
      keys[result] << [h_i - 1, w_i]
      arr[h_i - 1][w_i] = 1
    end
    if arr[h_i + 1][w_i] == 0 then
      keys[result] << [h_i + 1, w_i]
      arr[h_i + 1][w_i] = 1
    end
    if arr[h_i][w_i - 1] == 0 then
      keys[result] << [h_i, w_i - 1]
      arr[h_i][w_i - 1] = 1
    end
    if arr[h_i][w_i + 1] == 0 then
      keys[result] << [h_i, w_i + 1]
      arr[h_i][w_i + 1] = 1
    end
  end
  count += keys[result].size
end

puts result


io = STDIN
h,w=io.gets.split.map(&:to_i)
$board=[]
$board << [" "]*(w+2)
h.times do
  $board << ([" "]+io.gets.chomp.split(//)+[" "])
end
$board << [" "]*(w+2)
require 'pp'
stack=[]
(1..h).each do |i|
  (1..w).each do |j|
    if $board[i][j]=="#"
      stack << [i,j]
      $board[i][j]=0
    end
  end
end
cur=0
while (res=stack.shift;i,j=res)
  cur=$board[i][j]
  [[1,0],[0,-1],[-1,0],[0,1]].each do |x,y|
    if $board[i+x][j+y]=="."
      $board[i+x][j+y]=cur+1
      stack << [i+x,j+y]
    end
  end
end
p cur


require 'matrix'

M = 999999
h, w = gets.chomp!.split(" ").map!(&:to_i)
a_hw = Array.new(h) {|index| gets.chomp.chars }
max_hw = Array.new(h) {|index| Array.new(w, M) }

black = []
a_hw.each_with_index do |arr, h2|
    arr.each_with_index do |ch, w2|
        if ch == "#"
            black.unshift([h2, w2, 0])
            max_hw[h2][w2] = 0
        end
    end
end

#i = 0

while black.empty?.!
    h2, w2, count = black.shift
    count += 1

    if h2 != 0
        if max_hw[h2-1][w2] == M
            max_hw[h2-1][w2] = count
            black.push([h2 - 1, w2, count])
        end
    end
    if h2 != h - 1
        if max_hw[h2 + 1][w2] == M
            max_hw[h2+1][w2] = count
            black.push([h2 + 1, w2, count])
        end
    end
    if w2 != 0
        if max_hw[h2][w2 - 1] == M
            max_hw[h2][w2 - 1] = count
            black.push([h2, w2 - 1, count])
        end
    end
    if w2 != w - 1
        if max_hw[h2][w2 + 1] == M
            max_hw[h2][w2 + 1] = count
            black.push([h2, w2 + 1, count])
        end
    end
    i += 1
end

#puts i
#puts max_hw.map {|x| x.join(",") }
puts max_hw.map{|x| x.max }.max


H, W = gets.split.map(&:to_i)
a = Array.new(W).map{Array.new(H)}
for i in 0..(H-1)
  a[i] = gets.chomp.split("")
end
blkN = whtN = 0
blk_i = []
blk_j = []
wht_i = []
wht_j = []
for i in 0..(H-1)
  for j in 0..(W-1)
    if a[i][j] == "."
      whtN += 1
      wht_i.push(i)
      wht_j.push(j)
    elsif a[i][j] == "#"
      blkN += 1
      blk_i.push(i)
      blk_j.push(j)
    end
  end
end
max = 0
for i in 0..(whtN - 1)
  mind = 10000
  for j in 0..(blkN - 1)
    d = (wht_i[i] - blk_i[j]).abs + (wht_j[i] - blk_j[j]).abs
    mind = d if mind > d
  end
  max = mind if max < mind
end
puts max


def rec(n, arr)
  div = (2..(n**0.5).to_i).find { |i| n % i == 0 }
  return arr << n if div.nil?

  rec(n / div, arr << div)
end

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

gcd = as.inject(:gcd)
as.map! { |a| a / gcd }

divisor = rec(as[0], []).sort.uniq
ans_without_a0 = as[1..-1].inject(:gcd)

deletes = []
divisor.each do |i|
  tmp = as.select { |a| a % i != 0 }
  deletes << tmp[0] if tmp.size == 1
end

ans = 1
deletes.each do |d|
  as_tmp = as.dup
  as_tmp.delete(d)
  ans = [as_tmp.inject(:gcd), ans].max
end
puts [ans, ans_without_a0].max * gcd

Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.


class SegmentTree
  ROOT = 1
  private_constant :ROOT

  attr_reader :size

  def initialize(n, x = 0)
    @size = 1
    @size *= 2 while @size < n
    @sum = Array.new(2 * @size){x}
    @parent = Array.new(2 * @size)
    @lchild = Array.new(2 * @size)
    @rchild = Array.new(2 * @size)
    (2 * @size).times do |i|
      @parent[i] = i / 2
      @lchild[i] = i * 2
      @rchild[i] = i * 2 + 1
    end
  end

  def update(i, v)
    i += @size
    @sum[i] = v
    until i == ROOT
      i = @parent[i]
      @sum[i] = @sum[@lchild[i]].gcd(@sum[@rchild[i]])
    end
  end

  def sum(l, r)
    sum_dfs(l, r, ROOT, 0, @size)
  end
  def sum_dfs(a, b, i, l, r)
    return 0       if b <= l || r <= a
    return @sum[i] if a <= l && r <= b
    m = (l + r) / 2
    sum_dfs(a, b, @lchild[i], l, m).gcd(sum_dfs(a, b, @rchild[i], m, r))
  end
end

N=gets.to_i
A=gets.split.map &:to_i

segtree = SegmentTree.new(N)
A.each.with_index do |a, i|
  segtree.update(i, a)
end
res = 0
N.times do |i|
  l = i.zero? ? 0 : segtree.sum(0, i)
  r = i+1==N  ? 0 : segtree.sum(i+1, N)
  d = l.gcd(r)
  res = [res, d].max
end
p res


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

l = Array.new(n+1)
r = Array.new(n+1)
l[0] = 0
r[n] = 0
(1..n).each do |i|
  l[i] = l[i-1].gcd(as[i-1])
  # r[i] = l[i-1].gcd(as[i-1])
end

(n-1).downto(0).each do |i|
  r[i] = r[i+1].gcd(as[i])
end

ms = Array.new(n)
ans = []
(0..n-1).each do |i|
  ans << l[i].gcd(r[i+1])
end

puts ans.max


N = gets.to_i
as = gets.split.map(&:to_i)
ans = 0
as.combination(2).to_a.each do |a,b|
  ans = a.gcd(b) if a.gcd(b) > ans
end
p ans


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

stack = []
2.times do |j|
  i = 1
  while i <= a[j] / i
    if a[j] % i == 0
      stack << i if !stack.include?(i)
      stack << a[0] / i if !stack.include?(a[0] / i)
    end
    i += 1
  end
end

stack.sort.reverse.each do |i|
  cnt = 0
  n.times do |j|
    cnt += 1 if a[j] % i != 0
  end
  if cnt <= 1
    puts i
    exit
  end
end


def recursive(val, arr)
  return arr.length == 0 ? val : val.gcd(recursive(arr[0], arr[1..-1]))
end

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

gcds = []

a.each_with_index do |_, i|
  gcds << recursive(0, a[0...i]).gcd(recursive(0, a[i+1..-1]))
end

puts gcds.max


n=gets.to_i
A=gets.chomp.split(' ').map(&:to_i)

L=[];R=[];L[0]=0;R[0]=0

n.times do |i|
    L[i+1] = L[i].gcd(A[i])
    R[i+1] = R[i].gcd(A[n-i-1])
end

ans = 0
n.times do |i|
   ans = [L[i].gcd(R[n-i-1]),ans].max
end
puts ans


N = gets.to_i
A = gets.split(' ').map(&:to_i)
gcd = []

N.times do |i|
  left  = A[0, i].inject(:gcd)
  right = A[i + 1, N - 1].inject(:gcd)

  left  = 0 if left.nil?
  right = 0 if right.nil?

  gcd.push([left, right].inject(:gcd))
end

puts gcd.max


io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
lar=Array.new(n) #left gcd累計
rar=Array.new(n) #right gcd累計
lar[0]=a[0]
(1...n).each do |i|
  lar[i]=lar[i-1].gcd(a[i])
end
rar[-1] = a[-1]
(n-2).downto(0).each do |i|
  rar[i]=a[i].gcd(rar[i+1])
end
ar= [
lar[-2],
(1..n-2).map{ |i|lar[i-1].gcd(rar[i+1])},
rar[1]
]
p ar.flatten.max


def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

def eratosthenes(size)
  prime_list = []
  is_prime = Array.new(size, true)
  is_prime[0] = false
  is_prime[1] = false

  2.upto(size-1){|i|
    if is_prime[i]
      prime_list << i
      (2).upto((size.to_f/i).ceil-1){|j|
        is_prime[j*i] = false
      }
    end
  }
  [prime_list, is_prime]
end

def dijkstra(s, e, cost)
  size = cost.length
  if s==e
    return 0
  end
  dp = {}
  dp[s] = 0
  undefined_node = {}
  size.times{|i|
    if i != s
      undefined_node[i] = cost[s][i]
    end
  }
  while undefined_node.length != 0
    min = undefined_node.min_by{|_, v| v}
    stock = {}
    temp = undefined_node.clone
    temp.each{|k, v|
      if min[1] == v
        undefined_node.delete(k)
        if k == e
          return v
        end
        dp[k] = v
        stock[k] = v
      end
    }

    stock.each{|k, v|
      undefined_node.each{|k2, v2|
        undefined_node[k2] = v + cost[k][k2] < v2 ?  v + cost[k][k2] : v2
      }
    }
  end
end

def get_bits(len)
  res =  []
  (2**len).times{|i|
    res << i.to_s(2).rjust(len, '0')
  }
  res
end

def get_GCD(m, n)
  tmp = [n, m].max
  n = [n, m].min
  m = tmp
  while n != 0
    tmp = m % n
    m = n
    n = tmp
  end
  m
end

n = i()
an = li()
def solve(n, an)
  if an.size == 2
    return an.max
  end
  a1 = Array.new(n-1)

  (1..(n-1)).each{|i|
    a1[i-1] = get_GCD(an[0], an[i])
  }

  (2..(n-1)).each{|i|
    a1[i-1] = [get_GCD(an[1], an[i]), a1[i-1]].max
  }
  a1.sort[1]
end

p solve(n, an)


# Your code here!
n=STDIN.gets.to_i
as= STDIN.gets.split(' ').map(&:to_i)

# find min index gcd and max value gcd
min = 1000000000
max = 0
index_min = 0
def gcd(a,b)
    while b > 0
        a,b = b,a%b
    end
    return a
end

for i in 0..n-2 do
    for j in i+1..n-1
        t = gcd(as[i], as[j])
        if (t < min)
            index_min = i
        end
        if (t > max)
            max = t;
        end
    end
end

as[index_min] = max;
def gcds(args)
    if args.length == 1
        return args
    end
    a = args.shift;
    b = args.shift
    args.push(gcd(a,b))
    gcds(args)
end

puts gcds(as)


def gcd(a, b)
  return b if (r = a % b).zero?
  gcd(b, r)
end
n = gets.chomp.to_i
as = gets.split.map(&:to_i)
if as.size == 2
  ans = as.max
else
  one_ans = gcd(as[0],as[1])
  two_ans = gcd(as[0],as[2])
  three_ans = gcd(as[1],as[2])
  one_count = 0
  two_count = 0
  three_count = 0
  as.each do |num|
    one_count += 1   if num % one_ans == 0
    two_count += 1   if num % two_ans == 0
    three_count += 1 if num % three_ans == 0
  end
  one_ans_next   = one_count   == (n - 1) ? one_ans : 1
  two_ans_next   = two_count   == (n - 1) ? two_ans : 1
  three_ans_next = three_count == (n - 1) ? three_ans : 1
  ans = [one_ans_next, two_ans_next, three_ans_next].max
end
puts ans


DMAX=17

def func(x,n)
    return if n==1
    gcds=[]
    (n/2).times do |i|
        gcds[i]=x[-1][2*i].gcd(x[-1][2*i+1])
    end
    x << gcds
    func(x,n/2)
end

def func2(x,i,level,temp)
    return if level==DMAX
    t=(i>>DMAX-level-1) ^ 1
    temp << x[DMAX-level-1][t]
    func2(x,i,level+1,temp)
end

N=gets.to_i
A=gets.split.map(&:to_i)
A2=Array.new(2**DMAX,A[-1])
A.each_with_index do |a,i|
    A2[i]=a
end
x=Array.new
x << A2
func(x,2**DMAX)
p x
max=0
N.times do |i|
    temp=[]
    func2(x,i,0,temp)
    g=temp.inject(&:gcd)
    max=g if max<g
end
puts max


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

sort_arr = arr.uniq.sort
ans = sort_arr[1] || sort_arr[0]
while ans > 1 do
  fail_count = 0
  arr.each do |num|
    fail_count += 1 if num % ans != 0
    break if fail_count >= 2
  end
  break if fail_count < 2

  if ans == sort_arr[1]
    ans = sort_arr[0]
  else
    ans -= 1
  end
end
puts ans


def gcd(a,b)
  gcd(b,a) if b > a
  return b if (r = a % b) == 0
  gcd(b,r)
end

def gcd_a(x)
  return x[0] if x.size == 1
  (x[1..-1]).inject(x[0]) {|r, n| gcd(r,n) }
end

N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)
if N > 1 then
  m = 1
  (0..(N-1)).each do |i|
    p = A.dup
    p.delete_at(i)
    q = gcd_a(p)
    m = q if m < q
  end
  puts m
else
  puts A[0]
end


require "set"

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

yakusu_arr = []
n.times do |t|
  yakusu_arr << Set.new
end

(1..Math.sqrt(arr.max).to_i).each do |t|
  arr.each_with_index do |a, i|
    if a % t == 0 then
      yakusu_arr[i] << t
      yakusu_arr[i] << a / t
    end
  end
end

max = 0
n.times do |i|
  p = yakusu_arr.select.with_index{|set, j| i != j}.reduce(&:&)
  max = p.max if p.max > max
end

puts max


class Array
  def gcd
    self.inject{|a,b| a.gcd(b)}
  end
end

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

array = []
now_b = 0
n.times do |i|
  b = a.dup
  x = b[i]
  if i == n-1
    b = [b[i]]
  else
    b = b.slice(i+1..n-1)
  end
  late_b = b.gcd
  array.push(late_b.gcd(now_b))
  if i == 0
    now_b = x
  else
    now_b = x.gcd(now_b)
  end
end

p array.max


require'prime'
n=gets.to_i
A=gets.split.map &:to_i
B=[1]*n
r=A.reduce:gcd
A.map!{|a|a/r}
M=A.max
Prime.each{|p|
	break if p>M
	f=true
	while f
		x=nil
		c=0
		n.times{|i|
			if A[i]%p==0
				A[i]/=p
				x=i
				c+=1
			end
		}
		if c==n-1
			B[x]*=p
		else
			f=false
		end
	end
}
p B.max*r


require 'prime'

class Integer
  def divisor_list
    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N = gets.to_i
A = gets.split.map(&:to_i)

counter = Hash.new(0)

A.each do |a|
  a.divisor_list.each do |v|
    counter[v] += 1
  end
end

puts counter.select { |k, v| v >= N - 1 }.keys.max


N = gets.to_i
As = gets.split.map(&:to_i)

class Array
  def gcd
      self.inject{|a,b| a.gcd(b)}
  end
end

max = 0

As.sort!

As.length.times do |i|
  as_ = As.dup
  as_[i] = as_[As.length - 1]

  m = as_.gcd

  if max <= m
    max = m
  end

end

puts max


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

result = a.combination(a.length-1).to_a.map do |c|
  c.inject(:gcd)
end.max

puts result


Score : 600 points

Problem Statement

You are given N integers. The i-th integer is a_i.
Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:

Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B.

Constraints

3 \leq N \leq 300

1 \leq a_i \leq 300(1\leq i\leq N)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1
:
a_N

Output

Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied.

Sample Input 1

4
1
1
1
2

Sample Output 1

18

We can only paint the integers so that the lengths of the sides of the triangle will be 1, 2 and 2, and there are 18 such ways.

Sample Input 2

6
1
3
2
3
5
2

Sample Output 2

150

Sample Input 3

20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4

Sample Output 3

563038556


N = gets.to_i
a = []
N.times do
  a << gets.to_i
end

MOD = 998244353
total = 0
a.each do |x|
  total += x
end
HALF = (total + 1) / 2

cnt_all = 1
N.times do
  cnt_all *= 3
  cnt_all %= MOD
end

# p cnt_all

# AのコストでDP
cost = { 0 => 1 }
N.times do |i|
  next_cost = Hash.new(0)
  cost.each do |k, v|
    # Aで塗った時
    k1 = k + a[i]
    next_cost[k1] = (next_cost[k1] + v) % MOD

    # B, C で塗った場合
    next_cost[k] = (next_cost[k] + 2 * v) % MOD
  end
  cost = next_cost
end
cnt_a = 0
# p cost
cost.each do |k,v|
  cnt_a += v if k >= HALF
  cnt_a -= MOD if cnt_a > MOD
end
# p cost.values.inject(0, &:+)

# C=0でDP
cnt_ab = 0
if total % 2 == 0
  sum = 0
  cost = { 0 => 1 }
  N.times do |i|
    sum += a[i]
    next_cost = Hash.new(0)
    cost.each do |k, v|
      # Aで塗る場合、
      k1 = k + a[i]
      next_cost[k1] = (next_cost[k1] + v) % MOD

      # Bで塗る場合
      k2 = sum - k
      next_cost[k2] = (next_cost[k2] + v) % MOD

      # Cを塗る場合、カウントしない
    end
    cost = next_cost
  end

  cost.each do |k,v|
    cnt_ab += v if k == HALF
    cnt_ab -= MOD if k > MOD
  end
end

# p [total, cnt_all, cnt_a, cnt_ab]

ans = cnt_all
3.times do
  ans -= cnt_a
  ans += MOD if ans <= 0
end
# p [ans, cnt_ab]
3.times do
  ans += cnt_ab
  ans -= MOD if ans > MOD
end
puts ans


# frozen_string_literal: true

# dp with dfs

N = gets.chomp.to_i
@arr = []
N.times do
  @arr.append(gets.chomp.to_i)
end

@dp = {}

def dfs(i, r, g, b)
  if i == N
    sanpen = [r, g, b].sort
    if sanpen[0] > 0 && sanpen[2] < sanpen[0] + sanpen[1]
      return 1
    else
      return 0
    end
  else
    ret = 0
    ret += dfs(i + 1, r + @arr[i], g, b)
    ret += dfs(i + 1, r, g + @arr[i], b)
    ret += dfs(i + 1, r, g, b + @arr[i])
    ret % 998_244_353
  end
end

puts dfs(0, 0, 0, 0)


Score : 100 points

Problem Statement

Takahashi likes the sound when he buys a drink from a vending machine.

That sound can be heard by spending A yen (the currency of Japan) each time.

Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time.

How many times will he hear the sound?

Constraints

All values in input are integers.

1 \leq A, B, C \leq 100

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times Takahashi will hear his favorite sound.

Sample Input 1

2 11 4

Sample Output 1

4

Since he has not less than 8 yen, he will hear the sound four times and be satisfied.

Sample Input 2

3 9 5

Sample Output 2

3

He may not be able to be satisfied.

Sample Input 3

100 1 10

Sample Output 3

0


a, b, c = gets.chomp.split("\s").map{|x| x.to_i}

puts [b / a, c].min


 list = gets.split(' ')
 n = list[0].to_i*list[2].to_i

if n > list[1].to_i
	s = list[1].to_i/list[0].to_i
	puts s
else
	puts list[2].to_i
end


a , b, c = gets.split.map(&:to_i)
if b % a == 0
  puts c
elsif b / a > 0
  puts b / a
else
  puts 0
end


A, B, C = gets.chomp.split.map(&:to_i)

if B / A >= C then
  puts C
else
  puts B / A
end


a, b, c = gets.split.map(&:to_i)
p b.div(a) < c ? b.div(a) : c


a,b,c = $stdin.read.split.map(&:to_i)
puts [b/a,c].min


a, b, c = gets.split.map(&:to_i)
p [b / a, c].min


line = gets
line.chomp!

/(\d+)\s+(\d+)\s+(\d+)/ =~ line
A = $1.to_i
B = $2.to_i
C = $3.to_i

sound = [B/A, C].min
puts sound


a,b,c = gets.split(" ").map(&:to_i)

if b>=a*c
  puts c
else
  puts b/a
end


a,b,c = gets.split.map(&:to_i)
p [b/a,c].min


line = $stdin.readline
a = line.split
A = a[0].to_i
B = a[1].to_i
C = a[2].to_i

ans = C

until A*ans <= B
	ans = ans - 1
	break if ans == 0
end

p ans


a,b,c=gets.chomp.split(" ").map(&:to_i);
if b/a >= c
    puts c
else
    d = b/a
    d = d.floor
    puts d
end


a,b,c=gets.split.map(&:to_i)
puts b/a>c ? c : b/a


require "numo/narray"

n = gets.to_i
h = Numo::Int64.parse(gets).reshape!(nil)
dp = Numo::Int64.new(n+10).fill(Numo::Int64::MAX)
dp[0] = 0

n.times do |i|
  1.upto(2) do |j|
    next unless i + j < n
    cost = (h[i+j] - h[i]).abs
    if dp[i+j] > dp[i] + cost
      dp[i+j] = dp[i] + cost
    end
  end
end
pp dp[n-1]

Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

4
10 30 40 20

Sample Output 1

30

If we follow the path 1 → 2 → 4, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

Sample Input 2

2
10 10

Sample Output 2

0

If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.

Sample Input 3

6
30 10 60 10 60 50

Sample Output 3

40

If we follow the path 1 → 3 → 5 → 6, the total cost incurred would be |30 - 60| + |60 - 60| + |60 - 50| = 40.


n = gets.to_i
$_h = gets.split.map {|x| x.to_i}

def h(i)
  return $_h[i-1]
end

def abs(x)
  return x < 0 ? -x : x
end
def min(x,y)
  return x < y ? x : y
end

$min_cost = Array.new(n+1, -1)

$min_cost[1] = 0
$min_cost[2] = abs(h(1) - h(2))

def calc(i)
  if ($min_cost[i] < 0)
    $min_cost[i] = min(calc(i-1) + abs(h(i) - h(i-1)), calc(i-2) + abs(h(i) - h(i-2)))
  end
  return $min_cost[i]
end

p calc(n)


n = gets.to_i
hs = gets.chomp.split.map(&:to_i)
dp = Array.new(n,10**18)
dp[0] = 0
(0..n-1).each do |i|
  dp[i+1] = [dp[i+1],dp[i] + (hs[i] - hs[i+1]).abs].min if i+1 < n
  dp[i+2] = [dp[i+2],dp[i] + (hs[i] - hs[i+2]).abs].min if i+2 < n
end
puts dp[n-1]


N = gets.to_i
H = gets.split.map(&:to_i)

dp = Array.new(N, Float::INFINITY)
dp[0] = 0

(N - 1).times do |i|
  if i == 0
    dp[1] = (H[i + 1] - H[i]).abs
  else
    dp[i + 1] = [(H[i + 1] - H[i]).abs + dp[i], (H[i + 1] - H[i - 1]).abs + dp[i - 1]].min
  end
end

puts dp[-1]


N = gets.to_i
HEIGHTS = gets.split.map(&:to_i)
# $count = 0
$costs = Array.new(N) { nil }

def get_cost(num)
  # $count += 1

  if $costs[num]
    # メモ化済みの場合には何もしない
  elsif num == 0
    $costs[num] = 0
  elsif num == 1
    $costs[num] = (HEIGHTS[num] - HEIGHTS[num-1]).abs + get_cost(num-1)
  else
    $costs[num] = [
      (HEIGHTS[num] - HEIGHTS[num-1]).abs + get_cost(num-1),
      (HEIGHTS[num] - HEIGHTS[num-2]).abs + get_cost(num-2),
    ].min
  end
  $costs[num]
end

puts get_cost(N-1)
# puts "count: #{$count}"


n = gets.chomp.to_i
heights = gets.chomp.split(" ").map(&:to_i)
dp = Array.new(n, Float::INFINITY)
dp[0] = 0

n.times do |i|
  next if i==0

  dp[i] = dp[i-1] + (heights[i] - heights[i-1]).abs if dp[i-1] + (heights[i] - heights[i-1]).abs < dp[i]
  if i > 1
    dp[i] = dp[i-2] + (heights[i] - heights[i-2]).abs if dp[i-2] + (heights[i] - heights[i-2]).abs < dp[i]
  end
end

p dp.last


#! /usr/bin/env ruby
begin
N, K = gets.chop.split.map(&:to_i)
H = gets.chop.split.map(&:to_i).unshift(0)
K.times do
  H.push(0)
end

TotalCosts = []

@deep = 0

def jump(from, step, paid_cost)
  now = from + step
  paid_cost += (H[from] - H[now]).abs

  if now == N
    TotalCosts << paid_cost
  elsif now < N
    K.times do |next_step|
      jump(now, next_step + 1, paid_cost)
    end
  end
end

K.times do |step|
  jump(1, step + 1 , 0)
end

p TotalCosts.min
rescue SystemStackError => ex
  p 111
end


#!/usr/bin/env ruby

if $0 == __FILE__
  N = gets.to_i
  H = gets.split(' ').map &:to_i

  dp = Array.new(N, 100000)
  dp[0] = 0

  (0...N).each do |i|
    dp[i+1] = [dp[i+1], (H[i+1] - H[i]).abs + dp[i]].min if i+1 <= N-1
    dp[i+2] = [dp[i+2], (H[i+2] - H[i]).abs + dp[i]].min if i+2 <= N-1
  end

  puts dp[N-1]
end


n,k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
k = [k,n-1].min
# 11行目で繰り返し最小値を比較するために一旦無限大で初期化
dp = Array.new(n){Float::INFINITY}
dp[0] = 0
# 飛び移れる最遠のところまでの初期値を入力
(1..k).each {|i| dp[i] = (h[i] - h[0]).abs}
# dp[i-j] <= j個手前までの最小コスト + そこから飛び移るときのコスト
(k+1...n).each do |i|
  (1..k).each {|j| dp[i] = [dp[i-j] + (h[i] - h[i-j]).abs, dp[i]].min}
end
p dp[n-1]

Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq K \leq 100

1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N K
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

5 3
10 30 40 50 20

Sample Output 1

30

If we follow the path 1 → 2 → 5, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

Sample Input 2

3 1
10 20 10

Sample Output 2

20

If we follow the path 1 → 2 → 3, the total cost incurred would be |10 - 20| + |20 - 10| = 20.

Sample Input 3

2 100
10 10

Sample Output 3

0

If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.

Sample Input 4

10 4
40 10 20 70 80 10 20 70 80 60

Sample Output 4

40

If we follow the path 1 → 4 → 8 → 10, the total cost incurred would be |40 - 70| + |70 - 70| + |70 - 60| = 40.


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

dp=Array.new(100010,INF)

dp[0]=0

for i in 1..h.length-1

for j in 1..k
 dp[i]=[dp[i-j]+(h[i-j]-h[i]).abs,dp[i]].min
end

end
#p dp[0..10]
p dp[h.length-1]


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

# i番目にたどり着くまでのコストの総和の最小値
dp = [0, (h_arr[1] - h_arr[0]).abs]
(2..n-1).each do |i|
  step = [k, i].min
  dp[i] = (1..step).map{ |j| dp[i-j] + (h_arr[i] - h_arr[i-j]).abs }.min
end
puts dp[n-1]


# frozen_string_literal: true

def chmin(a, b)
  a > b ? b : a
  end

n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
dp = Array.new(100_010, 1_000_000_007)
dp[0] = 0

(1..n - 1).each do |i|
  if i >= k
    (1..k).each do |j|
      dp[i] = chmin(dp[i], dp[i - j] + (h[i - j] - h[i]).abs)
    end
  end
  dp[i] = chmin(dp[i - 1] + (h[i] - h[i - 1]).abs, dp[i])
end
puts dp[n - 1]


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

dp = [10**18] * (10**5+10)
dp[0] = 0

(n-1).times do |i|
  k = n-i-1 if k > n-i-1
  k.times do |j|
    dp[i+j+1] = dp[i] + (h[i+j+1] - h[i]).abs  if dp[i+j+1] > dp[i] + (h[i+j+1] - h[i]).abs
  end
end

p dp[n-1]


n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
INF = 1001001001
dp = Array.new(n, INF)
dp[0] = 0
(n-1).times{|i|
  i+=1
  min = INF
  k.times{|j|
    j+=1
    min = [dp[i-j]+(h[i]-h[i-j]).abs, min].min if i>(j-1)
  }
  dp[i] = min
}
p dp[n-1]


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

if k >= n - 1
  puts (a[-1] - a[0]).abs
  exit
end

dp = [0xffffffff] * n
dp[0] = 0
(1...n).to_a.each do |i|
  lim = i - k >= 0 ? i - k : 0
  (i - 1).downto(lim) do |j|
    v = dp[j] + (a[i] - a[j]).abs

    dp[i] = v if v < dp[i]
  end
end

puts dp[-1]


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

if k >= n - 1
  puts (a[n - 1] - a[0]).abs
  exit
end

dp = [0] * n
(1...n).to_a.each do |i|
  min = 0xfffffff
  (i - 1).downto([i - k, 0].max) do |j|
    min = [min, dp[j] + (a[i] - a[j]).abs].min
  end
  dp[i] = min
end
puts dp[-1]


n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
dp = Array.new(n)
dp[0] = 0
(1...n).each do |i|
  dp[i] = (1..[k, i].min).map{|j| dp[i-j] + (h[i] - h[i-j]).abs}.min
end
puts dp.last


N, K = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
dp = []

N.times do |i|
  if i == 0
    dp << 0
  else
    tmp = (H[i] - H[i - 1]).abs + dp[i - 1]
    (2..i).each do |j|
      break if i > K
      tmp = [tmp, dp[i - j] + (H[i] - H[i - j]).abs].min
    end
    dp << tmp
  end
end

puts dp[N - 1]


ashiba_num, jump_num = gets.split(' ').map(&:to_i)
ashiba_cost = gets.split(' ').map(&:to_i)

dP = []
dP_comp = []
dP[0] = 0
dP[1] = (ashiba_cost[1] - ashiba_cost[0]).abs

range = 2..ashiba_num - 1
range2 = 1..jump_num
range.each do |move|

    range2.each do |jump|
        if move - jump >= 0
            dP_comp.push(dP[move - jump] + (ashiba_cost[move] - ashiba_cost[move - jump]).abs)
        else
            dP_comp.push((ashiba_cost[move] - ashiba_cost[0]).abs)
        end
    end

   dP[move] = dP_comp.min
   dP_comp.clear

end

p dP.last


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

number_of_steps = n.to_i
jump_power = k.to_i

# DP配列を初期化
dp = Array.new(number_of_steps, 0)

(1...number_of_steps).each do |index|
  # 各ステップ数毎のコストを格納する配列
  costs_of_jump = []
  (1..jump_power).each do |jump|
    # ex. 2ステップ目までのコストを考える時、3段ジャンプは計算しない
    break unless index >= jump

    costs_of_jump.push(dp[index - jump] + (h[index] - h[index - jump]).abs)
  end

  dp[index] = costs_of_jump.min
end

puts dp[number_of_steps - 1]


def frog2(n, k, h)
  dp = Array.new(n, 0)
  1.upto(n - 1) do |i|
    tmp = dp[i - 1] + (h[i] - h[i - 1]).abs
    2.upto(k) do |j|
      break if i - j < 0
      tmp = [tmp, dp[i - j] + (h[i] - h[i - j]).abs ].min
    end
    dp[i] = tmp
  end

  puts dp[n - 1]
end

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


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

dp = Array.new(n, 0)
dp[0] = 0
(1..n-1).each do |i|
  dp[i] = 10 ** 20
  ([0, i-k].max..i-1).each do |j|
    dp[i] = [dp[i], dp[j] + (hs[i] - hs[j]).abs].min
  end
end

puts dp[n-1]


def min2(a, b)
    return a <= b ? a : b
end

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

# cost[i] : i-1段目到達の最小コスト
cost = Array.new(h.length+1, Float::INFINITY)
cost[0] = 0

(1..(n-1)).each do |i|
    (1..k).each do |j|
        break if i < j
        cost[i] = min2(cost[i], cost[i-j] + (h[i]-h[i-j]).abs)
    end
end

# (0..n-1).each do |i|
#     puts "#{i} : #{cost[i]}"
# end
puts cost[n-1]


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

# dp = Array.new(n, 0)
dp = [0,0]

for i in 2..n
  # dp[i] = dp[i-1] + (hs[i-2] - hs[i-1]).abs
  # dp << dp[i-1] + (hs[i-2] - hs[i-1]).abs
  min = dp[i-1] + (hs[i-2] - hs[i-1]).abs
  for j in (1..[i-1,k].min)
    tmp = dp[i-j] + (hs[i-j-1] - hs[i-1]).abs
    # dp[i] = tmp if dp[i] > tmp
    # if dp[i] > tmp
    #   dp[i] = tmp
    # end
    if min > tmp
      min = tmp
    end
  end
  dp << min
end

puts dp[n]


require 'pp'

N,K = readline.split.map(&:to_i)
H = readline.split.map(&:to_i)

dp = Array.new(N,0)

dp[0] = 0

(1..(N-1)).each do |i|
  k = (i<K) ? i : K
  costs = (1..k).each.map {|k|
    dp[i-k] + (H[i-k]-H[i]).abs
  }
  dp[i] = costs.min
end

puts dp.last


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

ds = [0]
(1...n).each do |i|
  tmp = []
  [0, i-k].max.upto(i-1) do |j|
    tmp << (ds[j] + (arr[j] - arr[i]).abs)
  end
  ds << tmp.min
end

puts ds[-1]


N, W = gets.chomp.split.map(&:to_i)

weights = []
values  = []

N.times do
  weight, value = gets.chomp.split.map(&:to_i)

  weights << weight
  values  << value
end

dp = Array.new(N + 1) { Array.new(W + 1) { 0 } }

1.upto(N) do |i|
  1.upto(W) do |w|
    if w - weights.fetch(i - 1) >= 0
      w0 = weights.fetch(i - 1)
      v0 = values.fetch(i - 1)

      dp[i][w] = dp[i - 1][w - w0] + v0
    end

    dp[i][w] = dp[i - 1][w] if dp[i][w] < dp[i - 1][w]
  end
end

print dp[N][W]

Score : 100 points

Problem Statement

There are N items, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.

Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

Find the maximum possible sum of the values of items that Taro takes home.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq W \leq 10^5

1 \leq w_i \leq W

1 \leq v_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible sum of the values of items that Taro takes home.

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Items 1 and 3 should be taken.
Then, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

Sample Input 2

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 2

5000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Items 2, 4 and 5 should be taken.
Then, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.


n,m = gets.split.map &:to_i
w,v = Array.new(n){ gets.split.map &:to_i }.transpose
dp = Array.new(n+1){ Array.new(m+1,0) }

max = -> a,b { a > b ? a : b }

0.upto(n-1) do |i|
  0.upto(m) do |j|
    if j < w[i]
      dp[i+1][j] = dp[i][j]
    else
      dp[i+1][j] = max[dp[i][j], dp[i][j-w[i]] + v[i]]
    end
  end
end

puts dp[n][m]


def max(a, b)
  a > b ? a : b
end

N, W = gets.chomp.split.map(&:to_i)
dp = Array.new(W + 1) { -1 }
dp[0] = 0
idxes = [0]
N.times do
  wi, vi = gets.chomp.split.map(&:to_i)

  nidxes = []
  idxes.each do |i|
    ni = i + wi
    next if ni > W

    dp[ni] = max(dp[ni], dp[i] + vi)
    nidxes << ni
  end
  idxes = (nidxes + idxes).uniq.sort.reverse

  # puts "dp = #{dp}"
  # puts "idxes = #{idxes}"
end

puts dp.max


$N,$W= gets.split.map(&:to_i)
$w_ary = []
$v_ary = []
$N.times do |n|
  w,v = gets.split.map(&:to_i)
  $w_ary << w
  $v_ary << v
end

$cache = {}
def calc(n, left)
  total = 0
  return 0 if n == $N

  key = "#{n}_#{left}"
  return $cache[key] unless $cache[key].nil?

  if $w_ary[n] <= left
    tmp1 = calc(n+1, left)
    tmp2 = calc(n+1, left - $w_ary[n]) + $v_ary[n]
    total = [tmp1,tmp2].max
  else
    total = calc(n+1, left)
  end
  $cache[key] = total
  total
end

total = calc(0, $W)
puts total


n, w_max = gets.split.map(&:to_i)
items = Array.new(n){gets.split.map(&:to_i)}
dp = Hash.new(0)
dp[0] = 0
ans = 0
items.each do |w, v|
  dp.dup.each do |pw, pv|
    nw = pw + w
    nv = pv + v
    ans = dp[nw] = nv if nw <= w_max && dp[nw] < nv
  end
end
puts ans


n, w_max = gets.split.map(&:to_i)
items = Array.new(n){gets.split.map(&:to_i)}
dp = Array.new(w_max+1, 0)
items.each do |item|
  wi, vi = item
  tmp = dp.dup
  (wi..w_max).each{|w| tmp[w] = [dp[w], vi + dp[w-wi]].max}
  dp = tmp
end
puts dp.last


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

dp = Array.new(W+1,0)

n.times do |i|
  w, v = gets.chomp.split.map(&:to_i)
  W.downto(0).each do |weight|
    if w <= weight
      dp[weight] = dp[weight-w] + v if dp[weight] < dp[weight-w] + v
    end
  end
end

# dp.each{|line| p line}
# p dp
puts dp[W]


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

dp = Array.new(n+1) { Array.new(W+1,0) }
w = []
v = []
n.times do |i|
  ww, vv = gets.chomp.split.map(&:to_i)
  w.push ww
  v.push vv
end

n.times do |i|
  (W+1).times do |weight|
    dp[i+1][weight] = dp[i][weight]
    if w[i] <= weight
      dp[i+1][weight] = [dp[i][weight-w[i]] + v[i], dp[i][weight]].max
    end
  end
end

# dp.each{|line| p line}
puts dp[n][W]


num, weight = gets.chomp.split(" ").map(&:to_i)
# things = Array.new
# num.times do
#   things << gets.chomp.split(" ").map(&:to_i)
# end

# 縦軸を品物の順番、横軸を許容重量とし、価値の最大値を格納するテーブルdp
dp = Array.new(num + 1){Array.new(weight + 1, 0)}

# 1個目からnum個目までの品物を、ナップサックに入れるべきか順番に確認する
1.upto(num) do |n|
  # n個目の重量をtmp_weight、価値をtmp_valueとする
  tmp_weight, tmp_value = gets.chomp.split(" ").map(&:to_i)
  # 許容重量が0からweightまでの場合を、順番に確認する
  0.upto(weight) do |w_accepted|
    # tmp_weightが許容重量を超えている場合は、ナップサックに品物を入れられないため、
    # 1つ手前の品物の確認時と等しい価値を格納する
    value_not_changed = dp[n - 1][w_accepted]
    dp[n][w_accepted] = value_not_changed
    # その他の場合は、ナップサックに品物を入れる、入れない場合を比較し、価値が大きい方を格納する
    # 入れる場合の価値は、「1つ手前の品物の確認時における、許容重量がtmp_weight分少ない時の価値」 + tmp_valueとなる
    if tmp_weight <= w_accepted
      if dp[n - 1][w_accepted - tmp_weight] + tmp_value > value_not_changed
        dp[n][w_accepted] = dp[n - 1][w_accepted - tmp_weight] + tmp_value
      end
      # 「1つ手前の品物の確認時における、許容重量がtmp_weight分少ない時の価値」が、1つ手前の行の最大価値である場合は、
      # # 以降全ての許容重量にも同じ値を格納し、次の品物の処理へ進む
      # if dp[n - 1][w_accepted - tmp_weight] == dp[n - 1].last
      #   (1..weight - w_accepted).each do |index|
      #     dp[n][w_accepted + index] = dp[n - 1][w_accepted - tmp_weight]
      #   end
      #   break
      # end
    end
  end
end

# 最後の品物、最後の許容重量における価値を出力する
puts dp[num][weight]


s = gets.chomp.chars
t = gets.chomp.chars
n = s.size
m = t.size

dp = Array.new(n+1){Array.new(m+1, 0)}
n.times do |i|
  dp_cur = dp[i]
  dp_next = dp[i+1]
  m.times do |j|
    if s[i] == t[j]
      dp_next[j+1] = dp_cur[j] + 1
    else
      a = dp_cur[j+1]
      b = dp_next[j]
      dp_next[j+1] = a > b ? a : b
    end
  end
end

i, j = n, m
ans = ''
while i > 0 && j > 0 do
  if dp[i][j] == dp[i-1][j]
    i -= 1
  elsif dp[i][j] == dp[i][j-1]
    j -= 1
  else
    ans << s[i-1]
    i -= 1
    j -= 1
  end
end

puts ans.reverse

Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara


s = gets.chomp
t = gets.chomp
n = s.size
m = t.size

dp = Array.new(n+1){Array.new(m+1, 0)}
n.times do |i|
  m.times do |j|
    if s[i] == t[j]
      dp[i+1][j+1] = dp[i][j] + 1
    else
      dp[i+1][j+1] = dp[i][j+1] if dp[i][j+1] > dp[i+1][j+1]
      dp[i+1][j+1] = dp[i+1][j] if dp[i+1][j] > dp[i+1][j+1]
    end
  end
end

i, j = n, m
ans = ''
while i > 0 && j > 0 do
  if dp[i][j] == dp[i-1][j]
    i -= 1
  elsif dp[i][j] == dp[i][j-1]
    j -= 1
  else
    ans << s[i-1]
    i, j = i-1, j-1
  end
end

puts ans.reverse


s_orig = gets.chomp
t_orig = gets.chomp

s = s_orig.codepoints
t = t_orig.codepoints

dp = Array.new(s.length+1) { Array.new(t.length+1,0) }

0.upto(s.length-1).each do |i|
  0.upto(t.length-1).each do |j|
    if s[i] == t[j]
      dp[i+1][j+1] = dp[i][j] + 1
    else
      dp[i+1][j+1] = dp[i+1][j] > dp[i][j+1] ? dp[i+1][j] : dp[i][j+1]
    end
  end
end

ans = ''
current = dp[s.length][t.length]
y = s.length
x = t.length

while true
  if current == 0
    break
  elsif dp[y-1][x] == current
    y-=1
  elsif dp[y][x-1] == current
    x-=1
  else
    # p [y,x,current]
    y-=1
    x-=1
    ans += s_orig[y]
    current-=1
  end
end

# dp.each{|l| p l}

puts ans.reverse


s = gets
t = gets
ret = ''
[0,1].repeated_permutation(s.chars.size).sort_by {|a| a.count {|i| i == 1} }.reverse.each do |arr|
  subchars = arr.map.with_index do |a,i|
    a == 0 ? nil : s.chars[i]
  end.compact
  next unless subchars.all? {|c| t.chars.include?(c)}
  tmp = t.chars.dup
  flg = true
  subchars.each do |c|
    if i = tmp.index(c)
      tmp = tmp[(i+1)..-1]
    else
      flg = false
      break
    end
  end
  ret = subchars.join and break if flg
end
puts ret


n = gets.to_i
case n
when 25
  puts "Christmas"
when 24
  puts "Christmas Eve"
when 23
  puts "Christmas Eve Eve"
when 22
  puts "Christmas Eve Eve Eve"
end

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.


a=gets.strip.to_i
puts "Christmas" if a==25
puts "Christmas Eve" if a==24
puts "Christmas Eve Eve" if a==23
puts "Christmas Eve Eve Eve" if a==22


D = gets.to_i

case D
  when 25
    puts 'Chirstmas'
  when 24
    puts 'Chirstmas Eve'
  when 23
    puts 'Christmas Eve Eve'
  when 22
    puts 'Christmas Eve Eve Eve'
end


d = gets.chomp!.to_i

case d
when 22
    puts "Christmas Eve Eve Eve"
when 23
    puts "Christmas Eve Eve"
when 24
    puts "Christmas Eve"
when 25
    puts "Christmas"
end


D = gets.to_i
if D==25
  puts "Christmas"
elsif D==24
  puts "Christmas Eve"
elsif D==23
  puts "Christmas Eve Eve"
else
  puts "Cristmas Eve Eve Eve"
end


d =gets.split.map(&:to_i)
if d==25
  puts 'Christmas'

elsif d==24
    puts 'Christmas Eve'
elsif
    if d==23
      puts 'Christmas Eve Eve'

else d==22
        puts 'Christmas Eve Eve Eve'
      end


d = gets.to_i
case d
when 25 then puts 'Christmas'
when 24 then puts 'Christmas Eve'
when 23 then puts 'Christmas Eve Eve'
when 22 then puts 'Christmas Eve Eve Eve'
end


christmas_date=25
a = gets.to_i
s = ("Christmas " + "Eve " * (christmas_date - a)).rstrip
print s


d = gets.to_i

if d == 25
	puts "Christmas"
elsif d == 24
	puts "Christmas Eve"
elsif d == 23
	puts "Christmas Eve Eve"
else
	puts "Christmas Eve Eve Eve"
end


d=gets.chomp.to_i
str = case d
  when 25
    'Christmas'
  when 24
    'Christmas Eve'
  when 23
    'Christmas Eve Eve'
  when 22
    'Christmas Eve Eve Eve'
end
  print("#{str}\n")


puts "Christmas" + " Eve" * (25 - gets.to_i)


D = gets.to_i
puts (['Christmas'] + ['Eve']*(25-D)).join(' ')


n = gets.to_i

puts "Christmas" +  " Eve"*(25-n)


N,*xyhs=$<.read.split.map(&:to_i)

0.upto(100) do |cx|
    0.upto(100) do |cy|
        x,y,h = xyhs[0..2]
        ht = h+(x-cx).abs+(y-cy).abs
        b = xyhs.each_slice(3).all? do |x,y,h|
            ht == h+(x-cx).abs+(y-cy).abs
        end
        if b
            puts [cx,cy, ht].join(' ')
            exit
        end
    end
end

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.


def gs() STDIN.gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n = gi
xyhs = Array.new(n){gsmi}

def dis(x1,y1,x2,y2)
	(x1-x2).abs+(y1-y2).abs
end

101.times do |x|
	101.times do |y|
		h = dis(x,y,xyhs[0][0],xyhs[0][1]) + xyhs[0][2]

		flag = true
		(1...n).each do |i|
			xyh = xyhs[i]
			if (h-dis(x,y,xyh[0],xyh[1]))!=xyh[2]
				flag = false
				break
			end
		end

		puts [x,y,h].join(" ") if flag
	end
end


N = gets.to_i
lists = []
lists1 = []
lists2 = []
N.times do
  s, t, u = gets.split.map(&:to_i)
  if u != 0
    lists1 << [s, t, u]
  else
    lists2 << [s, t, u]
  end
  lists << [s, t, u]
end

(0..100).each do |i|
  (0..100).each do |j|
    pre = nil
    check = true
    dist = nil
    lists.each do |x, y, z|
      next if z != 0
      dist = z + (i - x).abs + (j - y).abs
      if (pre ||= dist) != dist
        check = false
        break
      end
    end
    lists2.each do |x, y, z|
      next if z == 0
      dist = (i - x).abs + (j - y).abs
      if pre > dist
        check = false
        break
      end
    end
    if check
      puts "#{i} #{j} #{dist}"
      exit
    end
  end
end


N = gets.to_i
lists1 = []
lists2 = []
N.times do
  s, t, u = gets.split.map(&:to_i)
  if u != 0
    lists1 << [s, t, u]
  else
    lists2 << [s, t, u]
  end
end

(0..100).each do |i|
  (0..100).each do |j|
    pre = nil
    check = true
    dist = nil
    lists1.each do |x, y, z|
      dist = z + (i - x).abs + (j - y).abs
      if (pre ||= dist) != dist
        check = false
        break
      end
    end
    lists2.each do |x, y, z|
      dist = z + (i - x).abs + (j - y).abs
      if pre > dist
        check = false
        break
      end
    end
    if check
      puts "#{i} #{j} #{dist}"
      exit
    end
  end
end


N = gets.to_i
lists = []
N.times do
  lists << gets.split.map(&:to_i)
end
# p lists
if lists.size == 1
  puts "#{lists[0]} #{lists[1]} #{lists[2]}"
  exit
end
(0..100).each do |i|
  (0..100).each do |j|
    pre = nil
    check = true
    dist = nil
    lists.each do |x, y, z|
      next if z < 1
      dist = z + (i - x).abs + (j - y).abs
      check = false if (pre ||= dist) != dist
    end
    if check
      puts "#{i} #{j} #{dist}"
      exit
    end
  end
end


#require 'pp'

n = gets.chomp!.to_i
points = []
n.times do |i|
    x, y, h = gets.chomp!.split(' ').map(&:to_i)
    points << [x, y, h]
end

0.upto(100) do |c_x|
    0.upto(100) do |c_y|
        ok = true
        before = nil
        n.times do |i|
            x, y, h = points[i]
            h_tmp = h + (x - c_x).abs + (y - c_y).abs
            before ||= h_tmp

            if before != h_tmp
                ok = false
                break
            end
        end

        if ok
            puts "#{c_x} #{c_y} #{before}"
            exit 0
        end
    end
end


n = gets.to_i
as = []
n.times do
  as << gets.split.map(&:to_i)
end

cx = nil
cy = nil
h = nil

(0..100).each do |x|
  (0..100).each do |y|
    a = as.find{|a| a[2] != 0}
    h = a[2] + (a[0] - x).abs + (a[1] - y).abs
    flg = as.all? do |a|
      a[2] == [h - (a[0] - x).abs - (a[1] - y).abs, 0].max
    end
    if flg
      puts "#{x} #{y} #{h}"
      exit
    end
  end
end


N = gets.to_i

points = []
N.times do
  x, y, h = gets.split.map(&:to_i)
  points << [x, y, h]
end

0.upto(101) do |x|
  0.upto(101) do |y|
    sum = []
    points.select {|p| p[2] > 0}.each do |p|
      sum << p[2] + (p[0] - x).abs + (p[1] - y).abs
    end

    # puts "#{points} x: #{x} y: #{y} => #{sum}"

    if sum.uniq.size == 1
      satisfied = true
      points.select {|p| p[2] == 0}.each do |p|
        if sum.first > (p[0] - x).abs + (p[1] - y).abs
          satisfied = false
          break
        end
      end
      if satisfied
        puts "#{x} #{y} #{sum.first}"
        exit 0
      end
    end
  end
end


N = gets.to_i
A = []
B = []
N.times do
  tmp = gets.split.map(&:to_i)
  if tmp[2] > 0
    A << tmp
  else
    B << tmp
  end
end

for cy in 0..100
  for cx in 0..100
    tmp = A.map{|x, y, h| h + (x - cx).abs + (y - cy).abs}
    if tmp.uniq.size == 1
      ht = tmp[0]
      if B.all?{|x, y , h0| ht <= (x - cx).abs + (y - cy).abs}
        puts "#{cx} #{cy} #{ht}"
        exit
      end
    end
  end
end


N = gets.to_i
xyh_list = N.times.map { gets.chomp.split(' ').map(&:to_i) }

def calc_ph((cx, cy), (x, y, h))
  [h + (x - cx).abs + (y - cy).abs, 0].max
end

(0..100).each do |cx|
  (0..100).each do |cy|
    cp = [cx, cy]
    ok = xyh_list.map do |xyh|
      calc_ph(cp, xyh)
    end.uniq.size == 1
    if ok
      xyh = xyh_list.first
      ph = calc_ph(cp, xyh)
      puts "#{cx} #{cy} #{ph}"
      exit 0
    end
  end
end


N = gets.chomp.to_i
x = Array.new(N)
y = Array.new(N)
h = Array.new(N)
flg = false
N.times do |i|
  x[i],y[i],h[i] = gets.chomp.split(" ").map(&:to_i)
end
MAX = 100;
(0..100).each do |posY|
  (0..100).each do |posX|
    needH = -1;
    N.times do |i|
      if h[i] > 0
        tmp = h[i] + (posY - y[i]).abs + (posX - x[i]).abs
        if needH == -1
          needH = tmp;
        else
          if needH != tmp
            needH = -2;
            break;
          end
        end
      end
    end
    if needH == -2
      next
    end
    N.times do |i|
      if h[i] == 0
        dist = (posY - y[i]).abs + (posX - x[i]).abs
        if needH > dist
          needH = -2
          break
        end
      end
      if needH == -2
        next;
      end

      puts posX.to_s + " " + posY.to_s + " " + needH.to_s
      flg = true
      break
    end
    if flg
      break
    end
  end
  if flg
    break
  end
end


nn = gets.to_i
xyh =[]
$stdin.each_line{|line|
xyh.push((line.split).map!(&:to_i))}
xyh.delete_if{|a|a[2] == 0}
if xyh.size == 1
  puts "#{xyh[0][0]} #{xyh[0][1]} #{xyh[0][2]}"
else
h = Array.new(xyh.size)
for i in (0..100)
  for j in (0..100)
    for k in (0..xyh.size-1)
      h[k] = (xyh[k][0] - i).abs + (xyh[k][1] - j).abs + xyh[k][2]
    end
    if h.uniq.size == 1
      puts "#{i} #{j} #{h[0]}"
    end
  end
end
end


N = gets.chomp.to_i
_H = 0
_Cx = 0
_Cy = 0
data = []
N.times do
  x, y, h = gets.chomp.split().map(&:to_i)
  data << [x, y, h]
end
(0..100).each do |cx|
  (0..100).each do |cy|
    hary = []
    hary_count = 0
    data.each do |d|
      x, y, height = d
      next if height == 0
      h = (x-cx).abs + (y-cy).abs + height
      hary << h
      break if (hary[hary_count] != hary[hary_count-1]) && hary_count >= 1
      hary_count += 1
    end
    s = hary.uniq
    if s.length == 1
      _H = s[0]
      _Cx = cx
      _Cy = cy
      puts "#{_Cx} #{_Cy} #{_H}"
      exit
    end
  end
end


n, T = gets.chomp.split(' ').map(&:to_i)
x = []
y = []
h = []
min = nil
for i in 0...n do
  x[i], y[i], h[i] = gets.chomp.split(' ').map(&:to_i)
end

for i in 0..100
  for j in 0..100
    hs = []
    for k in 0..(x.size - 1) do

      hi = (i - x[k]).abs + (j - y[k]).abs + h[k]
      hs << hi
    end
    if hs.uniq.size == 1
      puts "#{i} #{j} #{hs[0]}"
      exit
    end
  end
end


N = gets.to_i
xyh = $<.map{|s| s.split.map &:to_i }
xyh1, *xyh2 = xyh

def f(xyh, cx, cy)
  x, y, h = xyh
  ch = (cx - x).abs + (cy - y).abs + h
end

cy, cx = [*0..100].product([*0..100]).find{|cy, cx|
  ch = f(xyh1, cx, cy)
  ch >= 1 && xyh2.all?{|a|
    f(a, cx, cy) == ch
  }
}

ch = f(xyh1, cx, cy)
puts [cx, cy, ch]*" "


arr = gets.chomp.split(' ').map(&:to_i).sort.reverse
puts (arr[0].to_s + arr[1].to_s).to_i + arr[2]

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


nums = gets.split.map(&:to_i)
puts nums.max * 9 + nums.inject(:+)


a,b,c = gets.split.map(&:to_i).sort.reverse
puts a*10 + b + c


num = gets.split.map(&:to_i)
num.sort!
num.reverse!
sum = num[0] * 10
num.shift
sum += num.inject(:+)
puts sum


a, b, c = gets.split.map(&:to_i)
x = [a,b,c].sort.reverse
puts x[0]*10 + x[1] + x[2]


l=gets.chomp.split.map(&:to_i)
p l
m=l.max
l.delete_at l.index m
n=l.max
l.delete_at l.index n
puts m*10+n+l[0]


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

# ABC 110 A

A = gets.split.map(&:to_i)
A.sort!
ans = A[2]*10 + A[1] + A[0]
p ans


n,m,X,Y = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i)
y = gets.chomp.split(" ").map(&:to_i)
war = false
if X < Y
  n.times do |i|
    m.times do |j|
      if x[i] >= y[j]
        war = true
      end
    end
  end
  if x.max >= Y || y.min <= X
    war = true
  end
else
  war = true
end
if war
  puts "War"
else
  puts "No War"
end

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


N, M, X, Y = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i).sort
y = gets.chomp.split.map(&:to_i).sort

l = x[-1] + 1
r = y[0]

if ((l..r).to_a & (X+1..Y).to_a).size > 0
  puts 'No War'
else
  puts 'War'
end


def bb
    n,m,x,y = gets.chomp.split(/\s/).map{|x| x.to_i}

    xx = [gets.chomp.split(/\s/).map{|x| x.to_i}.max, x].max
    yy = [gets.chomp.split(/\s/).map{|x| x.to_i}.min, y].min

    puts xx < yy ? 'No War' : 'War'
end

bb


_, _, x, y = gets.chomp!.split(' ').map(&:to_i)
x_max = gets.chomp!.split(' ').map(&:to_i).max
y_min = gets.chomp!.split(' ').map(&:to_i).min

war = ((-100..100).find {|z|
    x_max < z && z <= y_min && x < z && z <= y
}) ? "No War" : "War"

puts war


N, M, X, Y = gets.strip.split.map(&:to_i)
xs = gets.strip.split.map(&:to_i)
ys = gets.strip.split.map(&:to_i)

Z = ys.min

do_war = true
if xs.all? { |x| x < Z } &&
   ys.all? { |y| y >= Z } &&
   (X < Z && Z <= Y)
  do_war = false
end

puts do_war ? 'War' : 'No War'


n,m,x,y = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i) + [x]
ys = gets.split.map(&:to_i) + [y]

puts xs.max < ys.min ? "No War" : "War"


n, m, x, y  = gets.chomp.split.map(&:to_i).sort
arr = gets.chomp.split.map(&:to_i)
arr2 = gets.chomp.split.map(&:to_i)

result = "War"
(x + 1).upto(y){|z|
    result = "No War" if z > arr.max && z <= arr2.min
}
puts result


_a,_b,c,d=gets.chomp.split(" ").map(&:to_i)
e=gets.chomp.split(" ").map(&:to_i).push(c)
f=gets.chomp.split(" ").map(&:to_i).push(d)

if e.max < f.max then
  puts "No War"
else
  puts "War"
end


n, m, x, y = gets.split.map(&:to_i)
xx = (gets.split.map(&:to_i) + [x]).sort
yy = (gets.split.map(&:to_i) + [y]).sort
puts xx[-1] < yy[0] ? "No War" : "War"


n,m,x,y = gets.split.map(&:to_i)
xa = gets.split.map(&:to_i) + [x]
ya = gets.split.map(&:to_i) + [y]

xa,ya = ya,xa if x>y

if xa.max<ya.min
  puts "No War"
else
  puts "War"
end


N,M,X,Y = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)
if (xs+[X]).max < (ys+[Y]).min
    puts "No War"
else
    puts "War"
end


N,M,X,Y = gets.split.map(&:to_i)
Xm = gets.split.map(&:to_i).max
YM = gets.split.map(&:to_i).min
if X < Y
  if Xm < YM
    if Xm < Y && X < YM
      puts "No War"
      exit
    end
  end
end
puts "War"


a,b =  gets.split(" ").map(&:to_i)
n = a * b
if n % 2 == 0
    puts "No"
else
    puts "Yes"
end

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


a, b = gets.split.map(&:to_i).sort
res = false
(a..b).each do |i|
  res = true if (a * b * i % 2) != 0
end
puts res ? 'Yes' : 'No'


a, b = gets.split.map(&:to_i)
if a*b.even?
  print "No"
else
  print "Yes"
end


a,b = gets.split(" ").map(&:to_i)
puts (a * b).odd? ? 'Yes' : 'No'


# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

aa = inputs[0][0]
bb = inputs[0][1]

if aa % 2 == 0 or bb % 2 == 0
  puts "No"
else
  puts "Yes"
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end


n = gets.to_i
ws = Array.new(n){gets.chomp}

ans = ws==ws.uniq ? "Yes" : "No"

ws.each_with_index do |w,i|
  if i < ws.length-1 && ws[i][-1] != ws[i+1][0]
    ans = "No"
  end
end

puts ans


a,b=gets.split.map(&:to_i)
ans = "No"
1.upto(3) do |c|
  if (a*b*c)%2!=0
    ans = "Yes"
  end
end

puts ans


arr = gets.chomp.split("")

ret = arr[0].to_i * arr[1].to_i

puts (ret%2)==0 ? "No" : "Yes"


a , b = gets.strip.split(' ').map(&:to_i);
ans0 = a * b;
ans1 = a * b * 2;
ans2 = a * b * 3;

if ans0 % 2 == 1 || ans1 % 2 == 1 || ans2 % 2 == 1
	puts "YES"
	else
	puts "NO"
end


a,b=gets.split.map &:to_i
if a==1||b==1
  puts :Yes
else
  puts :No
end


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

if a%2 == 1 && b%2 == 1
    puts "Yes"

else
    puts "No"
end


a, b = gets.split.map(&:to_i)
if a * b % 2 == 0
  puts "No"
else
  puts "Yes"
end


#!/usr/bin/env ruby

(a, b) = gets.chomp.split(/ /).map(&:to_i)

if (a % 2 == 0 || b % 2 == 0)
  puts "No"
else
  puts "Yes"
end


def ascan; gets.split.map(&:to_i); end

A,B = ascan

(1..3).each do |c|
    if (A*B*c).odd?
        puts "Yes"; exit
    end
end

puts "No"


h = gets.to_i
strs = h.times.map{ gets.chomp.split('') }

if strs.uniq.size != h
  puts 'No'
  exit
end

strs.each_with_index do |str, idx|
  break if idx == h-1
  if str[-1] != strs[idx+1][0]
    puts 'No'
    exit
  end
end

puts 'Yes'

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


def bb
    n = gets.chomp.to_i

    w = []
    for i in 1..n
        w.push(gets.chomp)
    end

    unless w.length == w.uniq.length
        puts 'No'
        exit
    end

    for i in 1..(n-1)
        unless w[i-1][-1] == w[i][0]
            puts 'No'
            exit
        end
    end

    puts 'Yes'
end

bb


n = gets.to_i
ss = n.times.map{gets.chomp}
puts ss.uniq.size == n && (n-2).times.all?{|i| ss[i][-1] == ss[i+1][0]} ? 'Yes' : 'No'


# Shiritori
N = gets.chomp.to_i
W = []
count = 1
flg = true
for i in N.times do
    W.push(gets.chomp.split("").map(&:to_s))
end
for i in 0..N-1 do #ルール１を実装
    for j in 0..N-1 do
        if W[i].join("") == W[j].join("") && i != j
            flg = false
        end
    end
end

for i in 0..N-1 do #ルール２の判定実装
    if i != 0
        if W[i][0] == W[i-1][W[i-1].length-1]
            count = count + 1
        end
    end
end

if flg == true && count == N
    puts "Yes"
else
    puts "No"
end


words = []
valid = true
gets.to_i.times do
  word = gets.chomp
  next unless valid

  next valid = false if words.include? word
  next valid = false unless words.empty? || words.last[-1] == word[0]
  words << word
end

puts valid ? "Yes" : "No"


n = gets.to_i
ans = "Yes"
words = []
s = gets.chomp
words << s
last = s[-1]
(n-1).times do
  s = gets.chomp
  ans = "No" if words.index(s) || s[0] != last
  words << s
  last = s[-1]
end
puts ans


N, X = gets.chomp.split().map(&:to_i)

x = []
gets.chomp.split().each do |s|
  x << (X - s.to_i).abs
end

ans = x[0]
x[1..].each do |i|
  ans = ans.gcd(i)
end

puts ans

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


def gcd(a,b)
  a.gcd(b)
end

n,X = gets.split.map(&:to_i)
x = gets.split.map{|v| (v.to_i-X).abs}

ans = x[0]

(1..(n-1)).each do |i|
  ans = gcd(ans, x[i])
end

puts ans


n, x = gets.split.map(&:to_i)
coordinates = gets.split.map(&:to_i)
coordinates.map! do |c|
  c = (c - x).abs
end

puts coordinates.inject(:gcd)


N, X = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
dists = (x + [X]).sort.each_cons(2).map do |a, b|
  b - a
end

ans = dists[0]
1.upto(dists.size - 1) do |i|
  ans = ans.gcd(dists[i])
end

puts ans


n,x=gets.chomp.split(" ").map(&:to_i)
d=gets.chomp.split(" ").map(&:to_i).map{|a|(a-x).abs}.sort
ans=0
max_d=d.min
stop=false
@yaku_arr=[]
def yaku(num)
  n=1
  while n**2<num do
    if num%n==0 then
      @yaku_arr.push(n,num/n)
    end
    n+=1
  end
  return @yaku_arr.sort.reverse
end
a=yaku(max_d)

k=1
while !stop do
  for i in 0..(n-1) do
    stop=true
    if d[i]%max_d!=0 then
      stop=false
      break
    end
  end
  if !stop then
    max_d=a[k]
    k+=1
  end
end
p max_d


n,x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort!

if x < a[0]
puts (a[0] - x).abs
	elsif x > a[a.length-1]
puts (x - a[a.length-1]).abs
	else
for i in 0..a.length-1
	if x < a[i]
   puts [(a[i] - x).abs,(x - a[i-1]).abs].min
   break
	end
end
end


def divisor_list(num)
  devisors = []
  2.upto(num/2) do |i|
    devisors << i if num%i == 0
  end
  devisors << num
  return devisors
end

N, X = gets.chomp.split(" ").map(&:to_i)
points = gets.chomp.split(" ").map(&:to_i)

abs_dis = []
points.each do |point|
  abs_dis.push( (point-X).abs )
end

div_list = divisor_list(abs_dis.min)
div_list.sort.reverse.each do |div|
  if abs_dis.count{|item| item % div !=0 } == 0 then
    print("#{div}")
    break
  end
end


_, x = gets.split.map(&:to_i)
cities = gets.split.map(&:to_i).push(x).sort

loop do
  min = cities.min
  cities = (cities.size-1).times.map { |i| cities[i+1] - cities[i] }.sort
  cities += min
  cities.uniq!

  break if cities.size == 1
end

puts cities[0]


def gcd(s, t)
  gcd(t, s) if t > s
  return t if (r = s % t).zero?
  gcd(t, r)
end

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

a = []
a << (X-x[0]).abs

(N-1).times do |i|
	a << (x[i].to_i-x[i+1].to_i).abs
end

g = a[0]

(N-1).times do |i|
	g = gcd(g, a[i+1])
end

puts g


_, x = gets.split.map(&:to_i)
cities = gets.split.map(&:to_i).push(x).sort

loop do
  cities = (cities.size-1).times.map { |i| cities[i+1] - cities[i] }.sort.uniq

  break if cities.size == 1

  if cities.include?(1)
    cities = [1]
    break
  end
end

puts cities[0]


module ArrayRefinement
  refine Array do
    # 配列に対する最小公倍数
    def lcm
      self.inject(:lcm)
    end

    # 配列に対する最大公約数
    def gcd
      self.inject(:gcd)
    end
  end
end

using ArrayRefinement

def main

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

  nums = gets.split.map do |s|
    i = s.to_i
    i - x
  end

  puts nums.gcd.abs
end

if __FILE__ == $0
  main
end


lines = $stdin.read
array = lines.split("\n")
N,X = array[0].split(" ").map(&:to_i)
x = [X].concat(array[1].split(" ").map(&:to_i)).sort

INF = 10**9
ans = INF
x.each_cons(2) do |next_to|
  diff = next_to.last - next_to.first
  ans = [ans, diff].min
end

puts ans


Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
d, n = gets_i_list

if d == 0
  puts n
elsif d == 1
  if n == 100
    puts n
  else
    puts n * 100
  end
else
  if n == 100
    puts n * 100
  else
    puts n * 100 * 100
  end
end


D, N = gets.split.map(&:to_i)
puts 100 ** D * N


d,n = gets.split.map(&:to_i)
start = 100**d
if n != 100
  puts start * n
else
  puts start * 101
end


d, n = gets.chomp.split(" ").map(&:to_i);

a = (100 ** d) * n

print("#{a}")


d, n = gets.chop.split.map(&:to_i)
if n == 100 then n = 101
  if d == 0
    puts n
  elsif d == 1
    puts n * 100
  end
elsif
  puts 100 ** d * n
end


D,N = gets.strip.split(' ').map(&:to_i)
if D == 0
    puts N-1
    elsif D == 1
    puts N*100
    else
    puts N*10000
end


nums = gets.chomp.split(" ").map(&:to_i)
one = nums[0]
two = nums[1]
if != 100
  if one == 0
    p two
  elsif one == 1
    p two * 100
  elsif one == 2
    p two * 10000
  end
else
    if one == 0
    p two + 1
  elsif one == 1
    p two * 101
  elsif one == 2
    p two * 10100
  end
end


D, N = gets.strip.split.map(&:to_i)
puts (D ** 10) * N


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

if n==100
  puts 101*(100**d)
else
  puts n*(100**d)
end


D, N = gets.chomp.split(" ").map(&:to_i)

puts (100**D)*N


x,n = gets.chomp.split(" ").map(&:to_i)
if n == 100 then
  n+= 1
end
y = 0
y = ((100 ** x) * n).to_s
puts y


d,n=gets.split.map(&:to_i)
if n==100
  puts n*(100*d)+1
else
  puts n*(100**d)
end


d,n = gets.chomp.split.map(&:to_i)
if d == 0
    if n == 100
        puts 101
    else
        puts n
    end
else
    puts 100**d*n
end


input = gets
input = input.strip.split(' ')
d = input[0].to_i
n = input[1].to_i

b = 100
if d == 0
  puts n
  return
end
while d-1 != 0
  b*=100
  d = d - 1
end
puts b * n


d, n = gets.split.map(&:to_i)
if n != 100
puts (100**d)*n
else
puts (100**d)*(n+1)
end


a=gets.to_i
b=gets.to_i
c=gets.to_i
x=gets.to_i

cnt=0

(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
    #500*i+100*j+50*k==x ? cnt+=1 : cnt
    cnt+=1 if 500*i+100*j+50*k==x
        end
    end
end
puts cnt

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


# 500 100 50 x

a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0

(a+1).times do |a_i|
  x_temp = x
  x_temp -= 500 * a_i
  break if x_temp < 0
  if x_temp == 0
    count += 1
    next
  end
  (b+1).times do |b_i|
    x_temp = x
    x_temp -= 500 * a_i
    x_temp -= 100 * b_i
    break if x_temp < 0
    if x_temp == 0
      count += 1
      next
    end
    (c+1).times do |c_i|
      x_temp = x
      x_temp -= 500 * a_i
      x_temp -= 100 * b_i
      x_temp -= 50 * c_i
      break if x_temp < 0
      if x_temp == 0
        count += 1
        next
      end
    end
  end
end

puts count


a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
ans = 0

0.upto(a) do |ai|
	0.upto(b) do |bi|
		0.upto(c) do |ci|
			ans += 1 if (ai * 500)+(bi * 100)+(ci * 50) == x
		end
	end
end

puts ans


a, b, c, x = `dd`.split.map &:to_i
r = 0
for i in 0..a
  for j in 0..b
    for k in 0..c
      r += 1 if x == 500*i + 100*j + 50*k
    end
  end
end
p r


A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

ans = 0

(A+1).times do |i|
  (B+1).times do |j|
    (C+1).times do |k|
      if (i * 500 + j * 100 + k * 50 == X) then
        ans += 1
      end
    end
  end
end

puts ans


require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

ans = 0
(a+1).times do |i|
  (b+1).times do |j|
    (c+1).times do |k|
      ans+=1 if i * 500 + j * 100 + k * 50 == x
    end
  end
end

puts ans


a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      if x == (500 * i) + (100 * j) + (50 * k)
        count += 1
      end
    end
  end
end

puts count


a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

ans = 0

(0..a).each do |i|
  (0..b).each do |j|
    r = x - ( 500 * i + 100 * j )
    break if r < 0
    ans += 1 if (r / 50 <= c and r % 50 == 0)
  end
end

puts ans


a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

ans = 0
(0..a).to_a.each do |ai|
  (0..b).to_a.each do |bi|
    (0..c).to_a.each do |ci|
      ans += 1 if 500*ai + 100*bi + 50*ci == x
    end
  end
end

puts ans


A = gets.strip.to_i + 1
B = gets.strip.to_i + 1
C = gets.strip.to_i + 1
X = gets.strip.to_i
count = 0

A.times do |i|
  B.times do |j|
    C.times do |k|
      count += 1 if 500*i + 100*j + 50*k == X
    end
  end
end

puts count


a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

cnt = 0

for i in 0..a do
  for j in 0..b do
    for k in 0..c do
      if x == 500 * i + 100 * j + 50 * k
        cnt += 1
      end
    end
  end
end

puts cnt


A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
X = gets.chomp.to_i

count = 0
(A+1).times do |a|
  (B+1).times do |b|
    (C+1).times do |c|
      if (500 * a) + (100 * b) + (50 * c) == X
        count += 1
      end
    end
  end
end

p count


# coin500 = gets.chomp.to_i
# coin100 = gets.chomp.to_i
# coin50 = gets.chomp.to_i
# pay = gets.chomp.to_i
answer = 0
0.upto(coin500 + 1) do |i|
  pay500 = 500 * i
  0.upto(coin100 + 1) do |j|
    pay100 = 100 * j
    0.upto(coin50 + 1) do |k|
      pay50 = 50 * k
      if pay == pay500 + pay100 + pay50
        answer += 1
      end
    end
  end
end
print answer


a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
x=gets.chomp.to_i
z=0
for n in 0..a do
  for m in 0..b do
    for l in 0..c do
      if n*500+m*100+l*50==x then
        z+=1
      end
    end
  end
end
puts z


a, b, c, x = 4.times.map { gets.to_i }
count = 0
(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
            count += 1 if i * 500 + j * 100 + k * 50 == x
        end
    end
end

puts count


a, b, c, x = 4.times.map { gets.to_i }
cnt = 0
(0.a).each do |i|
  (0.b).each do |j|
   (0.c).each do |k|
     if x == 500 * i + 100 * j + 50 * k
       cnt = cnt.cucc
     end
   end
  end
end


a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i

sum = 0
for i in 0..a do
    for j in 0..b do
        for k in 0..c do
            sum += 1 if 500*i+100*j+50*k==d
        end
    end
end
print sum
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i

sum = 0
for i in 0..a do
    for j in 0..b do
        for k in 0..c do
            sum += 1 if 500*i+100*j+50*k==d
        end
    end
end
print sum


def isExactPay( a, b, c, amount)
  500*a + 100*b + 50*c == amount && a + b + c <=50
end

a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
way_num = 0
a.times do |num_500|
  b.times do |num_100|
    c.times do |num_50|
      way_num += 1 if isExactPay(num_500, num_100, num_50, x)
    end
  end
end
print("#{way_num}")


a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
ans = 0
for i in 0..a
	for j in 0..b
		for k in 0..c
			if 500 * i + 100 * j + 50 * k == x
				ans += 1
			end
		end
	end
end
puts ans


a,b,c,d= readlines.map(&:to_i)
cnt = 0
 (0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      cnt += 1 if d == 500 * i + 100 * j + 50 * k
   end
  end
end
puts cnt


a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
count = 0

([x/500, a].min + 1).times do |i|
  r = x - 500 * i

  ([r/100, b].min + 1).times do |j|
    if (r - 100 * j)/50 <= c
      count += 1
    end
  end
end

puts count


fh = gets.to_i
oh = gets.to_i
ft = gets.to_i
total = gets.to_i

count = 0
while fh >= 0
#  puts "#{fh} 0 0"
  sub_total = 500*fh

  if sub_total > total
    fh -= 1
    next
  end
  if sub_total == total
    count += 1
    fh -= 1
    next
  end

  oh_tmp = oh
  while oh_tmp >= 0
    #puts "#{fh} #{oh_tmp} 0"
    sub_total = 500*fh + 100*oh_tmp

    if sub_total > total
      oh_tmp -= 1
      next
    elsif sub_total == total
      oh_tmp -= 1
      count += 1
      next
    end

    ft_tmp = ft
    while ft_tmp > 0
      #puts "#{fh} #{oh_tmp} #{ft_tmp}"
      sub_total = 500*fh + 100*oh_tmp + 50*ft_tmp
      ft_tmp -= 1
      if sub_total == total
        count += 1
      elsif sub_total < total
        break
      end
    end
    oh_tmp -= 1

  end

  fh -= 1
end

puts count


a,b,c,x = 4.times.map{gets.to_i}
count = 0
for i in 0..a
  for j in 0..b
    for k in 0..c
      if 500*i + 100*j + 50*k == x
        count += 1
      end
    end
  end
end
puts count


a = gets.to_i # 指定された入力値を受け取る。
b = gets.to_i # 指定された入力値を受け取る。
# 上記他記述例：a,b = gets.chomp.split.map(&:to_i);

if a * b % 2 == 0 # if文を使ってa×bが2で割り切れるかどうかを判定。
  puts "Even"
else
  puts "Odd"
end

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


a, b = gets.split.map(&:to_i)
puts a * b % 2 == 0 ? 'Even' : 'Odd'


# gets.split.map(&:to_i)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
a, b = gets.split.map(&:to_i)
puts a * b % 2 == 0 ? 'Even' : 'Odd'


a, b = gets.split.map &:to_i
if (a*b).even?
  puts :Even
else
  puts :Odd
end


def my_func(int1, int2)
  calculate = int1 * int2
  if calculate % 2 === 0
    return "Even"
  else
    return "Odd"
  end
end

p my_func(3, 5)


arr = gets.split(' ')
if (arr[0].to_i * arr[1].to_i) % 2 == 0
  'Even'
else
  'Odd'
end


a, b = gets.split.map(&:to_i)
puts (a * b).odd? ? 'Odd' : "Even"


a b = gets.split.map(&:to_i)
puts (a * b).odd? ? "Odd" : "Even"


a,b = gets.chomp.split(" ").map(&:to_i);
puts (a * b).even? ? "Even" : "Odd"


sum = gets.split.map(&:to_i).inject(:*)
puts sum.odd? ? 'Odd' : 'Even'


a,b = gets.strip.split.map(&:to_i)

a * b % 2 == 1 ? 'Odd' : 'Even'


a, b = gets.strip.split.map(&:to_i)
puts (a * b).odd? ? 'Odd' : 'Even'


input = gets.chomp.split.map!(&:to_i)
if (input[0]*input[1])%2 == 1 then
  puts "Odd"
else
  puts "Even"
end


a, b = gets.chomp.split(" ").map(&:to_i);

if (a * b) % 2 == 0
  puts "Even"
else
  puts "Odd"
end


puts gets.split.map(&:to_i).inject {|a,b| a * b}.even? ? 'Even' : 'Odd'


def checker(a, b)

  product = a * b

  if product % 2 == 0
    puts "Even"
  else
    puts "Odd"
  end
end


b,c=gets.chomp.split(" ").map(&:to_i)
int = b*c
if int % 2 == 0
  puts "Even"
else
  puts "Odd
end


(a,b)=STDIN.read.split
puts ((a.to_i*b.to_i)%2==0) ? 'even' : 'odd'


a,b = gets.chomp.split(" ").map(&:to_i)
if (a*b).divmod(2)[1] == 0
  print('Even')
else
  print('Odd')
end


a,b = gets.split.map(&:to_i)
puts (a*b).even? ? 'Even':'Odd'


a, b = gets.split(" ").map{&:to_i}
if ab%2 == 0
  puts Even
else
  puts Odd
end


a, b = gets.split.map(&:to_i)
puts (a * b % 2 == 1) ? "Odd" : "Even"


number1=a
number2=b
number3=a*b
if number3%2==0
  print(even)
end
else
print(odd)
end


a, b = gets.chomp.split.map(&:to_i)
print (a * b) % 2 == 0 ? "Even\n" : "Odd \n"


puts gets.split(' ').map{|n| n.to_i}.any?{|n| n.even?} ? 'Even' : 'Odd'


a, b = gets.strip.split.map(&:to_i)
puts (a*b).odd? ? "Odd" : "Even"


a, b = gets.chop.split.map(&:to_i)

if ( a * b) % 2 == 0
  puts 'Even'
else
  puts 'Odd'
end


a,b=gets.split.map(&:to_i)
puts a*b.odd? ? "Odd" : "Even"


a, b = gets.chomp.split.map(&:to_i)
puts a*b.odd? ? "Odd" : "Even"


a, b = gets.chomp.split.map(&:to_i)
mul = a * b
p mul.odd? ? "Odd" : "Even"


a,b = gets.chomp.split(" ").map(&:to_i)
if a * b / 2 == 0
puts "Even"
else
puts "Odd"
end


a,b = gets.chomp.split(" ").map(&:to_i)

if (a * b) % 2 == 1 then
  puts 'Odd'
else
  puts 'Even'
end


a, b = getsa, b = gets.split(" ")
result = a * b
print("#{result.odd? ? Odd : Even}")


a,b = gets.chomp.split(" ").map(&:to_i)
if a * b % 2 == 0
    puts 'Even'
elsif a * b % 2 == 1
    puts 'Odd'
end


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

if (a * b).odd?
    puts "Odd"
else
    puts "Even"
end


a,b=gets.split.map(&:to_i)
if a%2==0||b%2==0 then
  puts("Even")
else
  puts("Odd")
end


# input
a,b=gets.chomp.split(" ").map(&:to_i);

# odd_or_even?
def odd_or_even?(a, b)
  timed_val = a * b

  if timed_val % 2 == 0
    'Even'
  else
    'Odd'
  end
end

# output
print("#{odd_or_even?(a, b)}\n")


a,b = get.chomp.sprit(" ")

if (a.to_i * b.to_i ).even?
  puts "Even"
else
  puts "Odd"
end


a, b = gets.chomp.split(" ").map(&:to_i)

c = a*b

if c%2 == 0
    print("Even")
else
    print("0dd")
end


a, b = gets.chomp.split(" ").map(&:to_i)

if a*b%2 == 0
    print("Even\n")
else
    print("0dd\n")
end


a,b = gets.chomp.split(" ").map(&:to_i)
ans = (a*b)/2
if ans.even?
  puts "Even"
else
  puts "Odd"
end


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

if (a*b) % 2 == 0

    puts 'Even'

else

    puts 'Odd'

end


def product(a,b)
    if (a*b).modulo(2).zero?
        "Even"
    else
        "Odd"
    end
end
puts product(gets.to_i, gets.to_i)