Because you are un-syncing the two output streams by having the line “ios_base::sync_with_stdio(false);” in your code, and because you are having both printf and cout statements, the output becomes interleaved (see the example in that linked page).
If you just comment out the sync_with_stdio statement, your code gets AC-ed.