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:
# RE
import math
n = int(input())
a = [0] * n;  b = [0] * n;
for i in range(n):
    a[i], b[i] = [int(x) for x in input().split()]
p = 10 ** 9 + 7

# d = [0] * n
dict = {}
for i in range(n):
    d = math.gcd(a[i], b[i])
    if d > 0:
        aa = a[i] // d
        bb = b[i] // d
    else:
        aa = a[i]
        bb = b[i]
    if aa < 0: # 非負数にする
        aa = -aa
        bb = -bb
    if (aa, bb) in dict:
        dict[(aa, bb)] += 1
    else:
        dict[(aa, bb)] = 1

bad = []
others = []
zeros = 0
for (aa, bb) in dict:
    if dict[(aa, bb)] == 0: continue
    if aa == 0 and bb == 0:
        zeros += dict[(aa, bb)]
        dict[(aa, bb)] = 0
    elif (bb, -aa) in dict:
        bad.append((dict[(aa, bb)], dict[(bb, -aa)]))
        dict[(bb, -aa)] = 0
    elif (-bb, aa) in dict:
        bad.append((dict[(aa, bb)], dict[(-bb, aa)]))
        dict[(-bb, aa)] = 0
    else:
        others.append(dict[(aa, bb)])
    dict[(aa, bb)] = 0

ans = 1
for (x, y) in bad:
    ans = ans * (pow(2, x, p) + pow(2, y, p) - 1) % p
for z in others:
    ans = ans * pow(2, z, p) % p
ans = (ans - 1) % p
if zeros > 0:
    ans = (ans + zeros) % p
print(ans)

Submission status: Wrong Answer

Solution code:
PRIME = 1000000007
n = int(input())

fish = {}
taste_0 = 0
flavor_0 = 0

for i in range(n):
  a, b = map(int, input().split())
  if a != 0 and b != 0:
    if a / b in fish:
      fish[a / b] = fish[a / b] + 1
    else:
      fish[a / b] = 1
  elif a == 0 and b != 0:
    taste_0 += 1
  elif a != 0 and b != 0:
    flavor_0 += 1

cnt = 0
if taste_0 != 0 and flavor_0 != 0:
  ans = pow(2, taste_0, PRIME)
  ans += pow(2, flavor_0, PRIME) - 1
  ans %= PRIME
else:
  cnt += taste_0
  cnt += flavor_0
  ans = 1

for f in fish:
  if - 1 / f in fish and fish[f] > 0:
    ans1 = pow(2, fish[f], PRIME)
    ans1 += pow(2, fish[-1 / f], PRIME) - 1
    ans *= ans1
    ans %= PRIME
    fish[f] = 0
    fish[-1 / f] = 0
  elif -1 / f not in fish:
    cnt += fish[f]

ans *= pow(2, cnt, PRIME)
ans %= PRIME

ans += PRIME - 1
ans %= PRIME

print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N = int(input())
cnt = {}
a_zero_cnt = 0
b_zero_cnt = 0
for _ in range(N):
    A, B = map(int, input().split())
    if A == B == 0:
        continue
    if A == 0:
        a_zero_cnt += 1
        continue
    if B == 0:
        b_zero_cnt += 1
        continue
    neg = False
    if A < 0:
        neg ^= True
        A *= -1
    if B < 0:
        neg ^= True
        B *= -1
    g = gcd(A, B)
    sign = -1 if neg else 1
    A //= g
    B //= g
    frac = (-sign * A, B)
    if frac not in cnt:
        cnt[frac] = 0
    cnt[frac] += 1
ans = 1
used = set()
for frac, c in cnt.items():
    if frac in used:
        continue
    A, B = frac
    sign = 1
    if A < 0:
        A *= -1
        sign = -1
    bad = (B * -sign, A)
    if bad in cnt:
        b = cnt[bad]
        ans = ans * (pow(2, c, mod) + pow(2, b, mod) - 1) % mod
        used.add(bad)
    else:
        ans = ans * 2 % mod
