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



Sample input:
3
1 2
-1 1
2 -1


Sample output:
5

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))


def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]

    from collections import defaultdict
    dirs = defaultdict(dict)

    all0 = 0
    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            all0 += 1
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= (quick_pow(2, x0, mod) + quick_pow(2, y0, mod)-1 + mod) % mod
    elif x0:
        ans *= quick_pow(2, x0, mod)
    elif y0: 
        ans *= quick_pow(2, y0, mod)
    
    ans %= mod
    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= quick_pow(2, l[0],mod)
            else:
                ans *= quick_pow(2, l[1], mod)
        else:
            ans *= (quick_pow(2, l[0], mod) + quick_pow(2, l[1], mod)-1 + mod)%mod
        ans %= mod

    
    ans -= 1
    if all0:
        ans+= all0
    print(ans)
    

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))


def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]

    from collections import defaultdict
    dirs = defaultdict(dict)

    all0 = 0
    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            all0 += 1
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= (quick_pow(2, x0, mod) + quick_pow(2, y0, mod)-1) % mod
    elif x0:
        ans *= quick_pow(2, x0, mod)
    elif y0: 
        ans *= quick_pow(2, y0, mod)
    
    ans %= mod
    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= quick_pow(2, l[0],mod)
            else:
                ans *= quick_pow(2, l[1], mod)
        else:
            ans *= (quick_pow(2, l[0], mod) + quick_pow(2, l[1], mod)-1 + mod)%mod
        ans %= mod

    
    ans -= 1
    if all0:
        ans+= all0
    print(ans)
    

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))


def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]

    from collections import defaultdict
    dirs = defaultdict(dict)

    all0 = 0
    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            all0 += 1
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= (quick_pow(2, x0, mod) + quick_pow(2, y0, mod)-1) % mod
    elif x0:
        ans *= quick_pow(2, x0, mod)
    elif y0: 
        ans *= quick_pow(2, y0, mod)
    
    ans %= mod
    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= quick_pow(2, l[0],mod)
            else:
                ans *= quick_pow(2, l[1], mod)
        else:
            ans *= (quick_pow(2, l[0], mod) + quick_pow(2, l[1], mod)-1 + mod)%mod
        ans %= mod

    
    ans -= 1
    if all0:
        ans+= 1
    print(ans)
    

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))


def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]

    from collections import defaultdict
    dirs = defaultdict(dict)


    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= (quick_pow(2, x0, mod) + quick_pow(2, y0, mod)-1) % mod
    elif x0:
        ans *= quick_pow(2, x0, mod)
    elif y0: 
        ans *= quick_pow(2, y0, mod)
    
    ans %= mod
    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= quick_pow(2, l[0],mod)
            else:
                ans *= quick_pow(2, l[1], mod)
        else:
            ans *= (quick_pow(2, l[0], mod) + quick_pow(2, l[1], mod)-1 + mod)%mod
        ans %= mod

    
    print(ans-1)
    

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))


def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]

    from collections import defaultdict
    dirs = defaultdict(dict)


    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= ((1<<x0) + (1<< y0)-1) % mod
    elif x0:
        ans *= (1<< x0)%mod
    elif y0: 
        ans *= (1<<y0)%mod
    
    ans %= mod
    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= (1<<l[0])%mod
            else:
                ans *= (1<<l[1])%mod
        else:
            ans *= ((1<<l[0]) + (1<<l[1])-1)%mod
        ans %= mod

    
    print(ans-1)
    

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))


def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]

    from collections import defaultdict
    dirs = defaultdict(dict)


    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= ((1<<x0) + (1<< y0)-1) % mod
    elif x0:
        ans *= 1<< x0
    elif y0: 
        ans *= 1<<y0
    
    ans %= mod
    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= (1<<l[0])%mod
            else:
                ans *= (1<<l[1])%mod
        else:
            a = l[0]
            b = l[1]
            ans *= ((1<<a) + (1<<b)-1)%mod
        ans %= mod

    
    print(ans-1)
    

solve()

Submission status: Wrong Answer

