Under construction

Still being built. Things may change

Metro 2345

Time limit1sMemory limit512 MB

Summary
Given three metro lines meeting at three transfer stations with per-line edge times and a transfer cost, find the shortest travel time between two given stations.
Level

Medium4 of 10

Topics
Shortest path, Graph, Math, Implementation
Solved
No attempts yet

Problem

Kekopolis has three metro lines. They intersect near the city center, forming a triangle of three tunnels between adjacent stations. The first line has xx stations, the second line has yy stations, and the third line has zz stations. Stations on each line are numbered consecutively starting from 11.

At stations where the lines intersect, passengers can change between lines. It is possible to change between station aa of the first line and station b+1b+1 of the second line, between station a+1a+1 of the first line and station cc of the third line, and between station bb of the second line and station c+1c+1 of the third line.

The lines have different train speeds. The train on the first line travels between adjacent stations in t1t_1 seconds, the train on the second line does it in t2t_2 seconds, and the train on the third line does it in t3t_3 seconds. It takes dd seconds to change between lines. Ignore the time to enter or leave a station or a train, and the time a train stops at a station.

Dima needs to get to the Kekopolis Programming Contest. He starts from his home near station ii of the kk-th line and needs to reach Kekopolis University near station jj of the ll-th line. Dima overslept as usual, so he is running late. Dima wants to reach his destination as soon as possible.

Find the minimum time Dima needs to get from his home to the university. Dima does not enter or exit the metro at an interchange station.

Input

The first line of input contains three integers xx, yy, and zz (2≤x,y,z≤1092 \le x, y, z \le 10^9).

The second line contains three integers aa, bb, and cc (1≤a<x1 \le a < x, 1≤b<y1 \le b < y, 1≤c<z1 \le c < z).

The third line contains four integers t1t_1, t2t_2, t3t_3, and dd (1≤t1,t2,t3,d≤1091 \le t_1, t_2, t_3, d \le 10^9).

The fourth line contains four integers kk, ii, ll, and jj (1≤k,l≤31 \le k, l \le 3; it is guaranteed that the kk-th line has station ii and the ll-th line has station jj; the starting station is different from the destination station, and in particular they are not the two stations of the same interchange).

Output

Output one integer: the minimum time needed to travel from the starting station to the destination station.

Examples3

  1. Example 1

    Input
    4 4 4
    2 2 2
    1 1 1 1
    1 1 2 1
    
    Expected output
    4
    
  2. Example 2

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

    Input
    4 4 4
    2 2 2
    1 1 1 1
    1 1 1 4
    
    Expected output
    3