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

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

using namespace std;

int main() {
  int H;
  int W;
  cin >> H >> W;
  vector<string> a(H);
  vector<vector<int>> cnt(H, vector<int>(H, 0));
  for (int i = 0; i < H; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < H; ++i) {
    if (a[i][0] == '.')
      cnt[i][0] = 1;
    else
      break;
  }
  for (int i = 0; i < W; ++i) {
    if (a[0][i] == '.')
      cnt[0][i] = 1;
    else
      break;
  }
  int mod = pow(10, 9) + 7;
  for (int i = 1; i < H; ++i) {
    for (int j = 1; j < W; ++j) {
      if (a[i][j] == '.') {
        cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod;
      }
    }
  }
  cout << cnt[H - 1][W - 1];
}


Fixed submission:
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  int H;
  int W;
  cin >> H >> W;
  vector<string> a(H);
  vector<vector<int>> cnt(H, vector<int>(W, 0));
  for (int i = 0; i < H; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < H; ++i) {
    if (a[i][0] == '.')
      cnt[i][0] = 1;
    else
      break;
  }
  for (int i = 0; i < W; ++i) {
    if (a[0][i] == '.')
      cnt[0][i] = 1;
    else
      break;
  }
  int mod = pow(10, 9) + 7;
  for (int i = 1; i < H; ++i) {
    for (int j = 1; j < W; ++j) {
      if (a[i][j] == '.') {
        cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod;
      }
    }
  }
  cout << cnt[H - 1][W - 1];
}
Problem p03167 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
#define Fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define MOD 1000000007
using namespace std;

int m, n;
int arr[1001][1001];
ll solve(int i, int j) {
  if (i == m - 1 && j == n - 1)
    return 1;
  if (i > m - 1 || j > n - 1)
    return 0;

  ll ans = 0;
  if (arr[i + 1][j])
    ans += solve(i + 1, j) % MOD;
  if (arr[i][j + 1])
    ans += solve(i, j + 1) % MOD;

  return ans % MOD;
}

int main() {
  Fast

          cin >>
      m >> n;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      char x;
      cin >> x;
      if (x == '.')
        arr[i][j] = 1;
      else
        arr[i][j] = 0;
    }
  }

  cout << solve(0, 0);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define Fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define MOD 1000000007
using namespace std;

int m, n;
int arr[1001][1001];
ll solve(int i, int j) {
  if (i == m - 1 && j == n - 1)
    return 1;
  if (i > m - 1 || j > n - 1)
    return 0;

  ll ans = 0;
  if (arr[i + 1][j])
    ans += solve(i + 1, j) % MOD;
  if (arr[i][j + 1])
    ans += solve(i, j + 1) % MOD;

  return ans % MOD;
}

int main() {
  Fast

          cin >>
      m >> n;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      char x;
      cin >> x;
      if (x == '.')
        arr[i][j] = 1;
      else
        arr[i][j] = 0;
    }
  }

  // cout<<solve(0, 0)<<endl;

  ll dp[m][n];
  bool chk = false;

  for (int i = 0; i < n; i++) {
    if (arr[0][i] == 0)
      chk = true;

    if (chk)
      dp[0][i] = 0;
    else
      dp[0][i] = 1;
  }
  chk = false;
  for (int i = 0; i < m; i++) {
    if (arr[i][0] == 0)
      chk = true;

    if (chk)
      dp[i][0] = 0;
    else
      dp[i][0] = 1;
  }

  for (int i = 1; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (arr[i][j] == 0)
        dp[i][j] = 0;
      else
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
    }
  }

  cout << dp[m - 1][n - 1];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 30, M = 1000000007;
string s[N];
int i, j, n, m, dp[N][N];
bool vis[N][N];
int play(int x, int y) {
  if (x == n || y == m)
    return 0;
  if (s[x][y] == '#')
    return 0;
  if (vis[x][y])
    return dp[x][y];
  vis[x][y] = true;
  if (x == n - 1 && y == m - 1)
    return dp[x][y] = 1;
  return dp[x][y] = (play(x + 1, y) + play(x, y + 1)) % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(NULL);
  cin >> n >> m;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j)
      vis[i][j] = false;
  for (i = 0; i < n; ++i)
    cin >> s[i];
  cout << play(0, 0);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1030, M = 1000000007;
string s[N];
int i, j, n, m, dp[N][N];
bool vis[N][N];
int play(int x, int y) {
  if (x == n || y == m)
    return 0;
  if (s[x][y] == '#')
    return 0;
  if (vis[x][y])
    return dp[x][y];
  vis[x][y] = true;
  if (x == n - 1 && y == m - 1)
    return dp[x][y] = 1;
  return dp[x][y] = (play(x + 1, y) + play(x, y + 1)) % M;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(NULL);
  cin >> n >> m;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j)
      vis[i][j] = false;
  for (i = 0; i < n; ++i)
    cin >> s[i];
  cout << play(0, 0);
  return 0;
}
Problem p03167 (C++)

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

