#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
stack<char> st;
for(char c : s) {
if(!st.empty() && st.top() == c) {
st.pop(); // 如果当前字符与栈顶相同,消除
} else {
st.push(c); // 否则入栈
}
}
// 构建结果字符串
string res = "";
while(!st.empty()) {
res = st.top() + res;
st.pop();
}
return res.empty() ? "0" : res;
}
int main() {
string s;
cin >> s;
cout << solve(s) << endl;
return 0;
}
import java.util.*;
public class Main {
public static String solve(String s) {
Stack<Character> st = new Stack<>();
for(char c : s.toCharArray()) {
if(!st.empty() && st.peek() == c) {
st.pop();
} else {
st.push(c);
}
}
// 构建结果字符串
StringBuilder res = new StringBuilder();
while(!st.empty()) {
res.insert(0, st.pop());
}
return res.length() == 0 ? "0" : res.toString();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
System.out.println(solve(s));
}
}
def solve(s):
st = []
for c in s:
if st and st[-1] == c:
st.pop()
else:
st.append(c)
return ''.join(st) or '0'
# 读取输入
s = input()
print(solve(s))