intmain(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) f[i][i][0] = 1; for (int l = 1; l < n; ++l) for (int i = 1; i + l - 1 <= n; ++i) { int j = i + l - 1; if (i && a[i - 1] < a[i]) add(f[i - 1][j][0], f[i][j][0]); if (i && a[i - 1] < a[j]) add(f[i - 1][j][0], f[i][j][1]); if (j < n && a[j + 1] > a[i]) add(f[i][j + 1][1], f[i][j][0]); if (j < n && a[j + 1] > a[j]) add(f[i][j + 1][1], f[i][j][1]); } cout << (f[1][n][0] + f[1][n][1]) % p << endl; return0; }