#define F first
#define S second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define mod 1000000007
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
int n, m;
int rec(vector<vector<char>> &a, int i, int j, vector<vector<int>> &dp) {
  if (i > n or j > m or a[i][j] == '#') {
    return 0;
  }
  if (i == n - 1 and j == m - 1) {
    return 1;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  int x = rec(a, i + 1, j, dp);
  int y = rec(a, i, j + 1, dp);

  return dp[i][j] = (x % mod + y % mod) % mod;
}
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  c_p_c();

  cin >> n >> m;
  vector<vector<char>> a(n + 1, vector<char>(n + 1, -1));
  rep(i, 0, n) {
    rep(j, 0, m) { cin >> a[i][j]; }
  }
  vector<vector<int>> dp(n + 1, vi(m + 1, -1));

  cout << rec(a, 0, 0, dp) % mod;

  return 0;
}

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

#define F first
#define S second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define mod 1000000007
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
int n, m;
int rec(vector<vector<char>> &a, int i, int j, vector<vector<int>> &dp) {
  if (i > n or j > m or a[i][j] == '#') {
    return 0;
  }
  if (i == n - 1 and j == m - 1) {
    return 1;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  int x = rec(a, i + 1, j, dp);
  int y = rec(a, i, j + 1, dp);

  return dp[i][j] = (x % mod + y % mod) % mod;
}
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  c_p_c();

  cin >> n >> m;
  vector<vector<char>> a(n + 1, vector<char>(m + 1, -1));
  rep(i, 0, n) {
    rep(j, 0, m) { cin >> a[i][j]; }
  }
  vector<vector<int>> dp(n + 1, vi(m + 1, -1));

  cout << rec(a, 0, 0, dp) % mod;

  return 0;
}
Problem p03167 (C++)

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

using namespace std;

#define int long long

const int N = 1055;
char mat[N][N];
int dp[N][N], n, m;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int MOD = 1e9 + 7;

int sol(int i, int j) {
  if (i == n - 1 && j == m - 1)
    return 1;
  int ans = dp[i][j];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int k = 0; k < 2; k++) {
    int x = i + dx[k];
    int y = j + dy[k];
    if (x >= 0 && y >= 0 && x < n && y < m && mat[x][y] == '.') {
      ans = (ans + sol(x, y)) % MOD;
    }
  }
  return ans;
}

void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << sol(0, 0) << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}

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

using namespace std;

#define int long long

const int N = 1055;
char mat[N][N];
int dp[N][N], n, m;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int MOD = 1e9 + 7;

int sol(int i, int j) {
  if (i == n - 1 && j == m - 1)
    return 1;
  int &ans = dp[i][j];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int k = 0; k < 2; k++) {
    int x = i + dx[k];
    int y = j + dy[k];
    if (x >= 0 && y >= 0 && x < n && y < m && mat[x][y] == '.') {
      ans = (ans + sol(x, y)) % MOD;
    }
  }
  return ans;
}

void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << sol(0, 0) << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p03167 (C++)

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int>>
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

  int H, W;
  cin >> H >> W;
  char a[H + 2][W + 2];
  rep(j, 0, W + 2) a[0][j] = a[H + 2][j] = '#';
  rep(i, 0, H + 2) a[i][0] = a[i][W + 2] = '#';
  rep(i, 1, H + 1) rep(j, 1, W + 1) cin >> a[i][j];

  ll dp[H + 1][W + 1];
  rep(i, 0, H + 1) rep(j, 0, W + 1) dp[i][j] = 0ll;

  dp[0][0] = 1ll;
  dp[1][1] = 1ll;

  int mod = 1e9 + 7;
  rep(i, 1, H + 1) rep(j, 1, W + 1) {
    if (i + 1 <= H) {
      if (a[i + 1][j] == '.') {
        (dp[i + 1][j] += dp[i][j]) %= mod;
      }
    }

    if (j + 1 <= W) {
      if (a[i][j + 1] == '.') {
        (dp[i][j + 1] += dp[i][j]) %= mod;
      }
    }
  }

  cout << dp[H][W] % mod << endl;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int>>
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

  int H, W;
  cin >> H >> W;
  char a[H + 2][W + 2];
  rep(j, 0, W + 2) a[0][j] = a[H + 1][j] = '#';
  rep(i, 0, H + 2) a[i][0] = a[i][W + 1] = '#';
  rep(i, 1, H + 1) rep(j, 1, W + 1) cin >> a[i][j];

  ll dp[H + 1][W + 1];
  rep(i, 0, H + 1) rep(j, 0, W + 1) dp[i][j] = 0ll;

  dp[0][0] = 1ll;
  dp[1][1] = 1ll;

  int mod = 1e9 + 7;
  rep(i, 1, H + 1) rep(j, 1, W + 1) {
    if (i + 1 <= H) {
      if (a[i + 1][j] == '.') {
        (dp[i + 1][j] += dp[i][j]) %= mod;
      }
    }

    if (j + 1 <= W) {
      if (a[i][j + 1] == '.') {
        (dp[i][j + 1] += dp[i][j]) %= mod;
      }
    }
  }

  cout << dp[H][W] % mod << endl;
}
Problem p03167 (C++)

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

#define ll long long
#define FAST                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
ll mod = 1000000007;
ll INF = 1e9 + 5;
ll M = 1e9 + 7;

