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 Rust (1.15.1) (judge verdict: Accepted)

// ternary operation
#[allow(unused_macros)]
macro_rules! _if {
  ($_test:expr, $_then:expr, $_else:expr) => {
    if $_test { $_then } else { $_else }
  };
  ($_test:expr, $_pat:pat, $_then:expr, $_else:expr) => {
    match $_test {
      $_pat => $_then,
      _     => $_else
    }
  };
}

use std::io::{ stdin, stdout, BufWriter, Write, BufReader };

fn abc103_b() {
  let stdin = stdin();
  let mut reader = my::ByteReader::with_capacity(104, BufReader::new(stdin.lock()));

  let stdout = stdout();
  let mut writer = BufWriter::new(stdout.lock());

  let s = reader.read_string_until_lf();
  let t = reader.read_string_until_lf();
  let t = t.clone() + &t;

  if t.contains(&s) {
    writer.write(b"Yes\n").unwrap();
    writer.flush().unwrap();
    return;
  }

  writer.write(b"No\n").unwrap();
  writer.flush().unwrap();
}

fn main() {
  abc103_b();
}

//------------------------------------------------------------------------
mod my {

  #[derive(Debug)]
  pub struct Range<T> {
    x: T,
    y: T,
  }

  impl<T> Range<T>
    where T: PartialOrd +
             Copy +
             Debug
  {
    #[allow(dead_code)]
    pub fn new(x: T, y: T) -> Self {
      let mut p = Range {
        x: x,
        y: y,
      };
      if x > y {
        p.x = y;
        p.y = x;
      }
      p
    }

    #[allow(dead_code)]
    pub fn intersection(&self, other: &Self) -> Option<Self> {
      if self.x >= other.y || self.y <= other.x {
        return None;
      }

      let mut p = Range {
        x: self.x,
        y: self.y,
      };

      if self.x <= other.x {
        p.x = other.x;
      }
      if self.y >= other.y {
        p.y = other.y;
      }

      Some(p)
    }
  } // impl<T> Range<T>

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  pub fn rotate_right(vec: &mut Vec<u8>) {
    if vec.len() <= 1 {
      return;
    }

    let tmp = vec[vec.len() - 1];
    let mut i = vec.len() as i32 - 2;
    while i >= 0 {
      let x = i as usize;
      vec[x + 1] = vec[x];
      i -= 1;
    }
    vec[0] = tmp;
  }

  //----------------------------------------------------------------------
  #[allow(dead_code)]
  pub fn to_ascii_lowercase(mut b: u8) -> u8 {
    if b >= b'A' && b <= b'Z' {
      b += 0x20;
    }
    b
  }

  #[allow(dead_code)]
  pub fn to_ascii_uppercase(mut b: u8) -> u8 {
    if b >= b'a' && b <= b'z' {
      b -= 0x20;
    }
    b
  }

  #[allow(dead_code)]
  pub fn is_ascii_alphabetic(b: u8) -> bool {
    if b >= b'A' && b <= b'A' || b >= b'a' && b <= b'z' {
      return true;
    }
    false
  }

  //----------------------------------------------------------------------
  macro_rules! pub_fn_Int2Byte_from_ty {
    (uint, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      pub fn $name(&mut self, mut i: $_type) -> &[u8] {
        self.buf.clear();
        if i == 0 {
          self.buf.push(b'0');
          return self.buf.as_slice();
        }

        while i > 0 {
          self.buf.push((i % 10) as u8 + b'0');
          i /= 10;
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};

    (int, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      pub fn $name(&mut self, mut i: $_type) -> &[u8] {
        self.buf.clear();
        if i == 0 {
          self.buf.push(b'0');
          return self.buf.as_slice();
        }

        let mut negative = false;
        if i.is_negative() {
          negative = true;
          i = i.abs();
        }

        while i > 0 {
          self.buf.push((i % 10) as u8 + b'0');
          i /= 10;
        }
        if negative {
          self.buf.push(b'-');
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};
  }

  #[derive(Debug)]
  pub struct Int2Byte {
    buf: Vec<u8>,
  }

  impl Int2Byte {
    #[allow(dead_code)]
    pub fn new() -> Self {
      Int2Byte {
        buf: Vec::new(),
      }
    }

    #[allow(dead_code)]
    pub fn with_capacity(capa: usize) -> Self {
      Int2Byte {
        buf: Vec::with_capacity(capa),
      }
    }

    pub_fn_Int2Byte_from_ty!(
      uint,
      from_usize => usize,
      from_u8    => u8,
      from_u16   => u16,
      from_u32   => u32,
      from_u64   => u64
    );

    pub_fn_Int2Byte_from_ty!(
      int,
      from_isize => isize,
      from_i8    => i8,
      from_i16   => i16,
      from_i32   => i32,
      from_i64   => i64
    );
  } // impl Int2Byte

  //----------------------------------------------------------------------
  use std::io::{ BufRead, BufWriter, Write };
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul, Neg, Rem };
  use std::str::{ self, FromStr };

  #[allow(dead_code)]
  pub fn gcd<T>(x: T, y: T) -> T
    where T: Rem<Output=T> +
             Default +
             PartialEq +
             Copy +
             Debug
  {
    _if!(y == T::default(),
      x,
      gcd(y, x % y))
  }

  pub trait WriteWithDelim {
    fn write_delim(&mut self, buf: &[u8], delim: &[u8]) -> usize;
    fn write_sp(&mut self, buf: &[u8]) -> usize;
    fn write_lf(&mut self, buf: &[u8]) -> usize;
  }

  impl<W> WriteWithDelim for BufWriter<W>
    where W: Write
  {
    #[allow(dead_code)]
    fn write_delim(&mut self, buf: &[u8], delim: &[u8]) -> usize
    {
      self.write(buf).unwrap() +
      self.write(delim).unwrap()
    }

    #[allow(dead_code)]
    fn write_sp(&mut self, buf: &[u8]) -> usize
    {
      self.write_delim(buf, b" ")
    }

    #[allow(dead_code)]
    fn write_lf(&mut self, buf: &[u8]) -> usize
    {
      self.write_delim(buf, b"\n")
    }
  } // impl<W> WriteWithDelim for BufWriter<W>

  //----------------------------------------------------------------------
  const SP: u8 = b' ';
  const LF: u8 = b'\n';

  #[allow(dead_code)]
  #[derive(Debug)]
  pub enum Direction {
    Horizontal,
    Vertical
  }

  #[derive(Debug)]
  pub struct ByteReader<R> {
    reader: R,
    buf   : Vec<u8>,
  }

  impl<R> ByteReader<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    pub fn new(reader: R) -> Self {
      ByteReader {
        reader: reader,
        buf   : Vec::new(),
      }
    }

    #[allow(dead_code)]
    pub fn with_capacity(capa: usize, reader: R) -> Self {
      ByteReader {
        reader: reader,
        buf   : Vec::with_capacity(capa),
      }
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_1byte(&mut self) -> Option<u8> {
      self.buf.resize(1, 0);
      _if!(self.reader.read(&mut self.buf).unwrap() != 0,
        Some(self.buf[0]),
        None)
    }

    //--------------------------------------------------------------------
    fn read_until(&mut self, delim: u8) -> usize {
      self.buf.clear();
      self.reader.read_until(delim, &mut self.buf).unwrap()
    }

    #[allow(dead_code)]
    pub fn read_until_lf(&mut self) -> &[u8] {
      self.read_until(LF);
      self.buf.as_slice()
    }

    #[allow(dead_code)]
    pub fn read_until_sp(&mut self) -> &[u8] {
      self.read_until(SP);
      self.buf.as_slice()
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_until_lf_clone(&mut self) -> Vec<u8> {
      self.read_until(LF);
      let len = self.buf.len() - 1;
      if self.buf[len] == LF {
        self.buf.truncate(len);
      }
      self.buf.clone()
    }

    #[allow(dead_code)]
    pub fn read_string_until_lf(&mut self) -> String {
      unsafe { String::from_utf8_unchecked(self.read_until_lf_clone()) }
    }

    //--------------------------------------------------------------------
    fn parse_int<T>(&self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.buf.len();
      let mut i = 0;
      let mut n = T::default();
      let mut minus = false;

      if self.buf[i] == b'-' {
        minus = true;
        i += 1;
      } else if self.buf[i] == b'+' {
        i += 1;
      }

      while i < len && b'0' <= self.buf[i] && self.buf[i] <= b'9' {
        n = (n * T::from(10)) + T::from(self.buf[i] - b'0');
        i += 1;
      }

      _if!(minus,
        n.neg(),
        n)
    }

    fn parse_uint<T>(&self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.buf.len();
      let mut i = 0;
      let mut n = T::default();

      if self.buf[i] == b'+' {
        i += 1;
      }

      while i < len && b'0' <= self.buf[i] && self.buf[i] <= b'9' {
        n = (n * T::from(10)) + T::from(self.buf[i] - b'0');
        i += 1;
      }
      n
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_int_until_delim<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      self.parse_int()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_lf<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_sp<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(SP)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_uint_until_delim<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      self.parse_uint()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_uint_until_lf<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_uint_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_uint_until_sp<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_uint_until_delim(SP)
    }

    //--------------------------------------------------------------------

    fn from_utf8_unchecked(&mut self) -> &str {
      unsafe { str::from_utf8_unchecked(&self.buf) }
    }

    fn parse_tok<T>(&mut self) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.from_utf8_unchecked()
        .trim()
        .parse()
        .unwrap()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn parse_until_delim<T>(&mut self, delim: u8) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.read_until(delim);
      self.parse_tok()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn parse_until_lf<T>(&mut self) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.parse_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn parse_until_sp<T>(&mut self) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.parse_until_delim(SP)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_int_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.read_int_until_delim(delim));
      }
      vec.push(self.read_int_until_delim(LF));
      vec
    }

    #[allow(dead_code)]
    pub fn read_uint_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.read_uint_until_delim(delim));
      }
      vec.push(self.read_uint_until_delim(LF));
      vec
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    pub fn read_int_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.read_uint_until_lf();
      self.read_int_vec(n, Direction::Horizontal)
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    pub fn read_uint_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.read_uint_until_lf();
      self.read_uint_vec(n, Direction::Horizontal)
    }

    #[allow(dead_code)]
    pub fn read_uint_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.read_uint_vec(m, Direction::Horizontal));
      }
      vec
    }

    #[allow(dead_code)]
    pub fn read_int_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.read_int_vec(m, Direction::Horizontal));
      }
      vec
    }

  } // impl<R> ByteReader<R>

} // mod my