Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Ring

Write a program which finds a pattern $p$ in a ring shaped text $s$.

Input

In the first line, the text $s$ is given.

In the second line, the pattern $p$ is given.

Output

If $p$ is in $s$, print Yes in a line, otherwise No.

Constraints

$1 \leq $ length of $p \leq $ length of $s \leq 100$

$s$ and $p$ consists of lower-case letters

Sample Input 1

vanceknowledgetoad
advance

Sample Output 1

Yes

Sample Input 2

vanceknowledgetoad
advanced

Sample Output 2

No

Solution in Ruby (judge verdict: Runtime Error)

str1 = STDIN.gets.chomp
str2 = STDIN.gets.chomp

def check_others(str1, str2, index)
  # puts "str1 = #{str1}"
  # puts "str2 = #{str2}"
  flag = true
  str1 = str1 + str1
  for i in 0..str2.length - 1 do
    # puts str1[14]
    # p "i = #{i}, index = #{index}, str2[i] = #{str2[i]}, str1[i + index] = #{str1[i + index]}"
    if str2[i] != str1[i + index] then
      flag = false
      break
    end
  end
  return flag
end

substr1 = str1
# puts substr1
output = "No"
index = 0
while true
  if index == nil then break end
  index += substr1.index(str2.chr) + 1
  # p "index = #{index}"
  if index != nil then
    if check_others(str1, str2, index) then
      output = "Yes"
      break
    end
    substr1 = substr1[index + 1, str1.length]
    if substr1 == nil then break end
    # p substr1
  else
    break
  end
end

puts output