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

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

const int N = 100 * 100;
int dp[N], n, m;
vector<int> adj[N];
bool mark[N];

void dfs(int u) {
  mark[u] = true;
  for (auto v : adj[u]) {
    if (!mark[v]) {
      dfs(v);
      dp[u] = max(dp[u], dp[v] + 1);
    }
    dp[u] = max(dp[u], dp[v] + 1);
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
  }
  for (int i = 0; i < n; i++)
    if (!mark[i])
      dfs(i);
  int maxi = 0;
  for (int i = 0; i < n; i++)
    maxi = max(maxi, dp[i]);
  cout << maxi << endl;
}


Fixed submission:
/* be name Khoda */
// VJUDGE
#include <bits/stdc++.h>
using namespace std;

const int N = 100 * 1001;
int dp[N], n, m;
vector<int> adj[N];
bool mark[N];

void dfs(int u) {
  mark[u] = true;
  for (auto v : adj[u]) {
    if (!mark[v]) {
      dfs(v);
      dp[u] = max(dp[u], dp[v] + 1);
    }
    dp[u] = max(dp[u], dp[v] + 1);
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
  }
  for (int i = 0; i < n; i++)
    if (!mark[i])
      dfs(i);
  int maxi = 0;
  for (int i = 0; i < n; i++)
    maxi = max(maxi, dp[i]);
  cout << maxi << endl;
}
Problem p03166 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int n, m, k, u, v, fix[100005], length[100005], ans;
vector<int> V[100005];
int go(int u) {

  if (fix[u])
    return length[u];

  for (int i = 0; i < V[u].size(); i++) {
    length[u] = max(length[u], go(V[u][i]) + 1);
  }
  return length[u];
}
int main() {
  cin >> n >> m;
  for (k = 1; k <= m; k++) {
    cin >> u >> v;
    V[v].push_back(u);
  }

  for (k = 1; k <= n; k++) {
    if (fix[k] == 0) {
      go(k);
    }
    ans = max(ans, length[k]);
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, k, u, v, fix[100005], length[100005], ans;
vector<int> V[100005];
int go(int u) {

  if (fix[u])
    return length[u];
  fix[u] = 1;
  for (int i = 0; i < V[u].size(); i++) {
    length[u] = max(length[u], go(V[u][i]) + 1);
  }
  return length[u];
}
int main() {
  cin >> n >> m;
  for (k = 1; k <= m; k++) {
    cin >> u >> v;
    V[v].push_back(u);
  }

  for (k = 1; k <= n; k++) {
    if (fix[k] == 0) {
      go(k);
    }
    ans = max(ans, length[k]);
  }
  cout << ans;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int dx[2] = {-1, 0};
int dy[2] = {0, -1};
long long vec[555][555];
int MOD = 1e9 + 7;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> board(h, "");
  for (int i = 0; i < h; ++i) {
    cin >> board[i];
  }
  if (board[0][0] != '#')
    vec[0][0] = 1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (board[i][j] == '#')
        continue;
      for (int k = 0; k < 2; ++k) {
        int x = dx[k] + i;
        int y = dy[k] + j;
        if (x >= 0 && y >= 0) {
          if (board[x][y] != '#')
            vec[i][j] = (vec[i][j] + vec[x][y]) % MOD;
        }
      }
    }
  }
  cout << vec[h - 1][w - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int dx[2] = {-1, 0};
int dy[2] = {0, -1};
long long vec[1010][1010];
int MOD = 1e9 + 7;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> board(h, "");
  for (int i = 0; i < h; ++i) {
    cin >> board[i];
  }
  if (board[0][0] != '#')
    vec[0][0] = 1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (board[i][j] == '#')
        continue;
      for (int k = 0; k < 2; ++k) {
        int x = dx[k] + i;
        int y = dy[k] + j;
        if (x >= 0 && y >= 0) {
          if (board[x][y] != '#')
            vec[i][j] = (vec[i][j] + vec[x][y]) % MOD;
        }
      }
    }
  }
  cout << vec[h - 1][w - 1] << endl;
  return 0;
}
Problem p03167 (C++)

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

static int grid[1000][1000];
static uint path_count[1000][1000];
static const uint mod = 1'000'000'007;

int main() {
  int h, w;
  cin >> h >> w;

  for (auto row = 0; row < h; row++) {
    for (auto col = 0; col < w; col++) {
      char c;
      cin >> c;
      grid[row][col] = c == '#' ? 1 : 0;
    }
  }
  path_count[0][0] = 1;
  for (auto i = 0; i < h + w - 1; i++) {
    for (auto j = 0; j < w; j++) {
      int col = j;
      int row = i - j;
      if (row < 0)
        break;
      if (grid[row][col] != 0)
        continue;
      if (col + 1 < w && grid[row][col + 1] == 0) {
        path_count[row][col + 1] += path_count[row][col];
        path_count[row][col + 1] %= mod;
      }
      if (row + 1 < h && grid[row + 1][col] == 0) {
        path_count[row + 1][col] += path_count[row][col];
        path_count[row + 1][col] %= mod;
      }
    }
  }
  cout << path_count[h - 1][w - 1] << endl;
}


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

