This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
 *    author:  wxhtzdy
 *    created: 03.07.2022 11:20:17
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int L = 0, R = -2;
  for (int i = 0; i < n; i++) {
    for (int j = i + k - 1; j < n; j += k) {
      int len = (j - i + 1) / k;
      if (len <= R - L) {
        continue;
      }
      bool ok = true;            
      for (int p = i; p <= j; p++) {
        ok = (ok & (a[p] == a[i + (p - i) % len]));   
      }
      if (ok) {
        L = i;
        R = i + (j - i) / k;
      }
    }
  }
  cout << R - L + 1 << '\n';
  for (int i = L; i <= R; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |