package 剑指Offer;
import java.util.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNext()) {
String s = scan.next();
//System.out.print(s);
Stack stack = new Stack();
for(int i = 0; i < s.length(); i++) {
char a = s.charAt(i);
//System.out.print(a + " ");
while((a < 'a'||a > 'z') && (a < 'A'||a > 'Z')) {
while(!stack.empty()) {
char temp = (char) stack.pop();
System.out.print(temp);
}
System.out.print(a);
if(i + 1 < s.length()) {
i++;
a = s.charAt(i);
} else {
//System.out.println();
i++;
break;
}
}
//char b = s.charAt(s.length());
//if((b < 'a'||a > 'z') && (a < 'A'||a > 'Z')) {
if(i == s.length()) {
break;
}
stack.push(a);
}
while(!stack.empty()) {
char temp = (char) stack.pop();
System.out.print(temp);
}
System.out.print(" ");
}
//System.out.println();
}
/* public static void charSort(char temp) {
if((a < 'a'||a > 'z') && (a < 'A'||a > 'Z')) {
while(!stack.empty()) {
char temp = (char) stack.pop();
System.out.print(temp);
}
System.out.print(a);
if(i + 1 < s.length()) {
i++;
a = s.charAt(i);
} else {
//System.out.println();
break;
}
}
}*/
}