PAT 1040 java & cpp (java is 10 times slower than cpp...)