prithivMLmods/Coder-Stat huggingface dataset:
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  char D[4] = {'A', 'T', 'G', 'C'};
  int count = 0;
  vector<int> C;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (S.at(i) == D[j]) {
        count++;
        break;
      }
      if (j == 3) {
        C.push_back(count);
        count = 0;
      }
    }
  }
  cout << *max_element(C.begin(), C.end()) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  char D[4] = {'A', 'T', 'G', 'C'};
  int count = 0;
  vector<int> C;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (S.at(i) == D[j]) {
        count++;
        break;
      }
      if (j == 3) {
        C.push_back(count);
        count = 0;
      }
    }
  }
  C.push_back(count);
  cout << *max_element(C.begin(), C.end()) << endl;
}
Problem p03086 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define range(i, n, m) for (int i = n; i < m; i++)
#define rrange(i, n, m) for (int i = n - 1; i = > m; i--)
#define MOD 1000000007;

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;

  cin >> S;

  ll max = 0;
  ll count = 0;

  for (char s : S) {
    if (s == 'A' || s == 'C' || s == 'G' || s == 'T') {
      count++;
    } else {
      count = 0;
    }

    if (max < count) {
      max = count;
    }
  }

  cout << max;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define range(i, n, m) for (int i = n; i < m; i++)
#define rrange(i, n, m) for (int i = n - 1; i = > m; i--)
#define MOD 1000000007;

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;

  cin >> S;

  ll max = 0;
  ll count = 0;

  rep(i, S.size()) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      count++;
    } else {
      count = 0;
    }

    if (max < count) {
      max = count;
    }
  }

  cout << max;

  return 0;
}
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
S = input()

res = []
tmp = []
for s in S:
    if s == "A" or s == "C" or s == "G" or s == "T":
        tmp.append(s)
    else:
        res.append(len(tmp))
        tmp = []

print(max(res))


Fixed submission:
S = input()

res = []
tmp = []
for s in S:
    if s == "A" or s == "C" or s == "G" or s == "T":
        tmp.append(s)
    else:
        res.append(len(tmp))
        tmp = []
res.append(len(tmp))
print(max(res))
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
N = input()
answer_list = []
answer = 0

for i in range(len(N)):
    if N[i] == "A" or N[i] == "T" or N[i] == "C" or N[i] == "G":
        answer += 1
    else:
        answer_list.append(answer)
        answer = 0
print(max(answer_list))


Fixed submission:
N = input()
answer_list = []
answer = 0

for i in range(len(N)):
    if N[i] == "A" or N[i] == "T" or N[i] == "C" or N[i] == "G":
        answer += 1
    else:
        answer_list.append(answer)
        answer = 0
    if i + 1 == len(N):
        answer_list.append(answer)
print(max(answer_list))
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
S = input()
S_list = list(S)
answers = []
acgt = 0
for s in S_list:
    if s == "A" or s == "C" or s == "G" or s == "T":
        acgt += 1
    else:
        answers.append(acgt)
        acgt = 0
print(max(answers))


Fixed submission:
S = input()
S_list = list(S)
answers = []
acgt = 0
for s in S_list:
    if s == "A" or s == "C" or s == "G" or s == "T":
        acgt += 1
    else:
        answers.append(acgt)
        acgt = 0
answers.append(acgt)
if answers:
    print(max(answers))
else:
    print(acgt)
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
s = input()
i = 0
ans = 0
while i < len(s):
    if s[i] == "A" or s[i] == "T" or s[i] == "C" or s[i] == "G":
        for j in range(len(s) - i):
            if (
                s[i + j] != "A"
                and s[i + j] != "T"
                and s[i + j] != "C"
                and s[i + j] != "G"
            ):
                break
        ans = max(ans, j)
    i += j
print(ans)


Fixed submission:
s = input()
i = 0
ans = 0
atcg = "ACGT"
for i in range(len(s)):
    for j in range(i, len(s)):
        t = s[i : j + 1]
        cnt = 0
        for n in range(4):
            cnt += t.count(atcg[n])

        if cnt == len(t):
            ans = max(ans, cnt)


print(ans)
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
import re

s = input()
pat = r"[ACGT]+"
atgc = re.findall(pat, s)
ress = []
for i in atgc:
    ress.append(len(i))

print(max(ress))


Fixed submission:
import re

s = input()
pat = r"[ACGT]+"
atgc = re.findall(pat, s)
ress = []
for i in atgc:
    ress.append(len(i))
if ress == [""] or ress == []:
    print(0)
else:
    print(max(ress))
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
s = input()
ans = 0
li = ["A", "C", "G", "T"]
count = 0
for i in s:
    if i in li:
        count += 1
    else:
        if count > ans:
            ans = count
        count = 0
if count == len(ans):
    print(count)
