QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220379#5167. 魔术师hos_lyric#30 860ms32756kbC++145.6kb2023-10-20 09:24:482024-07-04 02:20:40

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:20:40]
  • 评测
  • 测评结果:30
  • 用时:860ms
  • 内存:32756kb
  • [2023-10-20 09:24:48]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


void expr() {
  for (int n = 1; n <= 10; ++n) {
    cerr << n << ":";
    for (int m = 1; m <= n; ++m) {
      queue<vector<int>> que;
      set<vector<int>> vis;
      {
        vector<int> ini(n);
        for (int i = 0; i < n; ++i) ini[i] = i;
        vis.insert(ini);
        que.push(ini);
      }
      for (; !que.empty(); ) {
        const auto as = que.front();
        que.pop();
        auto bs = as;
        for (int i = 0; i <= n - m; ++i) {
          reverse(bs.begin() + i, bs.begin() + (i + m));
          if (vis.insert(bs).second) {
            if (n == 6 && m == 4) {
              cout << as << " " << i << " " << bs << endl;
            }
            que.push(bs);
          }
          reverse(bs.begin() + i, bs.begin() + (i + m));
        }
      }
      cerr << " " << vis.size();
    }
    cerr << endl;
  }
}
/*
1: 1
2: 1 2
3: 1 6 2
4: 1 24 4 2
5: 1 120 12 10 2
6: 1 720 36 360 6 2
7: 1 5040 144 2520 72 14 2
8: 1 40320 576 20160 288 40320 8 2
9: 1 362880 2880 181440 1440 362880 480 18 2
10: 1 3628800 14400 1814400 7200 3628800 14400 1814400 10 2
*/


vector<int> brute(int n, int m, const vector<int> &ps) {
  assert(n <= 10);
  assert((int)ps.size() >= n);
  vector<int> fac(n + 1);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i;
  auto encode = [&](const vector<int> &as) -> int {
    int remain = (1 << n) - 1;
    int u = 0;
    for (int i = 0; i < n; ++i) {
      remain -= (1 << as[i]);
      (u *= (n - i)) += __builtin_popcount(remain & ((1 << as[i]) - 1));
    }
    return u;
  };
  auto decode = [&](int u) -> vector<int> {
    vector<int> as(n);
    for (int i = n; --i >= 0; ) {
      as[i] = u % (n - i);
      u /= (n - i);
      for (int j = i + 1; j < n; ++j) if (as[i] <= as[j]) ++as[j];
    }
    return as;
  };
  queue<int> que;
  vector<pair<int, int>> prv(fac[n], make_pair(-1, -1));
  prv[0] = make_pair(-2, -2);
  que.push(0);
  for (; !que.empty(); ) {
    const int u = que.front();
    que.pop();
    auto as = decode(u);
    for (int i = 0; i <= n - m; ++i) {
      reverse(as.begin() + i, as.begin() + (i + m));
      const int v = encode(as);
      if (!~prv[v].first) {
        prv[v] = make_pair(u, i);
        que.push(v);
      }
      reverse(as.begin() + i, as.begin() + (i + m));
    }
  }
  {
    int v = encode(ps);
    if (~prv[v].first) {
      vector<int> ans;
      for (; v != 0; ) {
        ans.push_back(prv[v].second);
        v = prv[v].first;
      }
      return ans;
    } else {
      return {-1};
    }
  }
}

int T, N, M;
vector<int> P;

vector<int> solve() {
  vector<int> ops;
  auto ps = P;
  auto check = [&]() -> bool {
    for (int i = 0; i < N; ++i) if (ps[i] != i) return false;
    return true;
  };
  auto oper = [&](int l) -> void {
    const int r = l + M;
    assert(0 <= l); assert(r <= N);
    ops.push_back(l);
    reverse(ps.begin() + l, ps.begin() + r);
  };
  if (M == 1) {
    if (check()) return ops;
    return {-1};
  } else if (M == N) {
    if (check()) return ops;
    oper(0);
    if (check()) return ops;
    return {-1};
  } else if (M == N - 1) {
    for (int h = 0; h < N; ++h) {
      if (check()) return ops;
      oper(0);
      if (check()) return ops;
      oper(1);
    }
    return {-1};
  } else {
    const int n0 = min(M + 2 + (M & 1), N);
    int n = N;
    for (; n > n0; --n) {
      int i = find(ps.begin(), ps.begin() + n, n - 1) - ps.begin();
      for (; i + (M-1) <= n - 1; i += (M-1)) {
        oper(i);
      }
      for (; ; ) {
        if (ps[n - 1] == n - 1) break;
        oper(n - M - 1);
        if (ps[n - 1] == n - 1) break;
        oper(n - M);
      }
    }
// cerr<<"n = "<<n<<", ops = "<<ops<<", ps = "<<ps<<endl;
    assert(n == n0);
    const auto res = brute(n, M, ps);
    if (res != vector<int>{-1}) {
      for (const int op : res) {
        oper(op);
      }
      assert(check());
      return ops;
    } else {
      return {-1};
    }
  }
}

int main() {
  // expr();
  
  for (; ~scanf("%d%d%d", &T, &N, &M); ) {
    P.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &P[i]);
      --P[i];
    }
    
    const auto ans = solve();
    if (ans != vector<int>{-1}) {
      printf("%d\n", (int)ans.size());
      for (const int op : ans) {
        printf("%d\n", op);
      }
    } else {
      puts("-1");
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 3804kb

input:

1 1 1
1

output:

0

result:

ok Perfect :) Use 0 operations

Test #2:

score: 5
Accepted
time: 0ms
memory: 3776kb

input:

1 10 1
1 2 3 4 5 6 7 8 9 10

output:

0

result:

ok Perfect :) Use 0 operations

Test #3:

score: 5
Accepted
time: 0ms
memory: 3720kb

input:

1 10 1
1 2 3 4 5 6 9 10 7 8

output:

-1

result:

ok No solutions

Test #4:

score: 5
Accepted
time: 0ms
memory: 4068kb

input:

1 4 3
1 2 3 4

output:

0

result:

ok Perfect :) Use 0 operations

Test #5:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

