Problem:
E - すごろく
友達のいないきつねのボブは，今日は一人ですごろく遊びをして過ごすことにした．
各面に整数
a_1,a_2,a_3,a_4,a_5,a_6
が書かれた6面ダイスと，駒と，直線上にM個のマスがあり
左から順に
1
から
M
までの番号が割り当てられたすごろく盤を用いることにした．
すごろく盤の各マスには指示が数字で書かれており，
i
番目のマスには数字
N_i
が書かれている．
これは，その値が正なら右，負なら左に，その絶対値だけ駒を移動せよという意味である．
すなわち，
i+N_i
番目のマスに駒を移動せよという意味である．
ボブは，以下のようにしてすごろく遊びをする．まず駒をスタート地点に置く．
次にサイコロを振り，サイコロが出た目の数を見て，駒を「現在のマスから右に移動する」か
「左に移動する」か「現在のマスに留まる」かを選択することができる．
マスから移動する場合は，サイコロの出目の距離だけ駒を移動して，移動した先のマスの指示に従う．
指示に従って移動した先のマスの指示には従わない．
以後，ボブは上記のようにサイコロを振って駒を移動することを繰り返す．
移動した結果すごろく盤の外に駒が出てしまったらボブの負けであり，誤答(
Wrong Answer
)と判定される．
この問題の目的はこのすごろくをゴールすることである．サイコロを振る回数は3000回以下とする．
入出力形式
入力は以下の形式で与えられる．
M
a_1
a_2
a_3
a_4
a_5
a_6
s
g
N_1
...
N_M
M
はすごろく盤のマスの数である．
a_1
...
a_6
はサイコロの各面に書かれている整数の値である．
s
と
g
はそれぞれすごろく盤のスタートとゴールの番号である．
N_i
は
i
番目のマスに書かれている指示である．
これらの入力の後，
さいころを振った結果を表す値
dice
が改行とともに引き続いて入力から与えられる．
これは，サイコロを振って出た目が
a
dice
であることを表す．
これに対して，あなたのプログラムは駒を進めるかどうかを決め，その選択を出力しなければならない．駒を右に移動するならば
1
を，左に移動するならば
-1
を，現在のマスに留まるならば
0
を出力せよ．出力の後には改行を出力せよ．
あなたのプログラムが進むか戻るか留まるかを出力すると，次のサイコロを振った結果を入力から受け取ることができる．これを繰り返す．
例えばC/C++では
scanf("%d", &dice);
としてサイコロの面の番号を受け取り，これに対して左に移動するなら
printf("-1\n"); fflush(stdout);
とする．次に，
scanf("%d", &dice);
とすると，次のサイコロの面の番号を受け取ることが出来る．すごろくにゴールしたら直ちにプログラムを終了せよ．
ゴールに辿り着くまでにサイコロを振る回数は3000回以下でなければならない．
サイコロを振った回数が途中で3000回を超えた場合，誤答と判定される．
制約
2 ≤ M ≤ 300
1 ≤ s ≤ M, 1 ≤ g ≤ M
s \neq g
1 ≤ a_i ≤ M-1
1 ≤ dice ≤ 6
N_s = N_g = 0
マスの命令に従って駒を進めて枠外に出る事はない．
dice
は
\{1,2,…,6\}
から擬似乱数で一様ランダムに選ばれる．
いくらサイコロを振ったとしてもゴールできない盤面は与えられない．
入力の値は全て整数である．
入出力例1
すごろくの説明
プログラムの出力
プログラムへの入力
サイコロの目
駒の移動後のマスの番号
10
1 6 2 5 3 4
1 10
0 -1 3 -1 3 -2 -6 -5 -7 0
1回目のサイコロ
1
1
1回目のプログラムの出力
0
1
2回目のサイコロ
3
2
2回目のプログラムの出力
1
6
3回目のサイコロ
5
3
3回目のプログラムの出力
0
6
4回目のサイコロ
1
1
4回目のプログラムの出力
-1
8
5回目のサイコロ
3
2
5回目のプログラムの出力
1
10

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
using namespace std;
const int MAX_T = 3000, MAX_M = 300;
int M, start, goal, dice[6];
vector<int> N, path(MAX_M, MAX_T + 1), visit(MAX_M, false);
bool isPositionValid(int p) { return 0 <= p && p < M; }
void MakePath(int from) {
  visit[from] = true;
  int bestpath = MAX_T;
  if (from == goal)
    bestpath = 0;
  else {
    for (int r = 0; r < 6; r++) {
      int moveto = from + dice[r];
      if (isPositionValid(moveto) && !visit[moveto]) {
        MakePath(moveto);
        bestpath = min(bestpath, path[moveto] + 1);
      }
      moveto = from - dice[r];
      if (isPositionValid(moveto) && !visit[moveto]) {
        MakePath(moveto);
        bestpath = min(bestpath, path[moveto] + 1);
      }
    }
  }
  path[from] = bestpath;
}
int main() {
  cin >> M;
  for (int r = 0; r < 6; r++)
    cin >> dice[r];
  cin >> start >> goal;
  start--, goal--;
  N.resize(M);
  for (int m = 0; m < M; m++)
    cin >> N[m];
  MakePath(start);
  int position = start;
  for (int t = 0; t < MAX_T; t++) {
    if (position == goal)
      break;
    int r;
    cin >> r;
    int d = dice[r - 1];
    int output;
    if (isPositionValid(position + d) && path[position] > path[position + d + N[position + d]]) {
      position = position + d + N[position + d];
      output = 1;
    }
    else if (isPositionValid(position - d) && path[position] > path[position - d + N[position - d]]) {
      position = position - d + N[position - d];
      output = -1;
    }
    else
      output = 0;
    cout << output << endl;
  }
  return 0;
}
accuracy: 0.18181818181818182
time_ms: 10
memory_kb: 3440
final_rank: 15

