Under construction

Still being built. Things may change

Super Bus

Time limit1.5sMemory limit512 MB

Summary
Find the shortest travel time from stop 1 to stop N, where a road can be used only when the sum of its two endpoints' disaster codes is prime.
Level

Medium5 of 10

Topics
Shortest path, Graph, Number theory
Solved
No attempts yet

Problem

Bo-seon, who is visiting Jinju, boards a bus to reach the Jinyangho Observatory, which she reserved in advance. She arrives at a nearby bus stop, but the bus information display shows no arrivals at all. Confused, she checks around until a message arrives from Jun-hee, a college classmate.

How does it taste?

Jun-hee sent it. In college, Jun-hee was a risotto fan who had to eat gukbap every day because of Bo-seon, a gukbap fanatic, and has held a grudge ever since. When Jun-hee learned that Bo-seon was visiting Jinju, Jun-hee used hacking skills to break into the bus information system and stop city buses from running.

Jinju treated the hacked bus system as a disaster and started running Super Bus. To keep Super Bus running smoothly, all other means of transportation were banned.

Jinju has NN bus stops numbered from 1 in order. There are MM bidirectional roads, each joining two different bus stops, with a fixed travel time on Super Bus. Two bus stops may be joined by two or more roads. Each bus stop has a disaster code, a positive integer at most 5 000 0005\,000\,000. Super Bus only runs on a road between two bus stops when the sum of their disaster codes is a prime. Here, a prime is an integer of at least 2 whose only divisors are 1 and itself.

Bo-seon starts at stop 1, and the Jinyangho Observatory is at stop NN. The stops are far apart, so Super Bus is the only way to travel. Bo-seon can board any Super Bus as soon as she arrives at a stop, and boarding or alighting takes no time. Find the shortest time for Bo-seon to reach stop NN.

Input

The first line contains the number of bus stops NN and the number of bidirectional roads MM, separated by a space. (2≤N≤400 0002 \le N \le 400\,000; 1≤M≤1 000 0001 \le M \le 1\,000\,000)

The second line contains the disaster codes D1,…,DND_1, \dots, D_N of the bus stops, separated by spaces. (1≤Di≤5 000 0001 \le D_i \le 5\,000\,000)

From the third line onward, the next MM lines each contain uiu_i, viv_i, and wiw_i, separated by spaces. This describes the ii-th bidirectional road, which joins stop uiu_i and stop viv_i and takes wiw_i time to travel on Super Bus. (1≤ui<vi≤N1 \le u_i < v_i \le N; 1≤wi≤400 0001 \le w_i \le 400\,000)

All input numbers are integers.

Output

On the first line, print the shortest time to reach the Jinyangho Observatory. If it cannot be reached, print Now where are you?.

Hint

Python 3 users are advised to submit with PyPy3.

Examples2

  1. Example 1

    Input
    5 5
    1 1 5 1 1
    1 2 2
    1 3 1
    2 4 2
    3 5 1
    4 5 2
    
    Expected output
    6
    
  2. Example 2

    Input
    5 5
    1 1 5 5 1
    1 2 2
    1 3 1
    2 4 2
    3 5 1
    4 5 2
    
    Expected output
    Now where are you?