stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int N = 5;

const string march = "MARCH";



ll n, ans, cnt[N];

string s;



int main() {

	ios::sync_with_stdio(false), cin.tie(0);

	cin >> n;

	while(n--) {

		cin >> s;

		for (int i = 0; i < N; i++)

			if(s[0] == march[i])

				cnt[i]++;

	}

	for (int i = 0; i < N; i++)

		for (int j = i + 1; j < N; j++)

			for (int k = j + 1; k < N; k++)

				ans += cnt[i] * cnt[j] * cnt[k];

	cout << ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.265939002963842x):
#include<cstdio>





long long count[5];

int combine[10][3] = {

	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}

};

int main()

{

	int n;

	long long ans;

	char str[15];

	while(~scanf("%d",&n)){

		ans = 0;

		for(int i = 0; i<5; i++)count[i] = 0;

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

			scanf("%s",str);

			if(str[0] == 'M') count[0]++;//M

			else if(str[0] == 'A') count[1]++;//A

			else if(str[0] == 'R') count[2]++;//R

			else if(str[0] == 'C') count[3]++;//C

			else if(str[0] == 'H') count[4]++;//H

			else continue;

		}

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

			ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];

		}

		printf("%lld\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;

int main()

{

	int n;

	long long  a[5];//march

	cin>>n;

	for(int i=0;i<5;i++)

	a[i]=0;

	for(int i=0;i<n;i++)

	{

		string s;

		cin>>s;

		if(s[0]=='M') a[0]++;

		else if(s[0]=='A') a[1]++;

		else if(s[0]=='R') a[2]++;

		else if(s[0]=='C') a[3]++;

		else if(s[0]=='H') a[4]++;

	}

	long long num=0;

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

		if(a[i]==0)continue;

		for(int j=i+1;j<5;j++)

		{

			if(a[j]==0) continue;

			for(int z=j+1;z<5;z++)

			{

				if(a[z]==0) continue;

				num+=a[i]*a[j]*a[z];

			}

		}

			

	}

	printf("%lld",num);	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.177425553892079x):
#include<cstdio>





long long count[5];

int combine[10][3] = {

	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}

};

int main()

{

	int n;

	long long ans;

	char str[15];

	while(~scanf("%d",&n)){

		ans = 0;

		for(int i = 0; i<5; i++)count[i] = 0;

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

			scanf("%s",str);

			if(str[0] == 'M') count[0]++;//M

			else if(str[0] == 'A') count[1]++;//A

			else if(str[0] == 'R') count[2]++;//R

			else if(str[0] == 'C') count[3]++;//C

			else if(str[0] == 'H') count[4]++;//H

			else continue;

		}

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

			ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];

		}

		printf("%lld\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>

#include<cstring>

using namespace std;

long long int n,rs,f[5];string s;

int main()

{

	cin>>n;

	memset(f,0,sizeof(f));

	while(n-->0)

	{

		cin>>s;

		if(s[0]=='M')f[0]++;else if(s[0]=='A')f[1]++;else if(s[0]=='R')f[2]++;else if(s[0]=='C')f[3]++;else if(s[0]=='H')f[4]++;

	}

	long long int ly=0;rs=0;

	for(int i=0;i<5;i++)if(f[i]>0)ly++;

	if(ly>=3)

	{

			for(int i=0;i<5;i++)

			{

				if(f[i]==0)continue;

				for(int j=i;j<5;j++)

				{

					if(j==i||f[j]==0)continue;

					for(int t=j;t<5;t++)

					{

						if(i==t||t==j||f[t]==0)continue;

						rs+=f[i]*f[j]*f[t];

					}

				}

			}

	}

	cout<<rs<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.200775962612581x):
#include<cstdio>





long long count[5];

int combine[10][3] = {

	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}

};

int main()

