# 50168. Subway

## I'm a slow walker, but I never walk backwards.

Write a program to calculate the distance between two subway stations. The subway system has three lines, R line, G line, and B line, each has at least 3 stations. All stations in a line are indexed from 1. For example, the R line has 6 stations, R1, R2, … R6, as in the following figure. Also G line connects R line and B line. For example in the following figure G1 is also R3, and G5 is also B2.

Subway
We will be given all the distance between two adjacent stations. Please write a function stationDistance to calculate the total distance between any two given stations. The prototype of the function $stationDistance$ will be given by stationDistance.h as follows.

int stationDistance(int R_distance[],int G_distance[],int B_distance[],int G_origin,int G_destination,int startStation[],int endStation[]);


The distance between two adjacent stations is given by three integer arrays, R_distance, G_distance and B_distance. For example, R_distance[0] is the distance between R1 and R2. All these arrays end with 0. G_origin is the index of the station of R line at the intersection of R and G lines. For example, G_origin = 3 means R3 is G1. Similarly G_destination is the index of the station of B line at the intersection of G and B lines. startStation and endStation are the two stations you need to calculate the distance between. Each of these two is an array containing two integers. The first element of the two arrays could be 0, 1 or 2, representing R, G or B lines. The second element is the station index of that line.

You can use the following main.c to test your function:

#include <stdio.h>#include "stationDistance.h"#define MAXN 10000 int main(int argc, char const *argv[]){    int R_distance[MAXN]={0};    int G_distance[MAXN]={0};    int B_distance[MAXN]={0};    int G_origin,G_destination;    int startStation[2],endStation[2];     int Rindex,Gindex,Bindex;    Rindex =0;     while(scanf("%d",&R_distance[Rindex])){        if( R_distance[Rindex]==0){            break;        }        Rindex++;    }    Gindex=0;    while(scanf("%d",&G_distance[Gindex])){        if( G_distance[Gindex]==0){            break;        }        Gindex++;    }        Bindex=0;    while(scanf("%d",&B_distance[Bindex])){        if( B_distance[Bindex]==0)            break;        Bindex++;    }    scanf("%d%d",&G_origin,&G_destination);    scanf("%d%d",&startStation[0],&startStation[1]);    scanf("%d%d",&endStation[0],&endStation[1]);    int distanceSum =stationDistance(R_distance,G_distance,B_distance,G_origin,G_destination,startStation,endStation);    printf("%d\n",distanceSum );}


## Input Format (for main.c)

The first three lines have the distance between two adjacent stations for R,G and B lines. The last number of these three lines should be 0. The fourth line has two numbers $a, b$ . $a$ is the index of the station on R at the intersection of R and G lines. $b$ is the index of the station on B at the intersection of B and G lines. The following two lines have the two stations between which we want to calculate the distance. Each line contains two numbers $X, Y$. $X$ could be 0,1 or 2, and it represents R,G or B line. $Y$ is the station index of the line.

## Output Format

All of the distance are integer. The return value of the function is integer.

## Sample Input 0

1 2 3 04 5 6 07 8 9 10 11 12 02 30 12 5


## Sample Ouput 0

35


## Sample Input 1

1 2 3 04 5 6 07 8 9 10 11 12 02 30 10 3


## Sample Ouput 1

3


## Sample Input 2

1 2 3 04 5 6 07 8 9 10 11 12 02 31 30 3


## Sample Ouput 2

11