Stepping Through Time Given a 24 hour time, e.g. 20:48, output the nearest time where each adjacent pair of digits has an absolute difference of 1, e.g. 21:01.

That is, each number in the output must differ from the numbers next to it by 1, and the output must be the closest time, forwards or backwards, for which this is true. Time can be considered to wrap around. For example, 23:55 and 00:05 are only 10 minutes apart.

Input


Input can be in any reasonable form which represents all four digits of a 24 hour time. E.x. a string, "20:48" (colon optional), a list of integers, [2, 0, 4, 8], or a single integer 2048.
Leading zeros are optional for input. Use whatever is most convenient.
You can assume the input will always represent a valid 24 hour time.


Output


You must output four integers which represent a valid 24 hour time. The individual integers can be represented in whatever form is most convenient. E.x. [2, 1, 0, 1] or "2101".
Leading zeros are not optional for output. E.x. you can't output 1:23 instead of 01:23.
You may optionally output a separator between the hours and minutes. This can be a colon, period, space, newline, or some other junk that saves you a byte. Whatever separator you choose, it must be consistent from one output to another.
If there are two equally close times to the input which satisfy the requirements, you may output either.
Note there are only 16 possible outputs: 01:01, 01:21, 01:23, 10:10, 10:12, 12:10, 12:12, 12:32, 12:34, 21:01, 21:21, 21:23, 23:21, 23:23, 23:43, and 23:45.


Test cases


00:10 -> 23:45
01:23 -> 01:23
05:46 -> 01:23
05:47 -> 10:10
12:00 -> 12:10
16:47 -> 12:34
16:48 -> 21:01
20:48 -> 21:01
21:22 -> 21:23 or 21:21


Python 3 reference implementation.

Score

This is code golf, so the shortest program in bytes wins. The standard loopholes are forbidden.
JavaScript (ES7),  136  132 bytes
Takes a single integer as input and returns a string.
s=&gt;(V=g=(d,t=s,k=0)=&gt;k&gt;V?R:[...S=([1e3]+t).slice(-4)].some(p=c=&gt;(p-(p=c))**2-1)?g(d,t=(t-~d)%2400,k+=t%100&lt;60):(V=k,R=S))()&amp;&amp;g(2398)

Try it online!
How?
The only valid hour prefixes are 01, 10, 12, 21 and 23. It means that any invalid minute count starting with a digit greater than 5 will be rejected by the test on the absolute difference between two consecutive digits.
So there's no need to explicitly handle the wrapping of minutes modulo 60. Instead, we can just make sure that the distance k is not incremented on invalid minutes:
k += t % 100 &lt; 60


JavaScript (Node.js),  148  146 bytes
Takes a single integer as input and returns a string.
This version picks the answer from a hardcoded table.
t=&gt;0x60553BCD48A3CE4F56D818FDC473FC726398E907D3A9n.toString(6).substr([22,85,9,423,462,x=98,x,9,9,413,461,9,x,x,9,9].findIndex(d=&gt;(t-=d+2)&lt;0)*4,4)

Try it online!
How?
Once converted to base-6, the integer 0x60553BCD48A3CE4F56D818FDC473FC726398E907D3A9n is turned into the following string, which holds all possible valid answers:
&quot;23450101012101231010101212101212123212342101212121232321232323432345&quot;

The correct answer is selected according to the interval in which the input time falls:
 answer | input interval
--------+----------------
 &quot;2345&quot; | 00:00 - 00:23
 &quot;0101&quot; | 00:24 - 01:10
 &quot;0121&quot; | 01:11 - 01:21
 &quot;0123&quot; | 01:22 - 05:46
 &quot;1010&quot; | 05:47 - 10:10
 &quot;1012&quot; | 10:11 - 11:10
 &quot;1210&quot; | 11:11 - 12:10
 &quot;1212&quot; | 12:11 - 12:21
 &quot;1232&quot; | 12:22 - 12:32
 &quot;1234&quot; | 12:33 - 16:47
 &quot;2101&quot; | 16:48 - 21:10
 &quot;2121&quot; | 21:11 - 21:21
 &quot;2123&quot; | 21:22 - 22:21
 &quot;2321&quot; | 22:22 - 23:21
 &quot;2323&quot; | 23:22 - 23:32
 &quot;2343&quot; | 23:33 - 23:43
 &quot;2345&quot; | 23:44 - 23:59

The lengths of the intervals in minutes (minus 2) are stored in an array.