Problem p03167 (C++)

Buggy submission (status: Runtime Error):
// srinivas
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(), (c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(), (c).rend()
#define fr(x, in, n, r) for (ll x = in; x < n; x += r)
#define ifr(x, n) for (ll x = 0; x < n; x++)
#define dfr(x, n) for (ll x = n - 1; x >= 0; x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fstm(m, n, r)                                                          \
  m.reserve(n);                                                                \
  m.max_load_factor(r)
#define os                                                                     \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef unordered_map<ll, ll> umap;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("/home/srinivas/Desktop/cp/input.txt", "r", stdin);
  // freopen("/home/srinivas/Desktop/output.txt","w",stdout);
#endif
  ll n, m;
  cin >> n >> m;
  string s[n];
  ifr(i, n) cin >> s[i];
  ll dp[n][m];
  ifr(i, n) ifr(j, m) dp[i][j] = 0;
  ifr(i, m) {
    if (s[0][i] == '.')
      dp[0][i] = 1;
    else
      break;
  }
  ifr(i, n) {
    if (s[i][0] == '.')
      dp[i][0] = 1;
    else
      break;
  }
  fr(i, 1, n, 1) {
    fr(j, 1, m, 1) {
      if (s[i][j] == '.')
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
    }
  }
  cout << dp[n - 1][m - 1] << endl;
  return 0;
}

Fixed submission:
// srinivas
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(), (c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(), (c).rend()
#define fr(x, in, n, r) for (ll x = in; x < n; x += r)
#define ifr(x, n) for (ll x = 0; x < n; x++)
#define dfr(x, n) for (ll x = n - 1; x >= 0; x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fstm(m, n, r)                                                          \
  m.reserve(n);                                                                \
  m.max_load_factor(r)
#define os                                                                     \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef unordered_map<ll, ll> umap;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  string s[n];
  ifr(i, n) cin >> s[i];
  ll dp[n][m];
  ifr(i, n) ifr(j, m) dp[i][j] = 0;
  ifr(i, m) {
    if (s[0][i] == '.')
      dp[0][i] = 1;
    else
      break;
  }
  ifr(i, n) {
    if (s[i][0] == '.')
      dp[i][0] = 1;
    else
      break;
  }
  fr(i, 1, n, 1) {
    fr(j, 1, m, 1) {
      if (s[i][j] == '.')
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
    }
  }
  cout << dp[n - 1][m - 1] << endl;
  return 0;
}