alexjercan/bugnet huggingface dataset:
Problem p01415 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main(void) {
  int n, k, t, u, v, l;
  char d[100000] = {};
  scanf("%d%d%d%d%d%d", &n, &k, &t, &u, &v, &l);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    d[t] = 1;
  }

  double res = 0.0, rem = 0.0;
  int carrot = 0;
  for (int i = 0; i < l; i++) {
    if (d[i])
      carrot++;
    if (carrot > k)
      carrot = k, rem = 1.0 * t;

    double now = 0.0;
    while (now < 1.0) {
      if (rem == 0.0) {
        if (carrot) {
          carrot--;
          rem = 1.0 * t;
        } else {
          res += (1.0 - now) / u;
          now = 1.0;
        }
      }

      if (rem > (1.0 - now) / v) {
        res += (1.0 - now) / v;
        rem -= (1.0 - now) / v;
        now = 1.0;
      } else {
        res += rem;
        now += rem * v;
        rem = 0.0;
      }
    }
  }
  printf("%f\\n", res);

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>

int main(void) {
  int n, k, t, u, v, l;
  char d[1000] = {};
  scanf("%d%d%d%d%d%d", &n, &k, &t, &u, &v, &l);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    d[t] = 1;
  }

  double res = 0.0, rem = 0.0;
  int carrot = 0;
  for (int i = 0; i < l; i++) {
    if (d[i])
      carrot++;
    if (carrot > k)
      carrot = k, rem = 1.0 * t;

    double now = 0.0;
    while (now < 1.0) {
      if (rem == 0.0) {
        if (carrot) {
          carrot--;
          rem = 1.0 * t;
        } else {
          res += (1.0 - now) / u;
          now = 1.0;
        }
      }

      if (rem > (1.0 - now) / v) {
        res += (1.0 - now) / v;
        rem -= (1.0 - now) / v;
        now = 1.0;
      } else {
        res += rem;
        now += rem * v;
        rem = 0.0;
      }
    }
  }
  printf("%f\\n", res);

  return 0;
}
Problem p01415 (C++) — buggy submission, verdict: Runtime Error

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

enum State { Carrot, End };

typedef struct Event {
  int x;
  State state;

  bool operator<(const Event &right) const { return x > right.x; }
} Event;

int N, K, T, U, V, L;
vector<int> D;

int main() {
  cout.precision(16);
  cout.setf(ios::fixed);

  cin >> N >> K >> T >> U >> V >> L;
  D.resize(N);
  for (auto &v : D)
    cin >> v;

  priority_queue<Event> que;
  for (auto v : D)
    que.push(Event({v, Carrot}));

  vector<bool> zone(L);
  int count = 0;
  while (!que.empty()) {
    auto event = que.top();
    que.pop();
    if (event.state == Carrot) {
      if (zone[event.x]) {
        if (count < K) {
          count++;
        } else {
          que.push({event.x + T * V, End});
          for (int x = min(L, event.x + T * V) - 1; event.x <= x && !zone[x];
               x--)
            zone[x] = true;
        }
      } else {
        que.push({event.x + T * V, End});
        for (int x = min(L, event.x + T * V) - 1; event.x <= x && !zone[x]; x--)
          zone[x] = true;
      }
    } else {
      if (count && event.x < L && !zone[event.x]) {
        count--;
        que.push({event.x + T * V, End});
        for (int x = min(L, event.x + T * V) - 1; event.x <= x && !zone[x]; x--)
          zone[x] = true;
      }
    }
  }

  double span = 0;
  for (int i = 0; i < L; i++)
    span += zone[i];

  cout << (L - span) / U + span / V << endl;

  return 0;
}

Error: WA

Fixed submission:

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

enum State { Carrot, End };

typedef struct Event {
  int x;
  State state;

  bool operator<(const Event &right) const { return x > right.x; }
} Event;

int N, K, T, U, V, L;
vector<int> D;

