class Yukicoder def initialize n, m = gets.chomp.split.map(&:to_i) s = gets.chomp t = gets.chomp dp = Array.new(n+1){ Array.new(m+1, [n,m].max)} n.times do |y| dp[y][0] = y end m.times do |x| dp[0][x] = x end 1.upto(n) do |i| 1.upto(m) do |j| if s[i-1] == t[j-1] dp[i][j] = [dp[i][j], dp[i-1][j-1]].min else dp[i][j] = [dp[i][j], dp[i-1][j-1]+1].min end dp[i][j] = [dp[i][j], dp[i-1][j]+1, dp[i][j-1]+1].min end end p dp[n][m] end end Yukicoder.new