Problem: We have N gemstones labeled 1 through N.  You can perform the following operation any number of times (possibly zero).    * Select a positive integer x, and smash all the gems labeled with multiples of x.  Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money.  By optimally performing the operation, how much yen can you earn?

Submission attempts (in order):
class Ford_Fulkerson:

	def __init__(self, v, inf=float("inf")):
		self.V = v
		self.inf = inf
		self.G = [[] for _ in range(v)]
		self.used = [False for _ in range(v)]

	def addEdge(self, fm, to, cap):
		self.G[fm].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
		self.G[to].append({'to':fm, 'cap':0, 'rev':len(self.G[fm])-1})


	def dfs(self, v, t, f):
		if v == t: return f
		self.used[v] = True

		for i in range(len(self.G[v])):
			e = self.G[v][i]
			if self.used[e["to"]] != True and e['cap'] > 0:
				d = self.dfs(e['to'], t ,min(f, e['cap']))
				if d > 0:
					e['cap'] -= d
					self.G[e['to']][e['rev']]['cap'] += d
					return d
		return 0

	def max_flow(self,s,t):
		flow = 0
		while True:
			self.used = [False for i in range(self.V)]
			f = self.dfs(s,t,self.inf)
			if f == 0: return flow
			flow += f


from sys import stdin, setrecursionlimit
def IL():return list(map(int, stdin.readline().split()))

setrecursionlimit(1000000)

def main():
    N = int(input())
    a=[-1]
    for i in IL():
        a.append(i)
        
    d = Ford_Fulkerson(102)
    s=0
    t=N+1
    
    _i=1
    _j=2
    while _i <= N:
        while _i*_j <=N:
            d.addEdge(_i, _i*_j, float("inf"))
            _j += 1
        _i += 1
    
    
    i=1
    while i <= N:
        d.addEdge(s,i,max(-a[i],0))
        d.addEdge(i,t,max(a[i],0))
        i+=1
    res = sum([max(i,0) for i in a])
 
    print(res - d.max_flow(s,t))
   
    
if __name__ == "__main__": main()

class Ford_Fulkerson:

	def __init__(self, v, inf=float("inf")):
		self.V = v
		self.inf = inf
		self.G = [[] for _ in range(v)]
		self.used = [False for _ in range(v)]

	def addEdge(self, fm, to, cap):
		
		self.G[fm].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
		self.G[to].append({'to':fm, 'cap':0, 'rev':len(self.G[fm])-1})


	def dfs(self, v, t, f):
		if v == t: return f
		self.used[v] = True

		for i in range(len(self.G[v])):
			e = self.G[v][i]
			if self.used[e["to"]] != True and e['cap'] > 0:
				d = self.dfs(e['to'], t ,min(f, e['cap']))
				if d > 0:
					e['cap'] -= d
					self.G[e['to']][e['rev']]['cap'] += d
					return d
		return 0

	def max_flow(self,s,t):
		flow = 0
		while True:
			self.used = [False for i in range(self.V)]
			f = self.dfs(s,t,self.inf)
			if f == 0: return flow
			flow += f



from sys import stdin, setrecursionlimit
def IL():return list(map(int, stdin.readline().split()))
 
setrecursionlimit(1000000)

def main():
	N = int(input())
	a = IL()
	d = Ford_Fulkerson(N+2)
	res = 0
	for i in range(N):
	    d.addEdge(N,i, max(0, -a[i]))
	    d.addEdge(i,N+1, max(0,a[i]))
	    res+=max(0,a[i])
	    t = 2*i+2
	    while t<=N:
	        d.addEdge(i,t-1,float('inf'))
	        t+=i+1
	print(res-d.max_flow(N,N+1))
	
	
if __name__ == "__main__": main()

Verdicts: Wrong Answer

Accepted