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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int cnt[30];
const int MOD = 1e9 + 7;
int main() {
  string s;
  int n;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    ans = (ans * (cnt[i] + 1LL)) % MOD;
  }
  cout << (ans + MOD - 1) % MOD << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int cnt[30];
const int MOD = 1e9 + 7;
int main() {
  string s;
  int n;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }
  long long ans = 1;
  for (int i = 0; i < 28; i++) {
    ans = (ans * (cnt[i] + 1LL)) % MOD;
  }
  cout << (ans + MOD - 1) % MOD << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
#define F first
#define S second

int n;
string s;
int a[28];
unordered_set<int> st;

signed main() {
  cin >> n;
  cin >> s;
  r(i, n) { a[s[i] - 'a']++; }
  int ans = 1, S = 0, sum = 0;
  r(i, 26) if (a[i]) S++;
  r(i, 26) {
    if (a[i]) {
      int x = a[i];
      r(j, n) if (i < j && a[j]) {
        x *= (a[j] + 1);
        x %= 1000000007;
      }
      x %= 1000000007;
      ans += x;
      ans %= 1000000007;
      S--;
    }
  }
  /*r(i,(1<<26)){
          int A=0,p=1;
          r(j,26){
                  if(i&(1<<j)){
                          A|=(1<<j);
                          p*=a[j];
                          p%=1000000007;
                  }
          }
          if(!st.count(A)&&p){
                  //cout<<A<<endl;
                  st.insert(A);
                  ans+=p;
                  ans%=1000000007;
          }
  }*/
  cout << ans - 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
#define F first
#define S second

int n;
string s;
int a[28];
unordered_set<int> st;

signed main() {
  cin >> n;
  cin >> s;
  r(i, n) { a[s[i] - 'a']++; }
  int ans = 1, S = 0, sum = 0;
  r(i, 26) if (a[i]) S++;
  r(i, 26) {
    if (a[i]) {
      int x = a[i];
      r(j, 26) if (i < j && a[j]) {
        x *= (a[j] + 1);
        x %= 1000000007;
      }
      x %= 1000000007;
      ans += x;
      ans %= 1000000007;
      S--;
    }
  }
  /*r(i,(1<<26)){
          int A=0,p=1;
          r(j,26){
                  if(i&(1<<j)){
                          A|=(1<<j);
                          p*=a[j];
                          p%=1000000007;
                  }
          }
          if(!st.count(A)&&p){
                  //cout<<A<<endl;
                  st.insert(A);
                  ans+=p;
                  ans%=1000000007;
          }
  }*/
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

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

typedef char SINT8;
typedef unsigned char UINT8;
typedef short SINT16;
typedef unsigned short UINT16;
typedef int SINT32;
typedef unsigned int UINT32;
typedef long long SINT64;
typedef unsigned long long UINT64;
typedef double DOUBLE;

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define MOD 1000000007

using namespace std;

int main() {

  SINT32 N = 0;
  string S;
  SINT64 ANS = 1;

  cin >> N;
  cin >> S;

  vector<SINT32> DATA(26);

  for (SINT32 i = 0; i < N; i++) {
    DATA[i] = 0;
  }

  for (SINT32 i = 0; i < N; i++) {
    DATA[S[i] - 'a']++;
  }

  for (SINT32 i = 0; i < 26; i++) {
    ANS = ANS * ((DATA[i] + 1) % MOD);
    ANS = ANS % MOD;
  }
  ANS--;

  cout << ANS << endl;
  return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
        SINT32 M = 3;
        vector<pair<SINT32,SINT32>> DATA2(M);
        for (SINT32 i = 0; i < M; i++) {
                cin >> DATA2[i].first;
                cin >> DATA2[i].second;
        }
        sort(DATA2.begin(),DATA2.end());
        cout << DATA2[0].first << endl;
        cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) -
//ADATA.begin(); 		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) -
//BDATA.begin();

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

typedef char SINT8;
typedef unsigned char UINT8;
typedef short SINT16;
typedef unsigned short UINT16;
typedef int SINT32;
typedef unsigned int UINT32;
typedef long long SINT64;
typedef unsigned long long UINT64;
typedef double DOUBLE;

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define MOD 1000000007

using namespace std;

int main() {

  SINT32 N = 0;
  string S;
  SINT64 ANS = 1;

  cin >> N;
  cin >> S;

  vector<SINT32> DATA(26);

  for (SINT32 i = 0; i < 26; i++) {
    DATA[i] = 0;
  }

  for (SINT32 i = 0; i < N; i++) {
    DATA[S[i] - 'a']++;
  }

  for (SINT32 i = 0; i < 26; i++) {
    ANS = ANS * ((DATA[i] + 1) % MOD);
    ANS = ANS % MOD;
  }
  ANS--;

  cout << ANS << endl;
  return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
        SINT32 M = 3;
        vector<pair<SINT32,SINT32>> DATA2(M);
        for (SINT32 i = 0; i < M; i++) {
                cin >> DATA2[i].first;
                cin >> DATA2[i].second;
        }
        sort(DATA2.begin(),DATA2.end());
        cout << DATA2[0].first << endl;
        cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) -
//ADATA.begin(); 		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) -
//BDATA.begin();
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  unordered_map<int, ll> m;
  for (int i = 0; i < n; i++) {
    m[s[i]]++;
  }
  ll dp[n + 1];
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i - 1] * 2) % mod;
  }
  ll pre = 0;
  ll f = 1;
  ll ans = (dp[n] - 1) % mod;
  for (auto x : m) {
    ll a = x.second;
    ll b = n - a - pre;
    pre += a;
    ll d = (dp[a] - a - 1) % mod;
    ll g = dp[b];
    ans = (ans - (((d * g) % mod) * f) % mod + mod) % mod;
    f = (f * (a + 1)) % mod;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll mod = 1e9 + 7;
int main() {
  /* #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output1.txt", "w", stdout);
   #endif*/
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  unordered_map<int, ll> m;
  for (int i = 0; i < n; i++) {
    m[s[i]]++;
  }
  ll dp[n + 1];
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i - 1] * 2) % mod;
  }
  ll pre = 0;
  ll f = 1;
  ll ans = (dp[n] - 1) % mod;
  for (auto x : m) {
    ll a = x.second;
    ll b = n - a - pre;
    pre += a;
    ll d = (dp[a] - a - 1) % mod;
    ll g = dp[b];
    ans = (ans - (((d * g) % mod) * f) % mod + mod) % mod;
    f = (f * (a + 1)) % mod;
  }
  cout << ans;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<char> vec(N);
  for (int i = 0; i < N; i++) {
    vec.at(i) = S.at(i);
  }
  sort(vec.begin(), vec.end());
  long long ans = 1;
  long long count = 1;
  for (int j = 0; j < N - 1; j++) {
    if (vec.at(j) == vec.at(j + 1)) {
      count++;
    } else {
      ans = ans * (count + 1) % 1000000007;
      count = 1;
    }
  }

  if (vec.at(N - 2) == vec.at(N - 1)) {
    ans = ans * (count + 1) % 1000000007;
  } else {
    ans *= 2;
  }
  cout << ans - 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<char> vec(N);
  for (int i = 0; i < N; i++) {
    vec.at(i) = S.at(i);
  }
  sort(vec.begin(), vec.end());
  long long ans = 1;
  long long count = 1;
  for (int j = 0; j < N - 1; j++) {
    if (vec.at(j) == vec.at(j + 1)) {
      count++;
    } else {
      ans = ans * (count + 1) % 1000000007;
      count = 1;
    }
  }
  if (N == 1) {
    ans = 2;
  } else if (vec.at(N - 2) == vec.at(N - 1)) {
    ans = ans * (count + 1) % 1000000007;
  } else {
    ans *= 2;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> s(26, 1);

  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    s[c - 97]++;
  }

  long long ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= s[i];
    ans %= 1000000007;
  }

  cout << ans - 1 << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> s(26, 1);

  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    s[c - 97]++;
  }

  long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= s[i];
    ans %= 1000000007;
  }

  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

