#include #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #define fi first #define se second #define int long long #define vec vector using namespace std; void solve() { int n, k; cin>>n>>k; vec a(n); for(int i = 0;i>a[i]; } vec> pred(n, vec(32, -1)); vec cur(32, -1); for(int i = 0;i 0 ){ cur[j] = i; } } pred[i] = cur; } vec block(n, -1); for(int i = 0;i 0)){ mn = min(pred[i][j], mn); } } if(block[i] >= mn){ continue; } else{ ans += (mn - block[i]); } } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tests = 1; while(tests--) { solve(); } }