AlgoUniversity
  • Go Back
Discussion
Divisible Strings :

Author

Shikhar Mehrotra

Difficulty Level : Easy

Submissions : 559

Asked In : Flipkart

Marks :10

: 8 | : 0

For two strings $$$S$$$ and $$$T$$$, we say "T divides S" if and only if $$$S$$$ = $$$T$$$ + ... + $$$T$$$ (i.e., $$$T$$$ is concatenated with itself one or more times).

Given two strings $$$str1$$$ and $$$str2$$$, return the largest string $$$x$$$ such that $$$x$$$ divides both $$$str1$$$ and $$$str2$$$.

Input

The first line of input consists of string $$$str1$$$ of $$$10^{4}\le size \le 10^{4}$$$ and consisting of uppercase latin letters only

The second line of input consists of string $$$str2$$$ of $$$10^{4}\le size \le 10^{4}$$$ and consisting of uppercase latin letters only

Output

Output $$$x$$$ as described in the statement and if the answer does not exist you can output empty string.

Examples

Input
ABCABC
ABC
Output
ABC
Input
ABABAB
ABAB
Output
AB
Input
ABHCHDBHC
AJBDHBCH
Output

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.