#include "../head.h"
#include <stack>
bool stackPermutation(stack<int> &A, stack<int> &B) {
stack<int> S, temp;
while (!B.empty()) {
temp.push(B.top());
B.pop();
}
while (!A.empty()) {
S.push(A.top());
A.pop();
if (temp.top() == S.top()) {
temp.pop();
S.pop();
while (!S.empty()) {
if (temp.top() == S.top()) {
temp.pop();
S.pop();
}
else return false;
}
}
}
return S.empty();
}
int main(int argc, char** argv) {
stack<int> a, b;
int ta, tb;
cout << "the base stack [--->: [";
while (cin >> ta)
a.push(ta);
if (cin.eof())
cout << "endoffile";
cin.clear();
cout << endl;
cout << "the test stack [--->: [";
while (cin >> tb)
b.push(tb);
if (stackPermutation(a, b))
cout << "true" << endl;
else cout << "false" << endl;
return 0;
}