static int grid[1000][1000];
static uint path_count[1000][1000];
static const uint mod = 1'000'000'007;

int main() {
  int h, w;
  cin >> h >> w;

  for (auto row = 0; row < h; row++) {
    for (auto col = 0; col < w; col++) {
      char c;
      cin >> c;
      grid[row][col] = c == '#' ? 1 : 0;
    }
  }
  path_count[0][0] = 1;
  for (auto i = 0; i < h + w - 1; i++) {
    for (auto j = 0; j < w; j++) {
      int col = j;
      int row = i - j;
      if (row >= h)
        continue;
      if (row < 0)
        break;
      if (grid[row][col] != 0)
        continue;
      if (col + 1 < w && grid[row][col + 1] == 0) {
        path_count[row][col + 1] += path_count[row][col];
        path_count[row][col + 1] %= mod;
      }
      if (row + 1 < h && grid[row + 1][col] == 0) {
        path_count[row + 1][col] += path_count[row][col];
        path_count[row + 1][col] %= mod;
      }
    }
  }
  cout << path_count[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 ld long double
#define pb push_back
#define popb pop_back
#define beg begin()
#define en end()
#define sz(v) (int)((v).size())
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define endl "\n"
#define forn(i, a, n) for (int i = a; i < int(n); ++i)
#define forb(i, a, n) for (int i = int(n) - 1; i >= a; --i)
#define cout(ans) cout << ans << "\n"
#define mod 1000000007
void speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

void solve() {
  int r, c;
  cin >> r >> c;
  char cc[r + 1][c + 1];
  ll dp[r + 1][c + 1];
  forn(i, 0, r) { cin >> cc[i]; }
  forn(i, 0, r) {
    forn(j, 0, c) {

      { dp[i][j] = -1; }
    }
  }
  int flag = 1;
  forn(i, 0, r) {
    if (cc[i][0] == '#') {
      flag = 0;
    }
    dp[i][0] = flag;
  }
  flag = 1;
  forn(i, 0, c) {
    if (cc[i][0] == '#') {
      flag = 0;
    }
    dp[0][i] = flag;
  }
  forn(i, 0, r) {
    forn(j, 0, c) {
      if (cc[i][j] == '#') {
        dp[i][j] = 0;
      }
    }
  }
  forn(i, 1, r) {
    forn(j, 1, c) {
      if (dp[i][j] != 0) {
        dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
        //	cout(dp[i][j]);
      }
    }
  }
  cout(dp[r - 1][c - 1] % mod);
}

int main() {
  speed();
  // int tc;cin>>tc;
  // while(tc--)
  { solve(); }
}

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

#define ll long long
#define ld long double
#define pb push_back
#define popb pop_back
#define beg begin()
#define en end()
#define sz(v) (int)((v).size())
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define endl "\n"
#define forn(i, a, n) for (int i = a; i < int(n); ++i)
#define forb(i, a, n) for (int i = int(n) - 1; i >= a; --i)
#define cout(ans) cout << ans << "\n"
#define mod 1000000007
void speed() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

void solve() {
  int r, c;
  cin >> r >> c;
  char cc[r + 1][c + 1];
  ll dp[r + 1][c + 1];
  forn(i, 0, r) { cin >> cc[i]; }
  forn(i, 0, r) {
    forn(j, 0, c) {

      { dp[i][j] = -1; }
    }
  }
  int flag = 1;
  forn(i, 0, r) {
    if (cc[i][0] == '#') {
      flag = 0;
    }
    dp[i][0] = flag;
  }
  flag = 1;
  forn(i, 0, c) {
    if (cc[0][i] == '#') {
      flag = 0;
    }
    dp[0][i] = flag;
  }
  forn(i, 0, r) {
    forn(j, 0, c) {
      if (cc[i][j] == '#') {
        dp[i][j] = 0;
      }
    }
  }
  forn(i, 1, r) {
    forn(j, 1, c) {
      if (dp[i][j] != 0) {
        dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
        //	cout(dp[i][j]);
      }
    }
  }
  cout(dp[r - 1][c - 1] % mod);
}

int main() {
  speed();
  // int tc;cin>>tc;
  // while(tc--)
  { solve(); }
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MAX 100007
#define MOD 1000000007
int b[105][105];
long long output[105][105];

int main() {
  int n, m;
  cin >> n >> m;

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

  for (int i = m - 2; i >= 0; i--) {
    if (b[n - 1][i] == 1) {
      for (int j = i; j >= 0; j--)
        output[n - 1][j] = 0;
      break;
    }
    output[n - 1][i] = 1;
  }

  for (int i = n - 2; i >= 0; i--) {
    if (b[i][m - 1] == 1) {
      for (int j = i; j >= 0; j--)
        output[i][m - 1] = 0;
      break;
    }
    output[i][m - 1] = 1;
  }

  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      if (b[i][j] == 1)
        continue;
      output[i][j] = output[i + 1][j] + output[i][j + 1];
      output[i][j] = output[i][j] % MOD;
    }
  }

  cout << output[0][0] << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MAX 100007
#define MOD 1000000007
int b[1005][1005];
long long output[1005][1005];

int main() {
  int n, m;
  cin >> n >> m;

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

  for (int i = m - 2; i >= 0; i--) {
    if (b[n - 1][i] == 1) {
      for (int j = i; j >= 0; j--)
        output[n - 1][j] = 0;
      break;
    }
    output[n - 1][i] = 1;
  }

  for (int i = n - 2; i >= 0; i--) {
    if (b[i][m - 1] == 1) {
      for (int j = i; j >= 0; j--)
        output[i][m - 1] = 0;
      break;
    }
    output[i][m - 1] = 1;
  }

  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      if (b[i][j] == 1)
        continue;
      output[i][j] = output[i + 1][j] + output[i][j + 1];
      output[i][j] = output[i][j] % MOD;
    }
  }

  cout << output[0][0] << endl;

  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define input_from_file freopen("input.txt", "r", stdin);

int main() {
  input_from_file;
  ll n, k, m, u, v;
  cin >> n >> m;
  vector<vector<char>> vec(n, vector<char>(m, 'a'));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++)
      cin >> vec[i][j];
  }
  vector<vector<ll>> dp(n, vector<ll>(m, 0));
  for (ll i = 0; i < n; i++) {
    if (vec[i][0] == '.')
      dp[i][0] = 1;
    else
      break;
  }
  for (ll i = 0; i < m; i++) {
    if (vec[0][i] == '.')
      dp[0][i] = 1;
    else
      break;
  }
  for (ll i = 1; i < n; i++) {
    for (ll j = 1; j < m; j++) {
      if (vec[i][j] == '.')
        dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
    }
  }
  // for(ll i=0;i<n;i++){
  //   for(ll j=0;j<m;j++){
  //     cout<<dp[i][j]<<" ";
  //   }cout<<endl;
  // }
  cout << dp[n - 1][m - 1] % mod;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define input_from_file freopen("input.txt", "r", stdin);