//////////////////////////////////////

//////////////////////////////////////

int main() {

  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> cnt(26);
  REP(i, N) { cnt[S[i] - 'a'] += 1; }
  ll ans = 1;
  REP(i, N) {
    ans *= (cnt[i] + 1);
    ans %= MOD_BIG;
  }
  ans -= 1;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

//////////////////////////////////////

//////////////////////////////////////

int main() {

  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> cnt(26);
  REP(i, N) { cnt[S[i] - 'a'] += 1; }
  ll ans = 1;
  REP(i, 26) {
    ans *= (cnt[i] + 1);
    ans %= MOD_BIG;
  }
  ans -= 1;
  cout << ans << endl;

  return 0;
}
Problem p03095 (C++)

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

int N;
string S;
long long cnt[26] = {};
long long ans = 1;
int main() {
  cin >> N >> S;
  for (int i = 0; i < N; i++)
    cnt[int(S[i] - 'a')]++;
  for (int i = 0; i < N; i++)
    ans = (long long)(ans * (cnt[i] + 1)) % (long long)(1e9 + 7);
  cout << ans - 1 << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;

int N;
string S;
long long cnt[26] = {};
long long ans = 1;
int main() {
  cin >> N >> S;
  for (int i = 0; i < N; i++)
    cnt[int(S[i] - 'a')]++;
  for (int i = 0; i < 26; i++)
    ans = (long long)(ans * (cnt[i] + 1)) % (long long)(1e9 + 7);
  cout << ans - 1 << endl;
  return 0;
}
Problem p03095 (C++)

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

long long MOD = 1000000007;
vector<long long> c(26, 0);

int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N; i++) {
    c[S[i] - 'a']++;
  }

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    ans *= c[i] + 1;
    if (ans >= MOD)
      ans %= MOD;
  }
  ans += MOD - 1;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

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