1 5 3
5 2 1 4 3

output:

2
0
2

result:

ok Perfect :) Use 2 operations

Test #6:

score: 5
Accepted
time: 0ms
memory: 3736kb

input:

1 5 3
3 2 1 4 5

output:

1
0

result:

ok Perfect :) Use 1 operations

Test #7:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

1 5 3
5 2 3 4 1

output:

3
0
2
0

result:

ok Perfect :) Use 3 operations

Test #8:

score: 5
Accepted
time: 0ms
memory: 4068kb

input:

1 10 3
9 10 5 4 3 8 7 2 1 6

output:

15
1
3
5
7
0
2
4
6
3
5
4
0
2
1
0

result:

ok Perfect :) Use 15 operations

Test #9:

score: 5
Accepted
time: 0ms
memory: 3880kb

input:

1 5 5
5 4 3 2 1

output:

1
0

result:

ok Perfect :) Use 1 operations

Test #10:

score: 5
Accepted
time: 0ms
memory: 3864kb

input:

1 6 5
5 6 1 2 3 4

output:

4
0
1
0
1

result:

ok Perfect :) Use 4 operations

Test #11:

score: 5
Accepted
time: 0ms
memory: 3908kb

input:

1 6 5
3 2 1 4 5 6

output:

-1

result:

ok No solutions

Test #12:

score: 5
Accepted
time: 0ms
memory: 3656kb

input:

1 6 5
6 5 4 3 2 1

output:

-1

result:

ok No solutions

Test #13:

score: 5
Accepted
time: 0ms
memory: 4104kb

input:

1 7 5
3 2 7 6 1 4 5

output:

3
0
2
1

result:

ok Perfect :) Use 3 operations

Test #14:

score: 5
Accepted
time: 0ms
memory: 3748kb

input:

1 7 5
5 2 7 4 3 6 1

output:

-1

result:

ok No solutions

Test #15:

score: 5
Accepted
time: 1ms
memory: 4040kb

input:

1 10 5
1 6 3 2 5 8 7 10 9 4

output:

6
4
5
4
2
3
1

result:

ok Perfect :) Use 6 operations

Test #16:

score: 5
Accepted
time: 1ms
memory: 3608kb

input:

1 10 5
5 8 3 10 1 4 9 2 7 6

output:

-1

result:

ok No solutions

Test #17:

score: 5
Accepted
time: 1ms
memory: 6076kb

input:

1 9 7
7 8 5 6 9 4 1 2 3

output:

9
0
1
2
0
2
1
0
1
0

result:

ok Perfect :) Use 9 operations

Test #18:

score: 5
Accepted
time: 2ms
memory: 6056kb

input:

1 9 7
1 6 9 8 3 2 5 4 7

output:

-1

result:

ok No solutions

Test #19:

score: 5
Accepted
time: 8ms
memory: 31520kb

input:

1 10 7
9 8 7 6 1 4 3 10 5 2

output:

8
0
2
0
1
3
2
3
0

result:

ok Perfect :) Use 8 operations

Test #20:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

1 10 9
3 4 5 6 7 8 9 10 1 2

output:

2
0
1

result:

ok Perfect :) Use 2 operations

Subtask #2:

score: 5
Accepted

Test #21:

score: 5
Accepted
time: 0ms
memory: 3864kb

input:

2 2 2
2 1

output:

1
0

result:

ok Perfect :) Use 1 operations

Test #22:

score: 5
Accepted
time: 1ms
memory: 3804kb

input:

2 3 2
1 3 2

output:

5
0
1
0
1
0

result:

ok Perfect :) Use 5 operations

Test #23:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

2 10 2
2 9 1 3 7 6 8 4 5 10

output:

15
1
2
3
4
5
6
7
5
6
3
4
5
3
4
0

result:

ok Perfect :) Use 15 operations

Test #24:

score: 5
Accepted
time: 0ms
memory: 3812kb

input:

2 4 4
1 2 3 4

output:

0

result:

ok Perfect :) Use 0 operations

Test #25:

score: 5
Accepted
time: 0ms
memory: 3808kb

input:

2 5 4
1 5 4 3 2

output:

9
0
1
0
1
0
1
0
1
0

result:

ok Perfect :) Use 9 operations

Test #26:

score: 5
Accepted
time: 0ms
memory: 3612kb

input:

2 4 4
3 4 1 2

output:

-1

result:

ok No solutions

Test #27:

score: 5
Accepted
time: 0ms
memory: 3716kb

input:

2 5 4
4 5 2 3 1

output:

-1

result:

ok No solutions

Test #28:

score: 5
Accepted
time: 0ms
memory: 3864kb

input:

2 10 4
3 5 10 9 1 7 6 2 8 4

output:

37
2
5
5
6
5
6
5
6
4
4
5
4
5
4
5
3
4
3
4
3
4
2
2
3
2
3
2
3
2
1
2
0
1
2
1
0
2

result:

ok Perfect :) Use 37 operations

Test #29:

score: 5
Accepted
time: 0ms
memory: 3936kb

input:

2 10 4
7 8 9 6 5 2 1 3 10 4

output:

-1

result:

ok No solutions

Test #30:

score: 5
Accepted
time: 10ms
memory: 3804kb

input:

2 10 6
7 3 5 10 1 9 8 2 6 4

output:

39
3
3
4
3
4
3
4
3
4
2
3
2
3
2
3
2
3
1
2
1
2
0
2
1
0
1
0
1
2
0
2
0
1
0
1
0
1
2
0

result:

ok Perfect :) Use 39 operations

Test #31:

score: 5
Accepted
time: 841ms
memory: 32492kb

input:

2 10 8
8 5 10 3 9 6 1 7 2 4

output:

30
0
2
1
2
0
2
1
0
1
0
1
2
0
1
0
2
1
0
1
0
1
0
1
0
2
0
1
0
2
0

result:

ok Perfect :) Use 30 operations

Test #32:

score: 5
Accepted
time: 860ms
memory: 32424kb

input:

2 10 8
5 4 3 2 6 1 9 10 8 7

output:

24
1
0
1
2
1
0
2
0
1
0
2
1
2
1
0
1
0
1
2
1
2
0
2
1