int main() {
  // input_from_file;
  ll n, k, m, u, v;
  cin >> n >> m;
  vector<vector<char>> vec(n, vector<char>(m, 'a'));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++)
      cin >> vec[i][j];
  }
  vector<vector<ll>> dp(n, vector<ll>(m, 0));
  for (ll i = 0; i < n; i++) {
    if (vec[i][0] == '.')
      dp[i][0] = 1;
    else
      break;
  }
  for (ll i = 0; i < m; i++) {
    if (vec[0][i] == '.')
      dp[0][i] = 1;
    else
      break;
  }
  for (ll i = 1; i < n; i++) {
    for (ll j = 1; j < m; j++) {
      if (vec[i][j] == '.')
        dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
    }
  }
  // for(ll i=0;i<n;i++){
  //   for(ll j=0;j<m;j++){
  //     cout<<dp[i][j]<<" ";
  //   }cout<<endl;
  // }
  cout << dp[n - 1][m - 1] % mod;
  return 0;
}
Problem p03167 (C++)

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

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define mem(x) memset(x, 0, sizeof(x));
#define what_is(x) cerr << #x << " is " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  ll dp[n + 1][m + 1];
  char a[n + 1][m + 1];

  rep(i, 0, n + 1) a[i][0] = '#';

  rep(i, 0, m + 1) a[0][i] = '#';

  rep(i, 1, n + 1) rep(j, 1, m + 1) cin >> a[i][j];

  mem(dp);

  dp[1][1] = 1;

  rep(i, 1, n + 1) {
    rep(j, 1, n + 1) {
      if (a[i][j] == '#')
        continue;
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % hell;
      dp[i][j] = (dp[i][j] + dp[i - 1][j]) % hell;
    }
  }

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

