dominator function on codility