// mc4b.cpp : Defines the entry point for the console application. // #include #include #include using namespace std; struct NOD { int index; int val; }; int n, i, a[105000]; bool instack[1000500]; stack stiva; int main() { cin >> n; for (i = 1; i <= 2 * n; i++) { cin >> a[i]; } int cnt = 0; for (i = 1; i <= 2 * n; i++) { if (instack[a[i]]) { while (!stiva.empty() && stiva.top() != a[i]) { cnt++; instack[stiva.top()] = false; stiva.pop(); } instack[stiva.top()] = false; stiva.pop(); } else { stiva.push(a[i]); instack[a[i]] = true; } } cout << cnt; }