// 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 mut res = (0..p-1).filter(|x| self.cnt[*x] == 0).map(|x| self.a[x]).sum();
            // debug!(p);
            // debug!(self.cnt);
            // debug!(res);
            for i in (p..self.n+1).rev() {
                if i%2 == 0 && i/2 >= p {
                    continue;
                }
                if i+i > self.n {
                    if self.a[i-1] > 0 && self.cnt[i-1] == 0 {
                        res += self.a[i-1];
                    }
                } else {
                    use std::cmp::max;
                    if self.cnt[i-1] == 0 {
                        if self.cnt[i+i-1] > 0 {
                            res += max(0, self.a[i-1]);
                        } else {
                            res += max(0, max(self.a[i-1], self.a[i-1]+self.a[i+i-1]));
                        }
                    }
                }
            }
            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