Problem IMO 1979 3
tested using advanced optimizations.