<>;$_.=<>;s/(-?\d+ )((?1))(\W\B)/"$1$3 $2"/ee?do$0:print