QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662064#5516. Modern Machineliuziao100 ✓1179ms815920kbC++238.7kb2024-10-20 20:25:412024-10-20 20:25:41

Judging History

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

  • [2024-10-20 20:25:41]
  • 评测
  • 测评结果:100
  • 用时:1179ms
  • 内存:815920kb
  • [2024-10-20 20:25:41]
  • 提交

answer

#include <bits/stdc++.h>

// #define int int64_t

const int kMaxN = 1.2e5 + 5, kLog = 18;

int n, m, q, cr, cb;
int a[kMaxN], nxt[kLog][kLog][kMaxN], rx[kMaxN], bx[kMaxN], lg[kMaxN], prer[kMaxN];
int64_t sumr[kLog][kLog][kMaxN], sumb[kLog][kLog][kMaxN];
std::string s;

struct SGT {
  std::vector<std::pair<int, int>> v[kMaxN * 4];

  int func(int x, int val) {
    auto it = std::upper_bound(v[x].begin(), v[x].end(), std::pair<int, int>(val, 1e9)) - 1;
    return val + it->second;
  }

  void pushup(int x) {
    int ls = (x << 1), rs = (x << 1 | 1);
    for (int i = 0; i < (int)v[ls].size(); ++i) {
      auto [L, val] = v[ls][i];
      int R = (i + 1 == (int)v[ls].size() ? n + 1 : v[ls][i + 1].first);
      auto itl = std::lower_bound(v[rs].begin(), v[rs].end(), std::pair<int, int>(L + val, -1e9));
      auto itr = std::lower_bound(v[rs].begin(), v[rs].end(), std::pair<int, int>(R + val, -1e9));
      v[x].emplace_back(L, 0);
      for (auto it = itl; it != itr; ++it) {
        v[x].emplace_back(it->first - val, 0);
      }
    }
    std::sort(v[x].begin(), v[x].end());
    v[x].erase(std::unique(v[x].begin(), v[x].end()), v[x].end());
    for (auto &[xx, val] : v[x]) {
      val = func(rs, func(ls, xx)) - xx;
    }
  }