{

	int n;

	long long ans;

	char str[15];

	while(~scanf("%d",&n)){

		ans = 0;

		for(int i = 0; i<5; i++)count[i] = 0;

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

			scanf("%s",str);

			if(str[0] == 'M') count[0]++;//M

			else if(str[0] == 'A') count[1]++;//A

			else if(str[0] == 'R') count[2]++;//R

			else if(str[0] == 'C') count[3]++;//C

			else if(str[0] == 'H') count[4]++;//H

			else continue;

		}

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

			ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];

		}

		printf("%lld\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#pragma comment(linker,"/STACK:102400000,102400000")

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <vector>

#include <string>

#include <cstring>

#include <cctype>

#include <climits>

#include <cmath>

#include <set>

#include <map>

#include <sstream>

#include <queue>

#include <stack>



using namespace std;



int main(){

	int n;

	scanf("%d",&n);

	char name[20];

	map<char,long long> arr;

	set<char> st;

	vector<char> letter;

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

		scanf("%s",name);

		switch(name[0]){

			case 'M':

				st.insert(name[0]);

				arr['M']++;

				break;

			case 'A':

				st.insert(name[0]);

				arr['A']++;

				break;

			case 'R':

				st.insert(name[0]);

				arr['R']++;

				break;

			case 'C':

				st.insert(name[0]);

				arr['C']++;

				break;

			case 'H':

				st.insert(name[0]);

				arr['H']++;

				break;

		}

	}

	for(auto it=st.begin();it!=st.end();it++)

		letter.push_back(*it);

	long long ans;

	if(st.size()<3) ans=0;

	else if(st.size()==3){

		ans=arr[letter[0]]*arr[letter[1]]*arr[letter[2]];

	}

	else if(letter.size()==4){

		ans=arr[letter[0]]*arr[letter[1]]*arr[letter[2]];

		ans+=arr[letter[0]]*arr[letter[1]]*arr[letter[3]];

		ans+=arr[letter[0]]*arr[letter[2]]*arr[letter[3]];

		ans+=arr[letter[1]]*arr[letter[2]]*arr[letter[3]];

	}

	else if(letter.size()==5){

		ans=arr[letter[0]]*arr[letter[1]]*arr[letter[2]];

		ans+=arr[letter[0]]*arr[letter[1]]*arr[letter[3]];

		ans+=arr[letter[0]]*arr[letter[2]]*arr[letter[3]];

		ans+=arr[letter[1]]*arr[letter[2]]*arr[letter[3]];

		ans+=arr[letter[0]]*arr[letter[1]]*arr[letter[4]];

		ans+=arr[letter[0]]*arr[letter[2]]*arr[letter[4]];

		ans+=arr[letter[0]]*arr[letter[3]]*arr[letter[4]];

		ans+=arr[letter[1]]*arr[letter[2]]*arr[letter[4]];

		ans+=arr[letter[1]]*arr[letter[3]]*arr[letter[4]];

		ans+=arr[letter[2]]*arr[letter[3]]*arr[letter[4]];

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.189059984422095x):
#include<cstdio>





long long count[5];

int combine[10][3] = {

	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}

};

int main()