result:

ok Perfect :) Use 24 operations

Test #33:

score: 5
Accepted
time: 860ms
memory: 32452kb

input:

2 10 8
8 5 1 9 3 7 6 2 10 4

output:

-1

result:

ok No solutions

Test #34:

score: 5
Accepted
time: 0ms
memory: 3780kb

input:

2 10 10
10 9 8 7 6 5 4 3 2 1

output:

1
0

result:

ok Perfect :) Use 1 operations

Test #35:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

2 10 10
6 5 3 4 9 1 7 10 8 2

output:

-1

result:

ok No solutions

Subtask #3:

score: 0
Runtime Error

Test #36:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

3 30 29
19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 30 29 28 27 26 25 24 23 22 21 20

output:

11
0
1
0
1
0
1
0
1
0
1
0

result:

ok Perfect :) Use 11 operations

Test #37:

score: 5
Accepted
time: 0ms
memory: 3652kb

input:

3 30 29
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5

output:

-1

result:

ok No solutions

Test #38:

score: 5
Accepted
time: 0ms
memory: 4080kb

input:

3 29 29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

output:

0

result:

ok Perfect :) Use 0 operations

Test #39:

score: 5
Accepted
time: 0ms
memory: 3720kb

input:

3 29 29
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1 2 3 4 5 6 7 8 9 10 11 12

output:

-1

result:

ok No solutions

Test #40:

score: 0
Runtime Error

input:

3 29 27
29 6 23 4 19 2 7 28 5 26 13 24 9 22 15 20 3 18 25 16 1 14 17 12 27 10 21 8 11

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #56:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

4 30 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

output:

0

result:

ok Perfect :) Use 0 operations

Test #57:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

4 30 30
20 23 4 16 27 18 7 9 19 11 2 28 14 25 26 30 13 1 10 6 12 17 3 8 5 15 22 29 21 24

output:

-1

result:

ok No solutions

Test #58:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

4 30 30
24 25 26 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

output:

-1

result:

ok No solutions

Test #59:

score: 5
Accepted
time: 0ms
memory: 3780kb

input:

4 29 28
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1

output:

30
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

result:

ok Perfect :) Use 30 operations

Test #60:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

4 29 28
4 3 12 18 13 9 2 19 10 14 21 25 5 6 22 20 27 7 16 23 28 11 26 29 24 17 15 8 1

output:

-1

result:

ok No solutions

Test #61:

score: 0
Runtime Error

input:

4 30 28
26 6 10 15 22 5 4 13 11 1 14 18 29 9 30 12 8 3 19 20 2 24 28 21 25 23 16 7 27 17

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #71:

score: 15
Accepted
time: 0ms
memory: 4064kb

input:

5 50 49
37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38

output:

13
0
1
0
1
0
1
0
1
0
1
0
1
0

result:

ok Perfect :) Use 13 operations

Test #72:

score: 15
Accepted
time: 0ms
memory: 3636kb

input:

5 50 49
37 16 13 38 27 32 11 36 7 42 33 12 19 50 23 18 9 8 39 2 3 26 47 10 5 44 17 46 1 20 41 4 31 34 49 22 45 40 29 30 43 24 15 6 21 28 25 14 35 48

output:

-1

result:

ok No solutions

Test #73:

score: 15
Accepted
time: 0ms
memory: 3612kb

input:

5 50 49
50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

output:

-1

result:

ok No solutions

Test #74:

score: 15
Accepted
time: 0ms
memory: 3676kb

input:

5 50 49
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

output:

-1

result:

ok No solutions

Test #75:

score: 15
Accepted
time: 0ms
memory: 3776kb

input:

5 49 49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

output:

0

result:

ok Perfect :) Use 0 operations

Test #76:

score: 15
Accepted
time: 0ms
memory: 3940kb

input:

5 49 49
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

output:

-1

result:

ok No solutions

Test #77:

score: 0
Runtime Error

input:

5 49 47
25 40 49 38 3 36 27 34 13 32 23 30 7 28 15 26 19 24 37 22 5 20 41 18 35 16 43 14 29 12 39 10 31 8 9 6 1 4 17 2 47 48 45 46 21 44 11 42 33

output:


result:


Subtask #6:

score: 0
Runtime Error

Test #101:

score: 5
Accepted
time: 0ms
memory: 3808kb

input:

6 50 50
50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

output:

1
0

result:

ok Perfect :) Use 1 operations

Test #102:

score: 5
Accepted
time: 0ms
memory: 3684kb

input:

6 50 50
29 35 5 48 19 9 24 14 7 20 27 30 32 23 18 42 26 38 36 16 28 39 33 40 34 4 43 13 17 47 15 46 41 8 11 49 45 50 25 3 10 21 37 44 22 6 1 31 2 12

output:

-1

result:

ok No solutions

Test #103:

score: 5
Accepted
time: 0ms
memory: 3720kb

input:

6 50 50
39 40 41 42 43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

output:

-1

result:

ok No solutions

Test #104:

score: 5
Accepted
time: 0ms
memory: 3876kb

input:

6 49 48
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

output:

32
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

result:

ok Perfect :) Use 32 operations

Test #105:

score: 5
Accepted
time: 0ms
memory: 3684kb

input:

6 49 48
45 12 30 24 16 21 2 47 42 36 34 14 26 33 48 23 29 9 10 25 18 13 22 38 43 40 37 27 39 32 11 19 31 1 4 46 8 35 3 17 6 5 41 20 28 7 49 15 44

output:

-1

result:

ok No solutions

Test #106:

score: 0
Runtime Error

input:

6 50 48
10 16 4 11 20 45 21 3 27 22 32 29 25 1 50 47 9 49 17 6 13 14 35 38 36 41 33 24 34 26 8 23 12 40 15 39 2 46 31 5 48 37 18 28 19 30 42 43 7 44

output:


result:


Subtask #7:

score: 0
Runtime Error

Test #116:

score: 5
Accepted
time: 0ms
memory: 3792kb

input:

7 200 199
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28...

output:

146
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

result:

ok Perfect :) Use 146 operations

Test #117:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

7 200 199
36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153...

output:

-1

result:

ok No solutions

Test #118:

score: 5
Accepted
time: 0ms
memory: 3808kb

input:

7 199 199
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

0

result:

ok Perfect :) Use 0 operations

Test #119:

score: 5
Accepted
time: 0ms
memory: 3704kb

input:

7 199 199
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 ...

output:

-1

result:

ok No solutions

Test #120:

score: 0
Runtime Error

input:

7 199 197
33 176 185 174 197 172 5 170 97 168 27 166 159 164 137 162 101 160 173 158 83 156 19 154 57 152 123 150 3 148 111 146 141 144 13 142 79 140 55 138 25 136 11 134 91 132 175 130 151 128 9 126 103 124 67 122 157 120 105 118 125 116 65 114 129 112 113 110 139 108 39 106 95 104 17 102 73 100 93...

output:


result:


Subtask #8:

score: 0
Runtime Error

Test #141:

score: 5
Accepted
time: 0ms
memory: 4096kb

input:

8 200 200
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

0

result:

ok Perfect :) Use 0 operations

Test #142:

score: 5
Accepted
time: 0ms
memory: 3584kb

input:

8 200 200
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 1...

output:

-1

result:

ok No solutions

Test #143:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

8 199 198
123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35...

output:

275
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
...

result:

ok Perfect :) Use 275 operations

Test #144:

score: 5
Accepted
time: 0ms
memory: 3684kb

input:

8 199 198
157 10 149 46 127 180 125 190 166 35 85 58 30 39 159 192 187 172 55 79 90 74 164 124 115 106 23 188 37 92 53 28 67 138 179 11 152 196 63 136 193 103 98 142 54 44 57 5 8 31 148 107 112 101 120 176 76 191 113 131 130 51 22 116 95 155 139 14 36 96 119 60 186 169 77 32 173 100 21 88 66 87 177 ...

output:

-1

result:

ok No solutions

Test #145:

score: 0
Runtime Error

input:

8 200 198
1 168 27 102 42 21 10 24 87 8 106 62 38 182 170 61 138 80 93 146 100 75 22 3 49 81 95 29 149 53 187 192 199 63 132 71 84 150 85 6 44 5 124 90 151 19 50 152 181 110 41 35 9 156 197 161 129 130 185 125 162 163 131 12 66 16 195 142 171 121 134 140 172 20 174 179 37 166 13 104 107 193 135 94 5...

output:


result:


Subtask #9:

score: 5
Accepted

Test #156:

score: 5
Accepted
time: 4ms
memory: 3940kb

input:

9 1000 5
211 100 879 298 625 856 443 312 159 430 391 546 577 436 137 720 561 290 847 592 187 120 953 60 979 94 583 700 623 80 627 732 675 24 987 340 221 974 1 816 881 280 495 432 853 212 117 986 667 148 127 664 481 524 725 82 543 906 819 394 581 950 91 866 573 496 251 392 775 730 273 784 511 90 359 ...

output:

62599
461
465
469
473
477
481
485
489
493
497
501
505
509
513
517
521
525
529
533
537
541
545
549
553
557
561
565
569
573
577
581
585
589
593
597
601
605
609
613
617
621
625
629
633
637
641
645
649
653
657
661
665
669
673
677
681
685
689
693
697
701
705
709
713
717
721
725
729
733
737
741
745
749
75...

result:

ok Perfect :) Use 62599 operations

Test #157:

score: 5
Accepted
time: 4ms
memory: 3908kb

input:

9 1000 5
991 372 741 582 45 614 789 632 177 444 907 842 385 240 835 992 461 722 465 82 39 338 881 182 647 656 553 24 949 642 971 160 229 322 69 488 367 768 533 348 191 878 965 398 181 132 303 216 171 204 5 748 867 188 557 858 993 784 233 866 63 888 605 184 145 482 903 94 173 168 175 248 875 610 527 ...

output:

61568
725
729
733
737
741
745
749
753
757
761
765
769
773
777
781
785
789
793
797
801
805
809
813
817
821
825
829
833
837
841
845
849
853
857
861
865
869
873
877
881
885
889
893
897
901
905
909
913
917
921
925
929
933
937
941
945
949
953
957
961
965
969
973
977
981
985
989
993
994
995
510
514
518
52...

result:

ok Perfect :) Use 61568 operations

Test #158:

score: 5
Accepted
time: 4ms
memory: 3916kb

input:

9 1000 5
225 426 517 772 477 142 703 312 71 710 371 854 891 776 483 388 929 148 19 922 621 564 629 810 863 442 449 652 819 782 335 762 171 868 789 154 257 770 695 292 821 910 237 146 269 872 395 56 251 208 813 248 417 546 505 594 711 566 41 72 435 308 101 876 295 466 363 434 611 640 685 240 759 898 ...

output:

62179
231
235
239
243
247
251
255
259
263
267
271
275
279
283
287
291
295
299
303
307
311
315
319
323
327
331
335
339
343
347
351
355
359
363
367
371
375
379
383
387
391
395
399
403
407
411
415
419
423
427
431
435
439
443
447
451
455
459
463
467
471
475
479
483
487
491
495
499
503
507
511
515
519
52...

result:

ok Perfect :) Use 62179 operations

Test #159:

score: 5
Accepted
time: 1ms
memory: 3888kb

input:

9 1000 5
185 540 819 982 831 622 777 776 311 978 641 1000 857 16 47 808 49 122 435 826 395 560 799 538 163 384 281 80 605 686 467 460 195 242 513 162 769 224 615 930 999 548 719 642 455 128 439 964 563 248 287 14 581 716 821 250 283 906 265 878 551 346 867 90 579 472 291 342 765 512 471 814 633 476 ...

output:

-1

result:

ok No solutions

Test #160:

score: 5
Accepted
time: 0ms
memory: 4036kb

input:

9 5 5
5 4 3 2 1

output:

1
0

result:

ok Perfect :) Use 1 operations

Test #161:

score: 5
Accepted
time: 0ms
memory: 3724kb

input:

9 5 5
1 5 4 2 3

output:

-1

result:

ok No solutions

Test #162:

score: 5
Accepted
time: 0ms
memory: 3908kb

input:

9 5 5
2 3 4 5 1

output:

-1

result:

ok No solutions

Test #163:

score: 5
Accepted
time: 0ms
memory: 3800kb

input:

9 6 5
1 2 3 4 5 6

output:

0

result:

ok Perfect :) Use 0 operations

Test #164:

score: 5
Accepted
time: 0ms
memory: 3612kb

input:

9 6 5
3 4 5 2 1 6

output:

-1

result:

ok No solutions

Test #165:

score: 5
Accepted
time: 0ms
memory: 3944kb

input:

9 6 5
6 5 4 3 2 1

output:

-1

result:

ok No solutions

Test #166:

score: 5
Accepted
time: 0ms
memory: 3848kb

input:

9 7 5
3 2 5 4 1 6 7

output:

4
2
0
2
1

result:

ok Perfect :) Use 4 operations

Test #167:

score: 5
Accepted
time: 0ms
memory: 3712kb

input:

9 7 5
7 6 3 2 5 4 1

output:

-1

result:

ok No solutions

Subtask #10:

score: 5
Accepted

Test #168:

score: 5
Accepted
time: 5ms
memory: 3940kb

input:

10 1000 4
758 267 63 485 736 202 48 317 86 106 157 637 213 476 900 811 830 915 333 457 665 423 51 881 837 615 228 201 151 69 87 753 312 999 810 483 409 630 790 497 120 838 969 170 3 271 316 365 831 598 801 199 931 200 768 16 357 874 869 481 771 262 508 850 146 67 136 674 670 649 845 621 109 602 150 ...

output:

85782
438
441
444
447
450
453
456
459
462
465
468
471
474
477
480
483
486
489
492
495
498
501
504
507
510
513
516
519
522
525
528
531
534
537
540
543
546
549
552
555
558
561
564
567
570
573
576
579
582
585
588
591
594
597
600
603
606
609
612
615
618
621
624
627
630
633
636
639
642
645
648
651
654
65...

result:

ok Perfect :) Use 85782 operations

Test #169:

score: 5
Accepted
time: 5ms
memory: 3908kb

input:

10 1000 4
326 290 647 848 941 832 911 134 198 884 970 805 644 391 564 317 193 244 217 933 257 826 279 860 405 496 112 950 498 436 547 185 866 144 294 786 164 653 419 711 956 215 565 534 418 481 910 392 629 266 70 56 395 155 342 656 795 879 480 682 523 570 278 8 259 158 397 808 367 937 180 555 91 163...

output:

82867
614
617
620
623
626
629
632
635
638
641
644
647
650
653
656
659
662
665
668
671
674
677
680
683
686
689
692
695
698
701
704
707
710
713
716
719
722
725
728
731
734
737
740
743
746
749
752
755
758
761
764
767
770
773
776
779
782
785
788
791
794
797
800
803
806
809
812
815
818
821
824
827
830
83...

result:

ok Perfect :) Use 82867 operations

Test #170:

score: 5
Accepted
time: 5ms
memory: 3908kb

input:

10 1000 4
301 482 326 645 714 415 956 715 708 128 233 410 586 17 964 611 436 684 860 644 235 159 259 262 899 632 929 652 542 780 636 664 716 176 36 720 173 990 653 690 167 371 260 588 775 821 560 211 375 399 138 203 157 312 754 983 268 152 886 939 299 387 32 822 234 140 304 95 557 448 335 42 187 153...

output:

85381
761
764
767
770
773
776
779
782
785
788
791
794
797
800
803
806
809
812
815
818
821
824
827
830
833
836
839
842
845
848
851
854
857
860
863
866
869
872
875
878
881
884
887
890
893
896
899
902
905
908
911
914
917
920
923
926
929
932
935
938
941
944
947
950
953
956
959
962
965
968
971
974
977
98...

result:

ok Perfect :) Use 85381 operations

Test #171:

score: 5
Accepted
time: 0ms
memory: 3824kb

input:

10 1000 4
522 507 45 981 381 774 205 675 124 86 951 496 874 77 648 382 73 977 198 435 742 352 884 519 739 427 634 249 391 601 252 700 615 173 673 359 948 339 513 204 116 676 518 81 72 353 971 866 279 516 414 902 377 878 726 489 738 139 184 935 786 358 821 921 8 931 152 422 21 708 603 988 668 350 298...

output:

-1

result:

ok No solutions

Test #172:

score: 5
Accepted
time: 0ms
memory: 3860kb

input:

10 4 4
1 2 3 4

output:

0

result:

ok Perfect :) Use 0 operations

Test #173:

score: 5
Accepted
time: 0ms
memory: 3940kb

input:

10 4 4
2 1 4 3

output:

-1

result:

ok No solutions

Test #174:

score: 5
Accepted
time: 0ms
memory: 3784kb

input:

10 5 4
2 1 5 4 3

output:

3
0
1
0

result:

ok Perfect :) Use 3 operations

Test #175:

score: 5
Accepted
time: 0ms
memory: 3612kb

input:

10 5 4
5 4 1 3 2

output:

-1

result:

ok No solutions

Subtask #11:

score: 5
Accepted

Test #176:

score: 5
Accepted
time: 7ms
memory: 31896kb

input:

11 1000 7
975 294 573 546 575 370 471 988 77 438 155 162 877 176 441 260 189 178 381 936 495 106 405 854 739 674 395 332 627 628 605 1000 1 422 485 594 879 882 849 620 265 424 55 500 149 378 47 708 137 410 775 44 283 112 823 70 499 64 397 606 793 190 753 752 545 580 651 206 963 730 815 968 263 698 6...

output:

42972
31
37
43
49
55
61
67
73
79
85
91
97
103
109
115
121
127
133
139
145
151
157
163
169
175
181
187
193
199
205
211
217
223
229
235
241
247
253
259
265
271
277
283
289
295
301
307
313
319
325
331
337
343
349
355
361
367
373
379
385
391
397
403
409
415
421
427
433
439
445
451
457
463
469
475
481
48...

result:

ok Perfect :) Use 42972 operations

Test #177:

score: 5
Accepted
time: 11ms
memory: 31716kb

input:

11 1000 7
179 376 839 760 97 952 973 600 267 298 175 766 773 236 607 920 75 118 409 416 387 538 321 450 65 554 199 212 511 90 393 246 259 620 311 392 835 132 939 70 763 988 203 638 141 758 55 686 589 414 731 372 355 358 509 426 557 996 517 182 181 460 933 586 665 442 671 488 627 452 367 844 125 328 ...

output:

42687
83
89
95
101
107
113
119
125
131
137
143
149
155
161
167
173
179
185
191
197
203
209
215
221
227
233
239
245
251
257
263
269
275
281
287
293
299
305
311
317
323
329
335
341
347
353
359
365
371
377
383
389
395
401
407
413
419
425
431
437
443
449
455
461
467
473
479
485
491
497
503
509
515
521
5...

result:

ok Perfect :) Use 42687 operations

Test #178:

score: 5
Accepted
time: 10ms
memory: 31672kb

input:

11 1000 7
263 450 239 844 467 274 151 150 539 796 575 858 895 766 129 784 797 546 61 768 219 104 15 434 563 676 209 634 951 976 167 222 927 252 625 112 581 780 627 406 863 620 41 608 203 988 333 354 453 220 847 126 749 30 591 978 299 860 77 928 127 740 311 754 541 374 385 18 923 158 7 552 335 562 69...

output:

42094
115
121
127
133
139
145
151
157
163
169
175
181
187
193
199
205
211
217
223
229
235
241
247
253
259
265
271
277
283
289
295
301
307
313
319
325
331
337
343
349
355
361
367
373
379
385
391
397
403
409
415
421
427
433
439
445
451
457
463
469
475
481
487
493
499
505
511
517
523
529
535
541
547
55...

result:

ok Perfect :) Use 42094 operations

Test #179:

score: 5
Accepted
time: 0ms
memory: 3844kb

input:

11 7 7
1 2 3 4 5 6 7

output:

0

result:

ok Perfect :) Use 0 operations

Test #180:

score: 5
Accepted
time: 0ms
memory: 3668kb

input:

11 7 7
1 7 5 4 2 6 3

output:

-1

result:

ok No solutions

Test #181:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

11 7 7
2 3 4 5 6 7 1

output:

-1

result:

ok No solutions

Test #182:

score: 5
Accepted
time: 0ms
memory: 3872kb

input:

11 8 7
7 8 1 2 3 4 5 6

output:

6
0
1
0
1
0
1

result:

ok Perfect :) Use 6 operations

Test #183:

score: 5
Accepted
time: 0ms
memory: 3652kb

input:

11 8 7
8 7 6 5 4 3 2 1

output:

-1

result:

ok No solutions

Test #184:

score: 5
Accepted
time: 0ms
memory: 5964kb

input:

11 9 7
7 2 1 4 5 6 3 8 9

output:

6
1
2
0
1
0
2

result:

ok Perfect :) Use 6 operations

Test #185:

score: 5
Accepted
time: 0ms
memory: 6024kb

input:

11 9 7
3 6 5 4 1 2 9 8 7

output:

-1

result:

ok No solutions

Test #186:

score: 5
Accepted
time: 1ms
memory: 5956kb

input:

11 9 7
1 2 9 8 7 6 3 4 5

output:

-1

result:

ok No solutions

Subtask #12:

score: 5
Accepted

Test #187:

score: 5
Accepted
time: 13ms
memory: 4200kb

input:

12 1000 6
416 514 385 469 20 211 283 558 116 425 351 927 713 189 649 827 54 441 327 759 273 466 971 829 108 738 200 21 557 577 266 541 507 115 480 646 673 179 820 430 84 458 249 869 676 127 482 80 606 545 639 919 974 826 718 783 741 775 549 693 202 477 291 528 48 366 137 483 95 350 709 966 55 312 62...

output:

54309
750
755
760
765
770
775
780
785
790
795
800
805
810
815
820
825
830
835
840
845
850
855
860
865
870
875
880
885
890
895
900
905
910
915
920
925
930
935
940
945
950
955
960
965
970
975
980
985
990
993
994
993
994
384
389
394
399
404
409
414
419
424
429
434
439
444
449
454
459
464
469
474
479
48...

result:

ok Perfect :) Use 54309 operations

Test #188:

score: 5
Accepted
time: 9ms
memory: 3916kb

input:

12 1000 6
734 154 614 856 690 198 413 666 220 327 148 920 553 585 757 76 923 789 365 901 622 228 290 202 471 990 718 877 598 579 644 507 552 941 694 917 714 781 752 112 187 545 616 586 92 85 30 99 813 4 372 440 653 277 539 207 760 584 115 637 822 692 688 919 98 709 563 825 143 73 809 863 939 516 84 ...

output:

52810
732
737
742
747
752
757
762
767
772
777
782
787
792
797
802
807
812
817
822
827
832
837
842
847
852
857
862
867
872
877
882
887
892
897
902
907
912
917
922
927
932
937
942
947
952
957
962
967
972
977
982
987
992
993
994
264
269
274
279
284
289
294
299
304
309
314
319
324
329
334
339
344
349
35...

result:

ok Perfect :) Use 52810 operations

Test #189:

score: 5
Accepted
time: 13ms
memory: 3916kb

input:

12 1000 6
426 451 150 843 860 130 729 178 669 279 458 306 620 198 795 955 549 937 31 650 469 464 770 651 632 4 309 247 367 151 143 259 529 177 944 644 226 498 483 423 515 390 865 850 358 264 437 420 386 879 919 723 667 411 856 302 435 343 193 452 11 739 161 338 698 783 637 675 106 965 55 666 305 821...

output:

55195
604
609
614
619
624
629
634
639
644
649
654
659
664
669
674
679
684
689
694
699
704
709
714
719
724
729
734
739
744
749
754
759
764
769
774
779
784
789
794
799
804
809
814
819
824
829
834
839
844
849
854
859
864
869
874
879
884
889
894
899
904
909
914
919
924
929
934
939
944
949
954
959
964
96...

result:

ok Perfect :) Use 55195 operations

Test #190:

score: 5
Accepted
time: 840ms
memory: 32532kb

