
#include <bits/stdc++.h>
using namespace std;

int main()
{
    
    vector<int>h={4,1,1,5,6};
    int n=h.size();
    vector<vector<int>>dp(n,vector<int>(4,0));
    dp[0][2]=0;
    dp[0][3]=0;
    dp[1][2]=h[0]+h[1];
    dp[1][3]=0;
    dp[2][2]=h[1]+h[2];
    dp[2][3]=h[0]+h[1]+h[2];
    int maxi=0;
    for(int i=3;i<n;i++){

        int ans=0;
        for(int j=i-3;j>=0;j--){
            if(j==i-3){
                ans=max(ans,dp[j][2]);
            }
            else{
            ans=max(ans,max(dp[j][2],dp[j][3]));
            }
        }        
        dp[i][2]=h[i]+h[i-1]+ans;
        int ans1=0;
        for(int j=i-5;j>=0;j--){
            ans1=max(ans1,max(dp[j][2],dp[j][3]));
        }
        dp[i][3]=h[i]+h[i-1]+h[i-2]+ans1;
        
        maxi=max(maxi,max(dp[i][2],dp[i][3]));
        
    }
    
    //cout<<max(dp[n-1][2],dp[n-1][3]); this is wrong because it is not necessary that largest sum will happen only when last robbed house is n-1 indexed or last hpuse.
    //eg 1,5,5,5,1
    cout<<maxi<<endl;
    return 0;
}