import check

sums = 0
for i in range(2,5):
	sq = i*i
	sums = sums + sq
print(i)
print(sums)
	
		
for j in range(10,2,2):
    print(j)
#print(j)


flag = False
if flag == True:
    M = [[1,2,3], [[4],[5, 6]], [7,8,9], [10, []]]
    print(len(M))
    print(M[0])
    print(len(M[0]))
    print(M[0][2])
    print(len(M[1]), len(M[1][1]))
    print(M[1][1][1])
    print(M[3][0])
    print(len(M[3][1]))
    
print("---")

## nested(max) produces the largest value in alol
## nested_max: (listof (listof Int)) -> Int
## requires: alol is nonempty
##           Lists in alol are nonempty
## Example:
## nested_max([[1,5,3], [3],[35,1,2]]) =>  35
def nested_max(alol):
    ### set the initial value
    cur_max = alol[0][0]
    for L in alol:
        print(L)
        for elem in L:
            if elem > cur_max:
                cur_max = elem
    return cur_max

check.expect("nm1",  nested_max([[1,5,3], [3],[35,1,2]]),   35)    


L = [2,4,6,8,10]
for x in L:
    if x%2==0:
        L.remove(x)
print(L)

## This is the corrected version of the above code!
L = [2,4,6,8,10]
p = 0
while p < len(L):
    if L[p] % 2 == 0:
       L.pop(p)
    else:
       # Only increment if you didn't pop!
       p += 1



##Using accumulative [and possibly generative] recursion, write a
##function sum_duplicates that consumes a list of integers and
##produces the sum of all the duplicate elements in your list. 
##For example, sum_duplicates([3,3,3,5,5,6])=> 19
##Bonus: Can you do this without using any extra lists?

## Remember, to be accumulative recursion, you need:
## 1. An accumulator
## 2. To return the accumulator in the base case
## (Note: Helper functions are likely required but
## strictly speaking not necessary).

def sum_duplicates_acc(L,acc,pos):
    if pos == len(L):
        return acc
    val = L.count(L[pos])
    if val > 1 and L[pos] not in L[0:pos]:
        acc += val*L[pos]
    return sum_duplicates_acc(L,acc,pos+1)

def sum_duplicates(L):
    return sum_duplicates_acc(L,0,0)