input:

12 1000 8
916 106 622 283 77 349 76 65 701 14 634 16 659 71 567 371 367 417 857 83 629 161 932 882 657 524 931 997 995 970 22 893 449 59 1000 234 291 752 725 357 420 262 191 458 503 869 552 419 463 81 590 672 744 573 15 868 218 422 435 442 176 624 545 326 913 816 751 612 688 181 687 397 302 241 471 ...

output:

42614
34
41
48
55
62
69
76
83
90
97
104
111
118
125
132
139
146
153
160
167
174
181
188
195
202
209
216
223
230
237
244
251
258
265
272
279
286
293
300
307
314
321
328
335
342
349
356
363
370
377
384
391
398
405
412
419
426
433
440
447
454
461
468
475
482
489
496
503
510
517
524
531
538
545
552
559
...

result:

ok Perfect :) Use 42614 operations

Test #191:

score: 5
Accepted
time: 839ms
memory: 32508kb

input:

12 1000 8
842 480 888 935 207 901 669 311 841 401 223 192 971 569 974 215 235 353 33 758 609 161 188 655 495 885 153 983 571 409 403 825 39 283 894 87 934 640 709 304 313 258 159 976 183 7 603 838 742 432 565 367 689 543 262 4 793 895 796 992 826 998 173 531 456 93 898 662 127 653 116 729 402 479 63...

output:

42940
910
917
924
931
938
945
952
959
966
973
980
987
991
992
991
992
991
992
991
992
991
992
991
992
991
992
508
515
522
529
536
543
550
557
564
571
578
585
592
599
606
613
620
627
634
641
648
655
662
669
676
683
690
697
704
711
718
725
732
739
746
753
760
767
774
781
788
795
802
809
816
823
830
83...

result:

ok Perfect :) Use 42940 operations

Test #192:

score: 5
Accepted
time: 841ms
memory: 32456kb

input:

12 1000 8
351 377 405 356 716 720 634 526 665 700 908 999 538 207 549 936 896 288 102 311 739 27 474 550 63 632 913 162 448 950 360 241 193 561 208 942 229 673 198 308 582 461 399 143 839 838 96 158 342 837 614 46 189 476 275 643 323 728 762 455 258 491 359 519 857 99 927 132 103 510 61 684 251 797 ...

output:

42383
563
570
577
584
591
598
605
612
619
626
633
640
647
654
661
668
675
682
689
696
703
710
717
724
731
738
745
752
759
766
773
780
787
794
801
808
815
822
829
836
843
850
857
864
871
878
885
892
899
906
913
920
927
934
941
948
955
962
969
976
983
990
991
992
11
18
25
32
39
46
53
60
67
74
81
88
95...

result:

ok Perfect :) Use 42383 operations

Test #193:

score: 5
Accepted
time: 835ms
memory: 32756kb

input:

12 1000 8
803 115 31 95 772 296 615 417 636 380 712 255 238 470 257 552 874 212 377 679 909 520 484 30 513 651 383 414 546 34 532 983 865 645 861 888 80 830 607 824 821 200 521 141 381 67 114 91 516 130 625 476 419 630 860 641 896 397 775 757 613 314 624 317 43 20 391 109 895 911 56 469 64 272 171 1...

output:

-1

result:

ok No solutions

Test #194:

score: 5
Accepted
time: 0ms
memory: 4068kb

input:

12 7 6
1 7 6 5 4 3 2

output:

13
0
1
0
1
0
1
0
1
0
1
0
1
0

result:

ok Perfect :) Use 13 operations

Test #195:

score: 5
Accepted
time: 0ms
memory: 3660kb

input:

12 7 6
4 5 7 6 3 2 1

output:

-1

result:

ok No solutions

Test #196:

score: 5
Accepted
time: 0ms
memory: 3840kb

input:

12 8 8
1 2 3 4 5 6 7 8

output:

0

result:

ok Perfect :) Use 0 operations

Test #197:

score: 5
Accepted
time: 0ms
memory: 3672kb

input:

12 8 8
1 3 8 2 7 6 5 4

output:

-1

result:

ok No solutions

Test #198:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

12 8 8
6 7 8 1 2 3 4 5

output:

-1

result:

ok No solutions

Test #199:

score: 5
Accepted
time: 0ms
memory: 4072kb

input:

12 9 8
2 1 9 8 7 6 5 4 3

output:

7
0
1
0
1
0
1
0

result:

ok Perfect :) Use 7 operations

Test #200:

score: 5
Accepted
time: 0ms
memory: 3676kb

input:

12 9 8
2 6 4 8 3 7 9 5 1

output:

-1

result:

ok No solutions

Subtask #13:

score: 0
Runtime Error

Test #201:

score: 5
Accepted
time: 0ms
memory: 4072kb

input:

13 60 59
53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 60 59 58 57 56 55 54

output:

7
0
1
0
1
0
1
0

result:

ok Perfect :) Use 7 operations

Test #202:

score: 5
Accepted
time: 0ms
memory: 3676kb

input:

13 60 59
59 42 3 20 41 40 51 30 31 38 33 32 43 18 53 6 37 60 19 8 29 10 45 50 21 34 5 44 7 54 55 52 15 22 57 4 17 26 23 16 11 36 39 12 1 28 9 46 47 24 13 56 25 48 35 14 27 58 49 2

output:

-1

result:

ok No solutions

Test #203:

score: 5
Accepted
time: 0ms
memory: 3720kb

input:

13 60 59
60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

output:

-1

result:

ok No solutions

Test #204:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

13 60 59
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

output:

-1

result:

ok No solutions

Test #205:

score: 5
Accepted
time: 0ms
memory: 3808kb

input:

13 59 59
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

output:

0

result:

ok Perfect :) Use 0 operations

Test #206:

score: 5
Accepted
time: 0ms
memory: 3684kb

input:

13 59 59
36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37

output:

-1

result:

ok No solutions

Test #207:

score: 0
Runtime Error

input:

13 61 59
1 60 41 58 57 56 61 54 13 52 53 50 37 48 25 46 47 44 15 42 19 40 5 38 3 36 59 34 31 32 29 30 55 28 51 26 39 24 43 22 45 20 9 18 23 16 17 14 7 12 21 10 11 8 35 6 33 4 49 2 27

