
    Design a fraud detection algorithm that analyzes a sequence of transaction amounts from a bank account to identify the largest possible sum of transactions that follow a suspicious pattern where the amounts first increase and then decrease. The pattern of gradually increasing deposits followed by decreasing withdrawals could indicate potential money laundering, and identifying the maximum sum of such sequences helps determine the scale of suspicious activity.
    

    
def max_sum(arr):
    """
    Design a fraud detection algorithm that analyzes a sequence of transaction amounts from a bank account to identify the largest possible sum of transactions that follow a suspicious pattern where the amounts first increase and then decrease. The pattern of gradually increasing deposits followed by decreasing withdrawals could indicate potential money laundering, and identifying the maximum sum of such sequences helps determine the scale of suspicious activity.
    

    """
def max_sum(arr):
    """
    Design a fraud detection algorithm that analyzes a sequence of transaction amounts from a bank account to identify the largest possible sum of transactions that follow a suspicious pattern where the amounts first increase and then decrease. The pattern of gradually increasing deposits followed by decreasing withdrawals could indicate potential money laundering, and identifying the maximum sum of such sequences helps determine the scale of suspicious activity.
    

    """
    MSIBS = arr[:]
    for i in range(len(arr)):
        for j in range(0, i):
            if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
                MSIBS[i] = MSIBS[j] + arr[i]
    MSDBS = arr[:]
    for i in range(1, len(arr) + 1):
        for j in range(1, i):
            if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
                MSDBS[-i] = MSDBS[-j] + arr[-i]
    max_sum = float('-Inf')
    for (i, j, k) in zip(MSIBS, MSDBS, arr):
        max_sum = max(max_sum, i + j - k)
    return max_sum