final codes of first stage