Find S Algorithm Implementation In Python