This page is still under construction.

Parts of this page are still being built. What you see may change.

Infinite string

Interview

Time limit2sMemory limit512 MB

Summary
Given two strings of length at most 50, decide whether each repeated infinitely produces the same infinite string.
Level

Medium4 of 10

Topics
String, String matching
Solved
No attempts yet

Problem

For a string ss, define f(s)f(s) as the string obtained by concatenating ss infinitely many times. For example, if ss is abc, then f(s)f(s) is abcabcabcabc....

Two different strings ss and tt can still give the same f(s)f(s) and f(t)f(t). If ss is abc and tt is abcabc, then f(s)f(s) and f(t)f(t) are the same string.

Given ss and tt, write a program that decides whether f(s)f(s) and f(t)f(t) are the same string.

Input

The first line contains ss and the second line contains tt. The length of each string is a positive integer at most 5050, and both strings consist of lowercase letters only.

Output

Print 11 on the first line if f(s)f(s) and f(t)f(t) are the same, and 00 otherwise.

Examples2

  1. Example 1

    Input
    ab
    abab
    
    Expected output
    1
    
  2. Example 2

    Input
    abc
    bca
    
    Expected output
    0