Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sumof product 1

# 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 :: SUMOFPROD1 codechef solution 
Python :: how to scrape data from a html page saved locally 
Python :: Regular Expression to Stop at First Match 
Python :: python get type of variable 
Python :: python not in list 
Python :: sphinx autodoc extension 
Python :: create bootable usb apple 
Python :: python implementation of Min Heap 
Python :: dataframe summary | dataframe info 
Python :: remove common rows in two dataframes pandas 
Python :: ternary operator in python 
Python :: how to save frames in form of video in opencv python 
Python :: Python Tkinter Scale Widget 
Python :: how to take a list as input in python using sys.srgv 
Python :: listing of django model types 
Python :: if df[col].unique()==2 
Python :: how to extract zip file using python 
Python :: how to multiply in python 
Python :: python install graphviz and 
Python :: merge dataframe using pandas 
Python :: Django rest framework update or delete 
Python :: find if value exists in dictionary python 
Python :: Split the string using the separator 
Python :: how to join an array of characters in python 
Python :: python draw tree 
Python :: // meaning in python 
Python :: python check date between two dates 
Python :: dft numpz phase 
Python :: Python Print Variable Using the string formatting with positional arguments {} 
Python :: merge sort of two list in python 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =