kamiari algorithm