let foldi f a acc = 
    snd (Array.fold_right (fun v (i,acc) -> (i+1,f i v acc)) a (0,acc))