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

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

using namespace std;
typedef long long ll;
const ll mod = 1000'000'007;
const ll maxn = 123456;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  n *= 4;
  h = min(h, q * 2);
  s = min(s, h * 2);
  d = min(d, s * 2);
  ll ans = d * (n / 8);
  n %= 8;
  ans += s * (n / 4);
  n %= 4;
  ans += h * (n / 2);
  n %= 2;
  ans += q * (n / 1);
  cout << ans;
  return 0;
}

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

using namespace std;
typedef long long ll;
const ll mod = 1000'000'007;
const ll maxn = 123456;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  n *= 4;
  h = min(h, q * 2);
  s = min(s, h * 2);
  d = min(d, s * 2);
  ll ans = d * (n / 8);
  n %= 8;
  ans += s * (n / 4);
  n %= 4;
  ans += h * (n / 2);
  n %= 2;
  ans += q * (n / 1);
  cout << ans;
  return 0;
}
Problem p03617 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

struct ice {
  int money;
  double v;
  double ms;
} a[4];

bool cmp(ice a, ice b) { return a.ms < b.ms; }

int main() {
  int q, h, s, d;
  double n;
  cin >> q >> h >> s >> d >> n;
  a[0].v = 0.25, a[0].money = q, a[0].ms = q * 1.0 / 0.25;
  a[1].v = 0.5, a[1].money = h, a[1].ms = h * 1.0 / 0.5;
  a[2].v = 1, a[2].money = s, a[2].ms = s * 1.0 / 1.0;
  a[3].v = 2, a[3].money = d, a[3].ms = d * 1.0 / 2.0;
  sort(a, a + 4, cmp);
  long long sum = 0;
  while (n > 0) {
    for (int i = 0; i < 4; i++) {
      if (a[i].v > n || n - a[i].v < 0)
        continue;
      sum += a[i].money;
      n -= a[i].v;
      break;
    }
  }
  cout << sum << endl;
}

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

struct ice {
  int money;
  double v;
  double ms;
} a[4];

bool cmp(ice a, ice b) { return a.ms < b.ms; }

int main() {
  int q, h, s, d;
  double n;
  cin >> q >> h >> s >> d >> n;
  a[0].v = 0.25, a[0].money = q, a[0].ms = q * 1.0 / 0.25;
  a[1].v = 0.5, a[1].money = h, a[1].ms = h * 1.0 / 0.5;
  a[2].v = 1, a[2].money = s, a[2].ms = s * 1.0 / 1.0;
  a[3].v = 2, a[3].money = d, a[3].ms = d * 1.0 / 2.0;
  sort(a, a + 4, cmp);
  long long sum = 0;
  while (n > 0) {
    for (int i = 0; i < 4; i++) {
      if (a[i].v > n || n - a[i].v < 0)
        continue;
      int mid = n / a[i].v;
      while (mid--) {
        sum += a[i].money;
        n -= a[i].v;
      }
    }
  }
  cout << sum << endl;
}
Problem p03617 (Python)

Buggy submission (status: Time Limit Exceeded):
Q, H, S, D = map(int, input().split())
N = int(input())

p025 = Q
p05 = min(H, p025 * 2)
p1 = min(S, p05 * 2)
p2 = min(D, p1 * 2)

ans = 0
while N > 0:
    if N >= 2:
        N -= 2
        ans += p2
    elif N >= 1:
        N -= 1
        ans += p1

print(ans)


Fixed submission:
Q, H, S, D = map(int, input().split())
N = int(input())

p025 = Q
p05 = min(H, p025 * 2)
p1 = min(S, p05 * 2)
p2 = min(D, p1 * 2)

ans = 0
if N % 2 != 0:
    N -= 1
    ans += p1
ans += (N // 2) * p2

print(ans)
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;
typedef long long ll;
const ll INF = 1e+7;
const ll MAX = 6005;
char s[MAX];
ll n, cnt[26], ans;
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (ll i = 0; i < n; i++)
    cnt[s[i] - 'a']++;
  ans = n * (n + 1) / 2 + 1;
  for (ll i = 0; i < 26; i++)
    ans -= cnt[i] * (cnt[i] + 1) / 2;
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;
typedef long long ll;
const ll INF = 1e+7;
const ll MAX = 206005;
char s[MAX];
ll n, cnt[26], ans;
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (ll i = 0; i < n; i++)
    cnt[s[i] - 'a']++;
  ans = n * (n + 1) / 2 + 1;
  for (ll i = 0; i < 26; i++)
    ans -= cnt[i] * (cnt[i] + 1) / 2;
  printf("%lld\n", ans);
  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_N (100000)

int main(int argc, char *argv[]) {
  // read inputs
  char s[MAX_N + 1];
  scanf("%s", s);
  const long N = strlen(s);

  // count number of occurence of each letter
  long cnts[26] = {};
  for (long i = 0; i < N; i++) {
    cnts[s[i] - 'a']++;
  }
  long ans = N * (N - 1) / 2 + 1;
  for (long i = 0; i < 26; i++) {
    const long cnt = cnts[i];
    ans -= cnt * (cnt - 1) / 2;
  }
  printf("%ld\n", ans);

  return 0;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_N (200000)

int main(int argc, char *argv[]) {
  // read inputs
  char s[MAX_N + 1];
  scanf("%s", s);
  const long N = strlen(s);

  // count number of occurence of each letter
  long cnts[26] = {};
  for (long i = 0; i < N; i++) {
    cnts[s[i] - 'a']++;
  }
  long ans = N * (N - 1) / 2 + 1;
  for (long i = 0; i < 26; i++) {
    const long cnt = cnts[i];
    ans -= cnt * (cnt - 1) / 2;
  }
  printf("%ld\n", ans);

  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5 + 17;
int dp[MAXN], ocr[26 + 3];
int main(int argc, char const *argv[]) {
#ifdef noob
  freopen("Input.txt", "r", stdin);
  freopen("Output.txt", "w", stdout);
#endif
  string str;
  cin >> str;
  dp[0] = 1;
  ocr[str[0] - 'a']++;
  for (int i = 1; i < str.length(); ++i) {
    dp[i] = dp[i - 1] + i - ocr[str[i] - 'a'];
    ocr[str[i] - 'a']++;
  }
  cout << dp[str.length() - 1] << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e5 + 17;
LL dp[MAXN], ocr[26 + 3];
int main(int argc, char const *argv[]) {
#ifdef noob
  freopen("Input.txt", "r", stdin);
  freopen("Output.txt", "w", stdout);
#endif
  string str;
  cin >> str;
  dp[0] = 1;
  ocr[str[0] - 'a']++;
  for (int i = 1; i < str.length(); ++i) {
    dp[i] = dp[i - 1] + i - ocr[str[i] - 'a'];
    ocr[str[i] - 'a']++;
  }
  cout << dp[str.length() - 1] << endl;
  return 0;
}
Problem p03618 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()

count = 1

alphabets = {}

alphabets[s[0]] = 1

for i in range(1, len(s)):
    ss = s[0:i]
    for char, char_count in alphabets.items():
        if char != s[i]:
            count += char_count

    if s[i] in alphabets:
        alphabets[s[i]] += 1
    else:
        alphabets[s[i]] = 1

print(count)


Fixed submission:
s = input()

count = 1

alphabets = {}

alphabets[s[0]] = 1

for i in range(1, len(s)):
    for char, char_count in alphabets.items():
        if char != s[i]:
            count += char_count

    if s[i] in alphabets:
        alphabets[s[i]] += 1
    else:
        alphabets[s[i]] = 1

print(count)
Problem p03618 (C++)

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

#define db double
#define RG register
#define ll long long

inline int gi() {
  RG int r = 0;
  RG bool b = true;
  RG char c = getchar();
  while (c < '0' || c > '9')
    c == '-' ? b = false : 0, c = getchar();
  while (c >= '0' && c <= '9')
    r = (r << 1) + (r << 3) + c - '0', c = getchar();
  return b ? r : -r;
}

const int N = 142857, inf = 1 << 30;

char s[20050];
int n, cnt[30];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int i, j, k;
  ll ans;
  for (i = ans = 1; i <= n; ++i) {
    j = s[i] - 'a';
    ans += cnt[j];
    for (k = 0; k < 26; ++k)
      if (k != j)
        cnt[k]++;
  }
  printf("%lld\n", ans);
  return 0;
}

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

#define db double
#define RG register
#define ll long long

inline int gi() {
  RG int r = 0;
  RG bool b = true;
  RG char c = getchar();
  while (c < '0' || c > '9')
    c == '-' ? b = false : 0, c = getchar();
  while (c >= '0' && c <= '9')
    r = (r << 1) + (r << 3) + c - '0', c = getchar();
  return b ? r : -r;
}

const int N = 142857, inf = 1 << 30;

char s[200050];
int n, cnt[30];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int i, j, k;
  ll ans;
  for (i = ans = 1; i <= n; ++i) {
    j = s[i] - 'a';
    ans += cnt[j];
    for (k = 0; k < 26; ++k)
      if (k != j)
        cnt[k]++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03618 (C++)

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

const int maxn = 1e5 + 10;

int n;
int cnt[26];
char s[maxn];

int main() {
  //    freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; s[i]; ++i)
    cnt[s[i] - 'a']++;
  long long ans = 1 + 1ll * n * (n - 1) / 2;
  for (int i = 0; i < 26; ++i)
    ans -= 1ll * cnt[i] * (cnt[i] - 1) / 2;
  printf("%lld\n", ans);

  return 0;
}


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

const int maxn = 2e5 + 10;

int n;
int cnt[26];
char s[maxn];

int main() {
  //    freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; s[i]; ++i)
    cnt[s[i] - 'a']++;
  long long ans = 1 + 1ll * n * (n - 1) / 2;
  for (int i = 0; i < 26; ++i)
    ans -= 1ll * cnt[i] * (cnt[i] - 1) / 2;
  printf("%lld\n", ans);

  return 0;
}
Problem p03618 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define allsort(v) sort(v.begin(), v.end())
#define allsortg(v) sort(v.begin(), v.end(), greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
  cin.sync_with_stdio(false);
  string A;
  cin >> A;
  ll n = A.size();
  n = n * (n - 1) / 2;
  vector<string> t;
  t.push_back(A);
  rep(i, A.size() - 1) {
    reps(j, i + 1, A.size()) {
      string x = A;
      reverse(x.begin() + i, x.begin() + j + 1);
      t.push_back(x);
    }
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
  }
  cout << t.size() << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define allsort(v) sort(v.begin(), v.end())
#define allsortg(v) sort(v.begin(), v.end(), greater<int>());
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
  cin.sync_with_stdio(false);
  string A;
  cin >> A;
  ll n = A.size() * (A.size() - 1) / 2;
  ll flag[26] = {};
  rep(i, A.size()) { flag[A[i] - 'a']++; }
  rep(i, 26) { n -= flag[i] * (flag[i] - 1) / 2; }
  cout << n + 1 << endl;

  return 0;
}
Problem p03618 (C++)

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

using namespace std;

#define int long long

using ll = long long;
using pii = pair<int, int>;

const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9 + 7;

#define for_(i, a, b) for (int i = (a); i < (b); i++)
#define rfor_(i, a, b) for (int i = (b)-1; i >= (a); i--)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
// #define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

#define NMAX 256

char str[NMAX];
int n, a;
int str_num[26];

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);

  scanf("%s", str);

  n = strlen(str);
  a = n * (n - 1) / 2 + 1;

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < n; j++) {
      if (str[j] == 'a' + i) {
        str_num[i]++;
      }
    }
  }

  for (int i = 0; i < 26; i++) {
    a -= str_num[i] * (str_num[i] - 1) / 2;
  }

  cout << a << endl;

  return 0;
}

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

using namespace std;

#define int long long

using ll = long long;
using pii = pair<int, int>;

const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9 + 7;

#define for_(i, a, b) for (int i = (a); i < (b); i++)
#define rfor_(i, a, b) for (int i = (b)-1; i >= (a); i--)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
// #define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

#define NMAX 200000

char str[NMAX];
int n, a;
int str_num[26];

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);

  scanf("%s", str);

  n = strlen(str);
  a = n * (n - 1) / 2 + 1;

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < n; j++) {
      if (str[j] == 'a' + i) {
        str_num[i]++;
      }
    }
  }

  for (int i = 0; i < 26; i++) {
    a -= str_num[i] * (str_num[i] - 1) / 2;
  }

  cout << a << endl;

  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

ll nCr(ll n, ll r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}

//-----------------------ここから-----------

int main(void) {
  string s;
  cin >> s;
  ll cnt = 0;
  map<char, ll> mp;
  for (int i = 0; i < s.size(); i++) {
    mp[s[i]]++;
  }
  for (auto &i : mp) {
    if (i.second < 2)
      continue;
    cnt += nCr(i.second, 2);
  }

  ll ans = nCr(s.size(), 2) + 1;
  cout << ans - cnt << endl;
}

Fixed submission:
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

ll nCr(ll n, ll r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}

//-----------------------ここから-----------

