pat 1056 java version time out
APAT1056 C++ implementation