Solution code:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N = II()
    args = defaultdict(lambda:defaultdict(lambda:[0]*2))
    for _ in range(N):
        x,y = map(int,input().split())
        if x == 0:
            args[0][0][0] += 1
            continue
        elif y == 0:
            args[0][0][1] += 1
            continue
        
        g = gcd(x,y)
        x2,y2 = abs(x//g),abs(y//g)
        if x*y < 0:
            args[x2][y2][1] += 1
        else:
            args[y2][x2][0] += 1

    ans = 1
    for y, a in args.items():
        for x, p in a.items():
            ans *= (pow(2,p[0],P) + pow(2,p[1],P) -1)
            ans %= P
    print(ans-1)

main()

Submission status: Wrong Answer

Solution code:
from math import gcd

n = int(input())
ration = dict()
used = dict()
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 or b == 0:
        if a == b == 0:
            r = '0'
        elif a == 0:
            r = '0a'
        else:
            r = '0b'
    else:
        s = '-' if (a < 0) ^ (b < 0) else '+'
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        r = f'{s} {a//g} {b//g}'
    ration[r] = ration.get(r, 0) + 1
    used[r] = 0

res = 1
mod = 10**9+7
for k, v in ration.items():
    if used[k]:
        continue
    if k == '0':
        res *= v
        used[k] = 1
    elif k == '0a' or k == '0b':
        res *= 2**ration.get('0a', 0) + 2**ration.get('0b', 0) - 1
        used['0a'] = used['0b'] = 1
    else:
        r = k.split()
        l = f'{"-" if r[0]=="+" else "+"} {r[2]} {r[1]}'
        res *= 2**v + 2**ration.get(l, 0) - 1
        used[k] = used[l] = 1
    res %= mod

res -= 1
if res < 0:
    res += mod
print(res)

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))

def get_qsa(file_name):
    audio, size = readfile(file_name)
    headers = {
        'Connection': 'keep-alive',
        'Content-Length': str(size)
    }

    
    parameter = {
                "request_id":int(time.time()*100),
                "th":1,
                "tht":"qf492_100fps",
                "the":1.000000,
                "thst":"neural"
                }
    res = requests.post(f"http://{config['ip']}:{config['port']}", timeout=120, data=audio, headers=headers, params = parameter)
    # print(res.url)

    res_json = res.json()
    # print(res_json.keys())


    if res_json['retmsg']!="success":
        raise Exception
    

    bin_str = res_json["th"][0]["feat"]
    bin_data = base64.b64decode(bin_str)

    bin2qsa_siren(bin_data, file_name)

def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]
    sardin = []
    from collections import defaultdict
    dirs = defaultdict(dict)

    all0 = 0
    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            all0 += 1
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans *= ((1<<x0) + (1<< y0)-1) % mod
    elif x0:
        ans *= 1<< x0
    elif y0: 
        ans *= 1<<y0
    

    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= 1<<l[0]
            else:
                ans *= 1<<l[1]
        else:
            a = l.get(0,0)
            b = l.get(1,0)
            ans *= ((1<<a) + (1<<b)-1)%mod
        ans %= mod

    
    print(ans-1)
    

        
    

    
solve()

Submission status: Wrong Answer

Solution code:
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))

def get_qsa(file_name):
    audio, size = readfile(file_name)
    headers = {
        'Connection': 'keep-alive',
        'Content-Length': str(size)
    }

    
    parameter = {
                "request_id":int(time.time()*100),
                "th":1,
                "tht":"qf492_100fps",
                "the":1.000000,
                "thst":"neural"
                }
    res = requests.post(f"http://{config['ip']}:{config['port']}", timeout=120, data=audio, headers=headers, params = parameter)
    # print(res.url)

    res_json = res.json()
    # print(res_json.keys())


    if res_json['retmsg']!="success":
        raise Exception
    

    bin_str = res_json["th"][0]["feat"]
    bin_data = base64.b64decode(bin_str)

    bin2qsa_siren(bin_data, file_name)

def gcd(a,b):
    return b if a == 0 else gcd(b%a, a)

def quick_pow(x,n, mod):
    ans= 1
    while n:
        if n&1:
            ans *= x
            ans %= mod
        x *= x
        x %= mod
        n >>= 1
    
    return ans


def solve():
    mod = 1000000007
    n = f()[0]
    sardin = []
    from collections import defaultdict
    dirs = defaultdict(dict)

    all0 = 0
    x0 = 0
    y0 = 0

    for _ in range(n):
        a,b = f()
        if a ==0 or b == 0:
            all0 += 1
            continue
        if a == 0:
            x0 += 1
            continue
        if b == 0:
            y0 += 1
            continue

        if a <0:
            a = -a
            b = -b
        g = gcd(abs(a),abs(b))
        a //= g
        b //= g



        if a*b >0:
            dirs[(a,b)][0] = dirs[(a,b)].get(0, 0)+ 1
        else:
            dirs[(-b,a)][1] = dirs[(-b,a)].get(1,0) + 1
            
    
    ans = 1
    if x0 and y0:
        ans += ((1<<x0) + (1<< y0)-1) % mod
    elif x0:
        ans += 1<< x0
    elif y0: 
        ans += 1<<y0
    

    for _, l in dirs.items():
        if len(l) == 1:
            if 0 in l:
                ans *= 1<<l[0]
            else:
                ans *= 1<<l[1]
        else:
            a = l.get(0,0)
            b = l.get(1,0)
            ans *= ((1<<a) + (1<<b)-1)%mod
        ans %= mod

    
    print(ans-1)
    

        
    

    
solve()

Submission status: Wrong Answer

Solution code:
from decimal import *
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

#%%

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    
    common = gcd(a,b)
    a = a//common
    b = b//common
    
#%%
    
    if a < 0 and b < 0:
        a = -a
        b = -b
    elif a < 0:
        a = -a
        b = -b
    
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1
#%%
aa = 0
for value in dict_patterns.values():
    aa+= value


keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(-b)+","+str(-a) in dict_patterns:
        pattern_A += dict_patterns[str(-b)+","+str(-a)]
        dict_patterns[str(-b)+","+str(-a)] = 0
    
    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    if str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0)+1)  
    test.append([pattern_A, pattern_B])

answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print((answer-1+zerozero)%mod)

Submission status: Wrong Answer

Solution code:
from decimal import *
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

#%%

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    
    common = gcd(a,b)
    a = Decimal(a)/Decimal(common)
    b = Decimal(b)/Decimal(common)
    
#%%
    
    if a < 0 and b < 0:
        a = -a
        b = -b
    elif a < 0:
        a = -a
        b = -b
    
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1
#%%
aa = 0
for value in dict_patterns.values():
    aa+= value


keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(-b)+","+str(-a) in dict_patterns:
        pattern_A += dict_patterns[str(-b)+","+str(-a)]
        dict_patterns[str(-b)+","+str(-a)] = 0
    
    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    if str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0)+1)  
    test.append([pattern_A, pattern_B])

answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print((answer-1+zerozero)%mod)

Submission status: Wrong Answer

Solution code:
from decimal import *
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

#%%

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    
    common = gcd(a,b)
    aa = Decimal(a)/Decimal(common)
    ba = Decimal(b)/Decimal(common)
    
#%%
    
    if a < 0 and b < 0:
        a = -a
        b = -b
    elif a < 0:
        a = -a
        b = -b
    
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1
#%%
aa = 0
for value in dict_patterns.values():
    aa+= value


keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(-b)+","+str(-a) in dict_patterns:
        pattern_A += dict_patterns[str(-b)+","+str(-a)]
        dict_patterns[str(-b)+","+str(-a)] = 0
    
    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    if str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0)+1)  
    test.append([pattern_A, pattern_B])
#%%
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print((answer-1+zerozero)%mod)

#%%

Submission status: Wrong Answer

Solution code:

from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

for i in range(len(ab)):
    if ab[i][0] == 1000000000000000000 or ab[i][1] == 1000000000000000000:
        print(1)

#%%
from decimal import *
kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 1000000000000000000 or b == 1000000000000000000:
        print("1")
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    
    common = gcd(a,b)
    aa = Decimal(a)/Decimal(common)
    ba = Decimal(b)/Decimal(common)
    
#%%
    
    if a < 0 and b < 0:
        a = -a
        b = -b
    elif a < 0:
        a = -a
        b = -b
    
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1
#%%
aa = 0
for value in dict_patterns.values():
    aa+= value


keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))
    if str(-b)+","+str(-a) in dict_patterns:
        pattern_A += dict_patterns[str(-b)+","+str(-a)]
        dict_patterns[str(-b)+","+str(-a)] = 0
    
    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    if str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0)+1)  
    test.append([pattern_A, pattern_B])
#%%
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print((answer-1+zerozero)%mod)

#%%

Submission status: Wrong Answer

Solution code:

from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

#%%

kai = [1]*(n+1)
gyaku = [1]*(n+1)

for i in range(2, n+1):
    kai[i] = kai[i-1]*i % mod
    gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod

azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0

for i in range(n):
    minus = False
    a, b = ab[i]
    if a == 0 and b == 0:
        zerozero += 1
        continue
    elif b == 0:
        dict_patterns["1,0"] += 1
        continue
    elif a == 0:
        dict_patterns["0,-1"] += 1
        continue
    common = gcd(a,b)
    a, b = int(a/common), int(b/common)
    if a < 0 and b < 0:
        a,b = -a,-b
    elif a < 0:
        a,b = -a,-b
    
    to_str = str(a)+","+str(b)
    if to_str not in dict_patterns:
        dict_patterns[to_str] = 1
    else:
        dict_patterns[to_str] += 1

#%%
        

aa = 0
for value in dict_patterns.values():
    aa+= value

#%%

keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
    pattern_A = dict_patterns[keys[i]]
    dict_patterns[keys[i]] = 0
    pattern_B = 0
    a, b = map(int, keys[i].split(","))

    if str(b)+","+str(-a) in dict_patterns:
        pattern_B += dict_patterns[str(b)+","+str(-a)]
        dict_patterns[str(b)+","+str(-a)] = 0
    elif str(-b)+","+str(a) in dict_patterns:
        pattern_B += dict_patterns[str(-b)+","+str(a)]
        dict_patterns[str(-b)+","+str(a)] = 0
    if pattern_A != 0 or pattern_B != 0:
        patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0)+1)  
    test.append([pattern_A, pattern_B])
#%%
answer = 1
for i in range(len(patterns)):
    answer = answer*patterns[i] % mod

print((answer-1+zerozero)%mod)

Submission status: Wrong Answer

Solution code:
total = int(input())

l = [[0 for j in range(2)] for i in range(total)]

for i in range(total):
    a, b = map(int, input().split())
    l[i] = [a,b]

result = 0

for i in range(total):
  for j in range(i,total):
    if l[i][0]*l[j][0] + l[j][1]*l[i][1] != 0:  
      result = result + 1

print(result % 1000000007)

Submission status: Wrong Answer

Solution code:
total = int(input())

l = [[0 for j in range(2)] for i in range(total)]

for i in range(total):
    a, b = map(int, input().split())
    l[i] = [a,b]

result = 0

for i in range(total):
  for j in range(total):
    if i != j:
      if l[i][0]*l[j][0] + l[j][1]*l[i][1] != 0:
        
        result = result + 1
result = int(result/2) + total

print(result % 1000000007)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
zero = 0
mp = {}
for i in range(N):
    x, y = map(int, input().split())
    if (x == 0 and y == 0):
        zero += i
        continue
    g = math.gcd(x, y)
    x, y = x//g, y//g
    if (y < 0) or (y == 0 and x < 0):
        x = -x
        y = -y

    rot90 = True if x <= 0 else False
    if rot90:
        x, y = y, -x
    if (x, y) not in mp.keys():
        mp[(x, y)] = [0, 0]

    if rot90:
        mp[(x, y)][0] += 1
    else:
        mp[(x, y)][1] += 1

mod = 1000000007

ans = 1
for p in mp.values():
    s = p[0]
    t = p[1]
    now = 1
    now += pow(2, s, mod) - 1
    now += pow(2, t, mod) - 1
    ans *= now
    ans %= mod

ans = ans + zero - 1
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
zero = 0
mp = {}
for i in range(N):
    x, y = map(int, input().split())
    if (x == 0 and y == 0):
        zero += i
        continue
    g = math.gcd(x, y)
    x, y = x//g, y//g
    if y < 0:
        x = -x
        y = -y

    if y == 0 and x < 0:
        x = -x
        y = -y

    rot90 = True if x <= 0 else False
    if rot90:
        tmp = x
        x, y = y, -tmp
    if (x, y) not in mp.keys():
        mp[(x, y)] = [0, 0]

    if rot90:
        mp[(x, y)][0] += 1
    else:
        mp[(x, y)][1] += 1

mod = 1000000007

ans = 1
for p in mp.values():
    s = p[0]
    t = p[1]
    now = 1
    now += pow(2, s, mod) - 1
    now += pow(2, t, mod) - 1
    ans *= now
    ans %= mod

ans -= 1
ans += zero
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
zero = 0
mp = {}
for i in range(N):
    x, y = map(int, input().split())
    if (x == 0 and y == 0):
        zero += i
        continue
    g = math.gcd(x, y)
    x, y = x//g, y//g
    if y < 0:
        x = -x
        y = -y

    if y == 0 and x < 0:
        x = -x
        y = -y

    rot90 = True if x <= 0 else False
    if rot90:
        tmp = x
        x, y = y, -tmp
    if (x, y) not in mp.keys():
        mp[(x, y)] = [0, 0]

    if rot90:
        mp[(x, y)][0] += 1
    else:
        mp[(x, y)][1] += 1

mod = 1000000007

ans = 1
for p in mp.values():
    s = p[0]
    t = p[1]
    now = 1
    now += pow(2, s, mod) - 1
    now += pow(2, t, mod) - 1
    ans *= now%mod

ans -= 1
ans += zero
print(ans%mod)