ans = ans * (pow(2, a_zero_cnt, mod) + pow(2, b_zero_cnt, mod) - 1) % mod
print((ans - 1) % mod)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
MOD = 10**9+7
AB = []
x = 0
y = 0
d = defaultdict(int)
ch = defaultdict(int)
flag = 0
for _ in range(N):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        flag = 1
        continue
    elif a == 0:
        x += 1
        continue
    elif b == 0:
        y += 1
        continue
    else:
        c = a / b
        d[c] += 1
        AB.append(c)
n = len(AB)
ans = 1
for i in range(n):
    cc = AB[i]
    if ch[cc] != 0:
        continue
    m = d[cc]
    ccc = (-1)/cc
    l = d[ccc]
    ans *= (pow(2,m,MOD)+pow(2,l,MOD)-1)
    ch[cc] = 1
    ch[ccc] = 1
ans *= (pow(2,x,MOD)+pow(2,y,MOD)-1)
if flag == 0:
    ans -= 1
ans = ans % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = []
A0 = 0
B0 = 0
A0B0 = 0
for i in range(N):
    Atmp,Btmp = list(map(int,input().split()))
    if (Atmp!=0)and(Btmp!=0):
        AB.append(Atmp/Btmp)
    elif (Atmp==0)and(Btmp==0):
        A0B0 += 1
    elif (Atmp==0)and(Btmp!=0):
        A0 += 1
    elif (Atmp!=0)and(Btmp==0):
        B0 += 1

N += -1*A0B0

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

from collections import Counter
import math
C = Counter(AB)

kaburi = []
forsum = []
for key in C:
    if key<0:
        if C[-1/key]!=0:
            kaburi.append([C[key],C[-1/key]])
            forsum.append(C[key]+C[-1/key])

if (A0>0)and(B0>0):
    kaburi.append([A0,B0])
    forsum.append(A0+B0)

p = 10**9+7

free = N-sum(forsum)
free2 = power_func(2,free,p)
L = len(kaburi)


out = 1
for i in range(len(kaburi)):
    X = kaburi[i][0]
    Y = kaburi[i][1]
    B = power_func(2,X,p)
    C = power_func(2,Y,p)
    out = out*((B+C-1)%p)
    out = out%p