output:


result:


Subtask #14:

score: 0
Runtime Error

Test #231:

score: 5
Accepted
time: 0ms
memory: 3808kb

input:

14 60 60
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

output:

0

result:

ok Perfect :) Use 0 operations

Test #232:

score: 5
Accepted
time: 0ms
memory: 3908kb

input:

14 60 60
30 60 33 25 45 40 41 14 59 5 34 50 13 57 46 8 48 53 19 3 56 20 31 37 32 7 28 44 4 27 58 47 24 17 43 21 23 6 22 38 9 36 29 16 26 1 10 11 12 51 42 52 2 35 49 18 54 39 55 15

output:

-1

result:

ok No solutions

Test #233:

score: 5
Accepted
time: 0ms
memory: 3652kb

input:

14 60 60
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

output:

-1

result:

ok No solutions

Test #234:

score: 5
Accepted
time: 0ms
memory: 3876kb

input:

14 51 50
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 1 2 3 4 5 6 7 8 9 10 11

output:

62
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

result:

ok Perfect :) Use 62 operations

Test #235:

score: 5
Accepted
time: 0ms
memory: 3688kb

input:

14 51 50
36 50 35 4 24 38 16 42 26 12 19 44 7 27 39 10 1 5 3 18 25 20 14 33 17 51 43 11 31 2 22 34 13 23 41 37 6 45 32 47 15 28 8 40 21 48 49 9 29 46 30

output:

-1

result:

ok No solutions

Test #236:

score: 0
Runtime Error

input:

14 1000 40
783 688 933 732 144 245 668 115 364 678 148 794 8 177 728 420 371 932 686 184 292 964 600 322 851 96 617 816 707 586 248 434 409 951 736 878 801 610 655 185 698 882 632 38 961 929 145 557 111 826 679 923 441 508 760 135 827 888 568 392 917 898 429 881 190 76 21 706 298 995 459 391 841 393...

output:


result:


Subtask #15:

score: 0
Runtime Error

Test #246:

score: 15
Accepted
time: 1ms
memory: 3792kb

input:

15 1000 999
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 ...

output:

418
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
...

result:

ok Perfect :) Use 418 operations

Test #247:

score: 15
Accepted
time: 1ms
memory: 3696kb

input:

15 1000 999
463 334 963 680 867 710 343 40 177 562 657 468 255 652 481 498 669 88 443 864 701 378 277 106 203 240 643 452 257 750 173 384 131 22 243 550 709 904 563 476 827 274 441 308 917 136 381 716 771 206 425 222 31 178 191 34 219 950 711 854 999 968 467 616 199 302 39 988 887 702 387 952 49 320...

output:

-1

result:

ok No solutions

Test #248:

score: 15
Accepted
time: 0ms
memory: 3708kb

input:

15 1000 999
1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929...

output:

-1

result:

ok No solutions

Test #249:

score: 15
Accepted
time: 1ms
memory: 3700kb

input:

15 1000 999
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 ...

output:

-1

result:

ok No solutions

Test #250:

score: 15
Accepted
time: 0ms
memory: 3880kb

input:

15 999 999
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...

output:

0

result:

ok Perfect :) Use 0 operations

Test #251:

score: 15
Accepted
time: 0ms
memory: 3696kb

input:

15 999 999
761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727 726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 6...

output:

-1

result:

ok No solutions

Test #252:

score: 0
Runtime Error

input:

15 999 997
73 92 445 94 575 96 907 98 137 100 849 102 507 104 191 106 905 108 951 110 927 112 609 114 647 116 595 118 249 120 99 122 305 124 145 126 277 128 51 130 845 132 409 134 319 136 161 138 577 140 993 142 141 144 459 146 245 148 695 150 751 152 219 154 523 156 175 158 639 160 55 162 593 164 2...

output:


result:


Subtask #16:

score: 0
Runtime Error

Test #281:

score: 5
Accepted
time: 0ms
memory: 3812kb

input:

16 1000 1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

output:

0

result:

ok Perfect :) Use 0 operations

Test #282:

score: 5
Accepted
time: 0ms
memory: 3728kb

input:

16 1000 1000
913 227 730 357 862 645 631 393 32 331 181 324 798 469 402 999 936 158 385 956 419 430 46 592 550 655 841 221 541 664 109 334 440 270 502 740 888 177 501 537 72 311 243 382 284 836 488 498 113 995 81 770 720 345 949 37 709 49 235 274 659 84 695 948 234 471 288 604 877 554 678 468 517 54...

output:

-1

result:

ok No solutions

Test #283:

score: 5
Accepted
time: 0ms
memory: 3688kb

input:

16 1000 1000
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165...

output:

-1

result:

ok No solutions

Test #284:

score: 5
Accepted
time: 0ms
memory: 4076kb

input:

16 999 998
874 873 872 871 870 869 868 867 866 865 864 863 862 861 860 859 858 857 856 855 854 853 852 851 850 849 848 847 846 845 844 843 842 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 8...

output:

125
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0

result:

ok Perfect :) Use 125 operations

Test #285:

score: 5
Accepted
time: 1ms
memory: 3740kb

input:

16 999 998
461 792 701 275 902 634 949 637 39 689 476 260 276 875 438 698 311 496 410 682 432 173 818 399 943 160 364 961 560 150 929 891 301 958 271 129 995 318 359 354 148 539 17 705 741 986 337 839 926 174 908 11 238 938 373 869 817 652 225 255 816 683 376 973 942 380 773 602 437 145 716 205 166 ...

output:

-1

result:

ok No solutions

Test #286:

score: 0
Runtime Error

input:

16 1000 998
521 479 831 13 657 827 236 789 544 458 169 130 548 160 549 88 156 865 626 440 678 312 722 138 116 283 513 897 473 676 615 19 991 745 898 313 54 737 431 137 580 887 997 171 294 983 528 778 339 396 864 319 393 495 131 23 465 602 717 32 640 181 679 646 65 173 427 163 956 814 982 762 43 613 ...

output:


result: