Problem:
Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

10
3 2
3 2
-1 1
2 -1
-3 -9
-8 12
7 7
8 1
8 2
8 4

Sample Output 2

479

Solution in Perl (5.26.1) (judge verdict: Wrong Answer)

my $N = <>;chomp $N;
my $mod = 1000000007;
my %DB;
my %MDB;
my $sum=1;
my $zero=0;
for(my $i=0;$i<$N;$i++){
    my @dat = split(/ /,<>);
    if(($dat[0]*$dat[1])==0){
        $zero++;
        next;
    }
    my $g = gcd($dat[0],$dat[1]);
    my $v = ($dat[0]/$g)/($dat[1]/$g);
    my $aa = $dat[0]/$g;
    my $bb = $dat[1]/$g; 
    
    my $str = "${aa}w${bb}";
    #$DB{$str}++;
        $aa=abs($aa);
       $bb=abs($bb);
    $str = "${bb}w${aa}";
    $MDB{$str}++;
    #print "$v\n";
    if($v>0){
       $aa=abs($aa);
       $bb=abs($bb);
       $str = "${aa}999${bb}";
       $DB{$str}++;
    #  $DB{$v}++;
    }elsif($v<0){
      $str = "${bb}999${aa}";
      $MDB{$str}++;
      #$v = -1/$v;
      #$MDB{$v}++;  
    }
}
foreach my $key (sort {$a<=> $b} keys %MDB){
    #print "$key\n";
    if(defined($DB{$key})){
       #print "$N = $N - $DB{$key} - $MDB{$key}\n";
       #$sum = ($sum *  (2**$DB{$key} + 2** $MDB{$key} -1) )%$mod;
       $sum = ($sum *  (powmod(2,$DB{$key},$mod) + powmod(2,$MDB{$key},$mod) -1) )%$mod;
       $N = $N - $DB{$key} - $MDB{$key};
    }
}
#print "N$N\n";
$N = $N -$zero;
$sum = ($sum * ($zero +1))%$mod;
$sum= ((powmod(2,$N,$mod) * $sum )-1)%$mod;
print "$sum";

sub powmod{
   my ($a,$b,$m) = @_;
   if($b==0){return 1;}
   my $c = powmod(($a*$a)%$m,int($b/2),$m);
   if($b%2){
     $c = ($c*$a)%$m;
   }
   return $c;
}
sub gcd{ #最大公約数
    my ($a,$b) = @_;
    if($b == 0){
        return $a;
    }
 
    return gcd($b, $a%$b);
}