int main() {
  FAST;
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  ll c = 1;
  for (int i = 1; i <= h; i++) {
    if (a[0][i - 1] == '#' || c == 0) {
      dp[1][i] = 0;
      c = 0;
    } else {
      dp[1][i] = 1;
    }
  }
  c = 1;
  for (int i = 1; i <= h; i++) {
    if (a[i - 1][0] == '#' || c == 0) {
      dp[i][1] = 0;
      c = 0;
    } else {
      dp[i][1] = 1;
    }
  }
  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      if (a[i - 1][j - 1] == '#') {
        dp[i][j] = 0;
      } else {
        dp[i][j] = (dp[i - 1][j] % M + dp[i][j - 1] % M) % M;
      }
    }
  }
  cout << dp[h][w] << endl;
  return 0;
}


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

#define ll long long
#define FAST                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
ll mod = 1000000007;
ll INF = 1e9 + 5;
ll M = 1e9 + 7;

int main() {
  FAST;
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  ll c = 1;
  for (int i = 1; i <= w; i++) {
    if (a[0][i - 1] == '#' || c == 0) {
      dp[1][i] = 0;
      c = 0;
    } else {
      dp[1][i] = 1;
    }
  }
  c = 1;
  for (int i = 1; i <= h; i++) {
    if (a[i - 1][0] == '#' || c == 0) {
      dp[i][1] = 0;
      c = 0;
    } else {
      dp[i][1] = 1;
    }
  }
  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      if (a[i - 1][j - 1] == '#') {
        dp[i][j] = 0;
      } else {
        dp[i][j] = (dp[i - 1][j] % M + dp[i][j - 1] % M) % M;
      }
    }
  }
  cout << dp[h][w] << endl;
  return 0;
}
Problem p03167 (C++)

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

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> dp(n, 0), ndp(dp);
  dp[0] = 1;

  for (int i = 0; i < n; ++i) {
    string now;
    cin >> now;
    for (int j = 0; j < m; ++j) {
      if (now[j] == '#')
        ndp[j] = 0;
      else {
        ndp[j] = dp[j];
        if (j > 0)
          ndp[j] += ndp[j - 1];
        ndp[j] %= 1000000007;
      }
    }
    swap(dp, ndp);
  }
  cout << dp[m - 1] << endl;

  return 0;
}


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

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> dp(m, 0), ndp(dp);
  dp[0] = 1;

  for (int i = 0; i < n; ++i) {
    string now;
    cin >> now;
    for (int j = 0; j < m; ++j) {
      if (now[j] == '#')
        ndp[j] = 0;
      else {
        ndp[j] = dp[j];
        if (j > 0)
          ndp[j] += ndp[j - 1];
        ndp[j] %= 1000000007;
      }
    }
    swap(dp, ndp);
  }
  cout << dp[m - 1] << endl;

  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
// Medha's code  :

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define INF 0x3f3f3f3f3f
#define MOD 1000000007

int main() {

  fastio;

  ll h, w;

  cin >> h >> w;

  vector<vector<bool>> grid(h + 5, vector<bool>(w + 5));
  vector<vector<ll>> count(h + 5, vector<ll>(w + 5));

  char x;

  for (ll i = 1; i <= h; i++) {
    for (ll j = 1; j <= w; j++) {
      cin >> x;
      if (x == '.')
        grid[i][j] = true;
      else
        grid[i][j] = false;
    }
  }

  ll k = 1;
  while (grid[k][1] == true) {
    count[k][1] = 1;
    k++;
  }

  for (ll i = k; i <= w; i++) {
    count[i][1] = 0;
  }

  k = 1;
  while (grid[1][k] == true) {
    count[1][k] = 1;
    k++;
  }

  for (ll i = k; i <= w; i++) {
    count[1][i] = 0;
  }

  for (ll i = 2; i <= h; i++) {
    for (ll j = 2; j <= w; j++) {
      if (grid[i][j] == true) {
        count[i][j] = ((count[i][j - 1]) % MOD + (count[i - 1][j]) % MOD) % MOD;
      } else {
        count[i][j] = 0;
      }
    }
  }
  cout << (count[h][w]) % MOD;

  return 0;
}


Fixed submission:
// Medha's code  :

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define INF 0x3f3f3f3f3f
#define MOD 1000000007

