Algorithm (Pascal language description, for noi&noip)