Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef vector<int> vint;
#define rep(i,n) for(int i = 0; i < n; i++)

int main()
{
	ifstream ifs(stdin);
	int n, m;
	while(ifs >> n >> m && n)
	{
		int index = 0;
		vint field(n);
		rep(i, n) ifs >> field[i];

		int res = 1;
		for(;;res++)
		{
			int o;
			ifs >> o;

			if(n-1 <= index + o) break;
			else index += o + field[index + o];
		}
		cout << res << endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:27: error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(FILE*&)'
   25 |         ifstream ifs(stdin);
      |                           ^
In file included from a.cc:18:
/usr/include/c++/14/fstream:619:9: note: candidate: 'template<class _Path, class _Require> std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const _Path&, std::ios_base::openmode) [with _Require = _Path; _CharT = char; _Traits = std::char_traits<char>]'
  619 |         basic_ifstream(const _Path& __s,
      |         ^~~~~~~~~~~~~~
/usr/include/c++/14/fstream:619:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/fstream:64:60: error: request for member 'make_preferred' in 'std::declval<_IO_FILE*&>()', which is of pointer type '_IO_FILE*' (maybe you meant to use '->' ?)
   64 |            = decltype(std::declval<_Path&>().make_preferred().filename())>
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/14/fstream:627:7: note: candidate: 'std::basic_ifstream<_CharT, _Traits>::basic_ifstream(std::basic_ifstream<_CharT, _Traits>&&) [with _CharT = char; _Traits = std::char_traits<char>]'
  627 |       basic_ifstream(basic_ifstream&& __rhs)
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/fstream:627:39: note:   no known conversion for argument 1 from 'FILE*' to 'std::basic_ifstream<char>&&'
  627 |       basic_ifstream(basic_ifstream&& __rhs)
      |                      ~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/fstream:602:7: note: candidate: 'std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const std::string&, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::string = std::__cxx11::basic_string<char>; std::ios_base::openmode = std::ios_base::openmode]'
  602 |       basic_ifstream(const std::string& __s,
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/fstream:602:41: note:   no known conversion for argument 1 from 'FILE*' to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'}
  602 |       basic_ifstream(const std::string& __s,
      |                      ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/fstream:569:7: note: candidate: 'std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::ios_base::openmode]'
  569 |       basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/fstream:569:34: note:   no known conversion for argument 1 from 'FILE*' to 'const char*'
  569 |       basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
      |                      ~~~~~~~~~~~~^~~
/usr/include/c++/14/fstream:558:7: note: candidate: 'std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char; _Traits = std::char_traits<char>]'
  558 |       basic_ifstream() : __istream_type(), _M_filebuf()
      |       ^~~~~~~~~~~~~~
/usr/include/c++/14/fstream:558:7: note:   candidate expects 0 arguments, 1 provided