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

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

ll gcd(ll A, ll B) {
  while (0 != B) {
    A %= B;
    swap(A, B);
  }
  return A;
}

ll lcm(ll A, ll B) {
  ll G = gcd(A, B);
  return A / G * B;
}

ll myPow(ll x, ll n) {
  ll r = 1;
  while (n > 0)
    if (0 == n % 2) {
      x *= x;
      x %= MOD;
      n /= 2;
    } else {
      r *= x;
      r %= MOD;
      n--;
    }
  return r;
}

int main() {
  ll N;
  cin >> N;
  map<string, ll> PP;
  map<string, ll> NN;
  ll Z = 0;  // Case 0==A && 0==B
  ll ZA = 0; // Case 0==A && 0!=B
  ll ZB = 0; // Case 0!=A && 0==B
  vector<string> Key;
  Rep0(i, N) {
    ll A, B;
    cin >> A >> B;
    if ((0 == A) && (0 == B)) {
      Z++;
      continue;
    }
    if (0 == A) {
      ZA++;
      continue;
    }
    if (0 == B) {
      ZB++;
      continue;
    }
    ll AA, BB;
    AA = abs(A);
    BB = abs(B);
    ll G = gcd(AA, BB);
    AA /= G;
    BB /= G;
    string S = to_string(AA) + '.' + to_string(BB);
    string SS = to_string(BB) + '.' + to_string(AA);
    if ((A > 0) && (B > 0)) {
      PP[S]++;
      Key.push_back(S);
    } else if ((A < 0) && (B < 0)) {
      PP[S]++;
      Key.push_back(S);
    } else {
      NN[SS]++;
      Key.push_back(SS);
    }
  }
  Sort(Key);
  ll S = myPow(2, ZA) + myPow(2, ZB) - 1; // ZA combi. + ZA combi. + none
  S += MOD;
  S %= MOD;
  // Rep0(i, Key.size()) {
  ll NNNN = Key.size();
  for (ll i = 0; i < NNNN; i++) {
    if (i != 0)
      if (Key.at(i) == Key.at(i - 1))
        continue;
    string KK = Key.at(i);
    ll SS = 0;
    ll PPP = PP[KK];
    ll NNN = NN[KK];
    SS += myPow(2, PPP);
    SS += myPow(2, NNN);
    SS %= MOD;
    SS--;
    SS += MOD;
    SS %= MOD;
    S *= SS;
    S %= MOD;
  }
  // Z
  S += Z;
  S %= MOD;
  // Remove the case non selected
  S--;
  S += MOD;
  S %= MOD;
  cout << S << endl;
  return 0;
}


Error: 0

Fixed submission:

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807
// (-2^63 <= long < 2^63)

#define INF (1 << 30)
// 1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n) for (auto i = 0; i < n; i++)
#define Rep1(i, n) for (auto i = 1; i <= n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P) reverse(P.begin(), P.end())

ll gcd(ll A, ll B) {
  while (0 != B) {
    A %= B;
    swap(A, B);
  }
  return A;
}

ll lcm(ll A, ll B) {
  ll G = gcd(A, B);
  return A / G * B;
}

ll myPow(ll x, ll n) {
  ll r = 1;
  while (n > 0)
    if (0 == n % 2) {
      x *= x;
      x %= MOD;
      n /= 2;
    } else {
      r *= x;
      r %= MOD;
      n--;
    }
  return r;
}

int main() {
  ll N;
  cin >> N;
  map<string, ll> PP;
  map<string, ll> NN;
  ll Z = 0;
  vector<string> Key;
  Rep0(i, N) {
    ll A, B;
    cin >> A >> B;
    ll AA, BB;
    AA = abs(A);
    BB = abs(B);
    ll G = gcd(AA, BB);
    AA /= G;
    BB /= G;
    string S = to_string(AA) + '.' + to_string(BB);
    string SS = to_string(BB) + '.' + to_string(AA);
    if ((0 == A) || (0 == B))
      Z++;
    else if ((A > 0) && (B > 0)) {
      PP[S]++;
      Key.push_back(S);
    } else if ((A < 0) && (B < 0)) {
      PP[S]++;
      Key.push_back(S);
    } else {
      NN[SS]++;
      Key.push_back(SS);
    }
  }
  Sort(Key);
  ll S = Z + 1;
  // Rep0(i, Key.size()) {
  ll NNNN = Key.size();
  for (ll i = 0; i < NNNN; i++) {
    if (i != 0)
      if (Key.at(i) == Key.at(i - 1))
        continue;
    string KK = Key.at(i);
    ll SS = 0;
    ll PPP = PP[KK];
    ll NNN = NN[KK];
    SS += myPow(2, PPP);
    SS += myPow(2, NNN);
    SS %= MOD;
    SS--;
    SS += MOD;
    SS %= MOD;
    S *= SS;
    S %= MOD;
  }
  S--;
  S += MOD;
  S %= MOD;
  cout << S << endl;
  return 0;
}