Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
map<pair<ll, ll>, int> mm;
const int maxn = 200005;
ll a[maxn] = {0}, b[maxn] = {0};
ll getnum(int c) {
  ll ans = 1;
  ll d = 2;
  while (c) {
    if (c % 2)
      ans = ans * d % mod;
    d = d * d % mod;
    c /= 2;
  }
  return (ans + 1000000006) % mod;
}
int main() {
  //    cout << __gcd(100,-100)<<endl;
  //    cout << __gcd(-100,-100)<<endl;
  //    cout << __gcd(-100,100)<<endl;
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == b[i] && a[i] == 0)
      ans++;
    else if (a[i] != 0 && b[i] != 0) {
      if (a[i] < 0) {
        a[i] *= -1;
        b[i] *= -1;
      }
      ll gcd = __gcd(a[i], abs(b[i]));
      a[i] = a[i] / gcd;
      b[i] = b[i] / gcd;
      mm[make_pair(a[i], b[i])]++;
    } else {
      if (a[i])
        a[i] = 1;
      if (b[i])
        b[i] = 1;
      mm[make_pair(a[i], b[i])]++;
    }
  }

  ll temp = 1;
  for (int i = 0; i < n; i++) {
    // cout << i << endl;
    if (a[i] == b[i] && a[i] == 0)
      continue;
    if (mm[make_pair(a[i], b[i])]) {
      if (mm[make_pair(-b[i], a[i])] + mm[make_pair(b[i], -a[i])]) {
        ll d =
            (getnum(mm[make_pair(a[i], b[i])]) +
             getnum(mm[make_pair(-b[i], a[i])] + mm[make_pair(b[i], -a[i])]) +
             1) %
            mod;
        mm[make_pair(a[i], b[i])] = 0;
        mm[make_pair(-b[i], a[i])] = 0;
        mm[make_pair(b[i], -a[i])] = 0;
        temp = temp * d % mod;
      } else
        temp = temp * 2 % mod;
    }
  }
  cout << (temp + ans + 1000000006) % mod;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
map<pair<ll, ll>, int> mm;
const int maxn = 200005;
ll a[maxn], b[maxn];
ll getnum(ll c) {
  ll ans = 1;
  ll a = 2;
  while (c) {
    if (c % 2)
      ans = ans * a % mod;
    a = a * a % mod;
    c /= 2;
  }
  return (ans + 1000000006) % mod;
}
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    //        if(a[i]==b[i]&&a[i]==0)
    //            ans++;
    //        else if(a[i]!=0&&b[i]!=0){
    ll gcd = __gcd(a[i], b[i]);
    a[i] = a[i] / gcd;
    b[i] = b[i] / gcd;
    mm[make_pair(a[i], b[i])]++;
    //        }
  }
  ll temp = 1;
  for (int i = 0; i < n; i++) {
    // cout << i << endl;
    //        if(a[i]==b[i]&&a[i]==0)
    //            continue;
    //        else if(a[i]==0||b[i]==0){
    //            temp = temp *2 % mod;
    //            continue;
    //        }
    if (mm[make_pair(a[i], b[i])]) {
      if (mm[make_pair(-b[i], a[i])] + mm[make_pair(b[i], -a[i])]) {
        ll d =
            (getnum(mm[make_pair(a[i], b[i])]) +
             getnum(mm[make_pair(-b[i], a[i])] + mm[make_pair(b[i], -a[i])]) +
             1) %
            mod;
        //     cout << d << endl;
        mm[make_pair(a[i], b[i])] = 0;
        mm[make_pair(-b[i], a[i])] = 0;
        mm[make_pair(b[i], -a[i])] = 0;
        temp = temp * d % mod;
      } else
        temp = temp * 2 % mod;
    }
  }
  cout << (temp + ans + 1000000006) % mod;
  return 0;
}