long long MOD = 1000000007;
vector<long long> c(26, 0);

int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N; i++) {
    c[S[i] - 'a']++;
  }

  long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= c[i] + 1;
    if (ans >= MOD)
      ans %= MOD;
  }
  ans += MOD - 1;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
string s;
LL a[30], res = 0;
int vis[30];
void dfs(int pos, int len, LL val) {
  if (!len) {
    res = (res + val) % mod;
    return;
  }
  for (int i = pos; i < 26; ++i) {
    if (!a[i])
      continue;
    dfs(i + 1, len - 1, val * a[i] % mod);
  }
  return;
}
int main() {
  int n, k = 0;
  cin >> n >> s;
  for (int i = 0; i < n; ++i) {
    int t = s[i] - 'a';
    if (!a[t])
      k++;
    a[t]++;
  }
  for (int i = 1; i <= k; ++i)
    dfs(0, i, 1);
  cout << res;
  return 0;
}


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

using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
string s;
LL a[30], res = 0;
int vis[30];
void dfs(int pos, int len, LL val) {
  if (!len) {
    res = (res + val) % mod;
    return;
  }
  for (int i = pos; i <= 26 - len; ++i) {
    if (!a[i])
      continue;
    dfs(i + 1, len - 1, val * a[i] % mod);
  }
  return;
}
int main() {
  int n, k = 0;
  cin >> n >> s;
  for (int i = 0; i < n; ++i) {
    int t = s[i] - 'a';
    if (!a[t])
      k++;
    a[t]++;
  }
  for (int i = 1; i <= k; ++i)
    dfs(0, i, 1);
  cout << res;
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main() {
  long long N;
  vector<long long> c(26, 1);

  cin >> N;
  for (long long i = 0; i < N; i++) {
    char t;
    cin >> t;
    c[t - 'a']++;
  }

  long long total = 1;
  for (long long i = 0; i < N; i++) {
    total *= c[i];
    total %= MOD;
  }

  cout << total - 1 << endl;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main() {
  long long N;
  vector<long long> c(26, 1);

  cin >> N;
  for (long long i = 0; i < N; i++) {
    char t;
    cin >> t;
    c[t - 'a']++;
  }

  long long total = 1;
  for (long long i = 0; i < 26; i++) {
    total *= c[i];
    total %= MOD;
  }

  cout << total - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FLASH                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO                                                                 \
  freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin);                  \
  freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n;
string s;
signed main() {
#ifndef ONLINE_JUDGE
  FILEIO
#endif
  FLASH

  cin >> n >> s;

  int cnt[26] = {0};

  fr(i, 0, n) { cnt[s[i] - 'a']++; }

  int ans = 1;

  fr(i, 0, 26) {
    ans *= (cnt[i] + 1);
    ans %= mod;
  }
  ans += mod - 1;
  ans %= mod;
  cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
#define FLASH                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO                                                                 \
  freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin);                  \
  freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n;
string s;
signed main() {

  FLASH

  cin >> n >> s;

  int cnt[26] = {0};

  fr(i, 0, n) { cnt[s[i] - 'a']++; }

  int ans = 1;

  fr(i, 0, 26) {
    ans *= (cnt[i] + 1);
    ans %= mod;
  }
  ans += mod - 1;
  ans %= mod;
  cout << ans << '\n';
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> cnt(26, 0);
  for (int i = 0; i < n; ++i) {
    ++cnt[s[i] - 'a'];
  }
  const ll mod = 1000000007;
  ll dp = 1;
  for (int i = 0; i < n; ++i) {
    dp = (dp * (ll)(cnt[i] + 1)) % mod;
  }
  dp += mod - 1;
  dp %= mod;
  cout << dp << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> cnt(26, 0);
  for (int i = 0; i < n; ++i) {
    ++cnt[s[i] - 'a'];
  }
  const ll mod = 1000000007;
  ll dp = 1;
  for (int i = 0; i < 26; ++i) {
    dp = (dp * (ll)(cnt[i] + 1)) % mod;
  }
  dp += mod - 1;
  dp %= mod;
  cout << dp << endl;
}
Problem p03096 (C++)

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = n - 1; i >= 0LL; i--)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll N;
  cin >> N;

  vector<ll> C(N);
  REP(i, N) cin >> C[i];

  vector<ll> c;
  c.push_back(0);
  c.push_back(C[0]);
  REP(i, N - 1) {
    if (C[i] != C[i + 1]) {
      c.push_back(C[i + 1]);
    }
  }
  vector<ll> dp(c.size() + 1);
  dp[1] = 1;
  vector<ll> pre(100001);
  pre[c[1]] = 1;
  // cout << "dp" << endl;
  // REP(j, dp.size()) cout << dp[j] << " ";
  // cout << endl;
  // cout << "pre" << endl;
  // REP(j, 10) cout << pre[j] << " ";
  // cout << endl;
  FOR(i, 2, dp.size()) {
    dp[i] = dp[i - 1] + dp[pre[c[i]]];
    dp[i] %= MOD;
    pre[c[i]] = i;
    // cout << "dp" << endl;
    // REP(j, dp.size()) cout << dp[j] << " ";
    // cout << endl;
    // cout << "pre" << endl;
    // REP(j, 10) cout << pre[j] << " ";
    // cout << endl;
  }
  PRINT(dp.back());
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = n - 1; i >= 0LL; i--)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll N;
  cin >> N;

  vector<ll> C(N);
  REP(i, N) cin >> C[i];

  vector<ll> c;
  c.push_back(0);
  c.push_back(C[0]);
  REP(i, N - 1) {
    if (C[i] != C[i + 1]) {
      c.push_back(C[i + 1]);
    }
  }
  vector<ll> dp(c.size() + 1);
  dp[1] = 1;
  vector<ll> pre(1000000);
  pre[c[1]] = 1;
  // cout << "dp" << endl;
  // REP(j, dp.size()) cout << dp[j] << " ";
  // cout << endl;
  // cout << "pre" << endl;
  // REP(j, 10) cout << pre[j] << " ";
  // cout << endl;
  FOR(i, 2, dp.size()) {
    dp[i] = dp[i - 1] + dp[pre[c[i]]];
    dp[i] %= MOD;
    pre[c[i]] = i;
    // cout << "dp" << endl;
    // REP(j, dp.size()) cout << dp[j] << " ";
    // cout << endl;
    // cout << "pre" << endl;
    // REP(j, 10) cout << pre[j] << " ";
    // cout << endl;
  }
  PRINT(dp.back());
  return 0;
}
Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

