input: from typing import List
  
  def max_sum_no_adjacent_subsequence(nums: List[int], queries: List[List[int]]) -> int:
      """
      You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [pos_i, x_i].
  
      For query i, we first set nums[pos_i] equal to x_i, then we calculate the answer to query i which is the maximum sum of a
      subsequence
      of nums where no two adjacent elements are selected.
  
      Return the sum of the answers to all queries.
  
      Since the final answer may be very large, return it modulo 10^9 + 7.
  
      A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
  
      Examples:
      >>> nums = [3,5,9], queries = [[1,-2],[0,-3]]
      21
      >>> nums = [0,-1], queries = [[0,-5]]
      0
  
      Constraints:
      1 <= nums.length <= 5 * 10^4
      -10^5 <= nums[i] <= 10^5
      1 <= queries.length <= 5 * 10^4
      queries[i] == [pos_i, x_i]
      0 <= pos_i <= nums.length - 1
      -10^5 <= x_i <= 10^5
      """
  
output: 
      MOD = 10**9 + 7
      n = len(nums)
      dp = [0] * n
      dp[0] = max(0, nums[0])
      if n > 1:
          dp[1] = max(dp[0], nums[1])
      for i in range(2, n):
          dp[i] = max(dp[i-1], dp[i-2] + nums[i])
      
      total_sum = dp[-1]
      
      for pos, x in queries:
          nums[pos] = x
          dp[0] = max(0, nums[0])
          if n > 1:
              dp[1] = max(dp[0], nums[1])
          for i in range(2, n):
              dp[i] = max(dp[i-1], dp[i-2] + nums[i])
          total_sum = (total_sum + dp[-1]) % MOD
      
      return total_sum
  