Modular Taxi

시간 제한2초메모리 제한2048 MB

요약
일직선 위 도시들의 인구가 주어질 때, s번 도시에서 f번 도시로 가는 최소 횟수의 모듈로 택시 이동 경로를 구해 출력하거나 Impossible을 출력한다.
난이도

보통10점 중 7점

유형
그래프, BFS, 수학, 구현
정답자
아직 제출이 없습니다

문제

Longlandia is a very long country. All of its nn cities are located along a line segment. If we enumerate them from the beginning to the end of the segment, the ii-th city has a_ia\_i inhabitants.

You need to get from city ss to city ff. For this purpose, an infinite number of taxis called Kaban-2, Kaban-3, Kaban-4, Kaban-5, ... operate in Longlandia. A taxi named Kaban-mm can take you from city ii to city jj if the numbers of inhabitants in all cities from ii to jj inclusive are congruent modulo mm. Formally, for any integer kk such that min⁡i,j≤k≤max⁡i,j\min\\{i, j\\} \le k \le \max\\{i, j\\}, the relation a_k≡a_i(modm)a\_k \equiv a\_i \pmod m must hold.

Find the smallest number QQ of taxi calls required to get from city ss to city ff, and output QQ lines describing the route. If it is impossible to reach the destination by taxi, output "Impossible".

입력

The first line contains an integer nn: the number of cities in Longlandia (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n: the population of each city (1≤a_i≤1091 \le a\_i \le 10^9).

The third line contains two integers ss and ff: the starting and finishing city numbers (1≤s,f≤n1 \le s, f \le n; s≠fs \ne f).

출력

Let QQ be the smallest number of taxi calls required to get from city ss to city ff. Output QQ lines of the form "Kaban-$m_i$ $s_i$ $f_i$", indicating that the ii-th trip will be made by taxi Kaban-m_im\_i and will take you from city s_is\_i to city f_if\_i (1≤s_i,f_i≤n1 \le s\_i, f\_i \le n; 2≤m_i≤1092 \le m\_i \le 10^9). The following equalities must hold: s_1=ss\_1 = s; f_Q=ff\_Q = f; s_i+1=f_is\_{i + 1} = f\_i. And, of course, taxi Kaban-m_im\_i must be able to take you from city s_is\_i to city f_if\_i.

If it is impossible to reach from ss to ff with any number of taxi calls, output the word "Impossible".

Letter case does not matter, so you can output, for example, "kaBAN" and "IMPossiBle".

예제3

  1. 예제 1

    입력
    6
    1 2 3 4 5 6
    5 3
    
    예상 출력
    Impossible
    
  2. 예제 2

    입력
    8
    1 16 20 20 20 23 7 8
    1 7
    
    예상 출력
    Kaban-5 1 2
    Kaban-4 2 5
    Kaban-3 5 6
    Kaban-8 6 7
    
  3. 예제 3

    입력
    11
    55 55 55 55 55 55 55 55 55 55 55
    7 2
    
    예상 출력
    kaBAn-239239239 7 2