int main() {
  // #ifndef ONLINE_JUDGE
  // // for getting input from input.txt
  // freopen("input.txt", "r", stdin);
  // // for writing output to output.txt
  // freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int t = 1, i = 1;
  // cin>>t;

  while (t--) {
    // cout<<"Case #"<<i++<<": ";
    solve();
  }

  return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define mem(x) memset(x, 0, sizeof(x));
#define what_is(x) cerr << #x << " is " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  ll dp[n + 1][m + 1];
  char a[n + 1][m + 1];

  rep(i, 0, n + 1) a[i][0] = '#';

  rep(i, 0, m + 1) a[0][i] = '#';

  rep(i, 1, n + 1) rep(j, 1, m + 1) cin >> a[i][j];

  mem(dp);

  dp[1][1] = 1;

  rep(i, 1, n + 1) {
    rep(j, 1, m + 1) {
      if (a[i][j] == '#')
        continue;
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % hell;
      dp[i][j] = (dp[i][j] + dp[i - 1][j]) % hell;
    }
  }

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

int main() {
  // #ifndef ONLINE_JUDGE
  // // for getting input from input.txt
  // freopen("input.txt", "r", stdin);
  // // for writing output to output.txt
  // freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int t = 1, i = 1;
  // cin>>t;

  while (t--) {
    // cout<<"Case #"<<i++<<": ";
    solve();
  }

  return 0;
}
Problem p03167 (C++)

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

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x, n) memset(x, n, sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
const int inf = (1 << 30);
const LL llinf = (1ll << 60);
const double eps = (1e-10);
// const double pi=2*acos(0.0);
// const double GOLD=((1+sqrt(5))/2);
const int xx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const int yy[8] = {0, 1, 0, -1, -1, 1, 1, -1};

/* \( ·w·)~ Clapie ~(·w· )/ */

int H, W;
char input[1005][1005];
LL arr[1005][1005];

int main() {
  scanf("%d%d", &H, &W);
  getchar();
  for (int i = 0; i < H; i++) {
    scanf("%s", input[i]);
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (input[i][j] != '.')
        arr[i][j] = 0;
      else if (i == 0 && j == 0)
        arr[i][j] = 1;
      else
        arr[i][j] = (arr[i - 1][j] + arr[i][j - 1]) % MOD;
    }
  }

  printf("%lld\n", arr[H - 1][W - 1] % MOD);
}

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

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x, n) memset(x, n, sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
const int inf = (1 << 30);
const LL llinf = (1ll << 60);
const double eps = (1e-10);
// const double pi=2*acos(0.0);
// const double GOLD=((1+sqrt(5))/2);
const int xx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const int yy[8] = {0, 1, 0, -1, -1, 1, 1, -1};

/* \( ·w·)~ Clapie ~(·w· )/ */

int H, W;
char input[1005][1005];
LL arr[1005][1005];

int main() {
  scanf("%d%d", &H, &W);
  getchar();
  for (int i = 0; i < H; i++) {
    scanf("%s", input[i]);
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (input[i][j] != '.')
        arr[i][j] = 0;
      else if (i == 0 && j == 0)
        arr[i][j] = 1;
      else if (i == 0)
        arr[i][j] = arr[i][j - 1] % MOD;
      else if (j == 0)
        arr[i][j] = arr[i - 1][j] % MOD;
      else
        arr[i][j] = (arr[i - 1][j] + arr[i][j - 1]) % MOD;
    }
  }

  printf("%lld\n", arr[H - 1][W - 1] % MOD);
}
Problem p03167 (C++)

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

int D[1002][1002];

int MD = 1e9 + 7;
int main() {
  int H, W;

  cin >> H >> W;

  char M[1002][1002];
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++)
      cin >> M[i][j];
  }

  D[0][1] = 1;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++)
      D[i][j] = (M[i][j] != '#') ? (D[i - 1][j] + D[i][j - 1]) % MD : 0;
  }

  cout << D[H][W] << endl;

  int a, b;

  while (a != -1) {
    cin >> a >> b;
    cout << D[a][b] << endl;
  }
}

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

int D[1002][1002];

int MD = 1e9 + 7;
int main() {
  int H, W;

  cin >> H >> W;

  char M[1002][1002];
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++)
      cin >> M[i][j];
  }

  D[0][1] = 1;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++)
      D[i][j] = (M[i][j] != '#') ? (D[i - 1][j] + D[i][j - 1]) % MD : 0;
  }

  cout << D[H][W] << endl;
}
Problem p03167 (Python)

Buggy submission (status: Runtime Error):
def paths(i, j):
    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == "#":
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)


Fixed submission:
import sys

sys.setrecursionlimit(20000)


def paths(i, j):
    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == "#":
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
char a[1919][1919];
ll dp[1919][1919];
signed main() {
  ll h, w;
  cin >> h >> w;
  rep(i, h) { rep(j, w) cin >> a[i][j]; }
  dp[0][0] = 1;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] == '#')
        dp[i][j] = 0;
      else if (i != 0 || j != 0)
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[h - 1][w - 1] << endl;
  getchar();
  getchar();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
char a[1919][1919];
ll dp[1919][1919];
signed main() {
  ll h, w;
  cin >> h >> w;
  rep(i, h) { rep(j, w) cin >> a[i][j]; }
  dp[0][0] = 1;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] == '#')
        dp[i][j] = 0;
      else if (i == 0 && j != 0)
        dp[i][j] = dp[i][j - 1];
      else if (j == 0 && i != 0)
        dp[i][j] = dp[i - 1][j];
      else if (i != 0 || j != 0)
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[h - 1][w - 1] << endl;
  getchar();
  getchar();
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Time Limit Exceeded):
/////////////////////////////////TEST CASES////////////////////////////////////
/*
 */
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp)                                                                \
  ll inp;                                                                      \
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
ll h, w;
ll dp[1001][1001], vis[1001][1001];
char mat[1001][1001];
ll go(ll x, ll y) {
  if (x == h - 1 and y == w - 1)
    return 1;
  if (x >= h or y >= w or mat[x][y] == '#')
    return 0;
  if (vis[x][y] != 0)
    return dp[x][y];
  dp[x][y] = (go(x + 1, y) + go(x, y + 1)) % MOD;
  return dp[x][y];
}
void solve() {
  cin >> h >> w;
  FOR(i, 0, h) {
    FOR(j, 0, w) { cin >> mat[i][j]; }
  }
  cout << go(0, 0);
}
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
}

Fixed submission:
/////////////////////////////////TEST CASES////////////////////////////////////
/*
 */
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp)                                                                \
  ll inp;                                                                      \
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
ll h, w;
ll dp[1001][1001], vis[1001][1001];
char mat[1001][1001];
ll go(ll x, ll y) {
  if (x == h - 1 and y == w - 1)
    return 1;
  if (x >= h or y >= w or mat[x][y] == '#')
    return 0;
  if (vis[x][y] != 0)
    return dp[x][y] % MOD;
  vis[x][y] = 1;
  dp[x][y] = (go(x + 1, y) + go(x, y + 1));
  return (dp[x][y] >= MOD ? (dp[x][y] - MOD) : dp[x][y]);
}
void solve() {
  cin >> h >> w;
  FOR(i, 0, h) {
    FOR(j, 0, w) { cin >> mat[i][j]; }
  }
  cout << go(0, 0);
}
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fs                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

int main() {
  ll n, m, dp[101][101], mod = 1000000007;
  string s[101];
  cin >> n >> m;
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
  }
  if (s[0][0] == '.')
    dp[0][0] = 1;
  else
    dp[0][0] = 0;
  for (ll j = 1; j < m; j++) {
    if (s[0][j] == '.')
      dp[0][j] = dp[0][j - 1];
    else
      dp[0][j] = 0;
  }

  for (ll i = 1; i < n; i++) {
    if (s[i][0] == '.')
      dp[i][0] = dp[i - 1][0];
    else
      dp[i][0] = 0;
  }

  for (ll i = 1; i < n; i++) {
    for (ll j = 1; j < m; j++) {
      if (s[i][j] == '.') {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= mod;
      } else
        dp[i][j] = 0;
    }
  }
  cout << dp[n - 1][m - 1];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fs                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

int main() {
  ll n, m, dp[1001][1001], mod = 1000000007;
  string s[1001];
  cin >> n >> m;
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
  }
  if (s[0][0] == '.')
    dp[0][0] = 1;
  else
    dp[0][0] = 0;
  for (ll j = 1; j < m; j++) {
    if (s[0][j] == '.')
      dp[0][j] = dp[0][j - 1];
    else
      dp[0][j] = 0;
  }

  for (ll i = 1; i < n; i++) {
    if (s[i][0] == '.')
      dp[i][0] = dp[i - 1][0];
    else
      dp[i][0] = 0;
  }

  for (ll i = 1; i < n; i++) {
    for (ll j = 1; j < m; j++) {
      if (s[i][j] == '.') {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= mod;
      } else
        dp[i][j] = 0;
    }
  }
  cout << dp[n - 1][m - 1];
}
Problem p03167 (C++)

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

using namespace std;

const int mod = (int)1e9 + 7;

int n, m, dp[1005][1005];

char a[1005][1005];

int solve(int i, int j) {
  if (i == n && j == m)
    return 1;
  if (dp[i][j] != -1)
    return dp[i][j];
  int cur = 0;
  if (i + 1 <= n && a[i + 1][j] == '.')
    cur += solve(i + 1, j) % mod;
  if (j + 1 <= m && a[i][j + 1] == '.')
    cur += solve(i, j + 1) % mod;
  return cur % mod;
}

int main() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  cout << solve(1, 1);
  return 0;
}

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

using namespace std;

const int mod = (int)1e9 + 7;

int n, m, dp[1005][1005];

char a[1005][1005];

int solve(int i, int j) {
  if (i == n && j == m)
    return 1;
  if (dp[i][j] != -1)
    return dp[i][j];
  int cur = 0;
  if (i + 1 <= n && a[i + 1][j] == '.') {
    dp[i + 1][j] = solve(i + 1, j);
    if (dp[i + 1][j] >= mod)
      dp[i + 1][j] -= mod;
    cur += dp[i + 1][j];
  }
  if (j + 1 <= m && a[i][j + 1] == '.') {
    dp[i][j + 1] = solve(i, j + 1);
    if (dp[i][j + 1] >= mod)
      dp[i][j + 1] -= mod;
    cur += dp[i][j + 1];
  }
  if (cur >= mod)
    cur -= mod;
  return cur;
}

int main() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  cout << solve(1, 1);
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807 / 2;
const int MOD = 1000000007;
const int H_MAX = pow(10, 3);
const int W_MAX = pow(10, 3);

vector<vector<ll>> dp(H_MAX, vector<ll>(H_MAX, -1));
vector<vector<bool>> m(W_MAX, vector<bool>(H_MAX, true));

ll dfs(int h, int w) {
  if (h == 0 && w == 0)
    return dp[0][0] = 1;
  if (dp[h][w] != -1)
    return dp[h][w];

  ll result = 0;
  if (h != 0 && m[h - 1][w])
    result += dfs(h - 1, w);
  if (w != 0 && m[h][w - 1])
    result += dfs(h, w - 1);
  return dp[h][w] = result % MOD;
}

