Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

SUMOFPROD1

# Sum of Product 1:
# First system:

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))[:n]
    res = 0
    c = 0
    for i in range(n):
        if arr[i] == 1:
            c += 1
        else:
            res += c*(c+1)//2
            c = 0
    res += c*(c+1)//2
    print(res)
    
# Second system:

'''
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))[:n]
    res = 0
    c = 0
    for i in range(n):
        if arr[i] == 0:
            c = 0
        else:
            c += 1
        res += c
    print(res)
'''
Comment

PREVIOUS NEXT
Code Example
Python :: .counter python 
Python :: plynomial regression implementation python 
Python :: python find if string contains space 
Python :: return function python 
Python :: how to print 2 list in python as table 
Python :: create data frame in panda 
Python :: bubble sort in python 
Python :: the shape of your array numpy 
Python :: {:.1%} print one decimal pandas 
Python :: python hash and unhash string 
Python :: %s in python 
Python :: max value pandas 
Python :: how to convert string to float in python 
Python :: python tkinter menu widget 
Python :: python asyncio.run() 
Python :: use mark down with flask 
Python :: transpose of a matrix in python numpy 
Python :: python serve html 
Python :: Socket Programming Server Side 
Python :: re.search() 
Python :: DIVAB Solution 
Python :: python tkinter button color 
Python :: how to add one to a variable in python 
Python :: python online practice test 
Python :: load specific columns dataframe 
Python :: python print() 
Python :: pandas shape 
Python :: find the sitepckages for anaconda 
Python :: create frequency tables in pandas 
Python :: append two 1d arrays python 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =