from copy import deepcopy

N = int(eval(input()))

a0 = list(map(int, input().split()))



for i in range(N, 0, -1):

    if a0[i - 1] < 0:

        tmp = 0

        b = []

        for j in range(1, 101):

            if i * j - 1 >= N:

                break

            tmp += a0[i * j - 1]

            b.append(i * j - 1)

        if tmp < 0:

            for j in b:

                a0[j] = 0



for k1 in range(N, 0, -1):

    for k2 in range(k1-1, 0, -1):

        a = deepcopy(a0)

        for j in range(1, 101):

            if k1*j-1 >= N:

                break

            a[k1*j-1] = 0

        for j in range(1, 101):

            if k2*j-1 >= N:

                break

            a[k2*j-1] = 0

        for i in range(N, 0, -1):

            if a[i - 1] < 0:

                tmp = 0

                b = []

                for j in range(1, 101):

                    if i * j - 1 >= N:

                        break

                    tmp += a[i * j - 1]

                    b.append(i * j - 1)

                if tmp < 0:

                    for j in b:

                        a[j] = 0



        for i in range(N, 0, -1):

            if a0[i - 1] < 0:

                tmp = 0

                b = []

                for j in range(1, 101):

                    if i * j - 1 >= N:

                        break

                    tmp += a0[i * j - 1]

                    b.append(i * j - 1)

                if tmp < 0:

                    for j in b:

                        a0[j] = 0



        if sum(a) > sum(a0):

            a0 = a



print((sum(a0)))

def main():

    import sys

    input = sys.stdin.readline



    # Dinic's algorithm

    from collections import deque

    class Dinic:

        def __init__(self, N):

            self.N = N

            self.G = [[] for i in range(N)]



        def add_edge(self, fr, to, cap):

            forward = [to, cap, None]

            forward[2] = backward = [fr, 0, forward]

            self.G[fr].append(forward)

            self.G[to].append(backward)



        def add_multi_edge(self, v1, v2, cap1, cap2):

            edge1 = [v2, cap1, None]

            edge1[2] = edge2 = [v1, cap2, edge1]

            self.G[v1].append(edge1)

            self.G[v2].append(edge2)



        def bfs(self, s, t):

            self.level = level = [None] * self.N

            deq = deque([s])

            level[s] = 0

            G = self.G

            while deq:

                v = deq.popleft()

                lv = level[v] + 1

                for w, cap, _ in G[v]:

                    if cap and level[w] is None:

                        level[w] = lv

                        deq.append(w)

            return level[t] is not None



        def dfs(self, v, t, f):

            if v == t:

                return f

            level = self.level

            for e in self.it[v]:

                w, cap, rev = e

                if cap and level[v] < level[w]:

                    d = self.dfs(w, t, min(f, cap))

                    if d:

                        e[1] -= d

                        rev[1] += d

                        return d

            return 0



        def flow(self, s, t):

            flow = 0

            INF = 10 ** 9 + 7

            G = self.G

            while self.bfs(s, t):

                *self.it, = list(map(iter, self.G))

                f = INF

                while f:

                    f = self.dfs(s, t, INF)

                    flow += f

            return flow



    inf = 1<<40

    N = int(eval(input()))

    A = list(map(int, input().split()))

    dinic = Dinic(N+2)

    ans = 0

    for i, a in enumerate(A):

        if a > 0:

            ans += a

            #dinic.add_edge(0, i+1, 0)

            dinic.add_edge(i+1, N+1, a)

        else:

            dinic.add_edge(0, i+1, -a)

            #dinic.add_edge(i+1, N+1, 0)

    for i in range(1, N+1):

        for k in range(1, N+1):

            if i*k > N:

                break

            dinic.add_edge(i, i*k, inf)



    print((ans - dinic.flow(0, N+1)))





if __name__ == '__main__':

    main()
from copy import deepcopy

N = int(eval(input()))
a0 = list(map(int, input().split()))
for i in range(N, 0, -1):
    if a0[i - 1] < 0:
        tmp = 0
        b = []
        for j in range(1, 101):
            if i * j - 1 >= N:
                break
            tmp += a0[i * j - 1]
            b.append(i * j - 1)
        if tmp < 0:
            for j in b:
                a0[j] = 0
for k1 in range(N, 0, -1):
    for k2 in range(k1 - 1, 0, -1):
        a = deepcopy(a0)
        for j in range(1, 101):
            if k1 * j - 1 >= N:
                break
            a[k1 * j - 1] = 0
        for j in range(1, 101):
            if k2 * j - 1 >= N:
                break
            a[k2 * j - 1] = 0
        for i in range(N, 0, -1):
            if a[i - 1] < 0:
                tmp = 0
                b = []
                for j in range(1, 101):
                    if i * j - 1 >= N:
                        break
                    tmp += a[i * j - 1]
                    b.append(i * j - 1)
                if tmp < 0:
                    for j in b:
                        a[j] = 0
        for i in range(N, 0, -1):
            if a0[i - 1] < 0:
                tmp = 0
                b = []
                for j in range(1, 101):
                    if i * j - 1 >= N:
                        break
                    tmp += a0[i * j - 1]
                    b.append(i * j - 1)
                if tmp < 0:
                    for j in b:
                        a0[j] = 0
        if sum(a) > sum(a0):
            a0 = a
print((sum(a0)))