  void build(int x, int l, int r) {
    if (l == r) {
      if (n - a[l] > 0) {
        v[x].emplace_back(0, a[l] + 1);
        if (n - a[l] <= a[l] - 1) v[x].emplace_back(n - a[l], a[l] - n);
      } else {
        v[x].emplace_back(0, a[l] - n);
      }
      if (a[l] < n + 1 - a[l]) {
        v[x].emplace_back(a[l], a[l]);
        v[x].emplace_back(n - a[l] + 1, a[l] - (n + 1));
      } else {
        v[x].emplace_back(a[l], a[l] - (n + 1));
      }
      std::sort(v[x].begin(), v[x].end());
      return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
    pushup(x);
  }

  int query(int x, int l, int r, int ql, int qr, int val) {
    if (l > qr || r < ql) {
      return val;
    } else if (l >= ql && r <= qr) {
      return func(x, val);
    }
    int mid = (l + r) >> 1;
    return query(x << 1 | 1, mid + 1, r, ql, qr, query(x << 1, l, mid, ql, qr, val));
  }
} sgt;

void prework() {
  sgt.build(1, 1, m);

  lg[0] = -1;
  for (int i = 1; i <= 1.2e5; ++i) lg[i] = lg[i >> 1] + 1;

  for (int i = 1; i <= n; ++i) prer[i] = prer[i - 1] + (s[i] == 'R');

  for (int i = 1; i <= n + 1; ++i) {
    if (i == n + 1 || s[i] == 'B') {
      rx[++cr] = i - 1;
    }
  }
  for (int i = n; ~i; --i) {
    if (!i || s[i] == 'R') {
      bx[++cb] = n - i;
    }
  }

  for (int x = 0; x <= lg[n] + 1; ++x) {
    for (int y = 0; y <= lg[n] + 1; ++y) {
      int lenr, lenb;
      if (!x) lenr = 0;
      else lenr = (1 << (x - 1));
      if (!y) lenb = 0;
      else lenb = (1 << (y - 1));
      if (lenr + lenb > n) continue;
      for (int i = 1; i <= m; ++i) {
        sumr[x][y][i] = sumr[x][y][i - 1];
        sumb[x][y][i] = sumb[x][y][i - 1];
        if (a[i] <= lenr) sumr[x][y][i] += a[i];
        else if (n - a[i] + 1 <= lenb) sumb[x][y][i] += n - a[i];
      }
      nxt[x][y][m + 1] = m + 1;
      for (int i = m; i; --i) {
        if (a[i] > lenr && a[i] <= n - lenb) nxt[x][y][i] = i;
        else nxt[x][y][i] = nxt[x][y][i + 1];
      }
    }
  }
}

int getcntr(int l, int r) {
  if (l > r) return 0;
  return prer[r] - prer[l - 1];
}

int getcntb(int l, int r) {
  if (l > r) return 0;
  return (r - l + 1) - (prer[r] - prer[l - 1]);
}

char getch(int x, int nowr, int nowb) {
  assert(x >= 1 && x <= n);
  if (x <= rx[nowr]) return 'R';
  else if (x > n - bx[nowb]) return 'B';
  else return s[x];
}

int solve(int l, int r) {
  int pos = l - 1, nowr = 1, nowb = 1, val = -1;
  for (;;) {
    assert(rx[nowr] + bx[nowb] <= n);
    if (rx[nowr] + bx[nowb] >= n) {
      val = rx[nowr];
      break;
    }
    int x = lg[rx[nowr]] + 1, y = lg[bx[nowb]] + 1;
    int nxtp = std::min(nxt[x][y][pos + 1], r + 1);
    int detr = std::min<int>(sumr[x][y][nxtp - 1] - sumr[x][y][pos], n);
    int detb = std::min<int>(sumb[x][y][nxtp - 1] - sumb[x][y][pos], n);
    // std::cerr << pos << ' ' << nxtp << ' ' << rx[nowr] << ' ' << bx[nowb] << ' ' << detr << ' ' << detb << '\n';
    if (rx[std::min(nowr + detr, cr)] + bx[std::min(nowb + detb, cb)] < n) {
      // std::cerr << pos << ' ' << nxtp << ' ' << detr << ' ' << detb << ' ' << rx[nowr] << ' ' << bx[nowb] << ' ' << rx[std::min(nowr + detr, cr)] + bx[std::min(nowb + detb, cb)] << '\n';
      nowr += detr, nowb += detb, pos = nxtp;
      if (pos == r + 1) break;
      int cntr = rx[nowr] + getcntr(rx[nowr] + 1, n - bx[nowb]);
      if (getch(a[pos], nowr, nowb) == 'B') ++cntr;
      // std::cerr <<  "!!! " << pos << ' ' << getch(a[pos], nowr, nowb) << ' ' << nxtp << ' ' << rx[nowr] << ' ' << bx[nowb] << ' ' << cntr << '\n';
      if (n - cntr >= a[pos]) { // 把前 a[pos] 个 B 变成 R
        if (getch(a[pos], nowr, nowb) == 'B') ++nowr;
        nowr = std::min(nowr + a[pos], cr);
        // std::cerr <<  "??? " << pos << ' ' << nxtp << ' ' << rx[nowr] << ' ' << bx[nowb] << ' ' << cntr << '\n';
        if (rx[nowr] + bx[nowb] >= n) {
          val = cntr + a[pos];
          break;
        }
      } else { // 把后 n - a[pos] + 1 个 R 变成 B
        assert(cntr >= n - a[pos] + 1);
        if (getch(a[pos], nowr, nowb) == 'B') --nowb;
        nowb = std::min(nowb + n - a[pos] + 1, cb);
        // std::cerr << nowb << ' ' << rx[nowr] << ' ' << bx[nowb] << '\n';
        if (rx[nowr] + bx[nowb] >= n) {
          val = cntr - (n - a[pos] + 1);
          break;
        }
      }
    } else {
      // assert(pos < nxtp);
      // std::cerr << pos << ' ' << nxtp << '\n';
      // for (int i = pos + 1; i < nxtp; ++i) {
      //   int cntr = rx[nowr] + getcntr(rx[nowr] + 1, n - bx[nowb]);
      //   if (getch(a[pos], nowr, nowb) == 'B') ++cntr;
      //   int detr = 0, detb = 0;
      //   if (a[i] <= n - cntr) detr = a[i];
      //   else detb = n - a[i];
      //   if (rx[std::min(nowr + detr, cr)] + bx[std::min(nowb + detb, cb)] >= n) {
      //     pos = i;
      //     if (n - cntr >= a[i]) {
      //       val = cntr + a[i];
      //       break;
      //     } else {
      //       val = cntr - (n - a[i]);
      //       break;
      //     }
      //   } else {
      //     nowr += detr, nowb += detb;
      //   }
      // }
      // assert(val != -1);
      // break;
      // std::cerr << pos << ' ' << nowr << ' ' << nowb << '\n';
      int L = pos, R = nxtp, res = pos;
      while (L + 1 < R) {
        int mid = (L + R) >> 1;
        int detr = std::min<int>(sumr[x][y][mid] - sumr[x][y][pos], n);
        int detb = std::min<int>(sumb[x][y][mid] - sumb[x][y][pos], n);
        if (rx[std::min(nowr + detr, cr)] + bx[std::min(nowb + detb, cb)] >= n) R = res = mid;
        else L = mid;
      }
      assert(res > pos);
      int detr = std::min<int>(sumr[x][y][res - 1] - sumr[x][y][pos], n);
      int detb = std::min<int>(sumb[x][y][res - 1] - sumb[x][y][pos], n);
      nowr += detr, nowb += detb;
      assert(nowr <= cr && nowb <= cb && rx[nowr] + bx[nowb] < n);
      int cntr = rx[nowr] + getcntr(rx[nowr] + 1, n - bx[nowb]);
      if (getch(a[res], nowr, nowb) == 'B') ++cntr;
      // if (a[res] > rx[nowr] && a[res] <= n - bx[nowb] && getch(a[res], nowr, nowb) == 'B') ++cntr;
      // std::cerr << "heige " << res << ' ' << cntr << ' ' << rx[nowr] << ' ' << bx[nowb] << '\n';
      pos = res;
      if (a[res] <= n - cntr) {
        val = cntr + a[res];
        // val = rx[nowr + a[res]];
        break;
      } else {
        // val = n - bx[nowb + n - a[res]];
        val = cntr - (n - a[res] + 1);
        break;
      }
    }
  }
  // std::cerr << "fuckkkk " << val << ' ' << pos << ' ' << r << '\n';
  if (val == -1) {
    return rx[nowr] + getcntr(rx[nowr] + 1, n - bx[nowb]);
  } else {
    // for (int i = pos + 1; i <= r; ++i) {
    //   if (a[i] <= val) {
    //     val = (val + a[i]) % (n + 1);
    //   } else {
    //     val = (val + a[i] + 1) % (n + 1);
    //   }
    // }
    // return val;
    // std::cerr << val << '\n';
    return sgt.query(1, 1, m, pos + 1, r, val);
  }
}

void dickdreamer() {
  std::cin >> n >> m >> s;
  s = " " + s;
  for (int i = 1; i <= m; ++i) std::cin >> a[i];
  prework();
  std::cin >> q;
  for (int i = 1; i <= q; ++i) {
    int l, r;
    std::cin >> l >> r;
    std::cout << solve(l, r) << '\n';
  }
}

int32_t main() {
#ifdef ORZXKR
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
  int T = 1;
  // std::cin >> T;
  while (T--) dickdreamer();
  // std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 0ms
memory: 11912kb

input:

3 1
BBR
3
1
1 1

output:

0

result:

ok single line: '0'

Test #2:

score: 3
Accepted
time: 2ms
memory: 13852kb

input:

3 10
BBB
3 3 3 1 3 3 3 3 3 1
1
2 5

output:

2

result:

ok single line: '2'

Test #3:

score: 3
Accepted
time: 0ms
memory: 26340kb

input:

10 1
RBBBBRRBBR
9
1
1 1

output:

3

result:

ok single line: '3'

Test #4:

score: 3
Accepted
time: 3ms
memory: 22472kb

input:

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

output:

1

result:

ok single line: '1'

Test #5:

score: 3
Accepted
time: 0ms
memory: 64588kb

input:

300 300
BRRRRBBRBRBRBBBRBRRRBRBBRBBRRBBRBBRBRBRBRBBRRBBRBBRBBBBRRRRBRBRBBBBRBBBRBBRBBRBRBRRBRBBRRRRBRBBRRRBRRBRBBBRRRRBRRRBBBBRRBBRBBBRRRBRBBRBRBBRRBRBRRRBRBRBBBBRRBRBRRRRRBRRRRRBRRRBRBRRRRRBBBRRBBRBBRRRRBBBBRBRBBBRRRRBBBBBBBBBBRBRRBRBBRRRRBRBBRRRBBRBRRRBBRBRRBBRBBBBRBRBRBBBRBBRBRBBRBBRBRBRBRRRBBBBR...

output:

29

result:

ok single line: '29'

Test #6:

score: 3
Accepted
time: 0ms
memory: 70460kb

input:

300 300
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

149

result:

ok single line: '149'

Test #7:

score: 3
Accepted
time: 3ms
memory: 16288kb

input:

5 2
RBRBB
2 5
1
1 2

output:

4

result:

ok single line: '4'

Subtask #2:

score: 12
Accepted

Dependency #1:

100%
Accepted

Test #8:

score: 12
Accepted
time: 7ms
memory: 135140kb

input:

7000 7000
RRBRRRRRRBBRBRBRRRBRRRBRRRRBRBRBRBRBBBRBRRRBBBRBBBBBBRBBBRRBRBRBBRRRBBBBRRBBRBBRBBRRRBBRRBRBRRRRRBBRRBRBBBRBBRRRRBRBBBBRBBBBBBRRRBRBRBBRBRRBBBBBRRBBBBBBRBBBRRBBRRBBBBBBRBRBRBBRBBRBBBRRBRBBRBBBBBRBRRBRRBRRRBRBBBBBRRBRBRRBRRRRBBBBRRBBRRRRRBBBBBRRBBBBBBRRBBRBRRRRRRRBRRBRRBBBBBBBBRRRRBBRRRRRRR...

output:

5505

result:

ok single line: '5505'

Test #9:

score: 12
Accepted
time: 16ms
memory: 137680kb

input:

7000 7000
RRBRRRBBRRBBRBBBBRBRBRRBBBBBBBBBBRRRBRRBBRRRRBBRRBRRRRRBBRBBBBBRRBBBBRBBBBRBRBBBBBRBBRRRBBBBRRBRRBRRBRBBBRRRRBBRRBRRBRBBRBBBRBBBRRBRBBBRRBBBBBRBBRBRBRBBBBRRBBBRRRRBRRBBRBRBBBBBBRRRRRBBRRBBRRBBBRBBBRRRRRBRBBRBRBBRRBBRBRRRBBRRBBBRRBRRRRRRRBBRBRRBRBRBRBRBRBBRBRRBRBBBBBBBRRBRRRBBBBRRBBRRRBBRBR...

output:

5936

result:

ok single line: '5936'

Test #10:

score: 12
Accepted
time: 28ms
memory: 139620kb

input:

7000 7000
RBBRBRBRRRBBRBRRBRBBRBRRRBRBBBRBBRBRBRBRRBBBBRBRRRBBRRRRBBRRRRBBRBRBRRRRBBRRBBRBRBBBRBBBBBRBBRBBRRBBRRRRRBBRBRBRRBBRRRBRBBBRBRRBRRRBRRRBRBBBBRBBBBBBRBRRRBRRRBRBBBRBRRBBRRBRRBBBBBRBBRRRRBBRRBBBBRRBRBRRRRBBRRRRRBRBRRBBRRRRRBRRBRBBBBRRBBBBRBRRRBBRBRRRRRBRRBRRRBRRBRRRRRBBBRBBBRBRRRBRBBBBRRRRRR...

output:

6260

result:

ok single line: '6260'

Test #11:

score: 12
Accepted
time: 7ms
memory: 140572kb

input:

7000 7000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

output:

3499

result:

ok single line: '3499'

Test #12:

score: 12
Accepted
time: 21ms
memory: 139556kb

input:

7000 7000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

3906

result:

ok single line: '3906'

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 10
Accepted
time: 500ms
memory: 792844kb

input:

120000 120000
BBBBRBBRBRRBRRRBBBRRRRRBRRRRRRRRRRRBBBBRBRBBBBBBRBRBBBRBBRBRRBBRBRRRBRBBBBBRBRRBBRRRRRBBRBBBBRBBRRBRRRRBRBBBRRRBBBRRBRRBBBRRRBRRRBBRBBRRRBBBRBBRBBBBBRBRRRRBBRBRBRBBRRRRRRRBBRRBBBBRRRBBRRRRRBBBBRBBBBRBRRBBBRBRBBBRBRBRRBBRBRBBBRRBBRBBBBRBBRRBRBRBRBRRBBRBBBBBBBRRRRBRBRBRBRRRRBRRBBBRBRRBRB...

output:

110620
106126
106019
110676
111965

result:

ok 5 lines

Test #14:

score: 10
Accepted
time: 536ms
memory: 803228kb

input:

120000 120000
BRRBBBRRRRRRRBRRRRRRRBBRBBRRBBRRRRRBRBRRBRRRRRBRRBBBBRRBRRRBBBBRRBRBRBBBRBBRRBRRRBRRBRBBBBRRRBRBRBRBBBBRBRRRBRBBRBBBRRBBBRBBBBRRBBRRBBRBRRRBBBRBBBRRRRBBBBBRRRRBBBBBBBRRRRRRRBBBRRRBBRRRRBBBRBBBRRBBBRRRRRRRRRRRRRBRRBRRBRBRRBBBBBBRRRRBRRBRBBBBRRBRRRRRBRRBRRRBBRRRBBRRRRRBRBRRRRBBBBBBBRBRRR...

output:

96348
101002
105432
99656
104213

result:

ok 5 lines

Test #15:

score: 10
Accepted
time: 670ms
memory: 814212kb

input:

120000 120000
BRBRRBBBRBRBRRRRBRRRRBBRBRBBBBBBBRBBRRBRRRRRBRRRRBBBRRRBBRRBBRRBBBRBRRRBBRRRBBRRBRRRRRBRRBRBRBRRRRBRRRRBRBRBRRRBBBBRBBRRBRBRRBBRRBBBBRBRRRBRRRRBBBRBBRBBRRBBBBBBBBRBBBBRRBBBRRBRRRRRRBBRBRBRRRBBRRRRBBBBRBBBRBRBRBRBBRRRBBBBBBRRRRRRBRBBRRRRBRBBBRBBRBRRRRBBBRRRBBRBRRBBBRBRRBRRRRRRRBBRRRBRRB...

output:

21951
100124
2164
9705
84183

result:

ok 5 lines

Test #16:

score: 10
Accepted
time: 615ms
memory: 814320kb

input:

120000 120000
BBRBRRRRRBRRBBBBBRBRRBRRBBRBRRBBBBBBBBRRRBBBBRRBRRRBRBBBRRRBRBBRRBBBBBBBRBBRBBBBRBBBBBRRRRRRBBBRRRBRRRRRBRRBRBBRBBBRBBRRBRRRRRRRRRBRRRRBRRRBBRRBBBBRBBRBBBBRRBRRBBBRRRRRBRBRBRRRRRRRBRRBBBBBRRBBRRRBBRBBBRBBBRBRBRRRBBBBRRBRBBBRRRBBRBBBBBRBRRBBBRRRBRBRRRRRRBBRRRBRBBBBRRRBBBRBBBRBBRRRRRBBBR...

output:

1538
12691
15538
71544
59943

result:

ok 5 lines

Test #17:

score: 10
Accepted
time: 665ms
memory: 809384kb

input:

120000 120000
RRBRBBBRRBRBBBBRRBRBBRRRBRRBRBBBRRBBBBBRBRRBRBBRRRRBRBRRBRBRBRBRBRRRBBRRRRRBBBRRBRBBRRBRBRRBRRBBBBBBRBRRBBBBBBRBBBRBBRRRRBBRBBRRRBRBRRBBBRRRBBRBRBBBRBRBBRRRBBBBRRBBRRBRBBBBRRBBRRRRRRRBBRBRBBBRBRBRBBRBBRRRBBBRBRBRBBBBRBBRBBBRRBRRRRRBRBRBBRRRRRRBBBRBBRRRRRRRRRRBBBBRRBBRRBBRBRRBRRRBBRBRRR...

output:

40188
86078
5895
13418
41515

result:

ok 5 lines

Test #18:

score: 10
Accepted
time: 370ms
memory: 808472kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

92747
92740
60010
68177
92504

result:

ok 5 lines

Test #19:

score: 10
Accepted
time: 366ms
memory: 808440kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

24163
77301
16491
24538
26597

result:

ok 5 lines

Test #20:

score: 10
Accepted
time: 363ms
memory: 808884kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

21975
61282
31752
20423
27041

result:

ok 5 lines

Subtask #4:

score: 11
Accepted

Test #21:

score: 11
Accepted
time: 175ms
memory: 103936kb

input:

10 120000
RRRRRRRRRR
9 1 9 6 1 9 6 10 3 2 6 4 2 5 7 10 8 9 2 6 7 10 2 9 7 5 9 9 2 7 4 1 8 3 3 6 9 4 7 9 6 8 8 2 5 6 8 3 9 2 5 2 5 9 8 4 8 3 2 2 5 1 9 1 7 9 9 4 9 5 2 10 7 4 3 8 1 10 7 6 6 2 3 8 7 8 5 9 2 2 1 10 2 2 5 4 2 5 9 1 8 4 5 1 2 8 3 10 10 6 7 2 1 5 10 1 9 10 1 7 3 10 8 10 6 8 3 1 10 9 10 5 5...

output:

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

result:

ok 120000 lines

Test #22:

score: 11
Accepted
time: 214ms
memory: 107192kb

input:

10 120000
RRRRRRRRRR
5 3 4 3 3 4 3 7 7 7 6 9 4 10 10 9 9 7 8 8 9 4 8 9 5 8 4 8 8 6 4 10 9 4 8 6 3 1 7 8 1 7 5 5 1 6 4 5 1 1 9 1 5 6 9 7 4 5 8 10 3 2 3 10 2 9 8 3 3 5 5 9 5 7 10 6 2 6 9 10 5 3 1 6 2 8 1 1 3 9 3 6 9 7 6 8 8 4 7 9 8 8 6 6 7 7 8 4 9 5 9 9 3 4 8 1 6 6 10 7 2 10 8 10 5 4 5 8 7 5 5 7 2 9 8...

output:

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

result:

ok 120000 lines

Test #23:

score: 11
Accepted
time: 85ms
memory: 95396kb

input:

10 120000
RRRRRRRRRR
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...

output:

9
5
9
2
9
8
9
9
7
6
9
9
9
6
7
9
9
7
5
9
9
9
9
9
3
9
9
7
7
2
9
9
9
9
7
3
7
7
7
5
9
9
9
6
9
9
7
9
7
9
9
9
9
9
9
9
9
6
9
9
9
9
9
9
2
9
5
6
7
7
7
9
2
9
9
2
9
9
9
2
9
2
9
9
5
7
7
6
2
9
9
7
9
8
2
9
9
2
9
9
9
9
7
9
9
9
9
6
9
8
7
8
7
7
2
7
7
6
9
9
6
9
9
9
2
3
2
9
9
9
9
9
9
9
7
7
9
9
9
6
9
9
7
7
7
9
7
2
9
7
...

result:

ok 120000 lines

Test #24:

score: 11
Accepted
time: 126ms
memory: 102432kb

input:

10 120000
RRRRRRRRRR
9 1 5 3 5 6 4 7 4 3 2 2 5 3 1 8 6 6 2 4 7 5 5 4 8 4 7 10 1 4 7 6 8 4 9 2 9 9 6 6 2 1 8 6 3 8 6 7 9 10 7 10 5 10 10 1 4 10 9 8 7 1 6 5 2 8 3 6 9 5 7 4 4 9 9 9 1 5 4 3 6 1 4 1 8 10 7 2 10 1 5 3 2 3 2 6 2 9 5 1 5 6 3 1 9 8 1 4 5 8 8 10 6 2 8 4 2 7 5 9 2 10 2 8 10 7 3 5 3 9 5 9 3 9 ...

output:

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

result:

ok 120000 lines

Test #25:

score: 11
Accepted
time: 144ms
memory: 99516kb

input:

10 120000
RRRRRRRRRR
3 7 3 1 1 4 4 5 6 8 9 7 1 3 6 5 9 9 7 2 1 10 1 7 2 5 10 7 10 2 8 3 2 8 6 5 7 10 1 1 9 10 3 1 8 7 4 6 3 7 8 5 8 8 10 5 9 1 2 8 7 1 6 6 8 9 9 3 5 7 6 8 10 9 1 7 10 1 10 8 7 4 2 7 3 7 9 5 3 3 3 5 1 4 1 5 8 1 2 5 2 7 8 3 4 3 3 8 8 8 6 1 5 2 2 6 2 1 5 6 8 1 8 10 4 3 4 8 5 5 5 1 4 6 1...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 120000 lines

Subtask #5:

score: 26
Accepted

Test #26:

score: 26
Accepted
time: 928ms
memory: 814812kb

input:

120000 120000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

output:

23441
85217
55120
85435
90828
27927
63967
41321
97520
63588
53976
9028
23460
86914
85688
112911
68792
102907
14973
38475
71931
17922
62077
53185
57121
43774
12583
21332
82917
28259
92209
28023
51606
65188
44768
34904
96969
18999
3653
3865
42795
86270
55638
108702
7871
68493
109086
40077
60406
38299
...

result:

ok 120000 lines

Test #27:

score: 26
Accepted
time: 873ms
memory: 813952kb

input:

120000 120000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

output:

2018
77981
92021
56481
116102
56745
67069
27266
30240
27284
13740
91171
108960
56234
109524
112538
55657
42972
50147
67079
7111
117407
39871
76936
45716
91668
95720
77368
97105
85437
79208
67078
48361
96495
85567
55381
19702
20133
30919
44934
86141
2061
51472
119392
58595
83081
98072
70266
44208
836...

result:

ok 119999 lines

Test #28:

score: 26
Accepted
time: 638ms
memory: 813952kb

input:

120000 120000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

output:

74259
100417
22098
39799
56013
106728
100176
691
115099
118024
24216
53415
50787
78009
93371
114696
10114
113629
42308
99501
31925
2977
101690
15659
8409
87275
8847
117293
75701
3539
100844
31941
32198
3892
91695
29078
71179
92631
112213
43774
2220
17510
30742
69729
41857
84581
82608
73397
77072
935...

result:

ok 120000 lines

Test #29:

score: 26
Accepted
time: 704ms
memory: 813808kb

input:

120000 120000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

output:

93180
85506
102645
62667
72263
51220
85142
81308
76933
106402
99293
27616
94064
104319
9479
119556
70424
76433
61917
110968
48994
108260
66210
40756
64358
89287
104790
100481
108187
20280
118127
29501
61041
59815
17775
87287
77037
95623
78604
90259
65811
33371
14467
12846
35149
18246
32718
84622
903...

result:

ok 120000 lines

Subtask #6:

score: 17
Accepted

Test #30:

score: 17
Accepted
time: 621ms
memory: 793040kb

input:

120000 120000
RRBBRBRBBBRBRRBRBRRRBRBRRBRRRBBRBBBBBBRBBRBRBRBRRBRBRBRRRBRBBBBRRBBRRBBRRRBRRBRBBRRRBBBRRBBBBRBBBRBBBRBBBRBBRBBBBRBBBBRRBRRRRRRRBRRRBRBBBRBBBBRBBRBRBRRBBRRBRBBBBRBBBRBBRRBBBBRBBBBRBRRBRBBRBBBBRRBBBBBBRBBRBBBBBBRBBRRRRRBBBRBBBRBRRBBRBRBRBBRRBRRBBBRBRBRRRBBRRBBRRRRBRRBBRRBBBBBBBRBBBRBBBR...

output:

83101
101089
86861
90592
87368
108738
85550
95262
105111
86861
84761
89448
86987
84642
85927
98400
101647
115069
86358
88161
88124
102000
90017
82325
88897
98142
108041
110441
85050
97578
100054
87655
103638
97493
109084
94342
87147
88779
96474
87274
96348
81879
109022
85971
93668
106944
103118
8279...

result:

ok 120000 lines

Test #31:

score: 17
Accepted
time: 731ms
memory: 795136kb

input:

120000 120000
RRBBRBBRRRBBBRRRBBBBBBRRBRBRRRRRBRRBBRRRBBRRRBRRRBRRBRRRRBRRBBBBRRBBRRRRBRBBRBRRRBBBRBBRRRBRBBRBRBBRRRRBBBBBRBBBRRBBBRRBRBRBBBRBBRRBRRBRBRBBBRBRBBBBBBRRRRRBBBRBRRRBBRBRRRBRRRRRRBBBBRBRBRRRRBBRBBRRBRBRBBBBBBRBBBBBBRBRBRBRBBRBRRBRRRBRRRRBBBBBRBBRBRBBRBBRBBRRRRRBRRRBRBRRBRRRBBRBRBRRBRBBBR...

output:

92866
110882
108810
90785
94071
80631
102550
84384
94229
84657
84178
82402
109858
98117
83183
93410
91944
87028
87275
109575
91747
80319
88128
89077
81770
88487
86883
88321
91390
101033
88090
107250
105110
106812
83499
111670
84865
86486
81207
109597
83841
115123
89424
81691
84640
84874
85595
89074
...

result:

ok 120000 lines

Test #32:

score: 17
Accepted
time: 816ms
memory: 799024kb

input:

120000 120000
BBBRRRRRBBBRRRBRBBBRBBBRBBRRRBBRBRRRRRRRRBRBBBRBRRBBRRBRBBRBBRBBBRRRRBBRBBBRBBBBBBBBRRRBRBBRBRRRRRRRRRBBRBBBRBRRBRBBBRBBRRRBBRBBRRBRRBBRBRRRBRRBRBBBRRRRRBRBRRRBBBRBRBRRRRRBBBRBBBBRRBBRRBRRBBBBBRRBRBRBRBBRBRRBBBBBRRBRRBBBRRRBBBBBRRBBBRBRRBRRRBRRBRBBBBRBBBBRBRRBBBRBRRRBRBRRBRRRRBRRBBBBRR...

output:

100750
95747
94413
100546
108006
96874
95735
99003
92141
102234
97285
97127
96651
102069
92244
103460
99375
96829
95112
92109
105106
101757
95213
99873
113425
99147
100242
91629
100413
93587
105073
98303
98849
97452
104721
96662
110488
97452
89979
107495
99380
92656
90698
106911
106142
99158
101391
...

result:

ok 120000 lines

Test #33:

score: 17
Accepted
time: 896ms
memory: 801144kb

input:

120000 120000
RBRBRRBBRRBRRRBBRBBRRBRBRBRBBBBRRRRBRBBBBRBRRRBRRRBBBBRRRRBBBBRBRRBRBBRRBBRBBRBBBRBRBBRRRBBRBRBBRRBRBBRRBBBRBBBBBRBBBRBRBRRBRRRBRBRRBBRRRRBRRBRRBBRRBRRBBBRRBBRBBBRRBBRBRBBBRBRBBRRBRBRRRRBRRRRBRRRRRBRBRRBRBRBRBRBRRRBBRRBRRRRRRBBRBRBBBRRBBBRBRBBBBRBBBBRBBRBBBRRBRRRBBBBRBRRRBRRBBBRRRBBBRB...

output:

75946
73695
73900
72794
66617
89456
65128
86988
61618
65321
68792
68092
73196
119411
73247
90546
98247
72743
96076
93403
89744
70186
91501
86816
72216
105526
72887
68048
87792
79786
96068
67065
112466
86536
107562
74785
68073
79452
102666
79143
100234
81438
82253
81935
79677
83996
72501
68584
86855
...

result:

ok 120000 lines

Test #34:

score: 17
Accepted
time: 925ms
memory: 802036kb

input:

120000 120000
BRRBRBBRRRBBBRBRBRBRRRBBRRRBBBBBRBRBRRBRBRRBBRBBBRRRRRRBBRRBBBRRRBBRRBBBRBRBBRBBRRRBBBRBRBRBBBRBRRRBRBBRBRBRRRBRBRRRBRBRBRBBRBRRBRRRBRBBRRBBBRBBBBBRRRRRRBRRRBBRRRRRRBBRRRRBRRRBRBRBRBBRRRBRBBRBBBRBRRBBRBRRBBBBRBBRBRRBBRBBRBBRRRBRBBBRBBRBBBBBBBBRBBBBRBRRRBBRBRRBBBRBRBBBRBBRBBBBRBRBRBBBBB...

output:

82065
81819
78047
109174
96117
73289
96503
89219
115572
87385
84410
92281
95100
94705
77054
72350
119158
108622
79845
91467
116649
83346
84349
91015
2238
80936
91717
105267
96978
90698
76765
104058
78302
77244
103100
76016
85487
77258
114203
89635
87506
98855
108126
85006
82995
118932
99947
83939
93...

result:

ok 119999 lines

Test #35:

score: 17
Accepted
time: 441ms
memory: 789928kb

input:

120000 120000
BBRRBRRRRBBBBBBRBRRBBRRBBBRRRBRRBRBRRRRBBBRRRBBBBRRRRBBBBRRRRBRRRRRRBRBRRRBBBRBBBRBBRRRRBRBBBRRRRBBBBRRBRRRBBBRBBRBBRRRRRBRBBBRRBBRRBBBRRRBRRBRRBRBRBBBBBBRBBRRRBBBBBBBBBBBBBBRBBRBRRBRBRRRBBRBBBRRRBRBBRBBBRBRRRRBRRRRRBRBRBRBBBBRRRBBRBBRRRBRBRBBBBRRBBRRBRBRBRBBBBRRBRRBRBBBRRBRRRRBRRBRBBB...

output:

99244
98229
97603
97183
97261
98626
101594
96302
97487
95973
103367
96945
105167
105624
96262
101907
101469
99649
100159
98059
98498
99570
98580
102622
102965
98496
103044
100382
101067
98319
96213
102668
96132
97234
100936
100604
102358
103467
98910
104099
96640
96573
99136
99148
99419
97356
102090...

result:

ok 120000 lines

Test #36:

score: 17
Accepted
time: 428ms
memory: 789412kb

input:

120000 120000
BRRRBBBBBRBRBRBBRRBRBRRRRBRRRBRBBRBRRRBRBBRRBRBBBRBBBRBBRBBBBBBRBRRRBRRBRBRBBRBRRRBBBBRRRRRBBRRRRBBBBRBBRRBBRRRRRRBBBBBBBRBRRRBRRBRRRRRRBRRBBBBBBRRRRRRBRRRRRBRRBBBRBBBRRBBBBRBRRRBRBRRRBBBBRRRBRRRRRRBRBBRRRRRRBBRBRBRRRRBRRBRBRRRBBRBRRRRBRRBRBRRRBBBBBRBBBBRBBBBRRRRRRRRBBRRBRRRRRBBBBBRRBR...

output:

97817
107079
101735
97584
104503
101986
105953
99448
99475
102921
96656
96654
103112
102693
103449
100594
98010
104209
97080
104130
96277
102823
97698
99238
100091
99994
96914
103970
100533
106020
101667
101231
104643
104791
96698
99256
96820
100406
100324
103994
96514
103984
97192
101485
104858
103...

result:

ok 120000 lines

Test #37:

score: 17
Accepted
time: 200ms
memory: 779572kb

input:

120000 120000
BBRRRBRBRBBRBBBBRRBBRBBRBBBRRBBBBRRBBRRRBRRBRBBBRRRBBRRRRBBRBBRBRRBBRBBRBBBBBBRBRBRBRBBBRRRBRRBBRRRRRBBBBBRRRRBRBRRRRBRRBBBBRBBBBRRRBBBRBRBBBBRBRRRRRBRRBRBRBRRBBBBRBRRRRRRBRRRRRBRBRBRRRBBRRRRBBRBRRRBBBRBRRBBRBBBBRBBBBRBRBBBBBBBBRRBBRRBBRRBRRBBRRRBRBBBBBBRBRBRRBRRBBBRBRBRBRBBBBRBBBRRRRR...

output:

60464
60446
60359
60363
60599
60407
60379
60396
60413
60371
60407
60472
60445
60376
60331
60502
60389
60552
60430
60409
60403
60545
60521
60387
60379
60497
60430
60380
60438
60337
60474
60401
60550
60635
60535
60376
60536
60450
60418
60400
60392
60366
60550
60393
60413
60365
60383
60442
60365
60583
...

result:

ok 120000 lines

Test #38:

score: 17
Accepted
time: 207ms
memory: 779780kb

input:

120000 120000
BBRRRRBRRBBBBRBBBRBRRBRRRRRRRRRRRRRRBBBBBBRRRRRRRBRRRBBBBBRRRRBRRBBRRBRRBBRBBRRRRRBRBBBBRBBBRRBRRRRRRRRRBBBRBRBRBRRRRBRRBBRBBBRRBRBRRBRBBBRRBBRBBBRRBBBRBRBBBBBRRBRRBBBBRBRRBBBRRBRRBBBRRRBBRBBRBRRRRRRBRRBRBBRRBRRBBRRRBRBRRBBRRRRRBRRBBBRRBBRBRBRRBBRBRRRBRBBBBRBBRRRRRBBBRRBRBBRBBBRBBRRRBB...

output:

60802
60977
60891
60842
60853
60834
60967
60730
60942
60781
60929
60783
60782
60800
60790
60861
60900
60773
60779
60742
60791
60795
60763
60874
60878
60833
60844
60835
60749
60772
60928
60944
60756
60910
60906
60850
60809
60892
60791
60746
60767
60937
60864
60856
60900
60822
60778
60785
60880
60849
...

result:

ok 120000 lines

Test #39:

score: 17
Accepted
time: 491ms
memory: 807556kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

14710
37063
3353
6955
13419
57057
29638
36309
9744
11408
8907
20645
24106
17297
22351
25818
9661
39222
2788
45046
5279
44876
6442
21298
24321
2544
42190
15672
49632
49301
11610
7948
13124
16574
16081
34898
44314
16501
29833
23143
28619
19949
29447
32312
11679
41739
37975
9924
53207
17438
16846
34813...

result:

ok 120000 lines

Test #40:

score: 17
Accepted
time: 476ms
memory: 802372kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

10585
10465
86372
118843
113148
5643
2219
96235
117409
111785
10480
91865
117964
93792
113667
89617
95644
95855
1668
7768
114171
111527
5065
6612
111639
7051
219
86028
100578
118859
95986
99925
9065
115550
111847
11025
116522
105783
6807
11497
100644
11078
7316
11535
119153
8616
102458
2441
116224
1...

result:

ok 120000 lines

Subtask #7:

score: 21
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #41:

score: 21
Accepted
time: 850ms
memory: 804828kb

input:

120000 120000
BBBRBBBRRRRBBRBRBBBRRRRBBRBRRBRBBBBBRBBBBRRRRRBRRBBRBRBBBRBBRRRBBRBRBBRRRBRBBRRBRBRBBRBBRRBBBBRBRBBBBRBRBRBBBBBRRBBRBRBBBRBBBRBRRBBBRRRRBRBBBBBRRBBRRRRBBBRRRRRRRBBBRRRBBBRRBBRBBBRBRBRBBRRBBBRBRBBBBBRRRBRBRBBRBBRBBRBBRBBBBBBRRBBBBRBRBRBRBRRBBRRBBBRBRRRRBBRRRBBRBBBBRBRBBRRRRRRRBRRRRBRBBR...

output:

103430
108347
95882
82353
98822
91317
85564
103721
91997
86890
93583
106088
90290
86519
107859
102865
97042
100678
90384
104903
99475
106333
95990
91500
96470
102921
93357
92400
102494
92907
103224
104755
104295
91881
96965
89695
93551
93444
95986
103597
100556
95538
96950
101735
90673
92499
93390
9...

result:

ok 120000 lines

Test #42:

score: 21
Accepted
time: 1179ms
memory: 813472kb

input:

120000 120000
BBBBRBRBRBRRRBBRRRRRBRRRBRBRRRRRBBBRRRBRRRBBRBBRRRRBRRBBRRRBBBBBBRRRBBBRRRBRBBBBBBRBRBBBRRRBRBBRRBRBRBRRBBBBRBRRRBBBRBBRRBRBBRBBBRBBBBBBRRRRRRRBBBBBRRRRRRBBRRBBRBRBRRBBBRRRBRBBBRBBRBBRRRBRBBRRRBBRBBBRRBRBBBRRRBRRBRRRBRRRRRBRRRRRBRRBRBRBRBBRBRBRBRRBRRBRRBRBRRRBBRRBBBRBBBBBRRBBRRRRRRBRRB...

output:

114889
34985
49903
18201
117978
102268
79654
102620
55660
19264
31946
65120
47441
5353
34908
21592
2824
118112
118736
75603
97700
11784
28339
79686
66259
44336
40214
60990
32816
38536
79548
30226
23658
83111
100629
18791
106476
94262
103009
53269
81884
77406
44953
10371
21818
50915
20339
59645
58089...

result:

ok 120000 lines

Test #43:

score: 21
Accepted
time: 936ms
memory: 813324kb

input:

120000 120000
BBRRBBBRBRBRRRBRBRBBRBBRBBRRRRRRRBRBBBRBBRBBRRBRBBBBBBBRBRBBRBRBRBRRBRBRBBRBRRBBBBRRRRBBRBBBBRRRBRRBBRBRRBBBRBRRRRBRBRRRRBRBBBBBRRBRRBBBRBBRRRRRRRRBRRRBRRBBRRRBBRBRBRBBBRRRRBRBBRRBBRRBRRBBBBRRRRBBBBBRRRRBBRBRRBBBRRBBRRRBBBRRRBRBRRRRBRRRRRRBRBRRBBBRBRRBRRBBRRRBRBRBBRBBBRRRRBRRRRRBBRRRRB...

output:

58936
18221
11858
20356
96340
46411
32947
91478
2851
51623
110697
6058
50182
4516
78346
116495
76267
91519
12468
76978
87440
15962
79389
40314
48385
55553
96661
73860
26007
105491
97617
80151
69893
48806
23257
94269
3643
81214
84039
18512
103499
109872
98060
112742
79725
39428
16344
14870
87306
8555...

result:

ok 120000 lines

Test #44:

score: 21
Accepted
time: 1055ms
memory: 808392kb

input:

120000 120000
BRBBRBRRRBBBBRBBRBRRBRBRBRRRBBBBRBBBBBRRRRRBRBBRRBRRRBBBBRBRBBBRRRBBRRRRBRBBBBBBBBRRBBRBBRBBRRRBRBBBRBRRRRRBBRRBBBBRBBRRRRBBRRRBRBBBBRRRBBRRRBRBBBRRRRBRRBBRRBBBRBBBRRBRRRRBBBBBBBBBRBRRBBRBRBBBBBBRBRRRBBBRBRBRRRRRRRRBRBRRBBRBRBBRBBBBBRRBBBRBRRRBBRRRRBRRBRRBBBBBRRBBBRRBBBRRRBBRRRRBRRRBRB...

output:

40938
21998
52111
3006
25545
76228
87630
13810
112826
117162
26955
7952
75909
105900
63672
116110
46270
66757
57926
13134
63707
37043
112208
110655
102165
21855
108709
18338
105499
12188
103468
46470
79506
35374
41629
25076
8777
107865
111784
62563
59155
101012
51472
44006
48609
42977
34232
5676
766...

result:

ok 120000 lines

Test #45:

score: 21
Accepted
time: 279ms
memory: 779664kb

input:

120000 120000
RRBRRBRRRRRRBBRBRBRRBBRRBRRBBRBBRRBRBRBBRBRRRBRRRRRRRRBRRRRRBRRRRRBBRRRRBRBBBRBRRRBRBBRRBBBRBRRRBBBBBBRBBBRRBBBBRRBRBRBRBRRRRBRBBBBRRBBBBBBRBRBBBBRRBBRRRRBBBBRRRBRBBBBRRBRBBBBBRRBBBBRRRRRBBRRBRBRRBRBRBRBBRRBBRRBRBRBBBBBBRBRRBRRRRBRRRBBBRBRRRRBRRBRRBRBBBBBBRBRBBRRBBRBRRBRBRBBRRBRRRBBRRR...

output:

49463
49545
64919
112152
17816
4503
16311
112212
49557
16815
16822
399
33176
17295
16821
16788
33430
49555
18824
16819
2455
17800
20879
8599
108118
65878
16983
112214
17811
49367
47542
112214
48567
17816
17800
403
48551
1431
17295
17813
16821
108116
104055
48543
24919
104276
49496
37270
16808
32152
...

result:

ok 120000 lines

Test #46:

score: 21
Accepted
time: 258ms
memory: 779736kb

input:

120000 120000
BRBBBRBBRBBRBRBRRBRRBRBBBBRBBBRBRBBBRBRRBBRRRBBRRRRRBRBRRBRBRBBBRRBBRBRBRBBRRBRRBBRRBBRRRRBRRBRRRRRBRRBBRRRRRBBRRBBRBRRBRRBBBBRRBRRBRRBRRBBBRBBBRRRBBBBRRBBRBRRBBBRRBRRRRRRBRBRRBBBBBRBRBRRBRRBBRBBBRBRRRRBRRBRBBBBRBBRRBRRRBBRBRBBRRBRRRBRRRRBBRRRRRBRBRBRRBBBBBRRBBBBBRRRRRRBRRBRBRBRBRRBRRR...

output:

49330
65826
24370
17712
20786
16948
23857
81971
16679
49333
17586
17699
49962
20785
47410
49396
49443
65329
13618
45617
45362
24875
16693
20771
17586
16883
2354
16693
32946
16690
17714
16788
16677
45489
17707
17651
17074
49451
4402
20723
48440
16690
8498
24875
49443
49330
42292
16698
15666
20274
207...

result:

ok 120000 lines

Test #47:

score: 21
Accepted
time: 243ms
memory: 710140kb

input:

65536 120000
BRRRBBRBBBBRBBRRBBBRRBRBBRRRRBBBRRBRRRBBBBBBRBRRRBRBRBRRRBBRRRRRBBRBRBBBBBRRRBRRBRRRBBBBBBBRRBRRRBBRBRRBRRBRBBBBBBBRBBRRRBBBBRRRRBRRRBBRRBBRRBRBBRRBRRBRBRRBBBRBRRBBBBBBRRBBBRRRBRRBBRBRRBBRRBBBBBRBRBBBBRBBBRBBBRRRRRBBRRBRRBBRBRRBBBBRRBBBBBBRBRBRBRRRBRBRRRRRBBBRRBRBBBRRRRBRBRRRBBBBBRRBBBR...

output:

0
130
63632
32836
63505
61468
61456
61580
3
63508
49052
63632
32898
14
6
65174
63508
32799
94
34815
32896
63512
18
32900
130
65047
14
6
61460
130
128
32836
33028
256
63632
49052
128
65174
63632
36764
14
65535
128
26
61468
0
63505
40927
128
49151
32895
31
130
65535
36868
65535
49191
65321
130
128
6
6...

result:

ok 120000 lines

Test #48:

score: 21
Accepted
time: 287ms
memory: 711048kb

input:

65536 120000
RBBBRBRBRBRRBRRBRRBBBBBBBRBRRBRBBRBBBBRBRBBRBBRRBBRRRRBRRBRRRBBBRRRBBBBRRBBBRRBBBRBBBRBRRBRBRBBRRRBRBRBBRBBRRBBBBBRRRRBRRRBRBRRBBBBBRRRRBRBBBBRBBRBBRBBRRBBRRRBBBBRRRBBRBBRBRBBRRBBBRBBBRBBBRRBBRRRRRRBBRBBBRBRBBRRRRBBBBBRRBBRBRBRRRBRRBRRBBBRRBBBBRBRRBBRBRBRRBRBRRBBRBBRBBBRRBBRBRRRBRBBBRBR...

output:

33416
32936
34952
37000
16521
32688
32920
33416
37000
33429
25245
49288
32421
33416
33160
1174
1161
16303
33047
33400
33928
33928
662
4120
16473
34839
26781
37013
33303
4120
662
1161
16532
33928
4233
37000
29856
32933
32925
32688
33928
34952
32936
2198
33199
1161
33928
33303
4185
32912
28829
32920
4...

result:

ok 120000 lines

Test #49:

score: 21
Accepted
time: 641ms
memory: 739044kb

input:

65536 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

32887
33014
65518
63483
63483
57341
63483
65399
65399
33780
32824
32768
33269
63483
65519
32768
63483
33780
40945
32778
63483
65519
61436
32778
65399
65518
65519
64506
65508
32824
65508
65508
65017
32768
65399
65515
36850
65519
32793
32824
63483
40945
32887
32771
65519
65399
32771
65508
40945
61436
...

result:

ok 120000 lines

Test #50:

score: 21
Accepted
time: 688ms
memory: 808596kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

60246
59999
62035
60056
62035
60246
68177
92751
92751
60010
68177
62035
92750
60119
92725
88668
61012
76382
92740
88668
76368
91738
68177
91738
92694
84573
62035
60119
60246
92249
92725
60003
92750
84573
92725
92631
60246
60000
60000
90715
60025
88668
64082
60056
90715
60501
62035
92751
64082
59999
...

result:

ok 120000 lines

Test #51:

score: 21
Accepted
time: 684ms
memory: 808168kb

input:

119823 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

92161
59911
91650
84485
92161
59912
92637
88580
60158
92652
92652
59911
92606
84485
92662
90627
61947
59922
63994
92663
76294
60031
59912
76280
63994
92606
84485
60031
59915
92161
92606
92663
76294
92663
92161
92663
92637
61947
92663
92659
92161
92161
92663
59915
91650
60031
60158
59911
59915
60031
...

result:

ok 120000 lines

Test #52:

score: 21
Accepted
time: 953ms
memory: 815920kb

input:

119823 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

20294
51051
68305
38100
100014
29447
60553
32538
35695
105694
6678
6042
55944
92453
62393
41576
70273
26820
42730
101814
4820
81346
72259
92475
4688
17795
113017
106457
59560
17796
43697
71202
1910
88017
22373
85844
40718
8034
22367
1674
74511
115687
114759
57515
87666
71106
60833
109156
95318
11143...

result:

ok 120000 lines

Test #53:

score: 21
Accepted
time: 539ms
memory: 809308kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

42834
106328
92188
96540
105727
53547
62368
47498
13345
93586
87912
85028
89337
24188
83967
83087
36470
77645
82885
23770
76260
85225
80842
88075
107663
54960
51748
88396
21903
97103
37886
39438
52849
9142
62419
28900
84561
91168
20614
100877
23733
62036
61776
19340
72741
87834
82292
7920
56702
4747...

result:

ok 120000 lines

Test #54:

score: 21
Accepted
time: 560ms
memory: 808216kb

input:

120000 120000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

94676
59816
91980
25080
37905
17685
118924
40888
106526
32358
82816
34290
56251
64708
33092
18056
61480
19082
83963
59044
67906
47095
3224
41276
112139
102386
17933
37662
110084
85349
88920
86271
22524
85983
43839
55317
97086
46021
45261
7462
8314
50305
17545
83401
101792
117650
28989
39316
45986
35...

result:

ok 120000 lines

Extra Test:

score: 0
Extra Test Passed