Help me in whats the problem in this solution

My issue

can anyone explain the solution

My code

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod = 1000000007;


int main() {
	// your code goes here
	while(1){
	   int h;
	   cin>>h;
	   if(h==0)break;
	   int n = (1<<h) -1;
	   vector<ll>v1(n);
	   for(int i=0;i<n;i++){
	       cin>>v1[i];
	   }
	   vector<ll>l(n,1);
	   vector<ll>r(n,1);
	   ll ans = 0;
	   for(int i = n-1;i>=0;i--){
	       if(i==0){
	          ll ans1 = (l[i]%mod*v1[i]%mod)%mod;
	          ll ans2 = (r[i]%mod * v1[i]%mod)%mod;
	          ans = max(ans1%mod,ans2%mod);
	           
	       }
	       else if(i&1){
	          ll ans1 = (l[i]%mod*v1[i]%mod)%mod;
	          ll ans2 = (r[i]%mod * v1[i]%mod)%mod;
	          l[(i)/2] = max(ans1,ans2);
	       }
	       else{
	          ll ans1 = (1LL*l[i]%mod*v1[i]%mod)%mod;
	          ll ans2 = (1LL*r[i]%mod * v1[i]%mod)%mod;
	          r[(i-1)/2] = max(ans1,ans2);
	       }
	   }
	   cout<<ans%mod<<endl;
	}

}

Problem Link: Tree Product Practice Coding Problem - CodeChef