int main() {

  fastio;

  ll h, w;

  cin >> h >> w;

  vector<vector<bool>> grid(h + 5, vector<bool>(w + 5));
  vector<vector<ll>> count(h + 5, vector<ll>(w + 5));

  char x;

  for (ll i = 1; i <= h; i++) {
    for (ll j = 1; j <= w; j++) {
      cin >> x;
      if (x == '.')
        grid[i][j] = true;
      else
        grid[i][j] = false;
    }
  }

  ll k = 1;
  while (grid[k][1] == true) {
    count[k][1] = 1;
    k++;
  }

  for (ll i = k; i <= h; i++) {
    count[i][1] = 0;
  }

  k = 1;
  while (grid[1][k] == true) {
    count[1][k] = 1;
    k++;
  }

  for (ll i = k; i <= w; i++) {
    count[1][i] = 0;
  }

  for (ll i = 2; i <= h; i++) {
    for (ll j = 2; j <= w; j++) {
      if (grid[i][j] == true) {
        count[i][j] = ((count[i][j - 1]) % MOD + (count[i - 1][j]) % MOD) % MOD;
      } else {
        count[i][j] = 0;
      }
    }
  }
  cout << (count[h][w]) % MOD;

  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
/*
        dp[i][j] = no. of ways to reach (H, W) from (i, j)
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main() {
  int H, W;
  vector<vector<ll>> dp;
  vector<string> a;
  cin >> H >> W;
  a.assign(H + 1, "");
  dp.assign(H + 1, vector<ll>(H + 1, 0));
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  for (int i = W - 1; i >= 0; i--) {
    if (a[H - 1][i] != '#')
      dp[H - 1][i] = 1;
    else
      break;
  }
  for (int i = H - 1; i >= 0; i--) {
    if (a[i][W - 1] != '#')
      dp[i][W - 1] = 1;
    else
      break;
  }
  for (int i = H - 2; i >= 0; i--) {
    for (int j = W - 2; j >= 0; j--) {
      if (a[i][j] != '#')
        dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
    }
  }
  cout << dp[0][0] << "\n";
  /*for(int i=0;i<H;i++){
          for(int j=0;j<W;j++){
                  cout<<dp[i][j]<<" ";
          }
          cout<<"\n";
  }*/
  return 0;
}

Fixed submission:
/*
        dp[i][j] = no. of ways to reach (H, W) from (i, j)
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main() {
  int H, W;
  vector<vector<ll>> dp;
  vector<string> a;
  cin >> H >> W;
  a.assign(H + 1, "");
  dp.assign(H + 1, vector<ll>(W + 1, 0));
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  for (int i = W - 1; i >= 0; i--) {
    if (a[H - 1][i] != '#')
      dp[H - 1][i] = 1;
    else
      break;
  }
  for (int i = H - 1; i >= 0; i--) {
    if (a[i][W - 1] != '#')
      dp[i][W - 1] = 1;
    else
      break;
  }
  for (int i = H - 2; i >= 0; i--) {
    for (int j = W - 2; j >= 0; j--) {
      if (a[i][j] != '#')
        dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
    }
  }
  cout << dp[0][0] << "\n";
  /*for(int i=0;i<H;i++){
          for(int j=0;j<W;j++){
                  cout<<dp[i][j]<<" ";
          }
          cout<<"\n";
  }*/
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ll long long

using namespace std;

const int mod = 1e9 + 7;

int main() {
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  int h, w;
  scanf("%d %d", &h, &w);
  vector<vector<char>> a(h + 1, vector<char>(w + 1));
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      scanf(" %c", &a[i][j]);
  vector<vector<int>> cnt(h + 1, vector<int>(w + 1, 0));
  cnt[1][1] = 1;
  if (a[1][1] == '#' || a[h][w] == '#') {
    printf("0");
    return 0;
  }
  for (int j = 2; j <= w; j++) {
    if (a[1][j] != '#') {
      cnt[1][j] += (cnt[1][j - 1]) % mod;
    }
  }
  for (int i = 2; i <= h; i++) {
    if (a[i][1] != '#') {
      cnt[i][1] += (cnt[i - 1][1]) % mod;
    }
  }
  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      if (a[i][j] != '#') {
        cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod;
      }
    }
  }
  printf("%d", cnt[h][w] % mod);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ll long long

using namespace std;

const int mod = 1e9 + 7;

int main() {
  // freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
  int h, w;
  scanf("%d %d", &h, &w);
  vector<vector<char>> a(h + 1, vector<char>(w + 1));
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      scanf(" %c", &a[i][j]);
  vector<vector<int>> cnt(h + 1, vector<int>(w + 1, 0));
  cnt[1][1] = 1;
  if (a[1][1] == '#' || a[h][w] == '#') {
    printf("0");
    return 0;
  }
  for (int j = 2; j <= w; j++) {
    if (a[1][j] != '#') {
      cnt[1][j] += (cnt[1][j - 1]) % mod;
    }
  }
  for (int i = 2; i <= h; i++) {
    if (a[i][1] != '#') {
      cnt[i][1] += (cnt[i - 1][1]) % mod;
    }
  }
  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      if (a[i][j] != '#') {
        cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod;
      }
    }
  }
  printf("%d", cnt[h][w] % mod);
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define debug(x) cout << #x << "::" << x << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++) {
    cin >> v[i];
  }
  vector<vector<int>> dp(h, vector<int>(w, 0));
  dp[0][0] = 1;
  for (int i = 1; i < h; i++) {
    if (v[i][0] == '.') {
      dp[i][0] = dp[i - 1][0];
    }
  }
  for (int j = 1; j < w; j++) {
    if (v[0][j] == '.') {
      dp[0][j] = dp[0][j - 1];
    }
  }
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (v[i][j] == '.') {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
      }
    }
  }
  cout << dp[h - 1][w - 1] << '\n';
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t;
  t = 1;
  while (t--)
    solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define debug(x) cout << #x << "::" << x << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++) {
    cin >> v[i];
  }
  vector<vector<int>> dp(h, vector<int>(w, 0));
  dp[0][0] = 1;
  for (int i = 1; i < h; i++) {
    if (v[i][0] == '.') {
      dp[i][0] = dp[i - 1][0];
    }
  }
  for (int j = 1; j < w; j++) {
    if (v[0][j] == '.') {
      dp[0][j] = dp[0][j - 1];
    }
  }
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (v[i][j] == '.') {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
      }
    }
  }
  cout << dp[h - 1][w - 1] << '\n';
}

