using DP
\n# Code\npython3 []\nclass Solution:\n    def __init__(self):\n        self.n = 0\n        self.fruits = []\n        self.dp1 = [[-1] * 1001 for _ in range(100
\n# Code\n```python3 []\nclass Solution:\n    def __init__(self):\n        self.n = 0\n        self.fruits = []\n        self.dp1 = [[-1] * 1001 for _ in range(1001)]\n        self.dp2 = [[-1] * 1001 for _ in range(1001)]\n\n    def maxCollectedFruits(self, fruits):\n        self.n = len(fruits)\n        self.fruits = fruits\n        total = 0\n        \n        for i in range(self.n):\n            total += fruits[i][i]\n        \n        print(total) \n        total += self.find1(self.n - 1, 0)\n        total += self.find2(0, self.n - 1)\n        \n        return total\n\n    def find1(self, i, j):\n        if i == self.n - 1 and j == self.n - 1:\n            return 0\n        if j >= i:\n            return 0\n        if self.dp1[i][j] != -1:\n            return self.dp1[i][j]\n\n        maxV = 0\n        total = self.fruits[i][j]\n\n        # Recursive calls with different moves\n        if i - 1 >= 0:\n            maxV = max(maxV, total + self.find1(i - 1, j + 1))\n        maxV = max(maxV, total + self.find1(i, j + 1))\n        if i + 1 < self.n:\n            maxV = max(maxV, total + self.find1(i + 1, j + 1))\n\n        self.dp1[i][j] = maxV\n        return maxV\n\n    def find2(self, i, j):\n        if i == self.n - 1 and j == self.n - 1:\n            return 0\n        if i >= j:\n            return 0\n        if self.dp2[i][j] != -1:\n            return self.dp2[i][j]\n\n        maxV = 0\n        total = self.fruits[i][j]\n\n        if j - 1 >= 0:\n            maxV = max(maxV, total + self.find2(i + 1, j - 1))\n        maxV = max(maxV, total + self.find2(i + 1, j))\n        if j + 1 < self.n:\n            maxV = max(maxV, total + self.find2(i + 1, j + 1))\n\n        self.dp2[i][j] = maxV\n        return maxV\n\n```
['Python3']