// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

#[derive(Debug)]
struct Solver {
    n: usize,
    a: Vec<i64>,
    cnt: Vec<u32>,
}

impl Solver {
    fn solve(&mut self, p: usize) -> i64 {
        if p*3 > self.n {
            let n = self.n;
            let mut cnt = self.cnt.clone();
            for i in (p..self.n+1).rev() {
                if cnt[i-1] > 0 || self.a[i-1] > 0 {
                    continue;
                }
                if i+i > self.n {
                    cnt[i-1] += 1;
                } else {
                    let mut sum = self.a[i-1];
                    if cnt[(i+i)-1] == 0 {
                        sum += self.a[i+i-1];
                    }
                    if sum < 0 {
                        cnt[(i-1)] += 1;
                        cnt[(i+i)-1] += 1;
                    }
                }
                // let mut j = i;
                // let mut sum = 0;
                // while j <= self.n {
                //     if cnt[j-1] == 0 {
                //         sum += self.a[j-1];
                //     }
                //     j += i;
                // }
                // if sum < 0 && self.a[p-1] < 0 {
                //     let mut j = i;
                //     while j <= self.n {
                //         cnt[j-1] += 1;
                //         j += i;
                //     }
                // }
            }
            let res = (0..self.n).filter(|x| cnt[*x] == 0).map(|x| self.a[x]).sum();
            res
        } else {
            let mut ret = self.solve(p+1);
            if self.cnt[p-1] == 0 {
                let mut j = p;
                while j <= self.n {
                    self.cnt[j-1] += 1;
                    j += p;
                }
                ret = std::cmp::max(ret, self.solve(p+1));
                j = p;
                while j <= self.n {
                    self.cnt[j-1] -= 1;
                    j += p;
                }
            }
            ret
        }
    }
}

fn main() {
    let n = readl!(usize);
    let a = readlvec!(i64);
    let mut solver = Solver {n: n, a: a, cnt: vec![0;n]};
    // debug!(solver.solve(1));
    println!("{}", solver.solve(1));
    // debug!(solver);
}



Measured memory_bytes: 4352