int main() {
  int t;
  t = 1;
  while (t--)
    solve();
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int dp[1000][1000];
int main() {
  int t, h, w;
  char st[1003][1003];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    scanf("%s", st[i]);
  }
  dp[0][0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int c1 = j + 1;
      int r1 = i + 1;
      if (st[i][j] == '.') {
        if (st[i][c1] != '#') {
          dp[i][c1] += dp[i][j];
          if (dp[i][c1] >= mod)
            dp[i][c1] -= mod;
        }

        if (st[r1][j] != '#') {
          dp[r1][j] += dp[i][j];
          if (dp[r1][j] >= mod)
            dp[r1][j] -= mod;
        }
      }
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int dp[1005][1005];
int main() {
  int t, h, w;
  char st[1003][1003];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    scanf("%s", st[i]);
  }
  dp[0][0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int c1 = j + 1;
      int r1 = i + 1;
      if (st[i][j] == '.') {
        if (st[i][c1] != '#') {
          dp[i][c1] += dp[i][j];
          if (dp[i][c1] >= mod)
            dp[i][c1] -= mod;
        }

        if (st[r1][j] != '#') {
          dp[r1][j] += dp[i][j];
          if (dp[r1][j] >= mod)
            dp[r1][j] -= mod;
        }
      }
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main() {
  //   freopen("input.txt","r",stdin);
  //   freopen("output.txt","w",stdout);

  ll m, n;
  cin >> m >> n;
  ll dp[m][n];

  string h[m];
  for (ll i = 0; i < m; i++)
    cin >> h[i];
  int f = 0;
  for (ll i = 0; i < n; i++) {
    if (h[0][i] == '#') {
      dp[0][i] = 0;
      f = 1;
      continue;
    }
    if (f == 0)
      dp[0][i] = 1;
    else
      dp[0][i] = 0;
  }

  f = 0;
  for (ll i = 0; i < n; i++) {
    if (h[i][0] == '#') {
      dp[i][0] = 0;
      f = 1;
      continue;
    }
    if (f == 0)
      dp[i][0] = 1;
    else
      dp[i][0] = 0;
  }
  for (ll i = 1; i < m; i++) {
    for (ll j = 1; j < n; j++) {
      if (h[i][j] == '#')
        dp[i][j] = 0;
      else
        dp[i][j] = ((dp[i - 1][j]) % mod + (dp[i][j - 1]) % mod) % mod;
    }
  }

  cout << dp[m - 1][n - 1];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main() {
  //   freopen("input.txt","r",stdin);
  //   freopen("output.txt","w",stdout);

  ll m, n;
  cin >> m >> n;
  ll dp[m][n];

  string h[m];
  for (ll i = 0; i < m; i++)
    cin >> h[i];
  int f = 0;
  for (ll i = 0; i < n; i++) {
    if (h[0][i] == '#') {
      dp[0][i] = 0;
      f = 1;
      continue;
    }
    if (f == 0)
      dp[0][i] = 1;
    else
      dp[0][i] = 0;
  }

  f = 0;
  for (ll i = 0; i < m; i++) {
    if (h[i][0] == '#') {
      dp[i][0] = 0;
      f = 1;
      continue;
    }
    if (f == 0)
      dp[i][0] = 1;
    else
      dp[i][0] = 0;
  }
  for (ll i = 1; i < m; i++) {
    for (ll j = 1; j < n; j++) {
      if (h[i][j] == '#')
        dp[i][j] = 0;
      else
        dp[i][j] = ((dp[i - 1][j]) % mod + (dp[i][j - 1]) % mod) % mod;
    }
  }

  cout << dp[m - 1][n - 1];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define ii pair<int, int>
#define debug(index, num) cerr << "Case #" << index << ": " << num << endl
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back
const ll MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> g(n + 2, vector<char>(n + 2, '#'));
  vector<vector<ll>> dp(n + 2, vector<ll>(m + 2, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> g[i][j];
    }
  }
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (g[i][j] == '#')
        dp[i][j] = 0;
      else
        dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
      if (dp[i][j] >= MOD)
        dp[i][j] -= MOD;
    }
  }
  cout << dp[n][m];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define ii pair<int, int>
#define debug(index, num) cerr << "Case #" << index << ": " << num << endl
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back
const ll MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> g(n + 2, vector<char>(m + 2, '#'));
  vector<vector<ll>> dp(n + 2, vector<ll>(m + 2, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> g[i][j];
    }
  }
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (g[i][j] == '#')
        dp[i][j] = 0;
      else
        dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
      if (dp[i][j] >= MOD)
        dp[i][j] -= MOD;
    }
  }
  cout << dp[n][m];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java,
PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly,
HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere
in world.

*******************************************************************************/
#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int i, h, w, j;
  char t;
  scanf("%d %d ", &h, &w);
  int a[h + 1][w + 1];
  for (i = 0; i <= w; i++) {
    a[0][i] = 0;
  }
  for (j = 0; j <= h; j++) {
    a[j][0] = 0;
  }

  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {

      scanf("%c", &t);

      if (t == '.') {
        a[i][j] = ((a[i][j - 1]) + (a[i - 1][j]));
      } else {
        a[i][j] = 0;
      }

      a[1][1] = 1;
      a[i][j] = a[i][j] % 1000000007;
    }
    scanf("%c", &t);
  }

  for (i = 0; i <= w; i++) {

    for (j = 0; j <= h; j++) {
      printf("%d ", a[i][j]);
    }
    printf("\n");
  }
}


