Algorithm


E. Subsegments
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in , which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find the maximum element of those that occur on the given segment exactly once. Help Sasha solve this problem.

Input

The first line contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ n) — the number of array elements and the length of the segment.

Then follow n lines: the i-th one contains a single number ai ( - 109 ≤ ai ≤ 109).

Output

Print nk + 1 numbers, one per line: on the i-th line print of the maximum number of those numbers from the subarray ai ai + 1 … ai + k - 1 that occur in this subarray exactly 1 time. If there are no such numbers in this subarray, print "Nothing".

Examples
input
Copy
5 3
1
2
2
3
3
output
Copy
1
3
2
input
Copy
6 4
3
3
3
4
4
2
output
Copy
4
Nothing
3



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

struct lex_compare {
  bool operator() (const pair<int, int>& lhs, const pair<int, int>& rhs) const {
    if(lhs.second != rhs.second)
      return lhs.second < rhs.second;
    return lhs.first > rhs.first;
  }
};

int const N = 1e5 + 1;
int n, k, a[N], fr[N];
vector<int> all;
set<pair<int, int>, lex_compare> st;

int main() {
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		all.push_back(a[i]);
	}

	sort(all.begin(), all.end());
	all.resize(unique(all.begin(), all.end()) - all.begin());

	for(int i = 0; i < n; ++i)
		a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin();

	for(int i = 0; i < k; ++i)
		++fr[a[i]];

	for(int i = 0; i < N; ++i)
		if(fr[i] != 0)
			st.insert({i, fr[i]});

	int l = 0, r = k - 1;
	do {
		if((*st.begin()).second == 1)
			printf("%d\n", all[(*st.begin()).first]);
		else
			puts("Nothing");

		st.erase({a[l], fr[a[l]]});
		--fr[a[l]];
		if(fr[a[l]] != 0)
			st.insert({a[l], fr[a[l]]});

		++l, ++r;
		if(r >= n)
			break;

		if(fr[a[r]] != 0)
			st.erase({a[r], fr[a[r]]});

		++fr[a[r]];
		st.insert({a[r], fr[a[r]]});
	} while(r < n);

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 3
1
2
2
3
3

Output

x
+
cmd
1
3
2
Advertisements

Demonstration


Codeforcess Solution Subsegments, E. Subsegments C,C++, Java, Js and Python ,E. Subsegments,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+