#include using namespace std; vector adj[100000]; int A[100000]; vector q; int n,m; long long int t; int history[100000]; long long int visited[100000][2]; long long int Left[100001]; long long int Right[100001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for(int i=0;i> A[i]; adj[i].push_back((i + A[i])%n); } cin >> m; for(int i=0;i> t; q.push_back(t); } memset(visited,-1,sizeof(visited)); memset(history,-1,sizeof(history)); visited[0][0] = 0; visited[0][1] = 0; queue que; que.push(0); int pos = -1; int pos2 = -1; while(!que.empty()) { int now = que.front(); que.pop(); for(auto next : adj[now]) { if(visited[next][0]==-1) { visited[next][1] = visited[now][1] + A[now]; visited[next][0] = visited[now][0] + 1; history[next] = now; que.push(next); } else { pos = next; pos2 = now; break; } } } long long int L = visited[pos][0]; long long int P = visited[pos2][0] - visited[pos][0] + 1; long long int SUM1 = visited[pos][1]; long long int SUM2 = visited[pos2][1] - visited[pos][1] + A[pos2]; { int cnt = 0; queue que; que.push(0); Left[cnt] = 0; while(cnt que; que.push(pos); Right[cnt] = 0; while(cnt