const ll MOD = 1000000007;

int main(void) {
  cin.sync_with_stdio(false);
  ll N;
  cin >> N;

  vector<ll> prev_loc(N + 10, -1);
  vector<ll> dp(N + 10);
  dp[0] = 1;
  FOR(n, 1, N + 1) {
    ll c;
    cin >> c;
    if (n == 1) {
      dp[n] = 1;
    } else {
      dp[n] = dp[n - 1];
      if (prev_loc[c] == -1 || prev_loc[c] == n - 1) {
        // do nothing
      } else {
        dp[n] += dp[prev_loc[c]];
        dp[n] %= MOD;
      }
    }
    prev_loc[c] = n;
  }
  cout << dp[N] << endl;

  // REP(n, N + 1) cout << dp[n] << ","; cout << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

const ll MOD = 1000000007;

int main(void) {
  cin.sync_with_stdio(false);
  ll N;
  cin >> N;

  vector<ll> prev_loc(2 * 100001, -1);
  vector<ll> dp(N + 10);
  dp[0] = 1;
  FOR(n, 1, N + 1) {
    ll c;
    cin >> c;
    if (n == 1) {
      dp[n] = 1;
    } else {
      dp[n] = dp[n - 1];
      if (prev_loc[c] == -1 || prev_loc[c] == n - 1) {
        // do nothing
      } else {
        dp[n] += dp[prev_loc[c]];
        dp[n] %= MOD;
      }
    }
    prev_loc[c] = n;
  }
  cout << dp[N] << endl;

  // REP(n, N + 1) cout << dp[n] << ","; cout << endl;

  return 0;
}
Problem p03096 (C++)

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

typedef long long ll;
const int maxn = 3e4 + 20, maxm = 3e4 + 20;
int c[maxn], a[maxn];
ll mod = 1e9 + 7;
const ll inf = 1e9;
queue<int> q;
set<int> s;
set<int> s1;
int dp[maxn];

int X[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> a[i];

  dp[0] = 1;
  a[0] = a[1];
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1])
      dp[i] = dp[i - 1], c[a[i]] = i;
    else if (c[a[i]] != 0)
      dp[i] = (dp[c[a[i]]] + dp[i - 1]) % mod, c[a[i]] = i;
    else
      dp[i] = dp[i - 1] % mod, c[a[i]] = i;
  }

  cout << dp[n];
}


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

typedef long long ll;
const int maxn = 2e5 + 20, maxm = 2e5 + 20;
int c[maxn], a[maxn];
ll mod = 1e9 + 7;
const ll inf = 1e9;
queue<int> q;
set<int> s;
set<int> s1;
int dp[maxn];