else:
    print(ans)


Fixed submission:
s = input()
ans = 0
li = ["A", "C", "G", "T"]
count = 0
for i in s:
    if i in li:
        count += 1
    else:
        if count > ans:
            ans = count
        count = 0

if count > ans:
    ans = count
print(ans)
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0

print(max(ans))


Fixed submission:
S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0
ans.append(ll)

print(max(ans))
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
s = input()
ans = []
acgt = ["A", "C", "G", "T"]

cnt = 0
for i in range(len(s)):
    if s[i] in acgt:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0
print(max(ans))


Fixed submission:
s = input()
ans = []
acgt = ["A", "C", "G", "T"]

cnt = 0
for i in range(len(s)):
    if s[i] in acgt:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0
ans.append(cnt)
print(max(ans))
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
s = input()

s.append("X")
pat = ["A", "C", "G", "T"]
mx = 0
count = 0

for i in range(len(s)):
    if s[i] in pat:
        count += 1
    else:
        if count > mx:
            mx = count
        count = 0

print(mx)


Fixed submission:
s = input()

s += "X"
pat = ["A", "C", "G", "T"]
mx = 0
count = 0

for i in range(len(s)):
    if s[i] in pat:
        count += 1
    else:
        if count > mx:
            mx = count
        count = 0

print(mx)
Problem p03086 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B = 0, C = 1, D = 0, E;
  string S, K;
  cin >> S;
  A = S.size();
  for (int i = 0; i < A; i++) {
    for (int j = A; j > 0; j++) {
      K = S.substr(i, j);
      B = K.size();
      C = 1;
      for (int l = 0; l < B; l++) {
        if (C) {
          if (K[l] == 'A' || K[l] == 'T' || K[l] == 'G' || K[l] == 'C') {
            C = 1;
            E = j;
            if (E > D)
              D = E;
          } else
            C = 0;
        }
      }
    }
  }
  cout << D << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int B = 1, C = 0, D = 0, F, G = 0, H = 0, I = 0, S;
  string A;
  cin >> A;
  S = A.size();
  for (int i = 0; i < S; i++) {
    C = 0;
    for (int j = i; j < S; j++) {
      if (A[j] == 'A' || A[j] == 'T' || A[j] == 'G' || A[j] == 'C') {
        C++;
        if (C > D)
          D = C;
      } else
        C = 0;
    }
  }
  cout << D << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  string S;
  cin >> S;

  vector<int> count(S.size());

  int answer = 0;

  for (int i = 0; i <= S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      if (i == 0) {
        count[i] = 1;
      } else {
        count[i] = count[i - 1] + 1;
      }
      answer = max(answer, count[i]);
    } else {
      count[i] = 0;
    }
  }

  cout << answer << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {

  string S;
  cin >> S;

  vector<int> count(S.size());

  int answer = 0;

  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      if (i == 0) {
        count[i] = 1;
      } else {
        count[i] = count[i - 1] + 1;
      }
      answer = max(answer, count[i]);
    } else {
      count[i] = 0;
    }
  }

  cout << answer << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;

  vector<char> acgt = {'A', 'C', 'G', 'T'};

  vector<int> max;
  int num = 0;
  for (int i = 0; i < s.size(); i++) {
    if (!(count(acgt.begin(), acgt.end(), s[i]))) {
      max.push_back(num);
      num = 0;
    } else {
      num++;
    }
  }

  sort(max.begin(), max.end(), greater<int>());

  cout << max[0] << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  cin >> s;

  vector<char> acgt = {'A', 'C', 'G', 'T'};

  vector<int> max;
  int num = 0;
  for (int i = 0; i < s.size(); i++) {
    if (!(count(acgt.begin(), acgt.end(), s[i]))) {
      max.push_back(num);
      num = 0;
    } else {
      num++;
    }
  }

  max.push_back(num);

  sort(max.begin(), max.end(), greater<int>());

  cout << max[0] << endl;

  return 0;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int cou = 0;
  int ans = 0;
  string T = "AGCT";
  for (int i = 0; i < S.size(); i++) {
    bool isAGCT = false;
    for (int j = 0; j < 4; j++) {
      if (S.at(i) == S.at(j))
        isAGCT = true;
    }
    if (!isAGCT)
      cou = 0;
    else {
      cou++;
      ans = max(cou, ans);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int cou = 0;
  int ans = 0;
  string T = "AGCT";
  for (int i = 0; i < S.size(); i++) {
    bool isAGCT = false;
    for (int j = 0; j < 4; j++) {
      if (S.at(i) == T.at(j))
        isAGCT = true;
    }
    if (!isAGCT)
      cou = 0;
    else {
      cou++;
      ans = max(cou, ans);
    }
  }
  cout << ans << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') {
      int j = 0;
      while (s.at(i + j) == 'A' || s.at(i + j) == 'C' || s.at(i + j) == 'G' ||
             s.at(i + j) == 'T')
        j++;
      x = max(x, j);
      i += j;
    }
  }
  cout << x << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') {
      int j = 0;
      while (i + j < s.size() && (s.at(i + j) == 'A' || s.at(i + j) == 'C' ||
                                  s.at(i + j) == 'G' || s.at(i + j) == 'T'))
        j++;
      x = max(x, j);
      i += j;
    }
  }
  cout << x << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define ALL(l) (l).begin(), (l).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n + 1); i++)