Fixed submission:
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java,
PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly,
HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere
in world.

*******************************************************************************/
#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int i, h, w, j;
  char t;
  scanf("%d %d ", &h, &w);
  int a[h + 1][w + 1];
  for (i = 0; i <= w; i++) {
    a[0][i] = 0;
  }
  for (j = 0; j <= h; j++) {
    a[j][0] = 0;
  }

  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {

      scanf("%c", &t);

      if (t == '.') {
        a[i][j] = ((a[i][j - 1]) + (a[i - 1][j]));
      } else {
        a[i][j] = 0;
      }

      a[1][1] = 1;
      a[i][j] = a[i][j] % 1000000007;
    }
    scanf("%c", &t);
  }

  printf("%d ", a[h][w]);
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(NULL);                                             \
  cin.tie(NULL);
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define MOD 1000000007

using namespace std;

void init() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

// code from below

void solve() {
  int n, m;
  cin >> n >> m;
  char arr[n][m];
  FOR(i, n)
  FOR(j, m)
  cin >> arr[i][j];
  int dp[n][m];
  memset(dp, 0, sizeof(dp));

  // dp[i][j] denotes no. of ways to go from i,j to n,m

  // fill the last row with 1 and last col with 1
  for (int i = m - 1; i >= 0 and arr[n - 1][i] != '#'; i--)
    dp[n - 1][i] = 1;
  for (int i = n - 1; i >= 0 and arr[m - 1][i] != '#'; i--)
    dp[i][m - 1] = 1;
  // fill the remaining dp array
  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      if (arr[i][j] != '#') {
        dp[i][j] = ((ll)dp[i + 1][j] + (ll)dp[i][j + 1]) % MOD;
      }
    }
  }
  // for(int i=0;i<n;i++,cout<<endl)
  //     for(int j=0;j<m;j++)
  //         cout<<dp[i][j]<<" ";

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

int main() {
  int t = 1;
  // cin>>t;
  // cin.ignore(numeric_limits<streamsize>::max(),'\n');
  while (t--)
    solve();
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(NULL);                                             \
  cin.tie(NULL);
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define pb push_back
#define MOD 1000000007

using namespace std;

void init() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

// code from below

void solve() {
  int n, m;
  cin >> n >> m;
  char arr[n][m];
  FOR(i, n)
  FOR(j, m)
  cin >> arr[i][j];
  int dp[n][m];
  memset(dp, 0, sizeof(dp));

  // dp[i][j] denotes no. of ways to go from i,j to n,m

  // fill the last row with 1 and last col with 1
  for (int i = m - 1; i >= 0 and arr[n - 1][i] != '#'; i--)
    dp[n - 1][i] = 1;
  for (int i = n - 1; i >= 0 and arr[i][m - 1] != '#'; i--)
    dp[i][m - 1] = 1;
  // fill the remaining dp array
  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      if (arr[i][j] != '#') {
        dp[i][j] = ((ll)dp[i + 1][j] + (ll)dp[i][j + 1]) % MOD;
      }
    }
  }
  // for(int i=0;i<n;i++,cout<<endl)
  //     for(int j=0;j<m;j++)
  //         cout<<dp[i][j]<<" ";

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

int main() {
  int t = 1;
  // cin>>t;
  // cin.ignore(numeric_limits<streamsize>::max(),'\n');
  while (t--)
    solve();
}
Problem p03167 (C++)

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

void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void test_here() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}

ll no_of_paths_bu(vector<vector<char>> &grid, ll r, ll c) {
  vector<vector<ll>> dp(r + 1, vector<ll>(c + 1, 0));

  dp[r][c] = 1;

  for (ll i = r; i >= 1; i--) {
    for (ll j = c; j >= 1; j--) {
      if (i == r && j == c)
        continue;

      if (grid[i - 1][j - 1] != '.')
        dp[i][j] = 0;
      else
        dp[i][j] = ((i + 1 <= r ? dp[i + 1][j] : 0) +
                    (j + 1 <= c ? dp[i][j + 1] : 0)) %
                   M;
    }
  }
  return dp[1][1];
}