int X[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> a[i];

  dp[0] = 1;
  a[0] = a[1];
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1])
      dp[i] = dp[i - 1], c[a[i]] = i;
    else if (c[a[i]] != 0)
      dp[i] = (dp[c[a[i]]] + dp[i - 1]) % mod, c[a[i]] = i;
    else
      dp[i] = dp[i - 1] % mod, c[a[i]] = i;
  }

  cout << dp[n];
}
Problem p03096 (C++)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    --c[i];
  }

  const long long mod = 1e9 + 7;
  vector<long long> dp(n + 1);
  vector<int> l(n, -1);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    dp[i + 1] = dp[i];
    if (l[c[i]] != -1 && l[c[i]] != i) {
      dp[i + 1] += dp[l[c[i]]];
      dp[i + 1] %= mod;
    }
    l[c[i]] = i + 1;
  }
  cout << dp[n] << endl;

  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    --c[i];
  }

  const long long mod = 1e9 + 7;
  vector<long long> dp(n + 1);
  vector<int> l(*max_element(c.begin(), c.end()) + 1, -1);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    dp[i + 1] = dp[i];
    if (l[c[i]] != -1 && l[c[i]] != i) {
      dp[i + 1] += dp[l[c[i]]];
      dp[i + 1] %= mod;
    }
    l[c[i]] = i + 1;
  }
  cout << dp[n] << endl;

  return 0;
}
Problem p03096 (C++)

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

inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x;
}

const int maxn = 1e5;
const int mod = 1e9 + 7;
int num[maxn];
int a[maxn], pre[maxn], f[maxn] = {1};