int main() {
  cout.precision(16);
  cout.setf(ios::fixed);

  cin >> N >> K >> T >> U >> V >> L;
  D.resize(N);
  for (auto &v : D)
    cin >> v;

  priority_queue<Event> que;
  for (auto v : D)
    que.push(Event({v, Carrot}));

  vector<bool> zone(L);
  int count = 0;
  while (!que.empty()) {
    auto event = que.top();
    que.pop();
    if (event.state == Carrot) {
      if (zone[event.x]) {
        if (count < K) {
          count++;
        } else {
          que.push({event.x + T * V, End});
          for (int x = min(L, event.x + T * V) - 1; event.x <= x && !zone[x];
               x--)
            zone[x] = true;
        }
      } else {
        que.push({event.x + T * V, End});
        for (int x = min(L, event.x + T * V) - 1; event.x <= x && !zone[x]; x--)
          zone[x] = true;
      }
    } else {
      if (count && !zone[event.x]) {
        count--;
        que.push({event.x + T * V, End});
        for (int x = min(L, event.x + T * V) - 1; event.x <= x && !zone[x]; x--)
          zone[x] = true;
      }
    }
  }

  double span = 0;
  for (int i = 0; i < L; i++)
    span += zone[i];

  cout << (L - span) / U + span / V << endl;

  return 0;
}
Problem p01415 (C++) — buggy submission, verdict: Runtime Error

/*
 * 2298.cc: Starting Line
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 200;
const int MAX_L = 10000;

/* typedef */

/* global variables */

bool crts[MAX_L + 1];

/* subroutines */

/* main */

