• + 0 comments

    Getting RunTime Errors

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    def gcd(x, y):
        x,y = abs(x),abs(y)
        while(y): 
            x, y = y, x % y 
        return x
    
    def gcdAr(a):
        if len(a) == 2:
            return gcd(a[0],a[1])
        return gcd(a[0],gcdAr(a[1:]))
    # Complete the maximumValue function below.
    def maximumValue(a):
        l = len(a)
        
        mat = [[0]*l for i in range(l)]
        matSum = [[0]*l for i in range(l)]
        matMax = [[0]*l for i in range(l)]
        
        ma = -float('inf')
        
        for i in range(l):
            mat[i][i] = abs(a[i])
            matSum[i][i] = a[i]
            matMax[i][i] = a[i]
    
        for i in range(l):
            for j in range(i+1,l):
                mat[i][j] = gcd(a[j],mat[i][j-1])
                
        for i in range(l):
            for j in range(i+1,l):
                matSum[i][j] = matSum[i][j-1] + a[j]
        print(matSum)
        for i in range(l):
            for j in range(i+1,l):
                matMax[i][j] = max(matMax[i][j-1],a[j])
        print(matMax)
        for i in range(l):
            for j in range(i,l):
                f = mat[i][j]*(matSum[i][j] - matMax[i][j])
                if f > ma:
                    ma = f
        return ma
                
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        n = int(input())
    
        a = list(map(int, input().rstrip().split()))
    
        result = maximumValue(a)
    
        fptr.write(str(result) + '\n')
    
        fptr.close()