int main() {
  int H, W;
  cin >> H >> W;
  rep(i, H) {
    string row;
    cin >> row;
    rep(j, W) if (row[j] == '#') m[i][j] = false;
  }

  dfs(H, W);
  // rep(i, H) { rep(j, W) {cout << dp[i][j] << " ";} cout << endl; }
  cout << dp[H - 1][W - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807 / 2;
const int MOD = 1000000007;
const int H_MAX = pow(10, 4);
const int W_MAX = pow(10, 4);

vector<vector<ll>> dp(H_MAX, vector<ll>(H_MAX, -1));
vector<vector<bool>> m(W_MAX, vector<bool>(H_MAX, true));

ll dfs(int h, int w) {
  if (h == 0 && w == 0)
    return dp[0][0] = 1;
  if (dp[h][w] != -1)
    return dp[h][w];

  ll result = 0;
  if (h != 0 && m[h - 1][w])
    result += dfs(h - 1, w);
  if (w != 0 && m[h][w - 1])
    result += dfs(h, w - 1);
  return dp[h][w] = result % MOD;
}

int main() {
  int H, W;
  cin >> H >> W;
  rep(i, H) {
    string row;
    cin >> row;
    rep(j, W) if (row[j] == '#') m[i][j] = false;
  }

  dfs(H, W);
  // rep(i, H) { rep(j, W) {cout << dp[i][j] << " ";} cout << endl; }
  cout << dp[H - 1][W - 1] << endl;
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define m 1000000007
int dp[1005][1005];

int32_t main() {
  Fast_IO
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int r, c;
  cin >> r >> c;
  vector<vector<char>> grid(r, vector<char>(c));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '#')
        dp[i][j] = -1;
    }
  }
  for (int i = 0; i < r; i++) {
    if (grid[i][0] == '#')
      break;
    dp[i][0] = 1;
  }
  for (int i = 0; i < c; i++) {
    if (grid[0][i] == '#')
      break;
    dp[0][i] = 1;
  }
  for (int i = 1; i < r; i++) {
    for (int j = 1; j < c; j++) {
      if (grid[i][j] == '#')
        continue;
      dp[i][j] = (max(dp[i - 1][j], 0) + max(dp[i][j - 1], 0)) % m;
    }
  }
  // for(int i=0;i<r;i++){
  // 	for(int j=0;j<c;j++){
  // 		cout<<dp[i][j]<<" ";
  // 	}
  // 	cout<<"\n";
  // }
  cout << dp[r - 1][c - 1];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define m 1000000007
int dp[1005][1005];

int32_t main() {
  Fast_IO
#ifdef __WIN32
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int r, c;
  cin >> r >> c;
  vector<vector<char>> grid(r, vector<char>(c));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '#')
        dp[i][j] = -1;
    }
  }
  for (int i = 0; i < r; i++) {
    if (grid[i][0] == '#')
      break;
    dp[i][0] = 1;
  }
  for (int i = 0; i < c; i++) {
    if (grid[0][i] == '#')
      break;
    dp[0][i] = 1;
  }
  for (int i = 1; i < r; i++) {
    for (int j = 1; j < c; j++) {
      if (grid[i][j] == '#')
        continue;
      dp[i][j] = (max(dp[i - 1][j], 0) + max(dp[i][j - 1], 0)) % m;
    }
  }
  // for(int i=0;i<r;i++){
  // 	for(int j=0;j<c;j++){
  // 		cout<<dp[i][j]<<" ";
  // 	}
  // 	cout<<"\n";
  // }
  cout << dp[r - 1][c - 1];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define MOD 998244353
