Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Tanjiro’s Training With Kanao

By AK_74u · Limits 1s, 256 MB

After the fight in the Natagumo Mountain, Tanjiro felt the need to get sharper. Because in recent fights he has been missing the opening threads which shortens the fight by allowing him to defeat an opponent in one blow through that opening thread. While staying in the Butterfly Mansion, Tanjiro gets help from the residents of the mansion to improve his ability to find an opening thread as soon as possible.

As he spars with one of the residents of Butterfly Mansion, Kanao, the three servants of the mansion are tasked with monitoring the sparring of Tanjiro and Kanao. One of the trio watches Tanjiro, one watches Kanao and the last one compiles the observations of the first two and takes it to Shinobu, host of the mansion.

What Shinobu gets is two arrays of integers, AA and BB, of length mm and nn. The first one is the fighting strategy of Kanao and the second is Tanjiro’s. Shinobu observes the observations and if she finds some(at least one) non-negative xx and dd, such that for every i(0i<m)i(0 \leq i < m), A[i]A[i] being the ii-th element of AA and B[x+i×d]B[x+i \times d] being the (x+i×d)(x+i \times d)-th element of BB, A[i]B[x+i×d]A[i] - B[x+i \times d], stays the same, she will be ensured that Tanjiro found at least one opening. After that Shinobu will stop the sparring session and tell Tanjiro, “I can see you're working very hard.”, if Tanjiro found an opening, “Please do all that you can.”, otherwise, You have to tell what Shinobu will say to Tanjiro, based on the observation of the observations by the trio.


The first line of input contains mm and nn. Second-line contains mm integers, denoting the fighting strategy array of Kanao, AA and the third line contains nn integers, denoting the fighting strategy array of Tanjiro, BB.

1mn1001 \leq m \leq n \leq 100

The array elements will be positive and within 10910^{9}


You have to output a single line, what Shinobu will say to Tanjiro (without quotes), based on the observation.


6 13
4 23 6 5 7 9
12 1 6 2 25 6 8 12 7 7 9 10 11
I can see you're working very hard.

In the first case, if we take x=2x=2 and d=2d=2 and for every i(0i<m)i(0 \leq i < m), we get the following elements of array BB by taking all the (x+i×d)(x+i \times d)-th element: 6,25,8,7,9,11{6, 25, 8, 7, 9, 11}.

And the elements of array AA are: 4,23,6,5,7,9{4, 23, 6, 5, 7, 9}.

So here we can see that, (46)=(2325)=(68)=(57)=(79)=(911)(4-6)=(23-25)=(6-8)=(5-7)=(7-9)=(9-11).

So, we can say that an opening exists.

4 10
7 1 9 8
1 2 3 4 5 6 7 8 9 10
Please do all that you can.

No such xx and dd are found where for every i(0i<m)i(0 \leq i < m), A[i]B[x+i×d]A[i] - B[x+i \times d], stays the same.



    100% Solution Ratio

    alamkhanEarliest, 4d ago

    IU_SpiralForgeFastest, 0.0s

    alamkhanLightest, 33 kB

    IU_SpiralForgeShortest, 1262B


    Login to submit


    If read carefully, the problem is very clear and straightforward. You are given two arrays, you have...