int main() {
  srand(time(0));
  memset(num, -1, sizeof(num));
  int n = read();
  for (int i = 0; i < n; i++) {
    a[i] = read() - 1;
    pre[i] = num[a[i]];
    num[a[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    f[i] = f[i - 1];
    if (pre[i] >= 0 && pre[i] != i - 1)
      f[i] = (f[i] + f[pre[i]]) % mod;
  }
  printf("%d", f[n - 1]);
  return 0;
}


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

inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x;
}

const int maxn = 2e5;
const int mod = 1e9 + 7;
int num[maxn];
int a[maxn], pre[maxn], f[maxn] = {1};

int main() {
  srand(time(0));
  memset(num, -1, sizeof(num));
  int n = read();
  for (int i = 0; i < n; i++) {
    a[i] = read() - 1;
    pre[i] = num[a[i]];
    num[a[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    f[i] = f[i - 1];
    if (pre[i] >= 0 && pre[i] != i - 1)
      f[i] = (f[i] + f[pre[i]]) % mod;
  }
  printf("%d", f[n - 1]);
  return 0;
}
Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
ll const MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vi C;
  for (int i = 0; i < N; ++i) {
    int c;
    cin >> c;
    C.push_back(c);
  }

  ll dp[N];
  ll c_cum[N + 1];
  memset(c_cum, 0, sizeof(c_cum));
  dp[0] = 1;
  c_cum[C[0]] = 1;

  if (N != 1) {
    for (int i = 1; i < N; ++i) {
      if (C[i - 1] != C[i])
        (c_cum[C[i]] += dp[i - 1]) %= MOD;
      dp[i] = c_cum[C[i]];
    }
  }

  cout << dp[N - 1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
ll const MOD = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vi C;
  for (int i = 0; i < N; ++i) {
    int c;
    cin >> c;
    C.push_back(c);
  }

  ll dp[200010];
  ll c_cum[200010];
  memset(c_cum, 0, sizeof(c_cum));
  dp[0] = 1;
  c_cum[C[0]] = 1;

  if (N != 1) {
    for (int i = 1; i < N; ++i) {
      if (C[i - 1] != C[i])
        (c_cum[C[i]] += dp[i - 1]) %= MOD;
      dp[i] = c_cum[C[i]];
    }
  }

  cout << dp[N - 1] << endl;
  return 0;
}
Problem p03096 (C++)

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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair<int, int> pp;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int M[N];

signed main() {
  int n;
  cin >> n;
  int pre = 1;
  int prex = 0;
  int dp;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%lld", &x);
    if (x == prex)
      continue;
    dp = (M[x] + pre) % mod;
    //        cout << i << " " << dp << " ss\n";
    M[x] = (M[x] + pre) % mod;
    pre = dp;
    prex = x;
  }

  cout << dp;
  return 0;
}

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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair<int, int> pp;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int M[N];

signed main() {
  int n;
  cin >> n;
  int pre = 1;
  int prex = 0;
  int dp;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%lld", &x);
    if (x == prex)
      continue;
    dp = (M[x] + pre) % mod;
    //        cout << i << " " << dp << " ss\n";
    M[x] = (M[x] + pre) % mod;
    pre = dp;
    prex = x;
  }

  cout << dp;
  return 0;
}
Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI = 3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for (int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL

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

  int n;
  cin >> n;
  int c, prev = 0;
  vs32 pos(n + 1, -1);
  vs64 dp(n + 1);
  dp[0] = 1;
  rep(i, n) {
    cin >> c;
    if (c == prev || pos[c] == -1) {
      dp[i + 1] = dp[i];
    } else {
      dp[i + 1] = (dp[i] + dp[pos[c]]) % MOD;
    }
    pos[c] = i + 1;
    prev = c;
  }

  cout << dp[n] << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI = 3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for (int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL

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

  int n;
  cin >> n;
  int c, prev = 0;
  vs32 pos(200000 + 1, -1);
  vs64 dp(n + 1);
  dp[0] = 1;
  rep(i, n) {
    cin >> c;
    if (c == prev || pos[c] == -1) {
      dp[i + 1] = dp[i];
    } else {
      dp[i + 1] = (dp[i] + dp[pos[c]]) % MOD;
    }
    pos[c] = i + 1;
    prev = c;
  }

  cout << dp[n] << "\n";
  return 0;
}
Problem p03096 (C++)

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

using namespace std;

// #define double long double

typedef pair<int, int> ii;
typedef pair<int, long long> il;
typedef pair<long long, long long> ll;
typedef pair<ll, int> lli;
typedef pair<long long, int> li;
typedef pair<double, double> dd;
typedef pair<ii, int> iii;
typedef pair<double, int> di;
typedef pair<int, ii> iii2;
typedef pair<ii, ii> iiii;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;

int main() {

  int n;
  cin >> n;
  vector<int> c(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    c[i]--;
  }

  vector<int> cnt(n, 0);

  vector<int> dp(n, 0);

  cnt[c[0]] = 1;
  for (int i = 0; i < n; i++) {
    dp[i] = cnt[c[i]];
    dp[i] %= mod;
    if (i + 1 < n && c[i] != c[i + 1]) {
      cnt[c[i + 1]] += dp[i];
      cnt[c[i + 1]] %= mod;
    }
  }
  // for(int i=0;i<n;i++) cout<<i<<" "<<dp[i]<<endl;

  cout << dp[n - 1] << endl;

  return 0;
}


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

using namespace std;

// #define double long double

typedef pair<int, int> ii;
typedef pair<int, long long> il;
typedef pair<long long, long long> ll;
typedef pair<ll, int> lli;
typedef pair<long long, int> li;
typedef pair<double, double> dd;
typedef pair<ii, int> iii;
typedef pair<double, int> di;
typedef pair<int, ii> iii2;
typedef pair<ii, ii> iiii;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;

int main() {

  int n;
  cin >> n;
  vector<int> c(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    c[i]--;
  }

  vector<int> cnt(2000010, 0);

  vector<int> dp(n, 0);

  cnt[c[0]] = 1;
  for (int i = 0; i < n; i++) {
    dp[i] = cnt[c[i]];
    dp[i] %= mod;
    if (i + 1 < n && c[i] != c[i + 1]) {
      cnt[c[i + 1]] += dp[i];
      cnt[c[i + 1]] %= mod;
    }
  }
  // for(int i=0;i<n;i++) cout<<i<<" "<<dp[i]<<endl;

  cout << dp[n - 1] << endl;

  return 0;
}
Problem p03096 (C++)

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

int main() {
  long long mod = 1000000007;

  int n;
  std::vector<int> aList;
  std::vector<int> colorList;
  std::vector<long long> dpList;

  std::cin >> n;
  aList.resize(n);
  colorList.resize(n + 1, -1);
  dpList.resize(n, 0);

  for (int i = 0; i < n; i++)
    std::cin >> aList[i];

  dpList[0] = 1;
  colorList[aList[0]] = 0;

  for (int i = 1; i < n; i++) {
    dpList[i] = dpList[i - 1];

    if (aList[i] != aList[i - 1])
      if (colorList[aList[i]] >= 0)
        dpList[i] = (dpList[i] + dpList[colorList[aList[i]]]) % mod;

    colorList[aList[i]] = i;
  }

  std::cout << dpList[n - 1] << std::endl;

  return 0;
}

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

int main() {
  long long mod = 1000000007;

  int n;
  std::vector<int> aList;
  std::vector<int> colorList;
  std::vector<long long> dpList;

  std::cin >> n;
  aList.resize(n);
  colorList.resize(200001, -1);
  dpList.resize(n, 0);

  for (int i = 0; i < n; i++)
    std::cin >> aList[i];

  dpList[0] = 1;
  colorList[aList[0]] = 0;

  for (int i = 1; i < n; i++) {
    dpList[i] = dpList[i - 1];

    if (aList[i] != aList[i - 1])
      if (colorList[aList[i]] >= 0)
        dpList[i] = (dpList[i] + dpList[colorList[aList[i]]]) % mod;

    colorList[aList[i]] = i;
  }

  std::cout << dpList[n - 1] << std::endl;

  return 0;
}
Problem p03096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll M = 1e9 + 7;
const int MN = 200100;
inline ll mul(ll a, ll b) { return (a * b) % M; }
vi fr[MN];
int v[MN];
ll dp[MN];
ll ds(int id) {
  if (id == 0)
    return 1;
  int val = v[id];
  int pos = lower_bound(fr[val].begin(), fr[val].end(), id) - fr[val].begin();
  ll tot = ds(id - 1);
  if (pos > 0) {
    tot += ds(fr[val][pos - 1]);
    tot %= M;
  }
  return dp[id] = tot;
}
int main() {
  int n;
  memset(dp, -1, sizeof(dp));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int la = -1;
  int id = 0;
  while (n--) {
    int t;
    cin >> t;
    if (t != la && la > 0) {
      v[id] = la;
      fr[la].push_back(id++);
    }
    la = t;
  }
  v[id] = la;
  fr[la].push_back(id++);
  // cout << "SIZE " << id << '\n';
  cout << ds(id - 1) << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll M = 1e9 + 7;
const int MN = 200100;
inline ll mul(ll a, ll b) { return (a * b) % M; }
vi fr[MN];
int v[MN];
ll dp[MN];
ll ds(int id) {
  if (id == 0)
    return 1;
  if (dp[id] != -1)
    return dp[id];
  int val = v[id];
  int pos = lower_bound(fr[val].begin(), fr[val].end(), id) - fr[val].begin();
  ll tot = ds(id - 1);
  if (pos > 0) {
    tot += ds(fr[val][pos - 1]);
    tot %= M;
  }
  return dp[id] = tot;
}
int main() {
  int n;
  memset(dp, -1, sizeof(dp));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int la = -1;
  int id = 0;
  while (n--) {
    int t;
    cin >> t;
    if (t != la && la > 0) {
      v[id] = la;
      fr[la].push_back(id++);
    }
    la = t;
  }
  v[id] = la;
  fr[la].push_back(id++);
  // cout << "SIZE " << id << '\n';
  cout << ds(id - 1) << '\n';
}
Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  uint32_t n;
  cin >> n;
  vector<uint32_t> cs(n);
  for (uint32_t i = 0; i < n; i++) {
    cin >> cs[i];
  }

  vector<uint64_t> vals(n);
  vector<uint32_t> marks(n + 1, -1); // 1 origin, idx: c, elem : idx

  vals[0] = 1;
  marks[cs[0]] = 0;
  for (uint32_t i = 1; i < n; i++) {
    // cout << i << " "  << vals[i - 1] << endl;
    uint32_t c = cs[i];
    if (c == cs[i - 1]) {
      vals[i] = vals[i - 1];
      continue;
    }

    uint32_t &cur_mark = marks[c];
    if (cur_mark != -1) {
      vals[i] = vals[i - 1] + vals[cur_mark];
      vals[i] %= 1000000007;
    } else {
      vals[i] = vals[i - 1];
    }

    // cout << i << " " << c << " " << vals[i] << endl;

    cur_mark = i;
  }

  cout << vals[n - 1] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  uint32_t n;
  cin >> n;
  vector<uint32_t> cs(n);
  for (uint32_t i = 0; i < n; i++) {
    cin >> cs[i];
  }

  vector<uint64_t> vals(n);
  vector<uint32_t> marks(200001, -1); // 1 origin, idx: c, elem : idx

  vals[0] = 1;
  marks[cs[0]] = 0;
  for (uint32_t i = 1; i < n; i++) {
    // cout << i << " "  << vals[i - 1] << endl;
    uint32_t c = cs[i];
    if (c == cs[i - 1]) {
      vals[i] = vals[i - 1];
      continue;
    }

    uint32_t &cur_mark = marks[c];
    if (cur_mark != -1) {
      vals[i] = vals[i - 1] + vals[cur_mark];
      vals[i] %= 1000000007;
    } else {
      vals[i] = vals[i - 1];
    }

    // cout << i << " " << c << " " << vals[i] << endl;

    cur_mark = i;
  }

  cout << vals[n - 1] << endl;

  return 0;
}
Problem p03096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i < n; i++)
#define rep3(i, n) for (int i = n - 1; i >= 0; i--)
#define rep4(i, x, n) for (int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main() {
  int N;
  cin >> N;
  int C[N];
  rep(i, N) cin >> C[i];
  ll dp[N];
  map<int, int> mp;
  vector<int> vec[N];
  dp[0] = 1;
  mp[C[0]] = 0;
  vec[0].push_back(0);
  rep2(i, 1, N) {
    if (C[i] == C[i - 1])
      dp[i] = dp[i - 1];
    elif (!mp.count(C[i])) {
      dp[i] = dp[i - 1];
      mp[C[i]] = i;
      vec[i].push_back(i);
    }
    else {
      dp[i] = dp[i - 1];
      int j = mp[C[i]];
      rep(k, vec[j].size()) {
        int l = vec[j][k];
        if (l >= 1)
          dp[i] += dp[l - 1];
        else
          dp[i] += 1;
        dp[i] %= MOD;
      }
      vec[j].push_back(i);
    }
  }
  cout << dp[N - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i < n; i++)
#define rep3(i, n) for (int i = n - 1; i >= 0; i--)
#define rep4(i, x, n) for (int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main() {
  int N;
  cin >> N;
  int C[N];
  rep(i, N) cin >> C[i];
  ll dp[N];
  map<int, int> mp;
  vector<int> vec[N];
  dp[0] = 1;
  mp[C[0]] = 0;
  vec[0].push_back(0);
  rep2(i, 1, N) {
    if (C[i] == C[i - 1])
      dp[i] = dp[i - 1];
    elif (!mp.count(C[i])) {
      dp[i] = dp[i - 1];
      mp[C[i]] = i;
      vec[i].push_back(i);
    }
    else {
      dp[i] = dp[i - 1];
      int j = mp[C[i]];
      int k = vec[j].size() - 1;
      dp[i] += dp[vec[j][k]];
      dp[i] %= MOD;
      vec[j].push_back(i);
    }
  }
  cout << dp[N - 1] << endl;
}
Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  int n;
  cin >> n;

  vector<ll> c(n), dp(n + 1, 1);
  vector<vector<ll>> s(n + 1, vector<ll>());

  for (int i = 0; i < n; i++) {
    cin >> c[i];
    c[i];
    s[c[i]].push_back(i);
  }

  for (int i = 0; i < n; i++) {
    int x = lower_bound(s[c[i]].begin(), s[c[i]].end(), i) - s[c[i]].begin();
    if (x > 0) {
      if (s[c[i]][x] - s[c[i]][x - 1] > 1) {
        dp[i + 1] = dp[i] + dp[s[c[i]][x - 1] + 1];
        dp[i + 1] %= MOD;
      } else {
        dp[i + 1] = dp[i];
        dp[i + 1] %= MOD;
      }
    } else {
      dp[i + 1] = dp[i];
      dp[i + 1] %= MOD;
    }
  }

  cout << dp[n] << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  int n;
  cin >> n;

  vector<ll> c(n), dp(n + 1, 1);
  vector<vector<ll>> s(200010, vector<ll>());

  for (int i = 0; i < n; i++) {
    cin >> c[i];
    c[i];
    s[c[i]].push_back(i);
  }

  for (int i = 0; i < n; i++) {
    int x = lower_bound(s[c[i]].begin(), s[c[i]].end(), i) - s[c[i]].begin();
    if (x > 0) {
      if (s[c[i]][x] - s[c[i]][x - 1] > 1) {
        dp[i + 1] = dp[i] + dp[s[c[i]][x - 1] + 1];
        dp[i + 1] %= MOD;
      } else {
        dp[i + 1] = dp[i];
        dp[i + 1] %= MOD;
      }
    } else {
      dp[i + 1] = dp[i];
      dp[i + 1] %= MOD;
    }
  }

  cout << dp[n] << endl;
}
Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll, ll>
#define FOR(I, A, B) for (ll I = int(A); I < int(B); ++I)
#define FORR(I, A, B) for (ll I = int((B)-1); I >= int(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v)                                                             \
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v  x is sorted
#define POSU(x, v)                                                             \
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
} // saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;

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

  ll N, n = 2;
  cin >> N;
  vector<ll> C, dp(N + 3, 0), sum(N + 3, 0);
  C.push_back(0);
  FOR(i, 0, N) {
    ll k;
    cin >> k;
    if (C.size() == 1) {
      C.push_back(k);
    } else if (k != C[n - 1]) {
      C.push_back(k);
      n++;
    }
  }
  N = n;
  dp[1] = 1;
  sum[C[1]] = 1;
  FOR(i, 2, N + 1) {
    dp[i] = (dp[i - 1] + sum[C[i]]) % MOD;
    sum[C[i]] = dp[i];
  }
  cout << dp[N] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll, ll>
#define FOR(I, A, B) for (ll I = int(A); I < int(B); ++I)
#define FORR(I, A, B) for (ll I = int((B)-1); I >= int(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v)                                                             \
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v  x is sorted
#define POSU(x, v)                                                             \
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
} // saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;

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

  ll N, n = 2;
  cin >> N;
  if (N == 1 || N == 2) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> C, dp(N + 3, 0), sum(N + 3, 0);
  C.push_back(0);
  FOR(i, 0, N) {
    ll k;
    cin >> k;
    if (C.size() == 1) {
      C.push_back(k);
    } else if (k != C[n - 1]) {
      C.push_back(k);
      n++;
    }
  }
  N = n;
  dp[1] = 1;
  sum[C[1]] = 1;
  FOR(i, 2, N + 1) {
    dp[i] = (dp[i - 1] + sum[C[i]]) % MOD;
    sum[C[i]] = dp[i];
  }
  cout << dp[N] << endl;
}