Ex4 fist version of cost with more vectorization