{

	int n;

	long long ans;

	char str[15];

	while(~scanf("%d",&n)){

		ans = 0;

		for(int i = 0; i<5; i++)count[i] = 0;

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

			scanf("%s",str);

			if(str[0] == 'M') count[0]++;//M

			else if(str[0] == 'A') count[1]++;//A

			else if(str[0] == 'R') count[2]++;//R

			else if(str[0] == 'C') count[3]++;//C

			else if(str[0] == 'H') count[4]++;//H

			else continue;

		}

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

			ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];

		}

		printf("%lld\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long 

int main()

{

string s;char x;

 vector<char>v;

    map<char,ll>m;

    ll a,b,c,d,i,j,k,l=0;

  cin>>a;

for(i=1;i<=a;i++)

{

  cin>>s;x=s[0];  

if(x=='C'||x=='R'||x=='A'||x=='M'||x=='H'){

  if(m[x]==0)

  {

        v.push_back(x);

   }

            m[x]++;

  }

}

 for(i=0;i<v.size();i++)

{

for(j=i+1;j<v.size();j++)

   {

for(k=j+1;k<v.size();k++)

{

l+=(m[v[i]]*m[v[j]]*m[v[k]]);

}

}

 }

cout<<l<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.2523516838496676x):
#include<cstdio>





long long count[5];

int combine[10][3] = {

	{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}

};

int main()

{

	int n;

	long long ans;

	char str[15];

	while(~scanf("%d",&n)){

		ans = 0;

		for(int i = 0; i<5; i++)count[i] = 0;

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

			scanf("%s",str);

			if(str[0] == 'M') count[0]++;//M

			else if(str[0] == 'A') count[1]++;//A

			else if(str[0] == 'R') count[2]++;//R

			else if(str[0] == 'C') count[3]++;//C

			else if(str[0] == 'H') count[4]++;//H

			else continue;

		}

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

			ans +=count[combine[i][0]]*count[combine[i][1]]*count[combine[i][2]];

		}

		printf("%lld\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <algorithm>

#include <functional>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <bitset>

#include <cassert>

#include <exception>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll,ll> P;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<string> vs;

typedef vector<P> vp;

#define rep(i,a,n) for(ll i = (a);i < (n);i++)

#define per(i,a,n) for(ll i = (a);i > (n);i--)

#define lep(i,a,n) for(ll i = (a);i <= (n);i++)

#define pel(i,a,n) for(ll i = (a);i >= (n);i--)

#define clr(a,b) memset((a),(b),sizeof(a))

#define pb push_back

#define mp make_pair

#define all(c) (c).begin(),(c).end()

#define sz size()

#define print(X) cout << (X) << endl

const ll INF = 1e+9+7;

ll n,m,l;

string s,t;

ll d[200010],dp[550][550];



int main(){

  cin >> n;

  clr(d,0);

  rep(i,0,n){

    cin >> s;

    if(s[0] == 'M')d[0]++;

    if(s[0] == 'A')d[1]++;

    if(s[0] == 'R')d[2]++;

    if(s[0] == 'C')d[3]++;

    if(s[0] == 'H')d[4]++;

  }

  l = 0;

  rep(i,0,5){

    rep(j,i+1,5){

      rep(k,j+1,5){

        l += d[i] * d[j] * d[k];

      }

    }

  }

  print(l);

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.606276213333341x):
#include <iostream>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <algorithm>

#include <functional>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <bitset>

#include <cassert>

#include <exception>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll,ll> P;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<string> vs;

typedef vector<P> vp;

#define rep(i,a,n) for(ll i = (a);i < (n);i++)

#define per(i,a,n) for(ll i = (a);i > (n);i--)

#define lep(i,a,n) for(ll i = (a);i <= (n);i++)

#define pel(i,a,n) for(ll i = (a);i >= (n);i--)

#define clr(a,b) memset((a),(b),sizeof(a))

#define pb push_back

#define mp make_pair

#define all(c) (c).begin(),(c).end()

#define sz size()

#define print(X) cout << (X) << endl

const ll INF = 1e+9+7;

ll n,m,l;

string s,t;

ll d[200010],dp[550][550];



int main(){

  cin >> n;

  rep(i,0,n){

    cin >> s;

    if(s[0] == 'M')d[0]++;

    if(s[0] == 'A')d[1]++;

    if(s[0] == 'R')d[2]++;

    if(s[0] == 'C')d[3]++;

    if(s[0] == 'H')d[4]++;

  }

  l = 0;

  rep(i,0,5){

    rep(j,i+1,5){

      rep(k,j+1,5){

        l += d[i] * d[j] * d[k];

      }

    }

  }

  print(l);

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <string.h>

#include <vector>

#include <stdlib.h>

#include <cstdint>

#include <cmath>

#include <algorithm>

#include <float.h>

using namespace std;



#define N 100000



string s[N];



int main()

{

	int n;

	long long ans = 0;

 

	cin >> n;

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

		cin >> s[i];

	}



	long long nm[5] = {0};

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

		if( s[i][0] == 'M' ) {

			nm[0]++;

		}

		else if( s[i][0] == 'A' ) {

			nm[1]++;

		}

		else if( s[i][0] == 'R' ) {

			nm[2]++;

		}

		else if( s[i][0] == 'C' ) {

			nm[3]++;

		}

		else if( s[i][0] == 'H' ) {

			nm[4]++;

		}



	}



	ans += nm[0] * nm[1] * nm[2];

	ans += nm[0] * nm[1] * nm[3];

	ans += nm[0] * nm[1] * nm[4];

	ans += nm[0] * nm[2] * nm[3];

	ans += nm[0] * nm[2] * nm[4];

	ans += nm[0] * nm[3] * nm[4];

	ans += nm[1] * nm[2] * nm[3];

	ans += nm[1] * nm[2] * nm[4];

	ans += nm[1] * nm[3] * nm[4];

	ans += nm[2] * nm[3] * nm[4];



	cout << ans << endl;

 

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.315430654944365x):
#include <bits/stdc++.h>

using namespace std;



int main()

{

	int N;

	cin >> N;

	vector<int> c( 5 );

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

		string s;

		cin >> s;

		if( s[0] == 'M' ) c[0]++;

		else if( s[0] == 'A' ) c[1]++;

		else if( s[0] == 'R' ) c[2]++;

		else if( s[0] == 'C' ) c[3]++;

		else if( s[0] == 'H' ) c[4]++;

	}



	long long ans = 0;

	int per[5] = { 0, 0, 1, 1, 1 };

	do {

		long long m = 1;

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

			if( per[i] ) m *= c[i];

		}



		ans += m;

	} while( next_permutation( per, per + 5 ) );



	cout << ans << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define Int int64_t