int main(void) {
  string s;
  cin >> s;
  ll cnt = 0;
  map<char, ll> mp;
  for (int i = 0; i < s.size(); i++) {
    mp[s[i]]++;
  }
  for (auto &i : mp) {
    if (i.second < 2)
      continue;
    cnt += nCr(i.second, 2);
  }

  if (s.size() == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = nCr(s.size(), 2) + 1;
  cout << ans - cnt << endl;
}
Problem p03618 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
 * Created by KeigoOgawa
 */

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

string a;
ll ans = 0;

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

  cin >> a;
  REP(i, a.size()) {
    FOR(j, i + 1, a.size()) {
      if (a[i] == a[j])
        continue;
      ans++;
    }
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Fixed submission:
/*
 * Created by KeigoOgawa
 */

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

string a;
ll ans = 0;

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

  cin >> a;
  ll count[27] = {0};
  ans = (ll)a.size() * (ll)(a.size() - 1) / 2;

  REP(i, a.size()) { count[a[i] - 'a']++; }
  REP(i, 27) {
    ll c = count[i] - 1;
    if (c <= 0)
      continue;
    ans -= c * (c + 1) / 2;
  }
  ans++;
  cout << ans << endl;
  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[100050];
ll cnt[26];
int main() {
  scanf("%s", in);

  int i, j;
  for (i = 0; in[i] != 0; i++)
    cnt[in[i] - 'a']++;

  int N = strlen(in);

  ll ans = 0;
  for (i = 0; i < 26; i++)
    ans += cnt[i] * (N - cnt[i]);
  ans /= 2;
  printf("%lld\n", ans + 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[200050];
ll cnt[26];
int main() {
  scanf("%s", in);

  int i, j;
  for (i = 0; in[i] != 0; i++)
    cnt[in[i] - 'a']++;

  int N = strlen(in);

  ll ans = 0;
  for (i = 0; i < 26; i++)
    ans += cnt[i] * (N - cnt[i]);
  ans /= 2;
  printf("%lld\n", ans + 1);
  return 0;
}
Problem p03618 (C++)

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1000000007;

int main() {
  string a;
  cin >> a;
  int n = a.size();
  int ans = 1;
  REP(i, n - 1) FOR(j, i + 1, n) if (a[i] != a[j]) ans++;
  cout << ans << endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1000000007;

int main() {
  string a;
  cin >> a;
  ll n = a.size();
  ll ans = 1;
  vector<int> c(26, 0);
  REP(i, n) c[a[i] - 'a']++;
  REP(i, n - 1) {
    c[a[i] - 'a']--;
    ans += n - (i + 1) - c[a[i] - 'a'];
  }
  cout << ans << endl;
}
Problem p03618 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec)                                                             \
  for (auto v : vec) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << endl;

using namespace std;

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

  string A;
  cin >> A;

  ll total = 0;
  REP(i, A.size() - 1) {
    for (int j = i + 1; j < A.size(); j++) {
      if (A[i] != A[j])
        total++;
    }
  }

  cout << total + 1 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec)                                                             \
  for (auto v : vec) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << endl;

using namespace std;

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

  string A;
  cin >> A;

  ll c[26] = {};
  REP(i, A.size()) { c[A[i] - 'a']++; }

  ll total = A.size() * (A.size() - 1) / 2;
  REP(i, 26) { total -= c[i] * (c[i] - 1) / 2; }

  cout << total + 1 << endl;
  return 0;
}
Problem p03618 (C++)

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

const int N = 1e5 + 50;
char ch[N];
int n, cnt[26], s;
LL ans;
int main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  for (int i = 1; i <= n; i++)
    ans += s - cnt[ch[i] - 'a'], ++s, ++cnt[ch[i] - 'a'];
  cout << ans + 1 << '\n';
}

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

const int N = 2e5 + 50;
char ch[N];
int n, cnt[26], s;
LL ans;
int main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  for (int i = 1; i <= n; i++)
    ans += s - cnt[ch[i] - 'a'], ++s, ++cnt[ch[i] - 'a'];
  cout << ans + 1 << '\n';
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char ch[110000];
int A[30];
int main() {
  scanf("%s", ch + 1);
  int n = strlen(ch + 1);
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans += i - 1 - A[ch[i] - 'a'];
    A[ch[i] - 'a']++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char ch[210000];
int A[30];
int main() {
  scanf("%s", ch + 1);
  int n = strlen(ch + 1);
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans += i - 1 - A[ch[i] - 'a'];
    A[ch[i] - 'a']++;
  }
  cout << ans << endl;
}
Problem p03618 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 2e5 + 10;
char s[M];
int main() {
  while (scanf("%s", s) != EOF) {
    ll ans = 1;
    for (int i = 0; s[i]; ++i)
      for (int j = i + 1; s[j]; ++j)
        ans += s[i] != s[j];
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 2e5 + 10;
char s[M];
int main() {
  while (scanf("%s", s) != EOF) {
    ll ans = 1, len = strlen(s);
    sort(s, s + len);
    for (ll i = 0, t; i < len; i = t) {
      t = upper_bound(s + i + 1, s + len, s[i]) - s;
      if (t == len)
        break;
      ans += (t - i) * (len - t);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pii pair<int, int>
#define piii pair<int, pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cout << "!" << endl
#define SHOW(a, b) cout << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cout << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))

#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int, int, int> tiii;
#define mt make_tuple

int main() {
  ll ans = 0;
  string str;
  cin >> str;
  rep(i, str.size()) for (int j = i + 1; j < str.size();
                          j++) if (str[i] != str[j]) ans++;
  cout << ans + 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pii pair<int, int>
#define piii pair<int, pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cout << "!" << endl
#define SHOW(a, b) cout << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cout << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))

#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int, int, int> tiii;
#define mt make_tuple

int main() {
  ll ans = 0;
  string str;
  cin >> str;
  map<char, ll> table;
  rep(i, str.size()) table[str[i]]++;
  for (int i = 'a'; i <= 'z'; i++)
    for (int j = i + 1; j <= 'z'; j++)
      ans += table[i] * table[j];
  cout << ans + 1 << endl;
}
Problem p03618 (C++)

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

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

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> alp(26);
  lrep(i, 0, n) alp[s[i] - 'a']++;
  ll ans = 1;
  ans *= n;
  ans *= (n - 1);
  ans /= 2;
  lrep(i, 0, n) {
    if (alp[i] < 2)
      continue;
    ans -= alp[i] * (alp[i] - 1) / 2;
  }
  cout << ans + 1 << endl;
}

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

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

#define rep(i, cc, n) for (int i = cc; i < n; ++i)
#define lrep(i, cc, n) for (long long i = cc; i < n; ++i)
#define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i)
#define rrep(i, cc, n) for (long i = cc; i > n; --i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> alp(26);
  lrep(i, 0, n) alp[s[i] - 'a']++;
  ll ans = n * (n - 1) / 2;
  lrep(i, 0, 26) {
    if (alp[i] < 2)
      continue;
    ans -= alp[i] * (alp[i] - 1) / 2;
  }
  cout << ans + 1 << endl;
}
Problem p03618 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long

char buf[200005];
int main() {
  fread(buf, 1, sizeof(buf), stdin);
  int n = std::strlen(buf) - 1;

  ll ans = 1ll * n * (n - 1) / 2ll;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans -= (buf[i] == buf[j]);
    }
  }

  printf("%lld\n", ans + 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long

char buf[200005];
int main() {
  fread(buf, 1, sizeof(buf), stdin);
  int n = std::strlen(buf) - 1;

  ll ans = 1ll * n * (n - 1) / 2ll;
  for (int i = 0; i < 26; i++) {
    ll count = 0;
    char c = 'a' + i;
    for (int j = 0; j < n; j++)
      count += buf[j] == c;
    ans -= count * (count - 1) / 2;
  }

  printf("%lld\n", ans + 1);
  return 0;
}
Problem p03618 (C++)

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

const int MAXN = 100005;
char str[MAXN];
int T[26];

int main() {
  scanf("%s", str);
  for (char *p = str; *p != '\0'; p++)
    T[*p - 'a']++;
  int n = strlen(str);
  long long ans = (long long)n * (n - 1) / 2 + 1;
  for (int i = 0; i < 26; i++)
    ans -= (long long)T[i] * (T[i] - 1) / 2;
  cout << ans << endl;
  return 0;
}


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

const int MAXN = 200005;
char str[MAXN];
int T[26];

int main() {
  scanf("%s", str);
  for (char *p = str; *p != '\0'; p++)
    T[*p - 'a']++;
  int n = strlen(str);
  long long ans = (long long)n * (n - 1) / 2 + 1;
  for (int i = 0; i < 26; i++)
    ans -= (long long)T[i] * (T[i] - 1) / 2;
  cout << ans << endl;
  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int cnt[20000][26];
int main() {
  string A;
  cin >> A;
  int N = A.size();
  for (int i = 0; i < N; i++) {
    cnt[i][A[i] - 'a']++;
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < 26; j++)
      cnt[i][j] += cnt[i - 1][j];
  }
  LL ans = 1;
  for (int i = 0; i < N; i++) {
    ans += (N - 1 - i) - (cnt[N - 1][A[i] - 'a'] - cnt[i][A[i] - 'a']);
  }
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int cnt[200000][26];
int main() {
  string A;
  cin >> A;
  int N = A.size();
  for (int i = 0; i < N; i++) {
    cnt[i][A[i] - 'a']++;
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < 26; j++)
      cnt[i][j] += cnt[i - 1][j];
  }
  LL ans = 1;
  for (int i = 0; i < N; i++) {
    ans += (N - 1 - i) - (cnt[N - 1][A[i] - 'a'] - cnt[i][A[i] - 'a']);
  }
  cout << ans << endl;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<vector<P>> Graph;

int main() {

  string s;
  cin >> s;

  ll sum[26] = {};
  REP(i, s.size())
  sum[s[i] - 'a']++;

  ll ans = s.size() * (s.size() - 1) / 2;
  REP(i, s.size()) { ans -= sum[i] * (sum[i] - 1) / 2; }

  cout << ans + 1 << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<vector<P>> Graph;

int main() {

  string s;
  cin >> s;

  ll sum[26] = {};
  REP(i, s.size())
  sum[s[i] - 'a']++;

  ll ans = s.size() * (s.size() - 1) / 2;
  REP(i, 26) { ans -= sum[i] * (sum[i] - 1) / 2; }

  cout << ans + 1 << endl;

  return 0;
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(0);
  freopen("in.txt", "r", stdin);
  string str;
  while (cin >> str) {
    int num[27] = {0};
    ll ans = 0;
    for (int i = 0; i < str.size(); i++) {
      ans += i - num[str[i] - 'a'];
      num[str[i] - 'a']++;
    }
    cout << ans + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(0);
  // freopen("in.txt","r",stdin);
  string str;
  while (cin >> str) {
    int num[27] = {0};
    ll ans = 0;
    for (int i = 0; i < str.size(); i++) {
      ans += i - num[str[i] - 'a'];
      num[str[i] - 'a']++;
    }
    cout << ans + 1 << endl;
  }
}
Problem p03618 (C++)

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2 * acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 100010;

inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}

int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, -1, 1};

char s[N];

int cnt[123];

int main() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  ll ans = 0;
  for (int i = 1; i <= len; i++) {
    ans = ans + (i - 1);
    ans -= cnt[s[i]];
    cnt[s[i]]++;
  }
  printf("%lld\n", ans + 1ll);
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2 * acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 100010;

inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}

int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, -1, 1};

char s[N + N];

int cnt[123];

int main() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  ll ans = 0;
  for (int i = 1; i <= len; i++) {
    ans = ans + (i - 1);
    ans -= cnt[s[i]];
    cnt[s[i]]++;
  }
  printf("%lld\n", ans + 1ll);
}
Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
const int N = 1e5 + 9;
using namespace std;
char s[N];
int vis[N], a[N];
LL ans;
int main() {
  scanf("%s", &s);
  int len = strlen(s);
  for (int i = 1; i <= len; ++i)
    a[i] = s[i - 1] - 'a';

  vis[a[1]]++;
  for (int i = 2; i <= len; ++i) {
    ans = ans + i - 1 - vis[a[i]];
    vis[a[i]]++;
  }
  cout << ans + 1;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define LL long long
const int N = 3e5 + 9;
using namespace std;
char s[N];
int vis[N], a[N];
LL ans;
int main() {
  scanf("%s", &s);
  int len = strlen(s);
  for (int i = 1; i <= len; ++i)
    a[i] = s[i - 1] - 'a';

  vis[a[1]]++;
  for (int i = 2; i <= len; ++i) {
    ans = ans + i - 1 - vis[a[i]];
    vis[a[i]]++;
  }
  cout << ans + 1;
  return 0;
}
Problem p03619 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 200010;
const double PI = 3.141592653589793238462643383279502884197169399375;
int p[N], t[N];
struct Node {
  int x, y;
} w[N];

inline bool cmp(Node a, Node b) {
  if (a.x == b.x)
    return a.y > b.y;
  return a.x < b.x;
}

inline void add(int x, int k) {
  for (; x < N; x += (x & (-x))) {
    t[x] = max(t[x], k);
  }
}

inline int query(int x) {
  int ret = 0;
  for (; x; x -= (x & (-x))) {
    ret = max(ret, t[x]);
  }
  return ret;
}

int main() {
  int a, b, c, d, n;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  scanf("%d", &n);
  int tot = 0;
  for (register int i = 1, x, y; i <= n; ++i) {
    scanf("%d %d", &x, &y);
    if (min(a, c) <= x && x <= max(a, c) && min(b, d) <= y && y <= max(b, d)) {
      w[++tot].x = x, w[tot].y = y;
      p[tot] = y;
    }
  }
  sort(p + 1, p + tot + 1);
  if (c < a)
    swap(a, c), swap(b, d);
  if (b > d) {
    for (register int i = 1; i <= tot; ++i) {
      w[i].x = -w[i].x;
    }
  }
  sort(w + 1, w + tot + 1, cmp);
  for (register int i = 1; i <= tot; ++i) {
    int pos = lower_bound(p + 1, p + tot + 1, w[i].y) - (p + 1) + 1;
    int pt = query(pos - 1);
    add(pos, pt + 1);
  }
  int num = query(max(b, d));
  double ans = 100.0 * (abs(c - a) + abs(d - b)) - 20.0 * num + 5.0 * PI * num;
  if (num == min(abs(c - a), abs(d - b)) + 1)
    ans += 5.0 * PI;
  printf("%.13f\n", ans);
  return 0;
}

Fixed submission:
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 200010;
const double PI = 3.141592653589793238462643383279502884197169399375;
int p[N], t[N];
struct Node {
  int x, y;
} w[N];

inline bool cmp(Node a, Node b) {
  if (a.x == b.x)
    return a.y > b.y;
  return a.x < b.x;
}

inline void add(int x, int k) {
  for (; x < N; x += (x & (-x))) {
    t[x] = max(t[x], k);
  }
}

inline int query(int x) {
  int ret = 0;
  for (; x; x -= (x & (-x))) {
    ret = max(ret, t[x]);
  }
  return ret;
}

int main() {
  int a, b, c, d, n;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  scanf("%d", &n);
  int tot = 0;
  for (register int i = 1, x, y; i <= n; ++i) {
    scanf("%d %d", &x, &y);
    if (min(a, c) <= x && x <= max(a, c) && min(b, d) <= y && y <= max(b, d)) {
      w[++tot].x = x, w[tot].y = y;
      p[tot] = y;
    }
  }
  sort(p + 1, p + tot + 1);
  if (c < a)
    swap(a, c), swap(b, d);
  if (b > d) {
    for (register int i = 1; i <= tot; ++i) {
      w[i].x = -w[i].x;
    }
  }
  sort(w + 1, w + tot + 1, cmp);
  for (register int i = 1; i <= tot; ++i) {
    int pos = lower_bound(p + 1, p + tot + 1, w[i].y) - (p + 1) + 1;
    int pt = query(pos - 1);
    add(pos, pt + 1);
  }
  int num = query(tot);
  double ans = 100.0 * (abs(c - a) + abs(d - b)) - 20.0 * num + 5.0 * PI * num;
  if (num == min(abs(c - a), abs(d - b)) + 1)
    ans += 5.0 * PI;
  printf("%.13f\n", ans);
  return 0;
}
Problem p03619 (C++)

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

using namespace std;

const double PI = acos(-1.0);

int main() {
  vector<int> a(2), b(2);
  scanf("%d %d %d %d", &a[0], &a[1], &b[0], &b[1]);
  if (a[0] > b[0]) {
    swap(a, b);
  }
  int n;
  vector<vector<int>> var;
  scanf("%d", &n);
  int flag = a[1] <= b[1] ? 1 : -1;
  while (n--) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (x >= a[0] && x <= b[0] && y >= min(a[1], b[1]) &&
        y <= max(a[1], b[1])) {
      var.push_back({x, flag * y});
    }
  }
  sort(var.begin(), var.end());
  vector<int> t;
  for (auto &v : var) {
    if (t.empty() || t.back() < v[1]) {
      t.push_back(v[1]);
    } else {
      int low = 0, high = t.size() - 1;
      while (low < high) {
        int mid = (low + high) >> 1;
        if (t[mid] < v[1]) {
          mid = low + 1;
        } else {
          high = mid;
        }
      }
      t[low] = v[1];
    }
  }
  double res = 100.00 * (abs(a[0] - b[0]) + abs(a[1] - b[1]));
  if (t.size() == min(abs(a[0] - b[0]), abs(a[1] - b[1])) + 1) {
    res -= (t.size() - 1) * (20.0 - PI * 5.0) - (10.0 * PI - 20);
  } else {
    res -= t.size() * (20.0 - PI * 5.0);
  }
  printf("%.15f\n", res);
  return 0;
}


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

using namespace std;

const double PI = acos(-1.0);

int main() {
  vector<int> a(2), b(2);
  scanf("%d %d %d %d", &a[0], &a[1], &b[0], &b[1]);
  if (a[0] > b[0]) {
    swap(a, b);
  }
  int n;
  vector<vector<int>> var;
  scanf("%d", &n);
  int flag = a[1] <= b[1] ? 1 : -1;
  while (n--) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (x >= a[0] && x <= b[0] && y >= min(a[1], b[1]) &&
        y <= max(a[1], b[1])) {
      var.push_back({x, flag * y});
    }
  }
  sort(var.begin(), var.end());
  vector<int> t;
  for (auto &v : var) {
    if (t.empty() || t.back() < v[1]) {
      t.push_back(v[1]);
    } else {
      int low = 0, high = t.size() - 1;
      while (low < high) {
        int mid = (low + high) >> 1;
        if (t[mid] < v[1]) {
          low = mid + 1;
        } else {
          high = mid;
        }
      }
      t[low] = v[1];
    }
  }
  double res = 100.00 * (abs(a[0] - b[0]) + abs(a[1] - b[1]));
  if (t.size() == min(abs(a[0] - b[0]), abs(a[1] - b[1])) + 1) {
    res -= (t.size() - 1) * (20.0 - PI * 5.0) - (10.0 * PI - 20);
  } else {
    res -= t.size() * (20.0 - PI * 5.0);
  }
  printf("%.15f\n", res);
  return 0;
}
Problem p03619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define val p[i].y
using namespace std;

struct P {
  int x, y;
} st, en, p[101000], tmp;
int n = 0, m, fl, c[101000], tot = 0, pos;
double ans, pi = atan2(0, -1);

bool cmp(P p1, P p2) { return p1.x < p2.x; }

int main() {
  scanf("%d%d%d%d", &st.x, &st.y, &en.x, &en.y);
  if (st.x > en.x)
    swap(st, en);
  if (st.y > en.y)
    swap(st.y, en.y), fl = 1;

  for (scanf("%d", &m); m--;) {
    scanf("%d%d", &tmp.x, &tmp.y);
    if (tmp.x >= st.x && tmp.x <= en.x && tmp.y >= st.y && tmp.y <= en.y)
      p[++n] = tmp;
  }
  if (fl)
    for (int i = 1; i <= n; i++)
      p[i].y = (1e8) - p[i].y;
  sort(p + 1, p + n + 1, cmp);

  for (int i = 1; i <= n; i++) {
    if (val > c[tot]) {
      c[++tot] = val;
    } else {
      pos = lower_bound(c, c + tot + 1, val) - c;
      c[pos] = val;
    }
  }
  ans = ((double)en.x - st.x + en.y - st.y) * 100.0 - tot * (20.0 - 5.0 * pi);
  if (tot == en.x - st.x + 1 || tot == en.y - st.y + 1)
    ans += 5.0 * pi;
  printf("%.15lf", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define val p[i].y
using namespace std;

struct P {
  int x, y;
} st, en, p[201000], tmp;
int n = 0, m, fl, c[201000], tot = 0, pos;
double ans, pi = atan2(0, -1);

bool cmp(P p1, P p2) { return p1.x < p2.x; }

int main() {
  scanf("%d%d%d%d", &st.x, &st.y, &en.x, &en.y);
  if (st.x > en.x)
    swap(st, en);
  if (st.y > en.y)
    swap(st.y, en.y), fl = 1;

  for (scanf("%d", &m); m--;) {
    scanf("%d%d", &tmp.x, &tmp.y);
    if (tmp.x >= st.x && tmp.x <= en.x && tmp.y >= st.y && tmp.y <= en.y)
      p[++n] = tmp;
  }
  if (fl)
    for (int i = 1; i <= n; i++)
      p[i].y = (1e8) - p[i].y;
  sort(p + 1, p + n + 1, cmp);

  for (int i = 1; i <= n; i++) {
    if (val > c[tot]) {
      c[++tot] = val;
    } else {
      pos = lower_bound(c, c + tot + 1, val) - c;
      c[pos] = val;
    }
  }
  ans = ((double)en.x - st.x + en.y - st.y) * 100.0 - tot * (20.0 - 5.0 * pi);
  if (tot == en.x - st.x + 1 || tot == en.y - st.y + 1)
    ans += 5.0 * pi;
  printf("%.15lf", ans);
}