Problem:
Score : 100 points

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

You are given the values of the five variables after this assignment.

Find out which variable Snuke assigned 0.

Constraints

The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

Sample Input 1

0 2 3 4 5

Sample Output 1

1

In this case, Snuke assigned 0 to x_1, so we should print 1.

Sample Input 2

1 2 0 4 5

Sample Output 2

3

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,k,x,y,tx,ty;
    cin>>n>>m>>k>>x>>y>>tx>>ty;
    x--;
    y--;
    tx--;
    ty--;
    int dist[n][m];
    char t[n][m];
    bool vis[n][m];
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            cin>>t[i][j];
            dist[i][j]=1e5;
        }
    queue<int> r;
    queue<int> c;
    dist[x][y]=0;
    r.push(x);
    c.push(y);
    while(!r.empty()){
        int row=r.front();
        int col=c.front();
        r.pop();
        c.pop();
        if(vis[row][col])
            continue;
        vis[row][col]=1;
        for(int i=1;i<=k;i++){
            if(col+i>=m || t[row][col+i]=='@')
                break;
            if(vis[row][col+i])
                continue;
            r.push(row);
            c.push(col+i);
            dist[row][col+i]=min(dist[row][col+i],dist[row][col]+1);
        }
        for(int i=1;i<=k;i++){
            if(col-i<0 || t[row][col-i]=='@')
                break;
            if(vis[row][col-i])
                continue;
            r.push(row);
            c.push(col-i);
            dist[row][col-i]=min(dist[row][col-i],dist[row][col]+1);
        }
        for(int i=1;i<=k;i++){
            if(row+i>=n || t[row+i][col]=='@')
                break;
            if(vis[row+i][col])
                continue;
            r.push(row+i);
            c.push(col);
            dist[row+i][col]=min(dist[row+i][col],dist[row][col]+1);
        }
        for(int i=1;i<=k;i++){
            if(row-i<0 || t[row-i][col]=='@')
                break;
            if(vis[row-i][col])
                continue;
            r.push(row-i);
            c.push(col);
            dist[row-i][col]=min(dist[row-i][col],dist[row][col]+1);
        }
    }
    if(dist[tx][ty]==1e6)
        cout<<-1;
    else
        cout<<dist[tx][ty];
 }