Under construction

Still being built. Things may change

Least Common Divisor

Interview

Time limit2sMemory limit512 MB

Summary
Given two short strings, find the shortest string that divides both, meaning it repeats a whole number of times to form each, or report that none exists.
Level

Medium4 of 10

Topics
String, Math, Number theory, Brute force
Solved
No attempts yet

Problem

A divisor of string AA is a string DD that can be repeated an integer number of times to obtain AA. For example, the divisors of the string "aaaa" are "a", "aa", and "aaaa", and the divisors of the string "ababab" are "ab" and "ababab".

Given two strings SS and TT, find the shortest string that is both a divisor of SS and a divisor of TT, or determine that no such string exists.

Input

The first line contains the string SS, and the second line contains the string TT. Each string has length between 1 and 50 characters, inclusive, and consists only of lowercase English letters.

Output

Print the least common divisor of the strings SS and TT, or the string "No solution" if the least common divisor does not exist.

Examples3

  1. Example 1

    Input
    abab
    ababab
    
    Expected output
    ab
    
  2. Example 2

    Input
    aaaa
    aaaa
    
    Expected output
    a
    
  3. Example 3

    Input
    abc
    de
    
    Expected output
    No solution