using namespace std;
typedef long long ll;
// const ll mod =  1000000007;
// const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll =
    pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
  string s;
  cin >> s;
  int ans = 0;
  vi acgt;
  // cout<<s.size();
  rep(i, s.size()) {
    if (s.at(i) == 'A' || s.at(i) == 'T' || s.at(i) == 'G' || s.at(i) == 'C') {

    } else {
      acgt.push_back(i);
    }
  }

  ans = acgt.at(0);
  // rep(i,acgt.size())cout<<acgt.at(i);
  rep(i, acgt.size() - 1) { ans = max(ans, acgt.at(i + 1) - acgt.at(i) - 1); }
  // cout<<acgt.back()<<endl;
  int k = s.size() - acgt.back() - 1;
  ans = max(ans, k);
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

#define ALL(l) (l).begin(), (l).end()
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n + 1); i++)
using namespace std;
typedef long long ll;
// const ll mod =  1000000007;
// const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll =
    pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
  string s;
  cin >> s;
  int ans = 0;
  vi acgt;
  // cout<<s.size();
  rep(i, s.size()) {
    if (s.at(i) == 'A' || s.at(i) == 'T' || s.at(i) == 'G' || s.at(i) == 'C') {

    } else {
      acgt.push_back(i);
    }
  }
  if (acgt.size() == 0)
    cout << s.size();
  else {
    ans = acgt.at(0);
    // rep(i,acgt.size())cout<<acgt.at(i);
    rep(i, acgt.size() - 1) { ans = max(ans, acgt.at(i + 1) - acgt.at(i) - 1); }
    // cout<<acgt.back()<<endl;
    int k = s.size() - acgt.back() - 1;
    ans = max(ans, k);
    cout << ans << endl;
  }
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  vector<int> len;
  for (auto i = 0; i < S.length(); i++) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
      cnt++;
    } else {
      len.push_back(cnt);
      cnt = 0;
    }
  }
  cout << *max_element(len.begin(), len.end()) << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  vector<int> len;
  for (auto i = 0; i < S.length(); i++) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
      cnt++;
      if (i == S.length() - 1)
        len.push_back(cnt);
    } else {
      len.push_back(cnt);
      cnt = 0;
    }
  }
  cout << *max_element(len.begin(), len.end()) << endl;
}
Problem p03087 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
void need_enter() {
  while (getchar() != '\n')
    ;
  while (getchar() != '\n')
    ;
}
int main() {
  int N, Q;
  cin >> N >> Q;
  string str;
  cin >> str;
  str = " " + str;
  int *count = new int[N + 1];
  count[0] = 0;
  for (int i = 1; i <= N; ++i) {
    count[i] = count[i - 1];
    if (str.substr(i, 2) == "AC") {
      ++i;
      count[i] = count[i - 1] + 1;
    }
  }
  for (int i = 0; i < Q; ++i) {
    int a, b;
    cin >> a >> b;
    cout << count[b] - count[a] << endl;
  }
  need_enter();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
void need_enter() {
  while (getchar() != '\n')
    ;
  while (getchar() != '\n')
    ;
}
int main() {
  int N, Q;
  cin >> N >> Q;
  string str;
  cin >> str;
  str = " " + str;
  int *count = new int[N + 1];
  count[0] = 0;
  for (int i = 1; i <= N; ++i) {
    count[i] = count[i - 1];
    if (str.substr(i, 2) == "AC") {
      ++i;
      count[i] = count[i - 1] + 1;
    }
  }
  for (int i = 0; i < Q; ++i) {
    int a, b;
    cin >> a >> b;
    cout << count[b] - count[a] << endl;
  }
  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int *counter;
  counter = new int(N + 1);
  int i;
  counter[0] = 0;
  for (i = 0; i < N; i++) {
    counter[i + 1] = counter[i] + ((S[i] == 'A' && S[i + 1] == 'C') ? 1 : 0);
  }
  int head, tail;
  head = 0;
  tail = 0;
  for (i = 0; i < Q; i++) {
    cin >> head >> tail;
    head = head - 1;
    tail = tail - 1;
    cout << counter[tail] - counter[head] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int *counter;
  counter = new int[N + 1];
  int i;
  counter[0] = 0;
  for (i = 0; i < N; i++) {
    counter[i + 1] = counter[i] + ((S[i] == 'A' && S[i + 1] == 'C') ? 1 : 0);
  }
  int head, tail;
  head = 0;
  tail = 0;
  for (i = 0; i < Q; i++) {
    cin >> head >> tail;
    head = head - 1;
    tail = tail - 1;
    cout << counter[tail] - counter[head] << endl;
  }
  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

#define sp << " "
#define el << "\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i, a, n) for (i = a; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

void pre(int *ar, int n, string st) {
  int i, cnt = 0;
  ar[0] = cnt;
  For(i, 0, n - 1) {
    string demo = string(st.begin() + i, st.begin() + i + 2);
    if (demo == "AC")
      cnt++;
    // cout<<demo el;
    ar[i + 1] = cnt;
  }
  return;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, q, i;
  string st;
  cin >> n >> q >> st;
  int ar[n];
  pre(ar, n, st);
  // for(int t: ar) cout<<t sp;
  // cout el;
  For(i, 0, q) {
    int l, r;
    cin >> l >> r;
    r -= 1;
    l -= 1;
    // cout<<l sp<< r <<": ";
    cout << ar[r] - ar[l] el;
  }
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define sp << " "
#define el << "\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i, a, n) for (i = a; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

void pre(int *ar, int n, string st) {
  int i, cnt = 0;
  ar[0] = cnt;
  For(i, 0, n - 1) {
    string demo = string(st.begin() + i, st.begin() + i + 2);
    if (demo == "AC")
      cnt++;
    // cout<<demo el;
    ar[i + 1] = cnt;
  }
  return;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  /*#ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
  #endif*/
  int n, q, i;
  string st;
  cin >> n >> q >> st;
  int ar[n];
  pre(ar, n, st);
  // for(int t: ar) cout<<t sp;
  // cout el;
  For(i, 0, q) {
    int l, r;
    cin >> l >> r;
    r -= 1;
    l -= 1;
    // cout<<l sp<< r <<": ";
    cout << ar[r] - ar[l] el;
  }
  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int l[q][2];
  for (int i = 0; i < q; ++i) {
    cin >> l[i][0] >> l[i][1];
  }

  vector<int> cnt(n);
  int c = 0;
  for (int i = 0; i < n; ++i) {
    cnt.at(i) = c;
    if (s.at(i) != 'A')
      continue;
    if (s.at(i + 1) != 'C')
      continue;
    c++;
  }

  for (int i = 0; i < q; ++i) {
    int a = l[i][0] - 1, b = l[i][1] - 1;
    cout << cnt.at(b) - cnt.at(a) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int l[q][2];
  for (int i = 0; i < q; ++i) {
    cin >> l[i][0] >> l[i][1];
  }

  vector<int> cnt(n);
  int c = 0;
  for (int i = 0; i < n; ++i) {
    cnt.at(i) = c;
    if (s.at(i) != 'A')
      continue;
    if (i + 1 >= n)
      break;
    if (s.at(i + 1) != 'C')
      continue;
    c++;
  }

  for (int i = 0; i < q; ++i) {
    int a = l[i][0] - 1, b = l[i][1] - 1;
    cout << cnt.at(b) - cnt.at(a) << endl;
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  vector<int> sum(N + 1, 0);
  for (int i = 0; i < N + 1; ++i) {
    sum[i + 2] = sum[i + 1];
    if (S[i] == 'A' && S[i + 1] == 'C') {
      sum[i + 2]++;
    }
  }

  int l, r;
  for (int i = 0; i < Q; ++i) {
    cin >> l >> r;
    cout << sum[r] - sum[l] << endl;
  }
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  vector<int> sum(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    sum[i + 2] = sum[i + 1];
    if (S[i] == 'A' && S[i + 1] == 'C') {
      sum[i + 2]++;
    }
  }

  int l, r;
  for (int i = 0; i < Q; ++i) {
    cin >> l >> r;
    cout << sum[r] - sum[l] << endl;
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {
  int N, Q, l[10000] = {}, r[10000] = {}, count[10001] = {}, ans = 0;
  char s[100001];
  cin >> N >> Q;
  cin >> s;
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
    //	cout << l[i] << " " << r[i] << endl;
  }
  for (int i = 1; i < N + 1; i++) {
    count[i] = count[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C')
      count[i] += 1;
    // cout << count[i];
  }
  // cout << count[N];
  // cout << endl;
  for (int i = 0; i < Q; i++) {
    if (true) {
      cout << count[r[i] - 1] - count[l[i] - 1] << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {
  int N, Q, l[100000] = {}, r[100000] = {}, count[100001] = {}, ans = 0;
  char s[100001];
  cin >> N >> Q;
  cin >> s;
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
    //	cout << l[i] << " " << r[i] << endl;
  }
  for (int i = 1; i < N + 1; i++) {
    count[i] = count[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C')
      count[i] += 1;
    // cout << count[i];
  }
  // cout << count[N];
  // cout << endl;
  for (int i = 0; i < Q; i++) {
    if (true) {
      cout << count[r[i] - 1] - count[l[i] - 1] << endl;
    }
  }
  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

set<char> se = {'A', 'T', 'C', 'G'};

char s[100005];
int ans[10005];

int main() {
  int n, q;

  cin >> n >> q;

  scanf("%s", s);
  int len = n;
  int cnt = 0;

  for (int i = 0; i < len; ++i) {
    if (i > 0 && s[i] == 'C' && s[i - 1] == 'A')
      ++cnt;
    ans[i] = cnt;
  }

  // for(int i=0;i<len;++i)
  // cout<<i<<" "<<ans[i]<<endl;
  while (q--) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    cout << ans[b] - ans[a] << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

set<char> se = {'A', 'T', 'C', 'G'};

char s[100005];
int ans[100005];

int main() {
  int n, q;

  cin >> n >> q;

  scanf("%s", s);
  int len = n;
  int cnt = 0;

  for (int i = 0; i < len; ++i) {
    if (i > 0 && s[i] == 'C' && s[i - 1] == 'A')
      ++cnt;
    ans[i] = cnt;
  }

  // for(int i=0;i<len;++i)
  // cout<<i<<" "<<ans[i]<<endl;
  while (q--) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    cout << ans[b] - ans[a] << endl;
  }
  return 0;
}
Problem p03087 (Python)

Buggy submission (status: Runtime Error):
# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (2 * 10**5 + 10)
idx = 1
while idx <= len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])


Fixed submission:
# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (2 * 10**5 + 10)
idx = 1
while idx < len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])
Problem p03087 (Python)

Buggy submission (status: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

# lr = [list(map(int, input().split())) for _ in range(q)]

# 愚直な計算時間
# ループn回
# リスト切り取りO(n)
# O(n^2)
# 計算リミットが2000msで、n<=10^5
# 0(n)でn=10^6くらいが限度
# O8n^2)だと、n=3000くらい

# 先に回数を数える。累積和的に
hoge = [s[0 : (i + 1)].count("AC") for i in range(n)]

for _ in range(q):
    l, r = map(int, input().split())
    print(hoge[r - 1] - hoge[l - 1])


Fixed submission:
n, q = map(int, input().split())
s = input()

# lr = [list(map(int, input().split())) for _ in range(q)]

# 愚直な計算時間
# ループn回
# リスト切り取りO(n)
# O(n^2)
# 計算リミットが2000msで、n<=10^5
# 0(n)でn=10^6くらいが限度
# O8n^2)だと、n=3000くらい

# 先に回数を数える。累積和的に
# ここで結構時間かかる
# hoge = [s[0:(i + 1)].count('AC') for i in range(n)]

# 修正ver
hoge = [0]
cnt = 0
for i in range(1, n):
    if s[i - 1] + s[i] == "AC":
        cnt += 1
    hoge.append(cnt)

for _ in range(q):
    l, r = map(int, input().split())
    print(hoge[r - 1] - hoge[l - 1])
Problem p03087 (Python)

Buggy submission (status: Runtime Error):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readline_s = sys.stdin.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, Q = map(int, readline().split())
    S = list(readline_s().rstrip())
    ac_check = [0] * (N)
    tsum = [0] * (N + 1)

    for i in range(N - 1):
        if S[i] == "A" and S[i + 1] == "C":
            tsum[i + 2] += 1
            ac_check[i] = 1
            ac_check[i + 1] = 2

    for i in range(N):
        tsum[i + 1] += tsum[i]

    ans = []
    for i in range(Q):
        l, r = map(int, readline().split())
        count = tsum[r] - tsum[l - 1]
        if ac_check[l - 1] == 2:
            count -= 1
        ans.append(count)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Fixed submission:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readline_s = sys.stdin.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, Q = map(int, readline().split())
    S = list(readline().rstrip().decode())
    ac_check = [0] * (N)
    tsum = [0] * (N + 1)

    for i in range(N - 1):
        if S[i] == "A" and S[i + 1] == "C":
            tsum[i + 2] += 1
            ac_check[i] = 1
            ac_check[i + 1] = 2

    for i in range(N):
        tsum[i + 1] += tsum[i]

    ans = []
    for i in range(Q):
        l, r = map(int, readline().split())
        count = tsum[r] - tsum[l - 1]
        if ac_check[l - 1] == 2:
            count -= 1
        ans.append(count)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;
vector<int> ans(10010);
vector<int> memo(10010);
int main() {
  // 8 3
  //	ACACTACG
  //	3 7
  //	2 3
  //	1 8
  int N, Q;
  int l, r;

  string s;

  cin >> N >> Q;
  cin >> s;

  int count = 0;

  for (int i = 0; i < s.size(); i++) {
    if (i > 0 && s[i] == 'C' && s[i - 1] == 'A') {
      count++;
    }

    memo[i] = count;
  }

  for (int i = 0; i < Q; i++) {
    cin >> l >> r;

    int x = memo[r - 1] - memo[l - 1];

    ans[i] = x;
  }

  for (int i = 0; i < Q; i++) {
    std::cout << ans[i] << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;
vector<int> ans(100100);
vector<int> memo(100100);
int main() {
  // 8 3
  //	ACACTACG
  //	3 7
  //	2 3
  //	1 8
  int N, Q;
  int l, r;

  string s;

  cin >> N >> Q;
  cin >> s;

  int count = 0;

  for (int i = 0; i < s.size(); i++) {
    if (i > 0 && s[i] == 'C' && s[i - 1] == 'A') {
      count++;
    }

    memo[i] = count;
  }

  for (int i = 0; i < Q; i++) {
    cin >> l >> r;

    int x = memo[r - 1] - memo[l - 1];

    ans[i] = x;
  }

  for (int i = 0; i < Q; i++) {
    std::cout << ans[i] << endl;
  }

  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)
const ll MOD = 1000000007;

struct edge {
  int to, weight;
  edge(int to, int weight) : to(to), weight(weight) {}
};
using Graph = vector<vector<int>>;
using GraphEdge = vector<vector<int>>;

long long modinv(long long a, long long m = MOD) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
  /*MODの割り算の際に
  a/＝b;
  を
  a *= modinv(b,MOD);
  とする。
      */
}
int main() {

  int N, Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  int len = s.length();
  const int MAXN = 100001;
  int tm[MAXN];
  tm[0] = 0;
  Rep(i, len) {
    tm[i] = tm[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C')
      tm[i]++;
  }
  const int MAXQ = 100001;
  int l[MAXQ], r[MAXQ];
  rep(i, len) cout << tm[i] << " ";
  cout << endl;

  rep(i, Q) { cout << tm[r[i] - 1] - tm[l[i] - 1] << endl; }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)
const ll MOD = 1000000007;

struct edge {
  int to, weight;
  edge(int to, int weight) : to(to), weight(weight) {}
};
using Graph = vector<vector<int>>;
using GraphEdge = vector<vector<int>>;

long long modinv(long long a, long long m = MOD) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
  /*MODの割り算の際に
  a/＝b;
  を
  a *= modinv(b,MOD);
  とする。
      */
}
int main() {

  int N, Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  int len = s.length();
  const int MAXN = 100001;
  int tm[MAXN];
  tm[0] = 0;
  Rep(i, len) {
    tm[i] = tm[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C')
      tm[i]++;
  }
  const int MAXQ = 100001;
  int l[MAXQ], r[MAXQ];
  rep(i, Q) { cin >> l[i] >> r[i]; }

  rep(i, Q) { cout << tm[r[i] - 1] - tm[l[i] - 1] << endl; }

  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q), r(Q);
  for (int i = 0; i < Q; i++)
    cin >> l[i] >> r[i];

  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      A[i] = 1;
    } else {
      A[i] = 0;
    }
  }

  vector<int> Count(N);
  Count[0] = 0;
  int num = 0;
  for (int i = 1; i++; i < N) {
    num += A[i - 1];
    Count[i] = num;
    Count[i] = Count[i - 1] + A[i - 1];
  }

  for (int i = 0; i < Q; i++) {
    // for(int j=l[i] - 1; j < r[i] - 1; j++){
    //	count += A[j];
    // }
    cout << Count[r[i] - 1] - Count[l[i] - 1] << endl;
  }
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q), r(Q);
  for (int i = 0; i < Q; i++)
    cin >> l[i] >> r[i];

  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      A[i] = 1;
    } else {
      A[i] = 0;
    }
  }

  vector<int> Count(N);
  Count[0] = 0;
  // int num = 0;
  for (int i = 1; i < N; i++) {
    // num += A[i-1];
    // Count[i] = num;
    Count[i] = Count[i - 1] + A[i - 1];
  }

  for (int i = 0; i < Q; i++) {
    // for(int j=l[i] - 1; j < r[i] - 1; j++){
    //	count += A[j];
    // }
    cout << Count[r[i] - 1] - Count[l[i] - 1] << endl;
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  int Q;
  scanf("%d%d", &N, &Q);
  string S;
  vector<int> accumulate(Q + 1);
  cin >> S;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      cnt++;
    }
    accumulate[i + 1] = cnt;
  }

  for (int i = 0; i < Q; i++) {
    int l1;
    int l2;
    scanf("%d%d", &l1, &l2);
    printf("%d\n", accumulate[l2 - 1] - accumulate[l1 - 1]);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  int Q;
  scanf("%d%d", &N, &Q);
  string S;
  vector<int> accumulate(N + 2);
  cin >> S;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      cnt++;
    }
    accumulate[i + 1] = cnt;
  }

  for (int i = 0; i < Q; i++) {
    int l1;
    int l2;
    scanf("%d%d", &l1, &l2);
    printf("%d\n", accumulate[l2 - 1] - accumulate[l1 - 1]);
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, Q, count = 0, l, r;
  string S;
  cin >> N >> Q >> S;
  vector<int> vec(N, 0);

  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'C')
      vec.at(i + 1) = vec.at(i) + 1;
    else
      vec.at(i + 1) = vec.at(i);
  }

  for (int i = 0; i < Q; i++) {
    cin >> l >> r;
    cout << vec.at(r) - vec.at(l) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, Q, count = 0, l, r;
  string S;
  cin >> N >> Q >> S;
  vector<int> vec(N, 0);

  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'C')
      vec.at(i + 1) = vec.at(i) + 1;
    else
      vec.at(i + 1) = vec.at(i);
  }

  for (int i = 0; i < Q; i++) {
    cin >> l >> r;
    cout << vec.at(r - 1) - vec.at(l - 1) << endl;
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll dx[4] = {-1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
const ll MAX = 1e5 + 50;
const ll oo = 1e16;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(), v.end()
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n, m, q, ans;
string s;
int t[10100], sum[10100];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < n - 1; ++i)
    if (s[i] == 'A' && s[i + 1] == 'C')
      t[i + 1] = 1;

  for (int i = 1; i < n; ++i)
    sum[i] += t[i] + sum[i - 1];

  for (int i = 0; i < q; ++i) {
    int lo, hi;
    cin >> lo >> hi;
    --lo;
    --hi;
    cout << sum[hi] - sum[lo] << '\n';
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll dx[4] = {-1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
const ll MAX = 1e5 + 50;
const ll oo = 1e16;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(), v.end()
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n, m, q, ans;
string s;
int t[101000], sum[101000];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> q;
  cin >> s;
  for (int i = 0; i < n - 1; ++i)
    if (s[i] == 'A' && s[i + 1] == 'C')
      t[i + 1] = 1;

  for (int i = 1; i < n; ++i)
    sum[i] += t[i] + sum[i - 1];

  for (int i = 0; i < q; ++i) {
    int lo, hi;
    cin >> lo >> hi;
    --lo;
    --hi;
    cout << sum[hi] - sum[lo] << '\n';
  }

  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  int a[10000 + 1];
  memset(a, 0, sizeof(a));

  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      a[i + 1]++;
    }
  }

  for (int i = 0; i < n - 1; i++) {
    a[i + 1] = a[i] + a[i + 1];
  }

  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;

    cout << a[r - 1] - a[l - 1] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  int a[100000 + 1];
  memset(a, 0, sizeof(a));

  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      a[i + 1]++;
    }
  }

  for (int i = 0; i < n - 1; i++) {
    a[i + 1] = a[i] + a[i + 1];
  }

  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;

    cout << a[r - 1] - a[l - 1] << endl;
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  string s;
  vector<int> ac(10005);
  cin >> n >> q >> s;
  vector<int> l(q);
  vector<int> r(q);

  for (int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
  }

  int ac_c = 0;
  for (int i = 1; i <= n; i++) {
    ac[i] = ac_c;
    if (i == n) {
      break;
    }
    if (s[i - 1] == 'A') {
      if (s[i] == 'C') {
        // cout << "UP" << endl;
        ac[i] = ac_c++;
      }
    }
    // cout << i << " " << ac[i] << endl;
  }

  for (int i = 1; i <= q; i++) {
    cout << ac[r[i]] - ac[l[i]] << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  string s;
  vector<int> ac(100005);
  cin >> n >> q >> s;
  vector<int> l(q);
  vector<int> r(q);

  for (int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
  }

  int ac_c = 0;
  for (int i = 1; i <= n; i++) {
    ac[i] = ac_c;
    if (i == n) {
      break;
    }
    if (s[i - 1] == 'A') {
      if (s[i] == 'C') {
        // cout << "UP" << endl;
        ac[i] = ac_c++;
      }
    }
    // cout << i << " " << ac[i] << endl;
  }

  for (int i = 1; i <= q; i++) {
    cout << ac[r[i]] - ac[l[i]] << endl;
  }

  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i, first, end) for (int i = first; i < end; i++)

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;

  string s;
  cin >> s;

  vector<int> count(q, 0);

  vector<pair<int, int>> vec(q);

  rep(i, 0, q) {
    int l, r;
    cin >> l >> r;
    vec[i].first = l - 1;
    vec[i].second = r - 1;
  }
  rep(j, 0, n - 1) {
    if (s[j] == 'A' && s[j + 1] == 'C') {
      count[j + 1] = count[j] + 1;
    } else {
      count[j + 1] = count[j];
    }
  }

  rep(i, 0, q) { cout << count[vec[i].second] - count[vec[i].first] << endl; }
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define rep(i, first, end) for (int i = first; i < end; i++)

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;

  string s;
  cin >> s;

  vector<int> count(n, 0);

  vector<pair<int, int>> vec(q);

  rep(i, 0, q) {
    int l, r;
    cin >> l >> r;
    vec[i].first = l - 1;
    vec[i].second = r - 1;
  }
  rep(j, 0, n - 1) {
    if (s[j] == 'A' && s[j + 1] == 'C') {
      count[j + 1] = count[j] + 1;
    } else {
      count[j + 1] = count[j];
    }
  }

  rep(i, 0, q) { cout << count[vec[i].second] - count[vec[i].first] << endl; }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string>
#include <utility>
using namespace std;

int main() {
  int n, q;
  int sum = 0;
  int ans[10003] = {};
  cin >> n >> q;
  string s;
  cin >> s;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') {
      sum++;
    }
    ans[i] += sum;
  }
  for (int i = 0; i < q; i++) {
    int tempA, tempB;
    cin >> tempA >> tempB;
    cout << ans[tempB - 1] - ans[tempA - 1] << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>
#include <utility>
using namespace std;

int main() {
  int n, q;
  int sum = 0;
  int ans[100003] = {};
  cin >> n >> q;
  string s;
  cin >> s;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') {
      sum++;
    }
    ans[i] += sum;
  }
  for (int i = 0; i < q; i++) {
    int tempA, tempB;
    cin >> tempA >> tempB;
    cout << ans[tempB - 1] - ans[tempA - 1] << endl;
  }
  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;

  auto ans = [&](int l, int r) {
    int ans = 0;
    for (int i = l - 1; i <= r - 2; i++) {
      if (s[i] == 'A' && s[i + 1] == 'C')
        ans++;
    }
    cout << ans << endl;
  };

  vector<int> L(q), R(q);
  rep(i, q) cin >> L[i] >> R[i];
  rep(i, q) ans(L[i], R[i]);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> num(n);
  rep(i, n - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C')
      num[i]++;
  }
  rep(i, n) num[i + 1] += num[i];
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << num[r - 1] - num[l - 1] << endl;
  }
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vp;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
  rep(i, n) {                                                                  \
    ll x;                                                                      \
    cin >> x;                                                                  \
    v.push_back(x);                                                            \
  }