#define MOD2 1000000007
using namespace std;
int32_t main() {
  int m, n;
  cin >> m >> n;
  int dp[100][100];
  dp[0][0] = 1;
  string s[1001];
  for (int i = 0; i < m; i++)
    cin >> s[i];
  int i = 0, j = 0;
  while (i < n && s[0][i] == '.')
    dp[0][i++] = 1;
  i = 0;
  while (i < m && s[i][0] == '.')
    dp[i++][0] = 1;
  i = 0, j = 0;
  for (i = 1; i < m; i++) {
    for (j = 1; j < n; j++) {
      if (s[i][j] == '.')
        dp[i][j] = ((dp[i - 1][j] % MOD2) + (dp[i][j - 1] % MOD2)) % MOD2;
      else
        dp[i][j] = 0;
    }
  }
  cout << dp[m - 1][n - 1];
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define MOD 998244353
#define MOD2 1000000007
using namespace std;
int32_t main() {
  int m, n;
  cin >> m >> n;
  int dp[1001][1001];
  dp[0][0] = 1;
  string s[1001];
  for (int i = 0; i < m; i++)
    cin >> s[i];
  int i = 0, j = 0;
  while (i < n && s[0][i] == '.')
    dp[0][i++] = 1;
  i = 0;
  while (i < m && s[i][0] == '.')
    dp[i++][0] = 1;
  i = 0, j = 0;
  for (i = 1; i < m; i++) {
    for (j = 1; j < n; j++) {
      if (s[i][j] == '.')
        dp[i][j] = ((dp[i - 1][j] % MOD2) + (dp[i][j - 1] % MOD2)) % MOD2;
      else
        dp[i][j] = 0;
    }
  }
  cout << dp[m - 1][n - 1];
}
Problem p03167 (C++)

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

#define ll long long
const int mod = 1e9 + 7;

int xinc[2] = {0, 1};
int yinc[2] = {1, 0};

ll ans(char **rc, int r, int c) {
  ll res;
  ll **distanc = new ll *[r];
  bool **proc = new bool *[r];

  for (int i = 0; i < r; i++) {
    distanc[i] = new ll[c];
    proc[i] = new bool[c];
  }

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      proc[i][j] = 0, distanc[i][j] = 0;
  distanc[0][0] = 1;
  queue<int> xcor, ycor;
  xcor.push(0);
  ycor.push(0);
  while (!xcor.empty()) {
    int x = xcor.front(), y = ycor.front();
    xcor.pop();
    ycor.pop();
    if (proc[x][y])
      continue;

    for (int i = 0; i < 2; i++) {
      int xtemp = x + xinc[i];
      int ytemp = y + yinc[i];
      if (xtemp < 0 || ytemp < 0)
        continue;
      if (xtemp >= r || ytemp >= c)
        continue;
      if (rc[xtemp][ytemp] == '#')
        continue;
      distanc[xtemp][ytemp] = (distanc[xtemp][ytemp] + distanc[x][y]) % mod;
      xcor.push(xtemp);
      ycor.push(ytemp);
    }
    proc[x][y] = 1;
  }
  res = distanc[r - 1][c - 1];

  for (int i = 0; i < r; i++) {
    delete[] distanc[i];
    delete[] proc[i];
  }
  delete[] distanc;
  delete[] proc;

  return res;
}

int main() {
  int r, c;

  cin >> r >> c;
  char **rc;
  rc = new char *[r];
  for (int i = 0; i < r; i++) {
    rc[i] = new char[c];
    cin >> rc[i];
  }
  cout << ans(rc, r, c) << endl;

  for (int i = 0; i < r; i++) {
    delete[] rc[i];
  }
  delete[] rc;
  return 0;
}


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

#define ll long long
const int mod = 1e9 + 7;

int xinc[2] = {0, 1};
int yinc[2] = {1, 0};

ll ans(char **rc, int r, int c) {
  ll res;
  ll **distanc = new ll *[r];
  bool **proc = new bool *[r];

  for (int i = 0; i < r; i++) {
    distanc[i] = new ll[c];
    proc[i] = new bool[c];
  }

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      proc[i][j] = 0, distanc[i][j] = 0;
  distanc[0][0] = 1;
  queue<int> xcor, ycor;
  xcor.push(0);
  ycor.push(0);
  while (!xcor.empty()) {
    int x = xcor.front(), y = ycor.front();
    xcor.pop();
    ycor.pop();
    if (proc[x][y])
      continue;

    for (int i = 0; i < 2; i++) {
      int xtemp = x + xinc[i];
      int ytemp = y + yinc[i];
      if (xtemp < 0 || ytemp < 0)
        continue;
      if (xtemp >= r || ytemp >= c)
        continue;
      if (rc[xtemp][ytemp] == '#')
        continue;
      distanc[xtemp][ytemp] = (distanc[xtemp][ytemp] + distanc[x][y]) % mod;
      xcor.push(xtemp);
      ycor.push(ytemp);
    }
    proc[x][y] = 1;
  }
  res = distanc[r - 1][c - 1];

  for (int i = 0; i < r; i++) {
    delete[] distanc[i];
    delete[] proc[i];
  }
  delete[] distanc;
  delete[] proc;

  return res;
}

int main() {
  int r, c;

  cin >> r >> c;
  char **rc;
  rc = new char *[r];
  for (int i = 0; i < r; i++) {
    rc[i] = new char[c + 1];
    cin >> rc[i];
  }
  cout << ans(rc, r, c) << endl;

  for (int i = 0; i < r; i++) {
    delete[] rc[i];
  }
  delete[] rc;
  return 0;
}
Problem p03167 (C++)

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

const int mod = 1000000000 + 7;
const int N = 1000;

int dp[N][N];

int solve(int x, int y, int m, int n, char a[][1000]) {
  if (x == m - 1 && y == n - 1)
    return dp[x][y] = 1;
  if (a[x][y] == '#')
    return dp[x][y] = 0;

  if (dp[x][y] != -1)
    return dp[x][y];

  // middle
  if (x < m - 1 && y < n - 1) {
    if (dp[x][y + 1] == -1)
      solve(x, y + 1, m, n, a);
    if (dp[x + 1][y] == -1)
      solve(x + 1, y, m, n, a);

    dp[x][y] = (dp[x + 1][y] + dp[x][y + 1]) % mod;
  }
  // bottom
  else if (x == m - 1 && y < n - 1) {
    if (dp[x][y + 1] == -1)
      solve(x, y + 1, m, n, a);
    dp[x][y] = dp[x][y + 1];
  } else {
    if (dp[x + 1][y] == -1)
      solve(x + 1, y, m, n, a);
    dp[x][y] = dp[x + 1][y];
  }

  return dp[x][y];
}

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);

  int m, n;
  cin >> m >> n;
  int i, j;

  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      dp[i][j] = -1;
    }
  }

  char a[m][1000];
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  int ans = solve(0, 0, m, n, a);
  cout << ans << endl;
}

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

