Clean Python Code using Segment Tree
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n * log(n))$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass SegmentTree:\n    def __init__(self, n):\n        self.n = n\n        self.a1 = [0] * 4 * self.n # (l, r)\n        self.a2 = [0] * 4 * self.n # (l, r - 1)\n        self.a3 = [0] * 4 * self.n # (l + 1, r)\n        self.a4 = [0] * 4 * self.n # (l + 1, r - 1)\n    \n    def query(self):\n        return max(self.a1[0], self.a2[0], self.a3[0], self.a4[0])\n\n    def update(self, pos, val):\n        self.updateHelper(0, self.n - 1, 0, pos, val)\n    \n    def updateHelper(self, left, right, ind, pos, val):\n        if left==right:\n            self.a1[ind] = val\n            self.a2[ind] = 0\n            self.a3[ind] = 0\n            self.a4[ind] = 0\n            return\n        \n        mid = (left + right) // 2\n        if pos <= mid:\n            self.updateHelper(left, mid, ind*2 + 1, pos, val)\n        else:\n            self.updateHelper(mid + 1, right, ind*2 + 2, pos, val)\n\n        self.a1[ind] = max(self.a1[ind*2 + 1] + self.a3[ind*2 + 2], self.a2[ind*2 + 1] + self.a1[ind*2 + 2], self.a2[ind*2 + 1] + self.a3[ind*2 + 2])\n        self.a2[ind] = max(self.a1[ind*2 + 1] + self.a4[ind*2 + 2], self.a2[ind*2 + 1] + self.a2[ind*2 + 2], self.a2[ind*2 + 1] + self.a4[ind*2 + 2])\n        self.a3[ind] = max(self.a3[ind*2 + 1] + self.a3[ind*2 + 2], self.a4[ind*2 + 1] + self.a3[ind*2 + 2], self.a4[ind*2 + 1] + self.a1[ind*2 + 2])\n        self.a4[ind] = max(self.a3[ind*2 + 1] + self.a4[ind*2 + 2], self.a4[ind*2 + 1] + self.a2[ind*2 + 2], self.a4[ind*2 + 1] + self.a4[ind*2 + 2])\n\nclass Solution:\n    def maximumSumSubsequence(self, nums: List[int], queries: List[List[int]]) -> int:\n        n = len(nums)\n        segTree = SegmentTree(n)\n        total = 0\n        MOD = 10**9 + 7\n        for i, x in enumerate(nums):\n            segTree.update(i, x)\n\n        for i,x in queries:\n            segTree.update(i, x)\n            total += segTree.query()\n            total %= MOD\n        return total\n\n        \n```
['Python3']