int main() {
  int n, k, t, u, v, l;
  cin >> n >> k >> t >> u >> v >> l;

  for (int i = 0; i < n; i++) {
    int cr;
    cin >> cr;
    crts[cr] = true;
  }

  int cn = 0;
  double vtl = (double)t * v;
  double ans = 0.0, r0 = 0.0, r1 = 0.0;

  for (int i = 1; i <= l; i++) {
    if (r0 < r1 && r1 <= i) {
      ans += (r1 - r0) / v;
      r0 = r1;
      if (cn > 0) {
        cn--;
        r1 = min(r1 + vtl, (double)l);
      }
    }

    if (crts[i]) {
      if (r0 == r1) {
        ans += ((double)i - r1) / u;
        r0 = i, r1 = min((double)i + vtl, (double)l);
      } else if (++cn > k) {
        cn--;
        ans += ((double)i - r0) / v;
        r0 = i, r1 = min((double)i + vtl, (double)l);
      }
    }
  }

  ans += (l - r1) / u;

  printf("%.9lf\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

/*
 * 2298.cc: Starting Line
 */

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 200;
const int MAX_L = 10000;

/* typedef */

/* global variables */

bool crts[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k, t, u, v, l;
  cin >> n >> k >> t >> u >> v >> l;

  for (int i = 0; i < n; i++) {
    int cr;
    cin >> cr;
    crts[cr] = true;
  }

  int cn = 0;
  double vtl = (double)t * v;
  double ans = 0.0, r0 = 0.0, r1 = 0.0;

  for (int i = 0; i <= l; i++) {
    if (r0 < r1 && r1 <= i) {
      ans += (r1 - r0) / v;
      r0 = r1;
      if (cn > 0) {
        cn--;
        r1 = min(r1 + vtl, (double)l);
      }
    }

    if (crts[i]) {
      if (r0 == r1) {
        ans += ((double)i - r1) / u;
        r0 = i, r1 = min((double)i + vtl, (double)l);
      } else if (++cn > k) {
        cn--;
        ans += ((double)i - r0) / v;
        r0 = i, r1 = min((double)i + vtl, (double)l);
      }
    }
  }

  ans += (l - r1) / u;

  printf("%.9lf\\n", ans);
  return 0;
}
Problem p01415 (C++) — buggy submission, verdict: Runtime Error

// AOJ 2298
#include <algorithm>
#include <iomanip>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long double real;

const int NMAX = 300, LMAX = 100000;
const int KMAX = NMAX;
int N, K, T, U, V, L;
bool D[LMAX], accel[LMAX];

real solve() {
  int bag = 0, limit = 0;
  for (int x = 0; x < L; x++) {
    if (D[x]) {
      if (limit == 0) {
        limit = V * T;
      } else if (bag == K) {
        limit = V * T;
      } else {
        bag++;
      }
    }

    if (limit == 0 and bag > 0) {
      bag--;
      limit = V * T;
    }

    if (limit > 0) {
      limit--;
      accel[x] = true;
    }
  }

  int u = 0, v = 0;
  REP(x, L) {
    if (accel[x]) {
      v++;
    } else {
      u++;
    }
  }

  return ((real)u) / U + ((real)v) / V;
}

int main() {
  cin >> N >> K >> T >> U >> V >> L;
  REP(x, N) {
    int d;
    cin >> d;
    D[d] = true;
  }

  cout << fixed << setprecision(20) << solve() << endl;
}

Error: WA

Fixed submission:

// AOJ 2298
#include <algorithm>
#include <iomanip>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long double real;

const int NMAX = 300, LMAX = 20000;
const int KMAX = NMAX;
int N, K, T, U, V, L;
bool D[NMAX], accel[LMAX];

real solve() {
  int bag = 0, limit = 0;
  for (int x = 0; x < L; x++) {
    if (limit > 0) {
      limit--;
      accel[x] = true;
    }
    if (D[x]) {
      if (limit == 0) {
        limit = V * T;
      } else if (bag == K) {
        limit = V * T;
      } else {
        bag++;
      }
    }

    if (limit == 0 and bag > 0) {
      bag--;
      limit = V * T;
    }
  }

  int u = 0, v = 0;
  REP(x, L) {
    if (accel[x]) {
      v++;
    } else {
      u++;
    }
  }
  cout << endl;

  return ((real)u) / U + ((real)v) / V;
}

int main() {
  cin >> N >> K >> T >> U >> V >> L;
  REP(x, N) {
    int d;
    cin >> d;
    D[d] = true;
  }

  cout << setprecision(10) << solve() << endl;
}
Problem p01415 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;

int main() {
  lli n, k, t, u, v, l;
  std::cin >> n >> k >> t >> u >> v >> l;
  vector<lli> d(n);
  priority_queue<pii, vector<pii>, greater<pii>> que;
  for (int i = 0; i < n; i++) {
    std::cin >> d[i];
    que.push(pii(d[i], 0));
  }
  que.push(pii(l, 1));
  double ans = 0, prev, pos = 0, end = 0;
  bool fast = false;
  lli carrot = 0;
  while (not que.empty()) {
    prev = pos;
    pos = que.top().first;
    ans += (pos - prev) / ((fast) ? v : u);
    int event = que.top().second;
    que.pop();
    if (event == 0) {
      if (fast == false) {
        fast = true;
        end = min((double)l, pos + v * t);
        que.push(pii(min((double)l, pos + v * t), 1));
      } else if (carrot == k) {
        end = min((double)l, pos + v * t);
        que.push(pii(min((double)l, pos + v * t), 1));
      } else {
        carrot = min(k, carrot + 1);
      }
    } else if (end <= pos + 1e-9) {
      if (carrot > 0) {
        carrot--;
        end = min((double)l, pos + v * t);
        que.push(pii(min((double)l, pos + v * t), 1));
      } else {
        fast = false;
      }
    }
  }
  printf("%.12lf\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k, t, u, v, l;
  std::cin >> n >> k >> t >> u >> v >> l;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    std::cin >> d[i];
  }
  double ans = 0;
  vector<int> course(l, 0);
  for (int i = 0; i < n; i++) {
    for (int j = d[i]; j < d[i] + t * v; j++) {
      if (j >= l)
        continue;
      course[j] = min(course[j] + 1, k + 1);
    }
  }
  double sum = 0;
  for (int i = 0; i < l; i++) {
    sum += course[i];
  }
  std::cout << setprecision(12) << sum / v + (l - sum) / u << std::endl;
  return 0;
}
Problem p01415 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, K, T, L;
  double U, V;
  cin >> N >> K >> T >> U >> V >> L;
  cout << setiosflags(ios::fixed) << setprecision(15);
  vector<int> D(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  double Time = 0;
  int pos = 0;
  int Npos = 0;
  int until = 0;
  while (pos < L) {
    if (pos == D[Npos]) {
      ++Npos;
      until += T * V;
      if (until > (K + 1) * T * V) {
        until = (K + 1) * T * V;
      }
    }
    if (until == 0) {
      Time += 1 / U;
    } else {
      Time += 1 / V;
      --until;
    }
    pos += 1;
  }
  cout << setiosflags(ios::fixed) << setprecision(15) << Time << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, K, T, L;
  double U, V;
  cin >> N >> K >> T >> U >> V >> L;
  vector<int> D(N + 1, 0);
  D[N + 1] = 0;
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  double Time = 0;
  int pos = 0;
  int Npos = 0;
  int until = 0;
  while (pos < L) {
    if (pos == D[Npos]) {
      ++Npos;
      until += T * V;
      if (until > (K + 1) * T * V) {
        until = (K + 1) * T * V;
      }
    }
    // cout << "proceed" << endl;

    if (until == 0) {
      Time += 1 / U;
    } else {
      Time += 1 / V;
      --until;
    }
    pos += 1;
  }
  cout << setiosflags(ios::fixed) << setprecision(15) << Time << endl;
}
Problem p01416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> pii;
const int INF = 1 << 28;
char board[510][510];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  int H, W;
  scanf("%d%d", &H, &W);
  int rest = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf(" %c", &board[i][j]);
      if (isupper(board[i][j]))
        rest++;
    }
  }

  int ans = 0;
  while (1) {
    bool ok = false;
    pii INIT = make_pair(-INF, -INF);
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        vector<pii> rec(26, INIT);
        if (isupper(board[i][j]))
          continue;
        for (int k = 0; k < 4; k++) {
          int x = i, y = j;
          while (1) {
            x += dx[k], y += dy[k];
            if (x < 0 || x >= H || y < 0 || y >= W)
              break;
            if (isupper(board[x][y])) {
              int c = board[x][y] - 'A';
              if (rec[c] == INIT)
                rec[c] = make_pair(x, y);
              else {
                int u = rec[c].first, v = rec[c].second;
                // printf("found: (%d, %d) and (%d, %d): %c (%d, %d)\\n", u, v,
                // x, y, 'A' + c, i, j);
                board[u][v] = board[x][y] = '.';
                rec[c] = INIT;
                ok = true;
                ans += 2;
              }
              break;
            }
          }
        }
      }
    }
    if (!ok)
      break;
  }
  printf("%d\\n", ans);
  return 0;
}


Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> pii;
const int INF = 1 << 28;
char board[510][510];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  int H, W;
  scanf("%d%d", &H, &W);
  int rest = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf(" %c", &board[i][j]);
      if (isupper(board[i][j]))
        rest++;
    }
  }

  int ans = 0;
  while (rest--) {
    pii INIT = make_pair(-INF, -INF);
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        vector<pii> rec(26, INIT);
        if (isupper(board[i][j]))
          continue;
        for (int k = 0; k < 4; k++) {
          int x = i, y = j;
          while (1) {
            x += dx[k], y += dy[k];
            if (x < 0 || x >= H || y < 0 || y >= W)
              break;
            if (isupper(board[x][y])) {
              int c = board[x][y] - 'A';
              if (rec[c] == INIT)
                rec[c] = make_pair(x, y);
              else {
                int u = rec[c].first, v = rec[c].second;
                // printf("found: (%d, %d) and (%d, %d): %c (%d, %d)\\n", u, v,
                // x, y, 'A' + c, i, j);
                board[u][v] = board[x][y] = '.';
                rec[c] = INIT;
                ans += 2;
              }
              break;
            }
          }
        }
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p01416 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;

int M, N, K;
char S[550][550];
vector<int> y, x;
vector<char> c;
int dd[5] = {0, 1, 0, -1, 0};

bool isin(int y, int x) { return 0 <= y && y < M && 0 <= x && x < N; }

int main(void) {
  cin >> M >> N;
  K = 0;
  REP(i, 0, M) REP(j, 0, N) cin >> S[i][j];

  int ans = 0;
  bool visited[256];
  REP(i, 0, 256) visited[i] = false;
  bool f = true;
  while (f) {
    f = false;
    REP(i, 0, M) REP(j, 0, N) {
      if (S[i][j] == '.' || visited[S[i][j]]) {
        int cnt[256];
        REP(k, 0, 256) cnt[k] = 0;
        REP(k, 0, 4) {
          int ny = i + dd[k], nx = j + dd[k + 1];
          while (isin(ny, nx)) {
            if (S[ny][nx] != '.' && !visited[S[ny][nx]]) {
              cnt[S[ny][nx]]++;
              if (cnt[S[ny][nx]] == 2) {
                visited[S[ny][nx]] = true;
                ans += 2;
                f = true;
              }
              break;
            }
            ny += dd[k];
            nx += dd[k + 1];
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;

int M, N, K;
char S[550][550];
vector<int> y, x;
vector<char> c;
char s[550][550];
int dd[5] = {0, 1, 0, -1, 0};

int compress(vector<int> &a) {
  vector<int> v;

  REP(i, 0, a.size()) v.push_back(a[i]);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  REP(i, 0, a.size()) a[i] = find(v.begin(), v.end(), a[i]) - v.begin();

  return (int)v.size();
}

bool isin(int y, int x) { return 0 <= y && y < M && 0 <= x && x < N; }

int main(void) {
  cin >> M >> N;
  K = 0;
  REP(i, 0, M) REP(j, 0, N) {
    cin >> S[i][j];
    if (S[i][j] != '.') {
      y.push_back(i);
      x.push_back(j);
      c.push_back(S[i][j]);
      K++;
    }
  }
  REP(i, 0, M)
  REP(j, 0, N) REP(k, 0, 4) if (isin(y[i] + dd[i], x[k] + dd[k + 1])) {
    y.push_back(y[i] + dd[k]);
    x.push_back(x[i] + dd[k + 1]);
  }

  M = compress(y);
  N = compress(x);

  REP(i, 0, M) REP(j, 0, N) s[i][j] = '.';
  REP(i, 0, K) s[y[i]][x[i]] = c[i];

  int ans = 0;
  bool visited[256];
  REP(i, 0, 256) visited[i] = false;
  bool f = true;
  while (f) {
    f = false;
    REP(i, 0, M) REP(j, 0, N) {
      if (s[i][j] == '.' || visited[s[i][j]]) {
        int cnt[256];
        REP(k, 0, 256) cnt[k] = 0;
        REP(k, 0, 4) {
          int ny = i + dd[k], nx = j + dd[k + 1];
          while (isin(ny, nx)) {
            if (s[ny][nx] != '.' && !visited[s[ny][nx]]) {
              cnt[s[ny][nx]]++;
              if (cnt[s[ny][nx]] == 2) {
                visited[s[ny][nx]] = true;
                ans += 2;
                f = true;
              }
              break;
            }
            ny += dd[k];
            nx += dd[k + 1];
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p01416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;
typedef pair<int, int> P;
int res = 0;
int m, n;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
map<int, vector<P>> pos;

bool check(vector<string> &s, int sx, int sy) {
  map<int, int> mp;
  int gx, gy;
  bool f = false;
  for (int i = 0; i < 4; i++) {
    gx = sx, gy = sy;
    while (true) {
      gx += dx[i];
      gy += dy[i];
      if (gx < 0 || m <= gx || gy < 0 || n <= gy)
        break;
      if (s[gx][gy] == '.')
        continue;
      int idx = s[gx][gy] - 'A';
      if (mp[idx]) {
        res += 2;
        f = true;
        P p1 = pos[idx][0], p2 = pos[idx][1];
        s[p1.first][p1.second] = '.';
        s[p2.first][p2.second] = '.';
      } else
        mp[idx]++;
      break;
    }
  }
  return f;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> m >> n;
  vector<string> s(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    for (int j = 0; j < n; j++) {
      if (s[i][j] == '.')
        continue;
      int idx = s[i][j] - 'A';
      pos[idx].push_back(P(i, j));
    }
  }
  while (true) {
    bool f = false;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (s[i][j] != '.')
          continue;
        f |= check(s, i, j);
      }
    }
    if (!f)
      break;
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
typedef pair<int, int> P;
int res = 0;
int m, n;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
map<int, vector<P>> pos;

bool check(vector<string> &s, int sx, int sy) {
  map<int, int> mp;
  int gx, gy;
  bool f = false;
  for (int i = 0; i < 4; i++) {
    gx = sx, gy = sy;
    while (true) {
      gx += dx[i];
      gy += dy[i];
      if (gx < 0 || m <= gx || gy < 0 || n <= gy)
        break;
      if (s[gx][gy] == '.')
        continue;
      int idx = s[gx][gy] - 'A';
      if (mp[idx]) {
        res += 2;
        f = true;
        P p1 = pos[idx][0], p2 = pos[idx][1];
        s[p1.first][p1.second] = '.';
        s[p2.first][p2.second] = '.';
      } else
        mp[idx]++;
      break;
    }
  }
  return f;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> m >> n;
  vector<string> s(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    for (int j = 0; j < n; j++) {
      if (s[i][j] == '.')
        continue;
      int idx = s[i][j] - 'A';
      pos[idx].push_back(P(i, j));
    }
  }
  while (true) {
    bool f = false;
    for (int i = 0; i < m; i++) {
      if (f)
        break;
      for (int j = 0; j < n; j++) {
        if (f)
          break;
        if (s[i][j] != '.')
          continue;
        f |= check(s, i, j);
      }
    }
    if (!f)
      break;
  }
  cout << res << endl;
}