#define dump(x) cout << (x) << endl

#define fi first

#define se second

Int mod = 1e9+7;

Int INF = 1e18;

double EPS = 0.00000001;

//Int mod = 998244353;



int main() {

    Int a, b, c;

    cin >> a >> b >> c;

    dump(c - min(a - b, c));

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.253398280670239x):
    #include <stdio.h>



    int main(void){



    int a, b, c, d;



    scanf( "%d", &a);

    scanf( "%d", &b);

    scanf( "%d", &c);



    d = c + b - a;



    if( d < 0 ){



    printf( "0\n");

    }else{



    printf( "%d\n", d);

    }

        return 0;

    }
// Slower C++ solution:
#include<iostream>

#include<cmath>

#include<iomanip>

using namespace std;

struct P{

	double x,y;

	double abs()

	{

		return hypot(x,y);

	}

	P operator+(P b)

	{

		return{x+b.x,y+b.y};

	}

	P operator-(P b)

	{

		return{x-b.x,y-b.y};

	}

};

P div(P a,P b)

{

	return{a.x/a.abs()+b.x/b.abs(),a.y/a.abs()+b.y/b.abs()};

}

double theta(P a,P b)

{

	double ret=atan2(b.y,b.x)-atan2(a.y,a.x);

	ret=abs(ret);

	if(ret>M_PI)ret=2*M_PI-ret;

	return ret;

}

P take(P a,P b,double x)

{

	P q=div(a,b);

	double t=theta(a,b);

	double k=x/q.abs()/sin(t/2);

	return{q.x*k,q.y*k};

}

double cross(P a,P b){return a.x*b.y-a.y*b.x;}

bool in(P a,P b,P c,P p)

{

	return cross(p-a,b-a)*cross(p-a,c-a)<=0

		&&cross(p-b,c-b)*cross(p-b,a-b)<=0

		&&cross(p-c,a-c)*cross(p-c,b-c)<=0;

}

double dis(P p,P a,P b)

{

	double t=theta(b-a,p-a);

	return sin(t)*(p-a).abs();

}

bool check(P a,P b,P c,double x)

{

	P ab=take(a-c,b-c,x)+c,bc=take(b-a,c-a,x)+a,ca=take(c-b,a-b,x)+b;

	if(!in(a,b,c,ab)||!in(a,b,c,bc)||!in(a,b,c,ca))return false;

	if(dis(ab,a,b)<x||dis(bc,b,c)<x||dis(ca,c,a)<x)return false;

	return (ab-bc).abs()>=2*x||(bc-ca).abs()>=2*x||(ca-ab).abs()>=2*x;

}

main()

{

	P a,b,c;

	cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;

	double L=0,R=1e3;

	for(int i=0;i<100;i++)

	{

		double M=(L+R)/2;

		if(check(a,b,c,M))L=M;

		else R=M;

	}

	cout<<fixed<<setprecision(15)<<L<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.0937427664272235x):
#include<iostream>

#include<cmath>

#include<iomanip>

#include<algorithm>

using namespace std;

double ax,ay,bx,by,cx,cy,a,b,c,s,r;

main()

{

	cin>>ax>>ay>>bx>>by>>cx>>cy;

	a=hypot(ax-bx,ay-by);

	b=hypot(bx-cx,by-cy);

	c=hypot(cx-ax,cy-ay);

	s=sqrt((a+b+c)*(a+b-c)*(a-b+c)*(-a+b+c)/16);

	r=2*s/(a+b+c);

	a=max({a,b,c});

	cout<<fixed<<setprecision(15)<<a/(2+a/r)<<endl;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<vector>

#include<algorithm>

#include<queue>

#define INF -1000000

#define F first

#define S second

using namespace std;



int N,imap[100010],MINE;

int dp[100010];

bool Init(){

  cin >> N;

  if(N == 0)return false;

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

    cin >> imap[i];

    dp[i] = 1<<29;

  }

  for(int i=N;i<100010;i++)dp[i] = 1<<29;

  MINE = 1<<29;

  return true;

}



int main(){

  //while(true){

  //if(!Init())break;

  Init();



  deque<int> que;

  que.push_front(0);

  dp[0] = 0;



  while(!que.empty()){

    int p = que.front();que.pop_front();

   

    if(p >= N-1){

      cout << dp[p] << endl;

      break;

    }

    if(imap[p] != 0){

      int np = p + imap[p];

      if(dp[np] <= dp[p])continue;

      dp[np] = dp[p];

      que.push_front(np);//飛ばされてきた場合を優先する

      continue;

    }

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

      int np = p+i;

      if(dp[np] <= dp[p]+1)continue;

      dp[np] = dp[p]+1;

      que.push_back(np);

    }

  }

  //for(int i=1;i<N;i++)cout << "dp["<< i << "] = "  << dp[i] << endl;





  

  //}

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.394789275028507x):
#include<iostream>

#include<cstdio>

#include<vector>

#include<algorithm>

#include<queue>

#define INF -1000000

#define F first

#define S second

using namespace std;



int N,imap[100010],MINE;

int dp[100010];

bool Init(){

  cin >> N;

  if(N == 0)return false;

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

    cin >> imap[i];

    dp[i] = 1<<29;

  }

  for(int i=N;i<N+10;i++)dp[i] = 1<<29;

  MINE = 1<<29;

  return true;

}



int main(){

  //while(true){

  //if(!Init())break;

  Init();



  deque<int> que;

  que.push_front(0);

  dp[0] = 0;



  while(!que.empty()){

    int p = que.front();que.pop_front();

   

    if(p >= N-1){

      cout << dp[p] << endl;

      break;

    }

    if(imap[p] != 0){

      int np = p + imap[p];

      if(dp[np] <= dp[p])continue;

      dp[np] = dp[p];

      que.push_front(np);//飛ばされてきた場合を優先する

      continue;

    }

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

      int np = p+i;

      if(dp[np] <= dp[p]+1)continue;

      dp[np] = dp[p]+1;

      que.push_back(np);

    }

  }

  //for(int i=1;i<N;i++)cout << "dp["<< i << "] = "  << dp[i] << endl;





  

  //}

  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<vector>

#include<algorithm>

#include<queue>

#define INF -1000000

#define F first

#define S second

using namespace std;



int N,imap[100010],MINE;

int dp[100010];

bool Init(){

  cin >> N;

  if(N == 0)return false;

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

    cin >> imap[i];

    dp[i] = 1<<29;

  }

  for(int i=N;i<100010;i++)dp[i] = 1<<29;

  MINE = 1<<29;

  return true;

}



int main(){

  //while(true){

  //if(!Init())break;

  Init();



  deque<int> que;

  que.push_front(0);

  dp[0] = 0;



  while(!que.empty()){

    int p = que.front();que.pop_front();

   

    if(p >= N-1){

      cout << dp[p] << endl;

      break;

    }

    if(imap[p] != 0){

      int np = p + imap[p];

      if(dp[np] <= dp[p])continue;

      dp[np] = dp[p];

      que.push_front(np);//飛ばされてきた場合を優先する

      continue;

    }

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

      int np = p+i;

      if(dp[np] <= dp[p]+1)continue;

      dp[np] = dp[p]+1;

      que.push_back(np);

    }

  }

  //for(int i=1;i<N;i++)cout << "dp["<< i << "] = "  << dp[i] << endl;





  

  //}

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4147253103960122x):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<queue>

using namespace std;



int N,imap[100010],MINE;

int dp[100010];

void Init(){

scanf("%d",&N);

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

scanf("%d",&imap[i]);

    dp[i] = 1<<29;

  }

  for(int i=N;i<N+10;i++)dp[i] = 1<<29;

  MINE = 1<<29;

}