void qH() {
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> grid(h + 1, vector<char>(w + 1));

  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      cin >> grid[i][j];
  cout << no_of_paths_bu(grid, h, w);
  /*
          vector< vector<ll> > dp(h+1, vector<ll>(w+1,-1));

          cout<<no_of_paths(grid,h,w,dp,0,0);*/
}

int main() {
  test_here();
  qH();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007

void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void test_here() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}

ll no_of_paths_bu(vector<vector<char>> &grid, ll r, ll c) {
  vector<vector<ll>> dp(r + 1, vector<ll>(c + 1, 0));

  dp[r][c] = 1;

  for (ll i = r; i >= 1; i--) {
    for (ll j = c; j >= 1; j--) {
      if (i == r && j == c)
        continue;

      if (grid[i - 1][j - 1] != '.')
        dp[i][j] = 0;
      else
        dp[i][j] = ((i + 1 <= r ? dp[i + 1][j] : 0) +
                    (j + 1 <= c ? dp[i][j + 1] : 0)) %
                   M;
    }
  }
  return dp[1][1];
}

void qH() {
  ll h, w;
  cin >> h >> w;
  vector<vector<char>> grid(h + 1, vector<char>(w + 1));

  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      cin >> grid[i][j];
  cout << no_of_paths_bu(grid, h, w);
  /*
          vector< vector<ll> > dp(h+1, vector<ll>(w+1,-1));

          cout<<no_of_paths(grid,h,w,dp,0,0);*/
}

int main() {
  // test_here();
  qH();
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

double memo[3005][3005];
double datas[3005];
int n;
double solve(int x, int y) {
  if (x + y == n) {
    if (x > y)
      return 1.00;
    else
      return 0.00;
  }
  if (memo[x][y] > 0.00)
    return memo[x][y];
  return memo[x][y] = datas[x + y] * solve(x + 1, y) +
                      (1 - datas[x + y]) * solve(x, y + 1);
}
int main() {
  scanf("%d", &n);
  for (int a = 0; a < n; a++) {
    scanf("%lf", &datas[a]);
  }
  for (int a = 0; a <= 3000; a++) {
    for (int b = 0; b <= 3000; b++) {
      memo[a][b] = -1.00;
    }
  }
  printf("%.10lf\n", solve(0, 0));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

double memo[3005][3005];
double datas[3005];
int n;
double solve(int x, int y) {
  if (x + y == n) {
    if (x > y)
      return 1.00;
    else
      return 0.00;
  }
  if (memo[x][y] > -1.00)
    return memo[x][y];
  return memo[x][y] = datas[x + y] * solve(x + 1, y) +
                      (1 - datas[x + y]) * solve(x, y + 1);
}
int main() {
  scanf("%d", &n);
  for (int a = 0; a < n; a++) {
    scanf("%lf", &datas[a]);
  }
  for (int a = 0; a <= 3000; a++) {
    for (int b = 0; b <= 3000; b++) {
      memo[a][b] = -1.00;
    }
  }
  printf("%.10lf\n", solve(0, 0));
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dx[2] = {1, 0};
int dy[2] = {0, 1};
double p[3000];
double dp[1000][1000] = {};

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }

  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; i + j < N; ++j) {
      dp[i][j + 1] += dp[i][j] * p[i + j];
      dp[i + 1][j] += dp[i][j] * (1 - p[i + j]);
    }
  }

  double res = 0;
  for (int i = N; i > N / 2; --i)
    res += dp[N - i][i];
  printf("%.10f\n", res);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int dx[2] = {1, 0};
int dy[2] = {0, 1};
double p[3000];
double dp[3000][3000] = {};

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }

  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; i + j < N; ++j) {
      dp[i][j + 1] += dp[i][j] * p[i + j];
      dp[i + 1][j] += dp[i][j] * (1 - p[i + j]);
    }
  }

  double res = 0;
  for (int i = N; i > N / 2; --i)
    res += dp[N - i][i];
  printf("%.10f\n", res);
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include<bits/extc++.h>
using namespace std;
// using namespace __gnu_pbds;
// typedef
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
// set_t;
#define mp(a, b) make_pair((a), (b))
#define pii pair<int, int>
#define pll pair<LL, LL>
#define pdd pair<double, double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x) * (x))
#define EPS 1e-6
#define MEM(x) memset(x, 0, sizeof(x))
#define MEMS(x) memset(x, -1, sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
double dp[3005][3005];
int main() {
  int n;
  scanf("%d", &n);
  double p[1005];
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0) {
        dp[i][j] = dp[i - 1][j] * (1 - p[i]);
      } else
        dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = n / 2 + 1; i <= n; i++)
    ans += dp[n][i];
  printf("%.12f\n", ans);
}


Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include<bits/extc++.h>
using namespace std;
// using namespace __gnu_pbds;
// typedef
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
// set_t;
#define mp(a, b) make_pair((a), (b))
#define pii pair<int, int>
#define pll pair<LL, LL>
#define pdd pair<double, double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x) * (x))
#define EPS 1e-6
#define MEM(x) memset(x, 0, sizeof(x))
#define MEMS(x) memset(x, -1, sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
double dp[3005][3005];
int main() {
  int n;
  scanf("%d", &n);
  double p[3005];
  for (int i = 1; i <= n; i++) {
    scanf("%lf", &p[i]);
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0) {
        dp[i][j] = dp[i - 1][j] * (1 - p[i]);
      } else
        dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = n / 2 + 1; i <= n; i++)
    ans += dp[n][i];
  printf("%.12f\n", ans);
}
Problem p03168 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP Coins
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
bool visited[3005][3005];
double memo[3005][3005];
double arr[3005];
int n;