const ll INF = 99999999999999;
const ll MOD = 1000000007;

int main() {
  ll n, q;
  string s;
  vl l, r;
  cin >> n >> q >> s;

  rep(i, q) {
    ll x, y;
    cin >> x >> y;
    l.push_back(x);
    r.push_back(y);
  }
  vl count(n, 0);
  rep(i, n - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      count[i + 1] = count[i] + 1;
    } else {
      count[i + 1] = count[i];
    }
  }
  rep(i, n) { cout << count[r[i] - 1] - count[l[i] - 1] << endl; }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vp;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
  rep(i, n) {                                                                  \
    ll x;                                                                      \
    cin >> x;                                                                  \
    v.push_back(x);                                                            \
  }
const ll INF = 99999999999999;
const ll MOD = 1000000007;

int main() {
  ll n, q;
  string s;
  vl l, r;
  cin >> n >> q >> s;

  rep(i, q) {
    ll x, y;
    cin >> x >> y;
    l.push_back(x);
    r.push_back(y);
  }
  vl count(n, 0);
  rep(i, n - 1) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      count[i + 1] = count[i] + 1;
    } else {
      count[i + 1] = count[i];
    }
  }
  rep(i, q) { cout << count[r[i] - 1] - count[l[i] - 1] << endl; }

  return 0;
}
Problem p03087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, q, l, r;
vector<int> a;
string s;
int main() {
  cin >> n >> q;
  cin >> s;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'C' && s[i - 1] == 'A')
      a[i]++;
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= q; i++) {
    cin >> l >> r;
    l--, r--;
    cout << a[r] - a[l] << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, q, l, r;
int a[100005];
string s;
int main() {
  cin >> n >> q;
  cin >> s;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'C' && s[i - 1] == 'A')
      a[i]++;
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= q; i++) {
    cin >> l >> r;
    l--, r--;
    cout << a[r] - a[l] << endl;
  }
  return 0;
}