I have a different approach than suggested and it is getting 70 points and is not passing just one test case of the smaller sub-task. Please find a test case for which the test case fails or find the error.
My approach: At each position while moving forward, we have three choices to go to the next square or the next to the next or start moving backward.
While moving backward though, we have just two choices, but we should additionallt necessarily end at the first square.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tc ll t; cin>>t; while(t--)
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);