print((out*free2-1)%p)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def egcd(a: int, b: int):
    """
    A solution of ax+by=gcd(a,b). Returns
    (gcd(a,b), (x, y)).
    """
    if a == 0:
        return b, 0, 1
    else:
        g, x, y = egcd(b % a, a)
        return g, y - (b // a) * x, x


def modinv(a: int, mod: int = 10**9 + 7):
    """
    Returns a^{-1} modulo m.
    """
    g, x, y = egcd(a, mod)
    if g > 1:
        raise Exception('{}^(-1) mod {} does not exist.'.format(a, mod))
    else:
        return x % mod


def modpow(a: int, n: int, mod: int = 10**9 + 7):
    """
    Returns a^n mod m. (-inf < n < inf)
    """
    if a in [-1, 0, 1]:
        if a == -1:
            return 1 if n & 1 == 0 else mod - 1
        else:
            return a

    x, k = (a % mod, n) if n >= 0 else (modinv(a, mod), -n)

    ret = 1
    while k > 0:
        if k & 1 == 1:
            ret = ret * x % mod
        x = (x**2) % mod
        k = k >> 1

    return ret


def main():
    N = gete(int)

    d = dict()

    for _ in range(N):
        a, b = geta(int)
        if a == b == 0:
            if (0, 0) in d:
                d[(0, 0)][0] += 1
            else:
                d[(0, 0)] = [1, 0]
            continue

        if a != 0 and b != 0:
            g, _, _ = egcd(a, b)
            ai, bi = a // g, b // g
            if ai < 0:
                ai *= -1
                bi *= -1

            aj, bj = bi, -ai
            if aj < 0:
                aj *= -1
                bj *= -1
        elif a == 0:
            ai, bi = 0, 1
            aj, bj = 1, 0
        elif b == 0:
            ai, bi = 1, 0
            aj, bj = 0, 1

        if (ai, bi) in d:
            d[(ai, bi)][0] += 1
        elif (aj, bj) in d:
            d[(aj, bj)][1] += 1
        else:
            d[(ai, bi)] = [1, 0]

    mod = 1000000007
    ans = 1
    for k in d:
        if k != (0, 0):
            n = modpow(2, d[k][0], mod)
            m = modpow(2, d[k][1], mod)

            ans = ans * (n + m - 1) % mod
    ans -= 1
    if (0, 0) in d:
        dd = d[(0, 0)]
        ans += modpow(2, dd[0], mod) - 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    N = int(input())
    minus_iwashi = {}
    iwashi = {}
    a0 = 0
    b0 = 0
    a0b0 = 0
    
    for _ in range(N):
        a,b = map(int,input().split())
        if a < 0 and b > 0:
            a = -a
            b = -b
        elif a < 0 and b < 0:
            a = -a
            b = -b
        if a == 0 and b == 0:
            a0b0 += 1
            continue
        if a == 0 and b != 0:
            a0 += 1
            continue
        if b == 0 and a != 0:
            b0 += 1
            continue
        #print(a,b)
        if b < 0:
            a,b = -b,a
            #print('mini{}{}'.format(a,b))
            x = gcd(a,b)
            a //= x
            b //= x
            if (a,b) in minus_iwashi:
                minus_iwashi[(a,b)] += 1
            else:
                minus_iwashi[(a,b)] = 1
        elif b > 0:
            x = gcd(a,b)
            a //= x
            b //= x
            if (a,b) in iwashi:
                iwashi[(a,b)] += 1
            else:
                iwashi[(a,b)] = 1
    
    power = [1]
    for _ in range(N):
        power.append(power[-1]*2%MOD)
    '''
    print(power)
    print(iwashi)
    print(minus_iwashi)
    print(a0,b0)
    '''
    
    if a0 > 0 and b0 > 0:
        ans = (power[a0] + power[b0] - 1)%MOD
    elif a0 > 0:
        ans = power[a0]
    elif b0 > 0:
        ans = power[b0]
    else:
        ans = 1

    for k,v in iwashi.items():
        if k in minus_iwashi:
            ans *= (power[v] + power[minus_iwashi[k]] - 1)%MOD
            ans %= MOD
        else:
            ans *= power[v]
            ans %= MOD
    
    for k,v in minus_iwashi.items():
        if k in iwashi:
            continue
        else:
            ans *= power[v]
            ans %= MOD
    if a0b0 > 0:
        ans += power[a0b0] - 1
        print(ans%MOD)
    else:
        print((ans - 1)%MOD)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys
input = sys.stdin.readline

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

adivb = [-float('inf') if ab[i][1] == 0 else ab[i][0] / ab[i][1]
         for i in range(n)]
bdiva = [-float('inf') if ab[i][0] == 0 else -ab[i][1] / ab[i][0]
         for i in range(n)]

adb, bda = Counter(adivb), Counter(bdiva)
cntadb, cnt = defaultdict(int), 0
for i in adb:
    if (i in bda) and (i >= 0):
        cntadb[i] += bda[i] + adb[i] + 1
        cnt += bda[i] + adb[i]
ans = 1
for i in cntadb:
    ans *= cntadb[i]
print((ans * 2 ** (n - cnt) - 1) % mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
sin_dic = {}
import math
mod = 1000000007
INF = 10 ** 15

for i in range(N):
    a, b = list(map(int, input().split()))
    if a == 0 and b == 0:
        continue
    #sin = b/ math.sqrt(a**2 + b**2)
    if a == 0:
        asin = INF
    else:
        asin = b/a
    if asin in sin_dic:
        sin_dic[asin].append(i)
    else:
        sin_dic[asin] = [i]

ans = 1
half_pi = math.pi / 2
skip_dic = {}
#sin_tup = sorted(sin_dic.items(), key=lambda x:x[0])
for key, values in sin_dic.items():
    if key in skip_dic:
        continue
    elif key == 0:
        if INF in sin_dic:
            p = pow(2, len(sin_dic[key]), mod) - 1 + pow(2, len(sin_dic[INF]), mod)
            ans = (ans * p) % mod
            skip_dic[INF] = True
        else:
            ans = (ans * pow(2, len(sin_dic[key]), mod)) % mod 
    elif key == INF:
        if 0 in sin_dic:
            p = pow(2, len(sin_dic[key]), mod) - 1 + pow(2, len(sin_dic[0]), mod)
            ans = (ans * p) % mod
            skip_dic[0] = True
        else:
            ans = (ans * pow(2, len(sin_dic[key]), mod)) % mod 
    elif (- 1/ key) in sin_dic:
        p = pow(2, len(sin_dic[key]), mod) - 1 + pow(2, len(sin_dic[-1/key]), mod)
        ans = (ans * p) % mod
        skip_dic[-1/key] = True
    else:
        ans = (ans * pow(2, len(sin_dic[key]), mod)) % mod 

print( (ans-1) % mod)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

#通分
def f(a,b):
    f = math.gcd(a,b)
    return a//f, b//f

N = I()
A,B = LIR(N,2)

beki = [1]*(N+1)
for i in range(1,N+1):
    beki[i] = beki[i-1]*2
    beki[i] %= mod


dplus = defaultdict(int)
dminus = defaultdict(int)
dminus2 = defaultdict(int)
zero = 0
for i in range(N):
    if A[i] == 0 or B[i] == 0:
        zero += 1
    else:
        if A[i]*B[i] > 0:
            a,b = max(A[i],B[i]),min(A[i],B[i])
            a = abs(a)
            b = abs(b)
            a,b = f(abs(A[i]),abs(B[i]))
            dplus[(a,b)] += 1
        else:
            a,b = max(A[i],B[i]),min(A[i],B[i])
            a = abs(a)
            b = abs(b)
            a,b = f(abs(A[i]),abs(B[i]))
            dminus[(b,a)] += 1
            dminus2[(b,a)] += 1

ans = 1
count = 0

for k in dplus.keys():
    if dminus[k]:
        temp = beki[dplus[k]] + beki[dminus[k]] - 1
        ans *= temp
        ans %= mod
    else:
        count += dplus[k]

for k in dminus2.keys():
    if dplus[k]:
        continue
    else:
        count += dminus[k]

ans *= beki[count]
temp = ans-1
temp2 = ans*zero
ans = temp+temp2
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = 0
grid = [] 
for i in range(n):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
for i in range(n):
    for j in range(i+1,n):
        cal = grid[i][0]*grid[j][0] + grid[i][1]*grid[j][1]
        if cal == 0:
            l = l + 1
ans = (2**n)-1
if l == 0:
    print(ans)
else:
    for k in range(l):
        m = n - 2*l
        ans = ans - (2**m) - (2**m)* 2 * k
final = ans%1000000007
print(final)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def xy(x,y):
  x,y=abs(x),abs(y)
  g=gcd(x,y)
  x//=g
  y//=g
  return (10**20)*x+y
from collections import defaultdict
mod=10**9+7
n=int(input())
aabb=[list(map(int,input().split()))for _ in range(n)]
ab=[]
ans=0
for i in aabb:
  if i!=[0,0]:ab.append(i)
  else:
    n-=1
    ans+=1
az=bz=0
d=defaultdict(int)
dd=defaultdict(int)
for i in ab:
  if 0 in i:
    if i[0]==0:az+=1
    else:bz+=1
  else:
    a,b=i
    if a*b>0:d[xy(a,b)]+=1
    else:dd[xy(a,b)]+=1
ans+=pow(2,n,mod)-1
t=[]
tt=1
for i in dd:
  b,a=divmod(i,10**20)
  p,m=d[xy(a,b)],dd[i]
  if p*m:
    t.append((p,m))
    n-=p+m
    tt*=(pow(2,p,mod)+pow(2,m,mod)-1)
    tt%=mod
if az*bz:
  t.append((az,bz))
  n-=az+bz
  tt*=(pow(2,az,mod)+pow(2,bz,mod)-1)
  tt%=mod
tt=tt*pow(2,n,mod)%mod
for p,m in t:
  ttt=tt*pow(pow(2,p,mod)+pow(2,m,mod)-1,mod-2,mod)%mod
  ans-=p*m*ttt*(pow(2,p,mod)-1)*(pow(2,m,mod)-1)%mod
  if p*m>1:ans-=ttt
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
mod = 10**9+7
n = int(input())
dicn = {}
dicp = {}
dicz = {'a': 0, 'b': 0, 'z': 0}
for i in range(n):
  a, b = map(int, input().split())
  if a == 0 and b == 0:
    dicz['z'] += 1
  else:
    g = gcd(a,b)
    a //= g
    b //= g
    if a < 0:
      a *= -1
      b *= -1
    elif a == 0 and b < 0:
      b *= -1
    if a * b > 0:
      if a in dicp:
        if b in dicp[a]:
          dicp[a][b] += 1
        else:
          dicp[a][b] = 1
      else:
        dicp[a] = {b: 1}
    elif a * b < 0:
      if b in dicn:
        if a in dicn[b]:
          dicn[b][a] += 1
        else:
          dicn[b][a] = 1
      else:
        dicn[b] = {a: 1}
    else:
      if a == 0:
        dicz['a'] += 1
      else:
        dicz['b'] += 1

ans = 1

for a in dicp:
  for b in dicp[a]:
    if -a in dicn:
      if b in dicn[-a]:
        ans *= (pow(2, dicp[a][b], mod) + pow(2, dicn[-a][b], mod) - 1)
        dicn[-a][b] = 0
      else:
        ans *= pow(2, dicp[a][b], mod)
    else:
      ans *= pow(2, dicp[a][b], mod)
    ans %= mod

for b in dicn:
  for a in dicn[b]:
    ans *= pow(2, dicn[b][a], mod)
    ans %= mod
    
if dicz['a'] > 0 and dicz['b'] > 0:
  ans *= pow(2,dicz['a'],mod) + pow(2,dicz['b'],mod) - 1
elif dicz['a'] > 0:
  ans *= pow(2,dicz['a'],mod)
elif dicz['b'] > 0:
  ans *= pow(2,dicz['b'],mod)
  
ans += pow(2,dicz['z'],mod)
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
def pandm(a,b):
    cnt = 0
    for i in range(len(a[0])):
        pp = a[0][i]
        ppb = b[0][i]
        for j in range(len(a[2])):
            pm = a[2][j]
            pmb = b[2][j]
            if pp*pm + ppb*pmb == 0:
                cnt += 1
        for j in range(len(a[3])):
            mp = a[3][j]
            mpb = b[3][j]
            if pp*mp + ppb*mpb == 0:
                cnt += 1
    for i in range(len(a[1])):
        mm = a[1][i]
        mmb = b[1][i]
        for j in range(len(a[2])):
            pm = a[2][j]
            pmb = b[2][j]
            if mm*pm + mmb*pmb == 0:
                cnt += 1
        for j in range(len(a[3])):
            mp = a[3][j]
            mpb = b[3][j]
            if mm*mp + mmb*mpb == 0:
                cnt += 1

    return cnt

from scipy.special import comb

def solve():
    n = int(input())
    a = [[],[],[],[]]
    b = [[],[],[],[]]
    for _ in range(n):
        A, B = map(int, input().split())
        if A>=0 and B>=0:
            a[0].append(A)
            b[0].append(B)
        elif A<0 and B<0:
            a[1].append(A)
            b[1].append(B) 
        elif A>=0 and B<0:
            a[2].append(A)
            b[2].append(B)
        elif A<0 and B>=0:
            a[3].append(A)
            b[3].append(B)

    cnt = pandm(a,b)
    ans = 0
    for i in range(1, n+1):
        ans += comb(n, i, exact=True)

    return ans%1000000007
    

print(solve())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int


def pow2(x):
    res = 1
    a = 2
    while x > 0:
        if x & 1:
            res = (res * a) % MOD
        a = a * a % MOD
        x >>= 1
    return res

def solve(N: int, A: "List[int]", B: "List[int]"):
    m = {}

    for i in range(N):
        if A[i] == 0 and B[i] == 0:
            if "0" in m:
                m["0"][0] += 1
            else:
                m["0"] = [1, 0, 0]
            continue
        if A[i] == 0:
            if "0" in m:
                m["0"][1] += 1
            else:
                m["0"] = [0, 1, 0]
            continue
        if B[i] == 0:
            if "0" in m:
                m["0"][2] += 1
            else:
                m["0"] = [0, 0,1]
            continue


        gcd = math.gcd(A[i],B[i])

        a = A[i] // gcd
        b = B[i] // gcd
        if (a < 0 and b < 0 ) or (a > 0 and b > 0):
            key = str(abs(a)) + "/" + str(abs(b))
            if key in m:
                m[key][0] += 1
            else:
                m[key] = [1, 0]
        else:
            key =str(abs(b)) + "/" + str(abs(a))
            if key in m:
                m[key][1] += 1
            else:
                m[key] = [0, 1]

    ans = 1
    for k, v in m.items():
        if k == "0":
            ans = (ans * (pow2(v[1]) + pow2(v[2])  + v[0] - 1)) % MOD
        else:
            ans = (ans * (pow2(v[0]) + pow2(v[1]) - 1)) % MOD
    print(ans-1)
            
        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

# a, b: [a0, a1], [b0, b1]
def is_bad(a, b):
  tmp = a[0]*b[0] + a[1]*b[1]
  if tmp == 0:
    return True
  else:
    return False

def bad_list(lst):
  l = 0
  for i in range(len(lst)-1):
    for j in range(i+1, len(lst)):
      if is_bad(lst[i], lst[j]):
        l += 1
  return l

def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def calc(n, lst):
  bad_pairs = bad_list(lst)
  const = 1000000007
  total = n % const
  for r in range(2, n+1):
    tmp0 = comb(n, r)
    tmp1 = comb(n-2, r-2) * bad_pairs
    total += tmp0 - tmp1
    total = total % const
  return total

n = int(input())
lst = []
for i in range(n):
  lst.append(list(map(int, input().split())))

print(calc(n, lst))

Submission status: Wrong Answer

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
cnt = {}
pair = {}
bothzero = 0
for i in range(N):
    A,B = MI()
    if A==0 and B==0:
        bothzero += 1
    elif B==0:
        pair[0]=pair.get(0,0)+1
    elif A == 0:
        cnt[0]=cnt.get(0,0)+1
    elif A/B>0:
        cnt[A/B]=cnt.get(A/B,0)+1
    else:
        pair[-B/A]=pair.get(-B/A,0)+1
res = N-bothzero
ans = 1
for v in cnt:
    if pair.get(v,0)==0:
        continue
    res -= (cnt[v]+pair[v])
    ans == ans*(pow(2,cnt[v],MOD)+pow(2,pair[v],MOD)-1)%MOD
    ans = ans%MOD
ans = (ans*pow(2,res,MOD)-1)%MOD
ans = (ans+bothzero)%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import queue
from collections import deque
import heapq
mod = 10**9+7
ans = 1

def twoxxn(t,mod):
    ni = t
    an = 1
    n2 = 2
    while ni > 0:
        if ni%2 == 1:
            an = (an*n2)%mod
        n2 = (n2**2)%mod
        ni //= 2
    return an

n = int(input())
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if a < 0 :
        a = -a
        b = -b
    if a == 0:
        g = abs(b)
    elif b == 0:
        g = abs(a)
    else:
        g = math.gcd(abs(a),abs(b))
    if a == 0 and b == 0:
        continue
    else:
        p1 = str(a//g)+" "+str(b//g)
        if p1 in d:
            d[p1] += 1
        else:
            d[p1] = 1

for i in d.keys():
    i0, i1 = map(int,i.split())
    if str(i1)+" "+str(-i0) in d:
        if d[i] == 0:
            continue
        aaa = (twoxxn(d[str(i1)+" "+str(-i0)],mod)+twoxxn(d[i],mod)-1)%mod
        ans = (ans*aaa)%mod
        d[str(i1)+" "+str(-i0)] = 0
    elif str(-i1)+" "+str(i0) in d:
        if d[i] == 0:
            continue
        aaa = (twoxxn(d[str(-i1)+" "+str(i0)],mod)+twoxxn(d[i],mod)-1)%mod
        ans = (ans*aaa)%mod
        d[str(-i1)+" "+str(i0)] = 0
    else:
        ans = (ans*twoxxn(d[i],mod))%mod

if ans == 1:
    print(1)
    exit()
ans = (ans-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ablist = []
for i in range(n):
  ablist.append(list(map(int, input().split(" "))))

dp = [[0]*n]*n
for i in range(n-1):
  for j in range(i,n):
    if ablist[i][0]*ablist[i][1] + ablist[j][0]*ablist[j][1] == 0:
      dp[i][j] = 1
      dp[i][j] = 1

count = 0
for i in range(n):
  m=dp[i][i+1:n].count(0)
  count += 2**m

print(count%1000000007)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
d = {}
r = 0
for i in range(n):
    if a[i][0] == 0 and a[i][1]:
        r += 1
    elif a[i][0] == 0:
        if 0 in d:
            d[0][0] = d[0][0] +1
        else:
            d[0] = [1, 0]
    elif a[i][1] == 1:
        if 0 in d:
            d[0][1] = d[0][1] +1
        else:
            d[0] = [0, 1]
    else:
        if a[i][0] * a[i][1] > 0:
            s = a[i][0] / a[i][1]
            if s in d:
                d[s][0] = d[s][0] +1
            else:
                d[s] = [1, 0]
        else:
            s = -a[i][1] / a[i][0]
            if s in d:
                d[s][1] = d[s][1] +1
            else:
                d[s] = [0, 1]
ans = 1
m = 0
for i in d:
    m += 1
    ans *= max(0, 2**d[i][0]) + max(0, 2**d[i][1]) - 1
    print(ans)
ans += r
ans = ans%1000000007
#print(d)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n = I()
ab = LLI(n)

s = [[] for _ in range(n)]
for i in range(n):
  for j in range(i+1, n):
    if ab[i][0] * ab[j][0] == - ab[i][1] * ab[j][1]:
      # s[i].append(j)
      s[j].append(i)
left = [1] * n
for i in range(n):
  for j in s[i]:
    left[i] += left[j]
    left[j] += left[j]
    left[j] %= mod
  left[i] %= mod
print(left)
ans = 2 ** n - sum(left) - 1

print((ans)%mod)

Submission status: Wrong Answer

Solution code:
import itertools
from numpy import array
n = int(input())
a = [0]*n
b = [0]*n
v = [0]*n
for i in range(n):
	a[i],b[i] = map(int,input().split())
ans = 0
k = 0
for l in range(1,n+1):
	for T in itertools.combinations(range(0,n),l):
		for  O in itertools.combinations(T,2):
			if a[O[0]]*a[O[1]]+b[O[0]]*b[O[1]] != 0:
				k += 1
		if k == l*(l-1)//2:
			ans += 1
print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 10**9 + 7

a0,b0 = 0,0
count = {}

for _ in range(n):
  a,b = map(int,input().split())
  if a==b==0:
    n-=1
  elif a==0:
    a0 += 1
  elif b==0:
    b0 += 1
  elif (a,b) in count:
    count[(a,b)] +=1
  elif (-a,-b) in count:
    count[(-a,-b)] += 1
  else:
    count[(a,b)] = 1

queue = [(a0,b0)]
checked = set([])
free = 0
for a,b in count:
  if (a,b) in checked:
    continue
  if (-b,a) in count or (b,-a) in count:
    c = count[(-b,a)] if (-b,a) in count else count[(b,-a)]
    queue.append((count[(a,b)], c))
    checked.add((a,b))
    checked.add((-b,a))
    checked.add((b,-a))
  else:
    free += count[(a,b)]



div = []  
for i in range(n+1):
  div.append(pow(i,mod-2,mod))
hist = {}
def comb_all(i):
  if i in hist:
    return hist[i]
  else:
    res = 1
    cmb = 1
    for j in range(1,i+1):
      
      
      cmb *= (i-j+1) * div[j]
      cmb %= mod
      res += cmb
    hist[i] = res
    return res

ans = 1
while queue:
  c1,c2 = queue.pop(-1)
  if c1==c2==0:
    continue
  ans = ans * comb_all(c1) + ans * comb_all(c2)
  ans %= mod
ans *= comb_all(free)
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
list_A = []
list_B = []
for i in range(N):
    A, B = map(int, input().split())
    list_A.append(A)
    list_B.append(B)

seq = range(0, N)
seq_list = list(itertools.combinations(seq, 2))
count = 0
for element in seq_list:
    if list_A[element[0]] * list_A[element[1]] + list_B[element[0]] + list_B[element[1]] == 0:
        count += 1

pattern = 2 ** N - 1 - 2 ** count
print(pattern % 1000000007)