double dp(int a, int b) {
  if (a >= n && b != 0)
    return 0.0;
  if (visited[a][b])
    return memo[a][b];
  visited[a][b];
  if (b == 0) {
    double res = 1.0;
    for (int i = a; i < n; i++)
      res *= (1 - arr[i]);
    return memo[a][b] = res;
  }
  return memo[a][b] = (1.0 - arr[a]) * dp(a + 1, b) + arr[a] * dp(a + 1, b - 1);
}

int main() {
#ifdef LOCAL_OUTPUT
  freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
  freopen(LOCAL_INPUT, "r", stdin);
#endif
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int m = n / 2 + 1;
  double res = 0.0;
  for (int i = m; i <= n; i++)
    res += dp(0, i);
  cout << fixed << setprecision(12) << res << endl;
}


Fixed submission:
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP Coins
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
bool visited[3005][3005];
double memo[3005][3005];
double arr[3005];
int n;

double dp(int a, int b) {
  if (a >= n && b != 0)
    return 0.0;
  if (visited[a][b])
    return memo[a][b];
  visited[a][b] = 1;
  if (b == 0) {
    double res = 1.0;
    for (int i = a; i < n; i++)
      res *= (1 - arr[i]);
    return memo[a][b] = res;
  }
  return memo[a][b] = (1.0 - arr[a]) * dp(a + 1, b) + arr[a] * dp(a + 1, b - 1);
}

int main() {
#ifdef LOCAL_OUTPUT
  freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
  freopen(LOCAL_INPUT, "r", stdin);
#endif
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int m = n / 2 + 1;
  double res = 0.0;
  for (int i = m; i <= n; i++)
    res += dp(0, i);
  cout << fixed << setprecision(12) << res << endl;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 3006;

double T[2][N], sum, p;
int act, prevv, i, j, n;

int main() {
  scanf("%d", &n);
  T[0][n] = 1.0;
  for (i = 1; i <= n; i++) {
    scanf("%lf", &p);
    act = i % 2;
    prevv = 1 - act;
    T[act][n - i] = T[prevv][n - i + 1] * p;
    for (j = n - i + 2; j <= n + i - 2; j++)
      T[act][j] = T[prevv][j + 1] * p + T[prevv][j - 1] * (1 - p);
    T[act][n + i] = T[prevv][n + i - 1] * (1 - p);
  }
  sum = 0.0;
  for (j = 0; j < n; j += 2)
    sum += T[act][j];
  printf("%.11lf\n", sum);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 6006;

double T[2][N], sum, p;
int act, prevv, i, j, n;

int main() {
  scanf("%d", &n);
  T[0][n] = 1.0;
  for (i = 1; i <= n; i++) {
    scanf("%lf", &p);
    act = i % 2;
    prevv = 1 - act;
    T[act][n - i] = T[prevv][n - i + 1] * p;
    for (j = n - i + 2; j <= n + i - 2; j++)
      T[act][j] = T[prevv][j + 1] * p + T[prevv][j - 1] * (1 - p);
    T[act][n + i] = T[prevv][n + i - 1] * (1 - p);
  }
  sum = 0.0;
  for (j = 0; j < n; j += 2)
    sum += T[act][j];
  printf("%.11lf\n", sum);
  return 0;
}
Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define maxx 10
int n;
double p[maxx];
double dp[maxx][maxx];
double f(int n, int x) {
  if (x == 0)
    return 1.0;
  if (n == 1) {
    return p[n];
  }
  if (dp[n][x] != -1)
    return dp[n][x];
  if (n == x) {
    dp[n][x] = p[n] * f(n - 1, x - 1);
    return dp[n][x];
  }
  dp[n][x] = p[n] * f(n - 1, x - 1) + (1 - p[n]) * f(n - 1, x);
  return dp[n][x];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> p[i];
  for (int i = 0; i < maxx; i++)
    for (int j = 0; j < maxx; j++)
      dp[i][j] = -1;
  cout << fixed << setprecision(10) << f(n, (n + 1) / 2);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define maxx 3000
int n;
double p[maxx];
double dp[maxx][maxx];
double f(int n, int x) {
  if (x == 0)
    return 1.0;
  if (n == 1) {
    return p[n];
  }
  if (dp[n][x] != -1)
    return dp[n][x];
  if (n == x) {
    dp[n][x] = p[n] * f(n - 1, x - 1);
    return dp[n][x];
  }
  dp[n][x] = p[n] * f(n - 1, x - 1) + (1 - p[n]) * f(n - 1, x);
  return dp[n][x];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> p[i];
  for (int i = 0; i < maxx; i++)
    for (int j = 0; j < maxx; j++)
      dp[i][j] = -1;
  cout << fixed << setprecision(10) << f(n, (n + 1) / 2);
}