#include <stack>
#include <unordered_set>
#include <string>
#include <iostream>
using stkC = std::stack<char>;
using str = std::string;
using usetC = std::unordered_set<char>;
class Solution {
public:
usetC spec = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')'};
str reverseByType(str s) {
if (s.length() == 1) return s;
str ans;
stkC nor, spe; // Normal Chars, Speciula Chars
for (const char c: s) {
if (spec.contains(c)) spe.push(c);
else nor.push(c);
}
for (const char c: s) {
if (spec.contains(c)) {
ans += spe.top(); spe.pop();
} else {
ans += nor.top(); nor.pop();
}
}
return ans;
}
};
int main() {
str ip = ")ebc#da@f(";
Solution sol;
str res = sol.reverseByType(ip);
std::cout << res << "\n";
return 0;
}