int main(){

  Init();

  deque<int> que;

  que.push_front(0);

  dp[0] = 0;



  while(!que.empty()){

    int p = que.front();que.pop_front();

   

    if(p >= N-1){

      

printf("%d\n",dp[p]);

      break;

    }

    if(imap[p] != 0){

      int np = p + imap[p];

      if(dp[np] <= dp[p])continue;

      dp[np] = dp[p];

      que.push_front(np);//飛ばされてきた場合を優先する

      continue;

    }

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

      int np = p+i;

      if(dp[np] <= dp[p]+1)continue;

      dp[np] = dp[p]+1;

      que.push_back(np);

    }

  }

  return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<vector>

#include<string>

#include<algorithm>

#include<queue>

#include<map>

#include<set>



using namespace std;



#define reps(i,f,n) for(int i=f;i<int(n);i++)

#define rep(i,n) reps(i,0,n)

#define pb push_back





int n;

vector<int> dat;



bool input(){

	cin>>n;

	

	rep(i,n){

		int a;

		cin>>a;

		dat.pb(a);

	}

	

	return true;

}



const int N = 111111;





class P{

	public:

	int pos,val;

	P(int pos, int val):pos(pos), val(val){}

	bool operator < (const P& a) const{

		if(val==a.val)return pos>a.pos;;

		return val>a.val;

	}

};



typedef pair<int,int> pii;



vector<pii> edge[N];

int visit[N];

void solve(){

	

	rep(i,n){

		if(dat[i]!=0){

			edge[i].pb(pii(i+dat[i], 0));

		}

	}

	

	rep(i,n){

		rep(j,6){

			if(dat[i]==0){

				if(i+j+1<=n-1){

					edge[i].pb(pii(i+j+1, 1));

				}

			}

		}

	}

	

	priority_queue<P> que;

	que.push(P(0,0));

	

	rep(i,N)visit[i]=0;

	

	while(!que.empty()){

		P u = que.top();

		que.pop();

		

		if(visit[u.pos]==1)continue;

		visit[u.pos] = 1;

		

		//printf("pos = %d  val=%d\n",u.pos, u.val);

		

		if(u.pos==n-1){

			cout<<u.val<<endl;

			break;

		}

		

		rep(i,edge[u.pos].size()){

			que.push(P(edge[u.pos][i].first, u.val+edge[u.pos][i].second));

		}

	}

}



int main(){

	input();

	solve();

}

// Faster C++ solution for the same problem (measured speedup: 4.226778955814118x):
#include <iostream>

#include <vector>

#include <queue>

using namespace std;



int N;

vector<int> p;

//bool visited[10010];

//bool is_loop[10010];

bool dijkstra_visited[100100];

//int v[10010];



struct edge {

	int to;

	int cost;

	edge(int t_, int c_) {

		to = t_;

		cost = c_;

	}

};



struct status {

	int amt;

	int v;

	status(int a_, int v_) {

		amt = a_;

		v = v_;

	}

	bool operator<(const status &obj) const {

		return this->amt > obj.amt;

	}

};



vector<vector<edge> > e;



/*

bool loop(int n) {

	if(visited[n])

		return is_loop[n];

	visited[n] = true;

	is_loop[n] = true;

	if(p[n] == 0)

		return is_loop[n] = false;

	return is_loop[n] = loop(n + p[n]);

}

// */



int main() {

	cin >> N;

	p.resize(N);

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

		cin >> p[i];

	}

	/*

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

		loop(i);

	}

	// */

	e.resize(N);

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

		if(p[i] == 0) {

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

		//		if(!is_loop[i+j+1]) {

				if(i+j+1 < N) {

					e[i].push_back(edge(i+j+1, 1));

				}

		//		}

			}

		}

		else {

	//		if(!is_loop[i]) {

				e[i].push_back(edge(i+p[i], 0));

	//		}

		}

	}



	priority_queue<status> q;

	q.push(status(0,0));

	int res = 1e9;

	while(!q.empty()) {

		status cur = q.top();

		q.pop();

		if(dijkstra_visited[cur.v])

			continue;

		dijkstra_visited[cur.v] = true;

//		v[cur.v] = cur.amt;

		if(cur.v == N-1) {

			res = cur.amt;

			break;

		}

		for(int i = 0; i < e[cur.v].size(); i++) {

			if(!dijkstra_visited[e[cur.v][i].to]) {

				q.push(status(cur.amt + e[cur.v][i].cost, e[cur.v][i].to));

			}

		}

	}

//	for(int i = 0; i < N; i++)

//		cout << "i:" << i << " " << v[i] << endl;

	cout << res << endl;

}