intmain(){ scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); if (a[0] != 0) returnputs("1"), 0; int m = 0; for (int i = 1; i < n; i++){ if (a[i] > m + 1){ printf("%d", i + 1); return0; } m = max(a[i], m); } puts("-1"); return0; }
intmain(){ scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", l + i); for (int i = 0; i < n; i++) scanf("%d", r + i); if (l[0] != 0 || r[n - 1] != 0) returnputs("NO"), 0; for (int i = 0; i < n; i++){ a[i] = n - l[i] - r[i]; if (a[i] < 1) returnputs("NO"), 0; } for (int i = 0; i < n; i++){ int s1 = 0, s2 = 0; for (int j = 0; j < n; j++){ if (j < i && a[i] < a[j]) s1++; if (j > i && a[i] < a[j]) s2++; } if (s1 != l[i] || s2 != r[i]) returnputs("NO"), 0; } puts("YES"); for (int i = 0; i < n; i++) printf("%d ", a[i]); return0; }
intmain(){ scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); int s = 0; mp[0] = 1; for (int i = 0; i < n; i++){ int p = s ^ a[i], q = s ^ ((1 << k) - 1 - a[i]); if (mp[p] <= mp[q]) mp[s = p]++; else mp[s = q]++; } ll ans = 1ll * n * (n + 1) / 2; for (auto& x : mp){ int c = x.second; ans -= 1ll * c * (c - 1) / 2; } printf("%I64d", ans); return0; }