Problem:
Score : 200 points

Problem Statement

You are given string S and T consisting of lowercase English letters.

Determine if S equals T after rotation.

That is, determine if S equals T after the following operation is performed some number of times:

Operation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.

Here, |X| denotes the length of the string X.

Constraints

2 \leq |S| \leq 100

|S| = |T|

S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S equals T after rotation, print Yes; if it does not, print No.

Sample Input 1

kyoto
tokyo

Sample Output 1

Yes

In the first operation, kyoto becomes okyot.

In the second operation, okyot becomes tokyo.

Sample Input 2

abc
arc

Sample Output 2

No

abc does not equal arc after any number of operations.

Sample Input 3

aaaaaaaaaaaaaaab
aaaaaaaaaaaaaaab

Sample Output 3

Yes

Solution in JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

"use strict"
const YES = 'Yes'
const NO = 'No'
Object.entries = function (object) {
  return Object.keys(object).map(key => [key, object[key]])
}
const countChars = str =>
  Object.entries(str.split('')
    .reduce((c, curr, i) => {
      c[curr] = c[curr] || []
      c[curr].push(i)
      return c
    }, {})
  ).sort((a,b) => a[1].length - b[1].length || a[0].charCodeAt()-b[0].charCodeAt())

    
;(stdin => {
  const input = stdin.split('\n')
  const S = input[0]
  const T = input[1]
  if (S === T) return console.log(YES);
  const charsS = countChars(S)
  const charsT = countChars(T)
  if (charsS.length !== charsT.length) return console.log(NO)
  const startS = charsS.splice(0, 1)[0]
  const startT = charsT.splice(0, 1)[0]
  const startCharS = startS[0]
  const startCharT = startT[0]
  const startIndexesS = startS[1]
  const startIndexesT = startT[1]
  if (startCharS !== startCharT) return console.log(NO)
  if (startIndexesS.length !== startIndexesT.length) return console.log(NO)
  const rotations = []
  const len = S.length
  for (const iS of startIndexesS) {
    for (const iT of startIndexesT) {
      const gap = (iT - iS + len) % len
      if (rotations.indexOf(gap) !== -1) continue;
      rotations.push(gap)
    }
  }
  
  for (let i = 0; i<charsS.length; i++) {
    const charS = charsS[i][0]
    const indexesS = charsS[i][1]
    const charT = charsT[i][0]
    const indexesT = charsT[i][1]
    if (charS !== charT) return console.log(NO)
    if (indexesS.length !== indexesT.length) return console.log(NO)
    for (const iS of indexesS) {
      for (let i=0; i<rotations.length; i++) {
        const rotated = (iS + rotations[i]) % len
        if (indexesT.indexOf(rotated) !== -1) continue;
        rotations.splice(i--, 1)
      }
      if (!rotations.length) return console.log(NO, '6')
    }
  }
  console.log(YES)
})(require('fs').readFileSync('/dev/stdin', 'utf-8'))