longlongequal(vector<int> arr){ vector<longlong> req(5); longlong mi = *min_element(begin(arr), end(arr)); // make minimum - 0 to minimum - 4 and get minimin operations for(int i = 0; i < 5; i++) { for(auto& a : arr) { longlong d = a - mi; longlong five = 0, two = 0, one = 0; five = d / 5; d -= 5 * five; two = d / 2; d -= 2 * two; one = d; req[i] += five + two + one; } mi--; } return *min_element(begin(req), end(req)); }