def main():
    import sys

    input = sys.stdin.readline
    # Dinic's algorithm
    from collections import deque

    class Dinic:
        def __init__(self, N):
            self.N = N
            self.G = [[] for i in range(N)]

        def add_edge(self, fr, to, cap):
            forward = [to, cap, None]
            forward[2] = backward = [fr, 0, forward]
            self.G[fr].append(forward)
            self.G[to].append(backward)

        def add_multi_edge(self, v1, v2, cap1, cap2):
            edge1 = [v2, cap1, None]
            edge1[2] = edge2 = [v1, cap2, edge1]
            self.G[v1].append(edge1)
            self.G[v2].append(edge2)

        def bfs(self, s, t):
            self.level = level = [None] * self.N
            deq = deque([s])
            level[s] = 0
            G = self.G
            while deq:
                v = deq.popleft()
                lv = level[v] + 1
                for w, cap, _ in G[v]:
                    if cap and level[w] is None:
                        level[w] = lv
                        deq.append(w)
            return level[t] is not None

        def dfs(self, v, t, f):
            if v == t:
                return f
            level = self.level
            for e in self.it[v]:
                w, cap, rev = e
                if cap and level[v] < level[w]:
                    d = self.dfs(w, t, min(f, cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
            return 0

        def flow(self, s, t):
            flow = 0
            INF = 10**9 + 7
            G = self.G
            while self.bfs(s, t):
                (*self.it,) = list(map(iter, self.G))
                f = INF
                while f:
                    f = self.dfs(s, t, INF)
                    flow += f
            return flow

    inf = 1 << 40
    N = int(eval(input()))
    A = list(map(int, input().split()))
    dinic = Dinic(N + 2)
    ans = 0
    for i, a in enumerate(A):
        if a > 0:
            ans += a
            # dinic.add_edge(0, i+1, 0)
            dinic.add_edge(i + 1, N + 1, a)
        else:
            dinic.add_edge(0, i + 1, -a)
            # dinic.add_edge(i+1, N+1, 0)
    for i in range(1, N + 1):
        for k in range(1, N + 1):
            if i * k > N:
                break
            dinic.add_edge(i, i * k, inf)
    print((ans - dinic.flow(0, N + 1)))


if __name__ == "__main__":
    main()

-from copy import deepcopy +def main(): +    import sys -N = int(eval(input())) -a0 = list(map(int, input().split())) -for i in range(N, 0, -1): -    if a0[i - 1] < 0: -        tmp = 0 -        b = [] -        for j in range(1, 101): -            if i * j - 1 >= N: +    input = sys.stdin.readline +    # Dinic's algorithm +    from collections import deque + +    class Dinic: +        def __init__(self, N): +            self.N = N +            self.G = [[] for i in range(N)] + +        def add_edge(self, fr, to, cap): +            forward = [to, cap, None] +            forward[2] = backward = [fr, 0, forward] +            self.G[fr].append(forward) +            self.G[to].append(backward) + +        def add_multi_edge(self, v1, v2, cap1, cap2): +            edge1 = [v2, cap1, None] +            edge1[2] = edge2 = [v1, cap2, edge1] +            self.G[v1].append(edge1) +            self.G[v2].append(edge2) + +        def bfs(self, s, t): +            self.level = level = [None] * self.N +            deq = deque([s]) +            level[s] = 0 +            G = self.G +            while deq: +                v = deq.popleft() +                lv = level[v] + 1 +                for w, cap, _ in G[v]: +                    if cap and level[w] is None: +                        level[w] = lv +                        deq.append(w) +            return level[t] is not None + +        def dfs(self, v, t, f): +            if v == t: +                return f +            level = self.level +            for e in self.it[v]: +                w, cap, rev = e +                if cap and level[v] < level[w]: +                    d = self.dfs(w, t, min(f, cap)) +                    if d: +                        e[1] -= d +                        rev[1] += d +                        return d +            return 0 + +        def flow(self, s, t): +            flow = 0 +            INF = 10**9 + 7 +            G = self.G +            while self.bfs(s, t): +                (*self.it,) = list(map(iter, self.G)) +                f = INF +                while f: +                    f = self.dfs(s, t, INF) +                    flow += f +            return flow + +    inf = 1 << 40 +    N = int(eval(input())) +    A = list(map(int, input().split())) +    dinic = Dinic(N + 2) +    ans = 0 +    for i, a in enumerate(A): +        if a > 0: +            ans += a +            # dinic.add_edge(0, i+1, 0) +            dinic.add_edge(i + 1, N + 1, a) +        else: +            dinic.add_edge(0, i + 1, -a) +            # dinic.add_edge(i+1, N+1, 0) +    for i in range(1, N + 1): +        for k in range(1, N + 1): +            if i * k > N: -            tmp += a0[i * j - 1] -            b.append(i * j - 1) -        if tmp < 0: -            for j in b: -                a0[j] = 0 -for k1 in range(N, 0, -1): -    for k2 in range(k1 - 1, 0, -1): -        a = deepcopy(a0) -        for j in range(1, 101): -            if k1 * j - 1 >= N: -                break -            a[k1 * j - 1] = 0 -        for j in range(1, 101): -            if k2 * j - 1 >= N: -                break -            a[k2 * j - 1] = 0 -        for i in range(N, 0, -1): -            if a[i - 1] < 0: -                tmp = 0 -                b = [] -                for j in range(1, 101): -                    if i * j - 1 >= N: -                        break -                    tmp += a[i * j - 1] -                    b.append(i * j - 1) -                if tmp < 0: -                    for j in b: -                        a[j] = 0 -        for i in range(N, 0, -1): -            if a0[i - 1] < 0: -                tmp = 0 -                b = [] -                for j in range(1, 101): -                    if i * j - 1 >= N: -                        break -                    tmp += a0[i * j - 1] -                    b.append(i * j - 1) -                if tmp < 0: -                    for j in b: -                        a0[j] = 0 -        if sum(a) > sum(a0): -            a0 = a -print((sum(a0))) +            dinic.add_edge(i, i * k, inf) +    print((ans - dinic.flow(0, N + 1))) + + +if __name__ == "__main__": +    main()