#include <algorithm> #include <iostream> #include <stack> using namespace std; int arr[50005]; int ap1[50005]; int ap2[50005]; stack<int> st; int main() { int t; cin >> t; int s = 1; while (t--) { int n; scanf("%d", &n);...