ADITYA13 - FizzBuzz Happy 2013

Having cleared the ACM ICPC online round you receive a job offer of teaching JAVA programming to High School Students of Byteland. You gladly take the job offer and after a few days of teaching you give the students a program to write. You ask them to write a FIZZBUZZ program. They are either too smart or too lazy. They argue that it is too difficult and challenge you to do better than that without using any English letters. You consult senior programmer Mitch who suggests you a way out of the problem. "Do it in BF," he says. Tjandra suggests you do it in Whitespace.

Input

Two space separated one digit integers A and B. Then a newline. Then a string C of maximum length 5 followed by a newline. Then another string D of max length 5 followed by a newline. It is guaranteed that gcd(A,B) < A and gcd(A,B) < B. Also the strings comprise only alphanumeric characters.

Output

For all numbers in the set [1, 99] print C if the number is divisible by A, print D if divisible by B, print C concat D if divisible by both and the number (with preceding zeroes if required) if it divisible by neither A nor B.

Example

Input:
2 3
Happy
2013

Output:
01
Happy
2013
Happy
05
Happy2013
07
..........and you get the idea

Wishing all of you a HAPPY NEW YEAR 2013 :)

Edit: 05-01-2013 I am giving you all a link to mostafa_36a2's solution. You would be pleased... Download the encrypted text solution


Added by:Aditya Pande
Date:2013-01-01
Time limit:1s-5.116s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:BF WHITESPACE
Resource:Own

hide comments
2014-06-09 00:14:53 Smithers
I thought it was about time someone followed Tjandra's advice, so after finishing my brainfuck solution, I spent most of a day learning Whitespace so I could use it.
Then I combined the two solutions in a polyglot for submission because that's so easy to do with Whitespace.
Happy 2013 to all of you... er, forget that, happy whenever!
2013-01-07 15:16:21 Mostafa 36a2
oh thank you very much!! :)
2013-01-05 09:14:01 Aditya Pande
Link to Mostafa's solution posted under problem description.....
:)
2013-01-05 09:14:01 Mostafa 36a2
@Aditya Pande : its just a brain rest after brainf***## :D
you are welcome ;)
2013-01-05 09:14:01 Aditya Pande
@mostafa:
no wonder the ASCII art took you so long...
:)
2013-01-05 09:14:01 Mostafa 36a2
Nice Problem .. Enjoy 6 hours solving :D
thanks ..
hope to be a really happy new year for Syria :(
2013-01-05 09:14:01 (Tjandra Satria Gunawan)(曾毅昆)
@Aditya Pande: Thanks, that's not my fastest algo, but still got AC in 0.00s even in pyramid cluster ;-)
2013-01-05 09:14:01 Aditya Pande
Imho, About the cluster, I don't want anybody to get TLE. It is already hard to implement it correctly and a correct implementation should be Accepted regardless of efficiency...
:)

There is a way out
Changing the cluster and increasing the time limit...

Last edit: 2013-01-02 04:20:11
2013-01-05 09:14:01 Francky
Why not Python3 is allowed ???
(just kidding)
Happy new year 2013.
2013-01-05 09:14:01 Mitch Schwartz
Haha, thanks for letting me cameo in your problem, took me exactly 2 hours in BF too. I visit 16+|C|+|D| cells, not the fewest possible, but a pretty clean implementation. Glad I'm not the one who suggested Whitespace :P. Happy2013.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.