code_snippet: #include <iostream>
using namespace std;
const int MAX_T = 3000, MAX_M = 300;
int M, start, goal, dice[6], N[MAX_M], path[MAX_M];

bool isPositionValid(int p) {
  return 0 <= p && p < M;
}

void MakePath() {
  for (int m = 0; m < M; m++) {
    path[m] = MAX_T + 1;
  }
  path[goal] = 0;

  for (int i = 0; i < M; i++) {
    for (int r = 0; r < 6; r++) {
      int moveto = i + dice[r];
      if (isPositionValid(moveto)) {
        int position = moveto + N[moveto];
        path[i] = min(path[i], path[position] + 1);
      }
      moveto = i - dice[r];
      if (isPositionValid(moveto)) {
        int position = moveto + N[moveto];
        path[i] = min(path[i], path[position] + 1);
      }
    }
  }
}

int main() {
  cin >> M;
  for (int r = 0; r < 6; r++) {
    cin >> dice[r];
  }
  cin >> start >> goal;
  start--, goal--;
  for (int m = 0; m < M; m++) {
    cin >> N[m];
  }
  MakePath();
  int position = start;
  for (int t = 0; t < MAX_T; t++) {
    if (position == goal) {
      break;
    }
    int r;
    cin >> r;
    int d = dice[r - 1];
    int moveto = position + d;
    if (isPositionValid(moveto) && path[position] > path[moveto + N[moveto]]) {
      position = moveto + N[moveto];
      cout << 1 << endl;
    } else {
      moveto = position - d;
      if (isPositionValid(moveto) && path[position] > path[moveto + N[moveto]]) {
        position = moveto + N[moveto];
        cout << -1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
  return 0;
}
accuracy: 0.41818181818181815
time_ms: 10
memory_kb: 3528
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
using namespace std;

const int MAX_T = 3000, MAX_M = 300;
int M, start, goal, dice[6];
vector<int> N;
bool isPositionValid(int p) { return 0 <= p && p < M; }

void MakePath(vector<int> &path, int from) {
  static bool visit[MAX_M] = {};
  static auto checkPath = [&path](int moveto) -> int {
    if (!isPositionValid(moveto))
      return 2 * MAX_T;
    else {
      int position = moveto + N[moveto];
      if (!visit[position])
        MakePath(path, position);
      return path[position] + 1;
    }
  };
  
  if (path.empty()) {
    path.resize(M, MAX_T + 1);
  }
  
  visit[from] = true;
  int bestpath = MAX_T;
  if (from == goal)
    bestpath = 0;
  else {
    for (int r = 0; r < 6; r++) {
      int tempPath = checkPath(from + dice[r]);
      bestpath = min(bestpath, tempPath);
      bestpath = min(bestpath, tempPath);
    }
  }
  path[from] = bestpath;
}

int main() {
  cin >> M;
  for (int r = 0; r < 6; r++)
    cin >> dice[r];
  cin >> start >> goal;
  start--, goal--;
  N.resize(M);
  for (int m = 0; m < M; m++)
    cin >> N[m];
  vector<int> path;
  MakePath(path, start);
  int position = start;
  for (int t = 0; t < MAX_T; t++) {
    if (position == goal)
      break;
    int r;
    cin >> r;
    int d = dice[r - 1];
    static auto tryMove = [&path](int moveto, int path_before,
                                  int &position) -> bool {
      if (isPositionValid(moveto)) {
        if (path_before > path[moveto + N[moveto]]) {
          position = moveto + N[moveto];
          return true;
        }
      }
      return false;
    };
    int output;
    if (tryMove(position + d, path[position], position))
      output = 1;
    else if (tryMove(position - d, path[position], position))
      output = -1;
    else
      output = 0;
    cout << output << endl;
  }
  return 0;
}
accuracy: 0.18181818181818182
time_ms: 10
memory_kb: 3524
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_T = 3000;

vector<int> dice(6), N;
int M, start, goal;

bool isPositionValid(int p) { return 0 <= p && p < M; }

int MakePath(int from, vector<int>& path, vector<bool>& visit) {
    if(visit[from]) return path[from];
    visit[from] = true;
    int bestpath = MAX_T;
    if (from == goal)
        bestpath = 0;
    else {
        for (int r = 0; r < 6; r++) {
            int moveto = from + dice[r];
            if (isPositionValid(moveto))
                bestpath = min(bestpath, MakePath(moveto + N[moveto], path, visit) + 1);
            moveto = from - dice[r];
            if (isPositionValid(moveto))
                bestpath = min(bestpath, MakePath(moveto + N[moveto], path, visit) + 1);
        }
    }
    path[from] = bestpath;
    return bestpath;
}

int main() {
    cin >> M;
    for (int r = 0; r < 6; r++)
        cin >> dice[r];
    cin >> start >> goal;
    start--, goal--;

    N.resize(M);
    for (int m = 0; m < M; m++)
        cin >> N[m];

    vector<int> path(M, MAX_T);
    vector<bool> visit(M, false);
    MakePath(start, path, visit);

    int position = start;
    for (int t = 0; t < MAX_T; t++) {
        if (position == goal)
            break;
        int r;
        cin >> r;
        int d = dice[r - 1];
        auto tryMove = [&path](int moveto, int path_before, int &position) -> bool {
            if (isPositionValid(moveto)) {
                if (path_before > path[moveto + N[moveto]]) {
                    position = moveto + N[moveto];
                    return true;
                }
            }
            return false;
        };
        int output;
        if (tryMove(position + d, path[position], position))
            output = 1;
        else if (tryMove(position - d, path[position], position))
            output = -1;
        else
            output = 0;
        cout << output << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3544
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_T = 3000, MAX_M = 300;
int M, start, goal;
vector<int> dice(6), N, path(MAX_M, MAX_T + 1), visit(MAX_M, false);
bool isPositionValid(int p) { return 0 <= p && p < M; }
void MakePath(int from) {
  path[from] = (from == goal) ? 0 : MAX_T;
  visit[from] = true;
  for (int r = 0; r < 6; r++) {
    int moveto = from + dice[r];
    if (isPositionValid(moveto) && !visit[moveto]) {
      MakePath(moveto);
      path[from] = min(path[from], path[moveto] + 1);
    }
    moveto = from - dice[r];
    if (isPositionValid(moveto) && !visit[moveto]) {
      MakePath(moveto);
      path[from] = min(path[from], path[moveto] + 1);
    }
  }
}
int main() {
  cin >> M;
  for (int r = 0; r < 6; r++)
    cin >> dice[r];
  cin >> start >> goal;
  start--, goal--;
  N.resize(M);
  for (int m = 0; m < M; m++)
    cin >> N[m];
  MakePath(start);
  int position = start;
  for (int t = 0; t < MAX_T; t++) {
    if (position == goal)
      break;
    int r;
    cin >> r;
    int d = dice[r - 1];
    int output = 0;
    int moveto = position + d;
    if (isPositionValid(moveto) && path[position] > path[moveto + N[moveto]]) {
      position = moveto + N[moveto];
      output = 1;
    } else {
      moveto = position - d;
      if (isPositionValid(moveto) && path[position] > path[moveto + N[moveto]]) {
        position = moveto + N[moveto];
        output = -1;
      }
    }
    cout << output << endl;
  }
  return 0;
}
accuracy: 0.2
time_ms: 10
memory_kb: 3468
final_rank: 14

code_snippet: #include <iostream>
using namespace std;
const int MAX_T = 3000, MAX_M = 300;
int M, start, goal, dice[6], *N;
bool isPositionValid(int p) { return 0 <= p && p < M; }
int *MakePath(int *path, int from) {
  static bool visit[MAX_M] = {};
  static auto checkPath = [&path](int moveto) -> int {
    if (!isPositionValid(moveto))
      return 2 * MAX_T;
    else {
      int position = moveto + N[moveto];
      if (!visit[position])
        MakePath(path, position);
      return path[position] + 1;
    }
  };
  if (path == NULL) {
    path = new int[M];
    for (int m = 0; m < M; m++)
      path[m] = MAX_T + 1;
  }
  visit[from] = true;
  int bestpath = MAX_T;
  if (from == goal)
    bestpath = 0;
  else {
    for (int r = 0; r < 6; r++) {
      bestpath = min(bestpath, checkPath(from + dice[r]));
      bestpath = min(bestpath, checkPath(from - dice[r]));
    }
  }
  path[from] = bestpath;
  return path;
}
int main() {
  cin >> M;
  for (int r = 0; r < 6; r++)
    cin >> dice[r];
  cin >> start >> goal;
  start--, goal--;
  N = new int[M];
  for (int m = 0; m < M; m++)
    cin >> N[m];
  int *path = MakePath(NULL, start);
  int position = start;
  for (int t = 0; t < MAX_T; t++) {
    if (position == goal)
      break;
    int r;
    cin >> r;
    int d = dice[r - 1];
    static auto tryMove = [&path](int moveto, int path_before,
                                  int &position) -> bool {
      if (isPositionValid(moveto)) {
        if (path_before > path[moveto + N[moveto]]) {
          position = moveto + N[moveto];
          return true;
        }
      }
      return false;
    };
    int output;
    if (tryMove(position + d, path[position], position))
      output = 1;
    else if (tryMove(position - d, path[position], position))
      output = -1;
    else
      output = 0;
    cout << output << endl;
  }
  delete[] N;
  delete[] path;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3576
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

const int MAX_T = 3000, MAX_M = 300;
int M, start, goal, dice[6], N[MAX_M], path[MAX_M];
bool visit[MAX_M];

bool isPositionValid(int p) { return 0 <= p && p < M; }

void MakePath() {
    for (int i = 0; i < M; i++) path[i] = MAX_T + 1;
    queue<int> q;
    q.push(goal);
    path[goal] = 0;
    while (!q.empty()) {
        int cur = q.front(); q.pop();
        if (visit[cur]) continue;
        visit[cur] = true;
        for (int r = 0; r < 6; r++) {
            int moveto = cur + dice[r];
            if (isPositionValid(moveto)) {
                int position = moveto + N[moveto];
                if (!visit[position] && path[position] > path[cur] + 1) {
                    path[position] = path[cur] + 1;
                    q.push(position);
                }
            }
            moveto = cur - dice[r];
            if (isPositionValid(moveto)) {
                int position = moveto + N[moveto];
                if (!visit[position] && path[position] > path[cur] + 1) {
                    path[position] = path[cur] + 1;
                    q.push(position);
                }
            }
        }
    }
}

int main() {
    cin >> M;
    for (int r = 0; r < 6; r++) cin >> dice[r];
    cin >> start >> goal;
    start--, goal--;
    for (int m = 0; m < M; m++) cin >> N[m];
    memset(visit, false, sizeof(visit));
    MakePath();
    int position = start;
    for (int t = 0; t < MAX_T; t++) {
        if (position == goal) break;
        int r; cin >> r;
        int d = dice[r - 1];
        int output;
        if (isPositionValid(position + d) && path[position + d + N[position + d]] < path[position + N[position]]) {
            position = position + d + N[position + d];
            output = 1;
        } else if (isPositionValid(position - d) && path[position - d + N[position - d]] < path[position + N[position]]) {
            position = position - d + N[position - d];
            output = -1;
        } else {
            output = 0;
        }
        cout << output << endl;
    }
    return 0;
}
accuracy: 0.03636363636363636
time_ms: 10
memory_kb: 3444
final_rank: 18

code_snippet: #include <iostream>
using namespace std;
const int MAX_T = 3000, MAX_M = 300;
int M, start, goal, dice[6], *N;
inline bool isPositionValid(int p) { return 0 <= p && p < M; }
int *MakePath(int *path, int from) {
  static bool visit[MAX_M] = {};
  static auto checkPath = [&path](int moveto) -> int {
    if (!isPositionValid(moveto))
      return 2 * MAX_T;
    else {
      int position = moveto + N[moveto];
      if (!visit[position])
        MakePath(path, position);
      return path[position] + 1;
    }
  };
  if (path == NULL) {
    path = new int[M];
    for (int m = 0; m < M; m++)
      path[m] = MAX_T + 1;
  }
  visit[from] = true;
  int bestpath = MAX_T;
  if (from == goal)
    bestpath = 0;
  else {
    for (int r = 0; r < 6; r++) {
      bestpath = min(bestpath, checkPath(from + dice[r]));
      bestpath = min(bestpath, checkPath(from - dice[r]));
    }
  }
  path[from] = bestpath;
  return path;
}
int main() {
  cin >> M;
  for (int r = 0; r < 6; r++)
    cin >> dice[r];
  cin >> start >> goal;
  start--, goal--;
  N = new int[M];
  for (int m = 0; m < M; m++)
    cin >> N[m];
  int *path = MakePath(NULL, start);
  int position = start;
  for (int t = 0; t < MAX_T; t++) {
    if (position == goal)
      break;
    int r;
    cin >> r;
    int d = dice[r - 1];
    static auto tryMove = [&path](int moveto, int path_before,
                                  int &position) -> bool {
      if (isPositionValid(moveto)) {
        if (path_before > path[moveto + N[moveto]]) {
          position = moveto + N[moveto];
          return true;
        }
      }
      return false;
    };
    int output;
    if (tryMove(position + d, path[position], position))
      output = 1;
    else if (tryMove(position - d, path[position], position))
      output = -1;
    else
      output = 0;
    cout << output << endl;
  }
  delete[] N;
  delete[] path;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3540
final_rank: 3

code_snippet: #include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
constexpr int limit = 3000;
template<typename T>
bool valid_index(const std::vector<T> &vec, const int index) {
	return 0 <= index && index < vec.size();
}
std::vector<std::vector<double>> estimated(const int s, const int g, const std::vector<int> &dice, const std::vector<int> &direction) {
	std::vector<std::vector<double>> result(direction.size(), std::vector<double>(limit + 1, 0));
	result[g][0] = 0;
	for (auto i = 1; i < result.size(); ++i) {
		result[(i + g) % result.size()][0] = limit;
	}
	for (auto i = 1; i <= limit; ++i) {
		for (auto pos = 0; pos < result.size(); ++pos) {
			double min = 0;
			for (const auto d : dice) {
				double temp = result[pos][i - 1] + 1;
				if (valid_index(direction, pos + d) && valid_index(result, pos + d + direction[pos + d])) {
					if (temp > result[pos + d + direction[pos + d]][i - 1]) {
						temp = result[pos + d + direction[pos + d]][i - 1];
					}
				}
				if (valid_index(direction, pos - d) && valid_index(result, pos - d + direction[pos - d])) {
					if (temp > result[pos - d + direction[pos - d]][i - 1]) {
						temp = result[pos - d + direction[pos - d]][i - 1];
					}
				}
				min += temp / dice.size();
			}
			result[pos][i] = min + 1;
		}
		result[g][i] = 0;
	}
	return result;
}
int main() {
	int m; std::cin >> m;
	std::vector<int> dice(6);
	for (auto &d : dice) std::cin >> d;
	int s, g; std::cin >> s >> g; --s; --g;
	std::vector<int> direction(m);
	for (auto &d : direction) std::cin >> d;
	auto est = estimated(s, g, dice, direction);
	auto current = s;
	int di;
	for (auto count = limit; count > 0; --count) {
		std::cin >> di;
		auto d = dice[di - 1];
		double temp = est[current][count];
		int next = current;
		int out = 0;
		if (valid_index(direction, current + d) && valid_index(est, current + d + direction[current + d])) {
			if (temp > est[current + d + direction[current + d]][count]) {
				temp = est[current + d + direction[current + d]][count];
				out = 1;
				next = current + d + direction[current + d];
			}
		}
		if (valid_index(direction, current - d) && valid_index(est, current - d + direction[current - d])) {
			if (temp > est[current - d + direction[current - d]][count]) {
				out = -1;
				next = current - d + direction[current - d];
			}
		}
		//std::cout << "from " << current << ", to " << next << ", dice " << d << ", direction " << direction[current + out * d] << std::endl;
		current = next;
		std::cout << out << std::endl;
		if (current == g) return 0;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 10016
final_rank: 10

code_snippet: #include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, S, G;
	cin >> N;
	vector<int> D(6), A(N);
	for (int i = 0; i < 6; ++i) cin >> D[i];
	cin >> S >> G; --S, --G;
	for (int i = 0; i < N; ++i) cin >> A[i];
	vector<vector<int> > g(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 6; ++j) {
			for (int k = -1; k <= 1; k += 2) {
				int nxt = i + D[j] * k;
				if (0 <= nxt && nxt < N) {
					nxt += A[nxt];
					g[nxt].push_back(i);
				}
			}
		}
	}
	queue<int> que; que.push(G);
	vector<int> dist(N, -1); dist[G] = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : g[u]) {
			if (dist[i] == -1) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	int cur = S;
	while (cur != G) {
		int dice;
		cin >> dice; --dice;
		int res = 0;
		for (int j = -1; j <= 1; j += 2) {
			int nxt = cur + D[dice] * j;
			if (0 <= nxt && nxt < N && dist[nxt + A[nxt]] < dist[cur]) {
				res = j;
			}
		}
		cout << res << endl;
		if (res != 0) {
			cur += D[dice] * res;
			cur += A[cur];
		}
	}
	return 0;
}
accuracy: 0.509090909090909
time_ms: 20
memory_kb: 3308
final_rank: 11

code_snippet: #include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, S, G;
	cin >> N;
	vector<int> D(6), A(N);
	for (int i = 0; i < 6; ++i) cin >> D[i];
	cin >> S >> G; --S, --G;
	for (int i = 0; i < N; ++i) cin >> A[i];
	queue<int> que; que.push(G);
	vector<int> dist(N, -1); dist[G] = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i = 0; i < 6; ++i) {
			for (int j = -1; j <= 1; j += 2) {
				int nxt = u + D[i] * j - A[u];
				if (0 <= nxt && nxt < N && dist[nxt] == -1) {
					dist[nxt] = dist[u] + 1;
					que.push(nxt);
				}
			}
		}
	}
	int cur = S;
	while (cur != G) {
		int dice;
		cin >> dice; --dice;
		int res = 0;
		for (int j = -1; j <= 1; j += 2) {
			int nxt = cur + D[dice] * j;
			if (0 <= nxt && nxt < N && dist[nxt + A[nxt]] < dist[cur]) {
				res = j;
			}
		}
		cout << res << endl;
		if (res != 0) {
			cur += D[dice] * res;
			cur += A[cur];
		}
	}
	return 0;
}
accuracy: 0.21818181818181817
time_ms: 20
memory_kb: 3308
final_rank: 13

code_snippet: #include<iostream>
#include<cstdio>

using namespace std;

int m,s,g;
int a[7],n[501];
int path[501][501];
int dist[501];
int main(void){
	scanf("%d",&m);
	for(int i=1;i<=6;i++)scanf("%d",&a[i]);
	scanf("%d%d",&s,&g);
	for(int i=1;i<=m;i++)scanf("%d",&n[i]);
	for(int i=1;i<=m;i++){
		dist[i]=5000000;
		for(int j=1;j<=m;j++)path[i][j]=5000000;
		path[i][i]=0;
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=6;j++){
			for(int k=-1;k<=1;k+=2){
				int np=i+a[j]*k;
				if(np<=0 || np>m)continue;
				np+=n[np];
				if(np<=0 || np>m)continue;
				path[i][np]=min(path[i][np],1);
			}
		}
	}
	for(int k=1;k<=m;k++){
		for(int i=1;i<=m;i++){
			for(int j=1;j<=m;j++){
				path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
			}
		}
	}
	int nn=s;
	while(nn!=g){
		int dis;
		scanf("%d",&dis);
		int best=0,goods=path[nn][g],nc=nn;
		for(int i=-1;i<=1;i+=2){
			int np=nn+a[dis]*i;
			if(np<=0 || np>m)continue;
			np+=n[np];
			if(np<=0 || np>m)continue;
			if(goods>path[np][g]){
				goods=path[np][g];
				best=i;
				nc=np;
			}
		}
		nn=nc;
		printf("%d\n",best);
		fflush(stdout);
	}
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3788
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define inf 1000000000
using namespace std;

int m, s, g;
map<int, int> mp;
//ダイスの目
int dice[7] = {0};
//ワープ位置
int wp[305] = {0};
// iでjを出した時に行く場所のメモ(0で正、1で負)
int memo[305][7][2] = {0};
//ゴールに行くまでの最短手数と、そのときのダイスの目
pair<int, int> process[305];
// iに行くためにいる必要がある場所と、そのときに振る必要があるダイスの目のペア
vector<pair<int, int>> v[305];
// process埋め
queue<int> qu;
//ダイクストラ 辺の重み、現在の場所
priority_queue<pair<int, int>, vector<pair<int, int>>,
               greater<pair<int, int>>>
    pq;

int makerand();

int main() {
  srand((int)time(0));
  int i, j, x, now = 0, y;
  cin >> m;
  for(i = 0; i <= m; ++i) process[i].first = inf;

  for(i = 1; i <= 6; ++i) {
    cin >> dice[i];
    ++mp[dice[i]];
  }
  cin >> s >> g;
  for(i = 1; i <= m; ++i) cin >> wp[i];
  for(i = 1; i <= m; ++i)
    for(j = 1; j <= 6; ++j) {
      if(i + dice[j] <= m) {
        memo[i][j][0] = i + dice[j] + wp[i + dice[j]];
        v[memo[i][j][0]].push_back(make_pair(i, j));
      }
      if(i - dice[j] >= 1) {
        memo[i][j][1] = i - dice[j] + wp[i - dice[j]];
        v[memo[i][j][1]].push_back(make_pair(i, -j));
      }
    }
  qu.push(g);
  process[g].first = 0;
  /*while(qu.size() > 0) {
    x = qu.front();
    if(x == s) break;
    qu.pop();
    for(i = 0; i < v[x].size(); ++i)
      if(process[v[x][i].first].first >
         process[x].first + 1) {
        process[v[x][i].first].first = process[x].first
  + 1; qu.push(v[x][i].first);
        process[v[x][i].first].second = v[x][i].second;
      }
  }*/
  pq.push(make_pair(0, g));
  while(pq.size() > 0) {
    pair<int, int> np;
    np = pq.top();
    pq.pop();
    x = np.second;
    for(i = 0; i < v[x].size(); ++i) {
      y = process[x].first +
          60 / mp[dice[max(v[x][i].second,
                           -v[x][i].second)]];
      if(process[v[x][i].first].first > y) {
        process[v[x][i].first].first = y;
        process[v[x][i].first].second = v[x][i].second;
        pq.push(make_pair(process[v[x][i].first].first,
                          v[x][i].first));
      }
    }
  }
  now = s;
  /*for(i = 1; i <= m; ++i)
    cout << process[i].first << " " << process[i].second
         << endl;*/
  while(now != g) {
    cin >> x;
    // x = makerand();
    // cout << "x:" << x << " ";
    if(dice[max(process[now].second,
                -process[now].second)] == dice[x]) {
      if(process[now].second > 0) {
        cout << 1 << endl;
        now = memo[now][x][0];
      }
      else {
        cout << -1 << endl;
        now = memo[now][x][1];
      }
    }
    else {
      cout << 0 << endl;
    }
  }
  return 0;
}

int makerand(){

	return 1 + rand() % 6;
}
accuracy: 1
time_ms: 10
memory_kb: 3308
final_rank: 2

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 301

int M;
int table[6];
int start,goal,command[NUM];
int min_dist[NUM],to_dist[NUM];

bool rangeCheck(int loc){
	if(loc >= 0 && loc <= M-1){
		return true;
	}else{
		return false;
	}
}

int recursive(int loc,int sum_dist){

	if(min_dist[loc] != -1){

		if(min_dist[loc] == BIG_NUM){
			return BIG_NUM;
		}else{
			return min_dist[loc]+sum_dist;
		}
	}

	int ret = BIG_NUM,next_loc = 0;

	for(int i = 0; i < 6; i++){

		//右方向
		next_loc = loc+table[i];
		if(rangeCheck(next_loc) == true){
			next_loc += command[next_loc];
			if(to_dist[next_loc] > sum_dist+1){
				to_dist[next_loc] = sum_dist+1;
				ret = min(ret,recursive(next_loc,sum_dist+1));
			}
		}
		//左方向
		next_loc = loc-table[i];
		if(rangeCheck(next_loc) == true){
			next_loc += command[next_loc];
			if(to_dist[next_loc] > sum_dist+1){
				to_dist[next_loc] = sum_dist+1;
				ret = min(ret,recursive(next_loc,sum_dist+1));
			}
		}
	}

	return ret;
}


int main(){

	scanf("%d",&M);

	for(int i = 0; i < 6; i++)scanf("%d",&table[i]);

	scanf("%d %d",&start,&goal);
	start--;
	goal--;

	for(int i = 0; i < M; i++){
		scanf("%d",&command[i]);
	}

	for(int i = 0; i < M; i++){
		min_dist[i] = -1;
	}
	min_dist[goal] = 0;

	for(int i = 0; i < M; i++){
		if(i == goal)continue;
		for(int k = 0; k < M; k++)to_dist[k] = BIG_NUM; //そこへたどり着くまでのコスト

		to_dist[i] = 0;

		min_dist[i] = recursive(i,0);
	}

	int current_loc = start,dice;
	int right_loc,left_loc,right_dist,left_dist;

	while(true){

		scanf("%d",&dice);
		dice--;

		if(!rangeCheck(current_loc+table[dice])){
			right_dist = BIG_NUM;
		}else{
			right_loc = current_loc+table[dice];
			right_loc += command[right_loc];
			right_dist = min_dist[right_loc];
		}

		if(!rangeCheck(current_loc-table[dice])){
			left_dist = BIG_NUM;
		}else{
			left_loc = current_loc-table[dice];
			left_loc += command[left_loc];
			left_dist = min_dist[left_loc];
		}

		if(min_dist[current_loc] <= right_dist && min_dist[current_loc] <= left_dist){ //現在地が最適である場合

			printf("0\n");
			fflush(stdout);

		}else{

			if(left_dist < right_dist){
				printf("-1\n");
				fflush(stdout);
				current_loc = left_loc;
			}else{
				printf("1\n");
				fflush(stdout);
				current_loc = right_loc;
			}
		}

		if(current_loc == goal){
			return 0;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3296
final_rank: 8

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 301

int M;
int table[6];
int start,goal,command[NUM];
int min_dist[NUM],to_dist[NUM];

bool rangeCheck(int loc){
	if(loc >= 0 && loc <= M-1){
		return true;
	}else{
		return false;
	}
}

int recursive(int loc,int sum_dist){

	if(min_dist[loc] != -1){

		if(min_dist[loc] == BIG_NUM){
			return BIG_NUM;
		}else{
			return min_dist[loc]+sum_dist;
		}
	}

	int ret = BIG_NUM,next_loc = 0;

	for(int i = 0; i < 6; i++){

		//右方向
		next_loc = loc+table[i];
		if(rangeCheck(next_loc) == true){
			next_loc += command[next_loc];
			if(to_dist[next_loc] > sum_dist+1){
				to_dist[next_loc] = sum_dist+1;
				ret = min(ret,recursive(next_loc+command[next_loc],sum_dist+1));
			}
		}
		//左方向
		next_loc = loc-table[i];
		if(rangeCheck(next_loc) == true){
			next_loc += command[next_loc];
			if(to_dist[next_loc] > sum_dist+1){
				to_dist[next_loc] = sum_dist+1;
				ret = min(ret,recursive(next_loc+command[next_loc],sum_dist+1));
			}
		}
	}

	return ret;
}


int main(){

	scanf("%d",&M);

	for(int i = 0; i < 6; i++)scanf("%d",&table[i]);

	scanf("%d %d",&start,&goal);
	start--;
	goal--;

	for(int i = 0; i < M; i++){
		scanf("%d",&command[i]);
	}

	for(int i = 0; i < M; i++){
		min_dist[i] = -1;
	}
	min_dist[goal] = 0;

	for(int i = 0; i < M; i++){
		if(i == goal)continue;
		for(int k = 0; k < M; k++)to_dist[k] = BIG_NUM; //そこへたどり着くまでのコスト

		to_dist[i] = 0;

		min_dist[i] = recursive(i,0);
	}

	int current_loc = start,dice;
	int right_loc,left_loc,right_dist,left_dist;

	while(true){

		scanf("%d",&dice);
		dice--;

		if(!rangeCheck(current_loc+table[dice])){
			right_dist = BIG_NUM;
		}else{
			right_loc = current_loc+table[dice];
			right_loc += command[right_loc];
			right_dist = min_dist[right_loc];
		}

		if(!rangeCheck(current_loc-table[dice])){
			left_dist = BIG_NUM;
		}else{
			left_loc = current_loc-table[dice];
			left_loc += command[left_loc];
			left_dist = min_dist[left_loc];
		}

		if(min_dist[current_loc] <= right_dist && min_dist[current_loc] <= left_dist){ //現在地が最適である場合

			printf("0\n");
			fflush(stdout);

		}else{

			if(left_dist < right_dist){
				printf("-1\n");
				fflush(stdout);
				current_loc = left_loc;
			}else{
				printf("1\n");
				fflush(stdout);
				current_loc = right_loc;
			}
		}

		if(current_loc == goal){
			return 0;
		}
	}

	return 0;
}
accuracy: 0.16363636363636364
time_ms: 30
memory_kb: 3288
final_rank: 17

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 301

struct Info{
	Info(int arg_loc,int arg_sum_cost){
		loc = arg_loc;
		sum_cost = arg_sum_cost;
	}
	int loc,sum_cost;
};

int M;
int table[6];
int start,goal,command[NUM];
int min_dist[NUM];

bool rangeCheck(int loc){
	if(loc >= 0 && loc <= M-1){
		return true;
	}else{
		return false;
	}
}


int main(){

	scanf("%d",&M);

	for(int i = 0; i < 6; i++)scanf("%d",&table[i]);

	scanf("%d %d",&start,&goal);
	start--;
	goal--;

	for(int i = 0; i < M; i++){
		scanf("%d",&command[i]);
	}

	for(int i = 0; i < M; i++){
		min_dist[i] = BIG_NUM;
	}
	min_dist[goal] = 0;

	//ゴールからダイクストラ法を行う
	queue<Info> Q;
	Q.push(Info(goal,0));

	int next_loc;

	while(!Q.empty()){

		if(Q.front().sum_cost > min_dist[Q.front().loc]){

			Q.pop();

		}else{

			//右方向
			for(int i = 0; i < 6; i++){

				next_loc = Q.front().loc+table[i];
				if(!rangeCheck(next_loc))continue;

				next_loc += command[next_loc];

				if(min_dist[next_loc] > Q.front().sum_cost+1){
					min_dist[next_loc] = Q.front().sum_cost+1;
					Q.push(Info(next_loc,min_dist[next_loc]));
				}
			}

			//左方向
			for(int i = 0; i < 6; i++){

				next_loc = Q.front().loc-table[i];
				if(!rangeCheck(next_loc))continue;

				next_loc += command[next_loc];

				if(min_dist[next_loc] > Q.front().sum_cost+1){
					min_dist[next_loc] = Q.front().sum_cost+1;
					Q.push(Info(next_loc,min_dist[next_loc]));
				}
			}

			Q.pop();
		}
	}

	int current_loc = start,dice;
	int right_loc,left_loc,right_dist,left_dist;

	while(true){

		scanf("%d",&dice);
		dice--;

		if(!rangeCheck(current_loc+table[dice])){
			right_dist = BIG_NUM;
		}else{
			right_loc = current_loc+table[dice];
			right_loc += command[right_loc];
			right_dist = min_dist[right_loc];
		}

		if(!rangeCheck(current_loc-table[dice])){
			left_dist = BIG_NUM;
		}else{
			left_loc = current_loc-table[dice];
			left_loc += command[left_loc];
			left_dist = min_dist[left_loc];
		}

		if(min_dist[current_loc] <= right_dist && min_dist[current_loc] <= left_dist){ //現在地が最適である場合

			printf("0\n");
			fflush(stdout);

		}else{

			if(left_dist < right_dist){
				printf("-1\n");
				fflush(stdout);
				current_loc = left_loc;
			}else{
				printf("1\n");
				fflush(stdout);
				current_loc = right_loc;
			}
		}

		if(current_loc == goal){
			return 0;
		}
	}

	return 0;
}
accuracy: 0.03636363636363636
time_ms: 30
memory_kb: 3228
final_rank: 19

code_snippet: #include<iostream>
#include<algorithm>
#include<deque>
#include<climits>
#include<vector>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

int M,a[7],s,g,N[310];
vector<ii> G[310];
int mini[310];
ii pre[310];

void compute() {
  rep(i,M) {
    rep(j,6) {
      for(int coef=-1;coef<=1;coef+=2) {
	int nex = i + a[j] * coef;
	if( !( 0 <= nex && nex < M ) ) continue;
	nex += N[nex];
	if( !( 0 <= nex && nex < M ) ) continue;
	if( i == nex ) continue;
	G[i].push_back(ii(nex,(j+1) * coef));
      }
    }
  }
  rep(i,M) mini[i] = INT_MAX, pre[i] = ii(INT_MAX,INT_MAX);
  mini[s] = 0;
  deque<int> deq;
  deq.push_back(s);
  while( !deq.empty() ) {
    int cur = deq.front(); deq.pop_front();
    if( cur == g ) break;
    rep(i,(int)G[cur].size()) {
      int nex = G[cur][i].first;
      if( cur == nex ) continue;
      if( mini[nex] > mini[cur] + 1 ) {
	mini[nex] = mini[cur] + 1;
	deq.push_back(nex);
	pre[nex] = ii(cur,G[cur][i].second);
      }
    }
  }
  assert( pre[g].first != INT_MAX );
  vector<int> path;
  int cur = g;
  while( pre[cur].second != INT_MAX ) {
    path.push_back(pre[cur].second);
    cur = pre[cur].first;
  }
  reverse(path.begin(),path.end());
  //cout << "path.size() = " << path.size() << endl;
  //rep(i,(int)path.size()) cout << path[i] << endl;
  int v,ptr = 0;
  while( ptr < (int)path.size() ) {
    cin >> v;
    if( v == abs(path[ptr]) ) {
      if( path[ptr] < 0 ) cout << -1 << endl;
      else                cout <<  1 << endl;
      ++ptr;
    } else {
      cout << 0 << endl;
    }
  }
}

int main() {
  cin >> M;
  rep(i,6) cin >> a[i];
  cin >> s >> g;
  --s, --g;
  rep(i,M) cin >> N[i];
  compute();
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3280
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
 
//#define USING_LONG_LONG
#ifdef USING_LONG_LONG
    #define int long long
    const int INF=1001001001001001001ll;
#else
    const int INF=1001001001;
#endif
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREP(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define clr(a) memset((a),0,sizeof(a))
#define CLR(a) memset((a),-1,sizeof(a))
#define each(i,v) for(__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define minv(a,b) (a)=min((a),(b))
#define maxv(a,b) (a)=max((a),(b))
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<string>vs;
typedef pair<int,int>pii;
#define fi first
#define se second
 
int M;
int a[6],s,g;
int d[300];
int dist[300];
 
signed main(){
    scanf("%d",&M);rep(i,6)scanf("%d",&a[i]);scanf("%d%d",&s,&g);s--;g--;
    rep(i,M)scanf("%d",&d[i]);
 
    CLR(dist);
    dist[g]=0;
 
    queue<int>que;que.push(g);
 
    while(que.size()){
        int v=que.front();que.pop();
        rep(i,M){
            if(i+d[i]!=v)continue;
            rep(j,6){
                int va=i+a[j];
                int vb=i-a[j];
                if(0<=va&&va<M&&dist[va]==-1){
                    dist[va]=dist[v]+1;
                    que.push(va);
                }
                if(0<=vb&&vb<M&&dist[vb]==-1){
                    dist[vb]=dist[v]+1;
                    que.push(vb);
                }
            }
        }
    }
    int cnt=0;
    while(s!=g&&cnt<3000){
        int dice;scanf("%d",&dice);
        dice--;
        int va=s+a[dice];
        int vb=s-a[dice];
        if(va>=0&&va<M&&va+d[va]>=0&&va+d[va]<M&&dist[va+d[va]]!=-1&&dist[va+d[va]]<dist[s]){
            va+=d[va];
            printf("1\n");fflush(stdout);
            s=va;
        }
        else if(vb>=0&&vb<M&&vb+d[vb]>=0&&vb+d[vb]<M&&dist[vb+d[vb]]!=-1&&dist[vb+d[vb]]<dist[s]){
            vb+=d[vb];
            printf("-1\n");fflush(stdout);
            s=vb;
        }
        else{
            printf("0\n");fflush(stdout);
        }
        cnt++;
    }
 
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3244
final_rank: 6

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define M 302

int main() {
  int m, a[M], s, g;
  scanf("%d", &m);
  rep(i, 6) scanf("%d", a+i);
  scanf("%d %d", &s, &g); --s; --g;
  int n[M];
  rep(i, m) scanf("%d", &n[i]);

  int prev[M];
  int tod[M];
  int sign[M];

  queue<int> que;
  que.push(s);
  rep(i, m) prev[i] = -1;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    if(p == g) break;
    rep(i, 6) {
      if(0 <= p-a[i]) {
        int nxt = p-a[i];
        nxt += n[nxt];
        if(prev[nxt] == -1) {
          prev[nxt] = p;
          tod[nxt] = i;
          sign[nxt] = -1;
          que.push(nxt);
        }
      }
      if(p+a[i] < m) {
        int nxt = p+a[i];
        nxt += n[nxt];
        if(prev[nxt] == -1) {
          prev[nxt] = p;
          tod[nxt] = i;
          sign[nxt] = 1;
          que.push(nxt);
        }
      }
    }
  }
  vector<int> ss, ds;
  int v = g;
  while(v != s) {
    ds.push_back(tod[v]);
    ss.push_back(sign[v]);
    v = prev[v];
  }
  int c = ds.size() - 1;
  while(c >= 0) {
    int dice;
    scanf("%d", &dice);
    if(dice-1 == ds[c]) {
      printf("%d\n", ss[c]);
      --c;
    } else {
      printf("0\n");
    }
    fflush(stdout);
  }

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1312
final_rank: 7

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define M 302

int main() {
  int m, a[M], s, g;
  scanf("%d", &m);
  rep(i, 6) scanf("%d", a+i);
  scanf("%d %d", &s, &g); --s; --g;
  //int n[M];
  vector<int> n(m);
  rep(i, m) scanf("%d", &n[i]);

  vector<int> from[M];
  rep(p, m) {
    rep(i, 6) {
      if(0 <= p-a[i]) {
        int nxt = p-a[i];
        nxt += n[nxt];
        from[nxt].push_back(p);
      }
      if(p+a[i] < m) {
        int nxt = p+a[i];
        nxt += n[nxt];
        from[nxt].push_back(p);
      }
    }
  }

  int dist[M];
  rep(i, m) dist[i] = -1;
  queue<int> que;
  que.push(g);
  dist[g] = 0;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    if(p == s) continue;
    vector<int> &v = from[p];
    rep(i, v.size()) {
      int to = v[i];
      if(dist[to] == -1) {
        dist[to] = dist[p] + 1;
        que.push(to);
      }
    }
  }
  int pos = s;
  int count = 0;
  while(pos != g) {
    if(++count == 2990) exit(1);
    int dice;
    scanf("%d", &dice);
    int mv = a[dice-1];
    int ld = INF, lt = -1;
    if(0 <= pos-mv) {
      lt = pos-mv;
      lt += n[lt];
      ld = dist[lt];
    }
    int rd = INF, rt = -1;
    if(pos+mv < m) {
      rt = pos+mv;
      rt += n[rt];
      rd = dist[rt];
    }
    if(ld < dist[pos] && ld < rd) {
      printf("-1\n");
      pos = lt;
    }else if(rd < dist[pos] && rd < ld) {
      printf("1\n");
      pos = rt;
    } else {
      printf("0\n");
    }
    fflush(stdout);
  }
  return 0;
}
accuracy: 0.01818181818181818
time_ms: 30
memory_kb: 1304
final_rank: 20