const int mod = 1000000000 + 7;
const int N = 1000;

int dp[N][N];

int solve(int x, int y, int m, int n, char a[][1000]) {
  if (x == m - 1 && y == n - 1)
    return dp[x][y] = 1;
  if (a[x][y] == '#')
    return dp[x][y] = 0;

  if (dp[x][y] != -1)
    return dp[x][y];

  // middle
  if (x < m - 1 && y < n - 1) {
    if (dp[x][y + 1] == -1)
      solve(x, y + 1, m, n, a);
    if (dp[x + 1][y] == -1)
      solve(x + 1, y, m, n, a);

    dp[x][y] = (dp[x + 1][y] + dp[x][y + 1]) % mod;
  }
  // bottom
  else if (x == m - 1 && y < n - 1) {
    if (dp[x][y + 1] == -1)
      solve(x, y + 1, m, n, a);
    dp[x][y] = dp[x][y + 1];
  } else {
    if (dp[x + 1][y] == -1)
      solve(x + 1, y, m, n, a);
    dp[x][y] = dp[x + 1][y];
  }

  return dp[x][y];
}

int32_t main() {
  int m, n;
  cin >> m >> n;
  int i, j;

  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      dp[i][j] = -1;
    }
  }

  char a[m][1000];
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  int ans = solve(0, 0, m, n, a);
  cout << ans << endl;
}
Problem p03167 (C++)

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

typedef long long ll;

const int M = 1010;
const ll mod = 1e9L + 7;

char a[M][M];
ll dp[M][M];
int n, m;
void move(ll &a, ll b) { a = (a + b) % mod; }

int main() {
  freopen("input.txt", "r", stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  dp[1][1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int x = i - 1, y = i - 1;
      if (a[i - 1][j - 1] == '#')
        continue;
      // move(dp[i][j], dp[i-1][j-1]);
      move(dp[i][j], dp[i - 1][j]);
      move(dp[i][j], dp[i][j - 1]);
    }
  }
  // for (int i = 0; i <= n; ++i)
  // {
  //     for(int j = 0; j <= m; ++j)cout << dp[i][j] << " ";
  //         cout << endl;
  // }
  cout << dp[n][m] << endl;
}


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

typedef long long ll;

const int M = 1010;
const ll mod = 1e9L + 7;

char a[M][M];
ll dp[M][M];
int n, m;
void move(ll &a, ll b) { a = (a + b) % mod; }

int main() {
  // freopen("input.txt", "r", stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  dp[1][1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int x = i - 1, y = i - 1;
      if (a[i - 1][j - 1] == '#')
        continue;
      // move(dp[i][j], dp[i-1][j-1]);
      move(dp[i][j], dp[i - 1][j]);
      move(dp[i][j], dp[i][j - 1]);
    }
  }
  // for (int i = 0; i <= n; ++i)
  // {
  //     for(int j = 0; j <= m; ++j)cout << dp[i][j] << " ";
  //         cout << endl;
  // }
  cout << dp[n][m] << endl;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;

  ll n, m;
  cin >> n >> m;

  char a[n][m];
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < m; j++)
      cin >> a[i][j];

  ll dp[n][m];
  memset(dp, 0, sizeof(dp));

  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      if (i == 0 and j == 0)
        dp[i][j] = 1;

      else if (a[i][j] == '.') {
        if (i > 0)
          dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod;
        if (j > 0)
          dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod;
      }
    }
  }
  cout << dp[n - 1][m - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main() {
  fast;

  ll n, m;
  cin >> n >> m;

  char a[n][m];
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < m; j++)
      cin >> a[i][j];

  ll dp[n][m];
  memset(dp, 0, sizeof(dp));

  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      if (i == 0 and j == 0)
        dp[i][j] = 1;

      else if (a[i][j] == '.') {
        if (i > 0)
          dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod;
        if (j > 0)
          dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod;
      }
    }
  }
  cout << dp[n - 1][m - 1] << endl;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, f[7][7];
char b[7][7];
void add(int &x, int v) {
  x += v;
  if (x >= mod)
    x -= mod;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", b[i] + 1);
  }
  // int f[7][7];
  f[1][1] = 1;
  //	cout<<f[5][6];

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (b[i][j] == '.') {

        add(f[i][j], f[i - 1][j]);
        add(f[i][j], f[i][j - 1]);
      }
    }
  }
  printf("%d\n", f[n][m]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, f[1005][1005];
char b[1005][1005];
void add(int &x, int v) {
  x += v;
  if (x >= mod)
    x -= mod;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", b[i] + 1);
  }
  // int f[7][7];
  f[1][1] = 1;
  //	cout<<f[5][6];

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (b[i][j] == '.') {

        add(f[i][j], f[i - 1][j]);
        add(f[i][j], f[i][j - 1]);
      }
    }
  }
  printf("%d\n", f[n][m]);
  return 0;
}