Harryxun/stf_run huggingface dataset:
while True:
    a, b = map(int, input().split())
    if(a == 0 and b == 0):
        break
    for i in range(a):
        for j in range(b):
            if(1 < i < a and 1 < j < b):
                print(".", end = "")
            else print("#", end = "")
        print()


### FIXED CODE ###

while True:
    a, b = map(int, input().split())
    if(a == 0 and b == 0):
        break
    for i in range(a):
        for j in range(b):
            if(0 < i < a-1 and 0 < j < b-1):
                print(".", end = "")
            else:
                print("#", end = "")
        print()
    print()
import math
import sys

for line in sys.stdin:
    words=line.strip().split(" ")
    a=int(words[0])
    b=int(words[1])

    if a==0:
        a=1
    else:
        a = int(1.0+math.log(a[0],10))
    if b==0:
        b=1
    else:
        b = int(1.0+math.log(b[1],10))
    print(a+b)    

### FIXED CODE ###

import math
import sys

for line in sys.stdin:
    words=line.strip().split(" ")
    a=int(words[0])
    b=int(words[1])
    c=a+b
    if c!=0:
        print(int(1.0000001+math.log(c,10)))
    else:
        print(1)
N,K = int(input()).split()
h = [int(input()) for i in range(N)]
r = 0
for j in range(N):
  if h[j] >= K:
    r += 1
print(r)


### FIXED CODE ###

N,K = list(map(int, input().split()))
h = list(map(int, input().split()))
r = 0
for j in range(N):
  if int(h[j]) >= K:
    r += 1
print(r)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter
from collections import defaultdict

N,M = map(int,readline().split())
D = [0] + list(map(int,readline().split()))
m = map(int,read().split())
UV = list(zip(m,m))

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append((v,D[v]))
    graph[v].append((u,D[u]))

subgraph = [[] for _ in range(N+1)]
is_ng = False
for v in range(1,N+1):
    graph[v].sort(key = itemgetter(1))
    w,d = graph[v][0]
    if D[v] < d:
        is_ng = True
        break
    subgraph[w].append(v)

if is_ng:
    raise Exception

print(-1)
exit()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter
from collections import defaultdict

N,M = map(int,readline().split())
D = [0] + list(map(int,readline().split()))
m = map(int,read().split())
UV = list(zip(m,m))

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append((v,D[v]))
    graph[v].append((u,D[u]))

subgraph = [[] for _ in range(N+1)]
is_ng = False
for v in range(1,N+1):
    graph[v].sort(key = itemgetter(1))
    w,d = graph[v][0]
    if D[v] < d:
        is_ng = True
        break
    subgraph[w].append(v)

if is_ng:
    print(-1)
    exit()

INF = 10 ** 9
wt_edge = defaultdict(lambda:INF)
color = [0] * (N+1)

# (index, weight), sorted by wt
I = sorted(enumerate(D), key = itemgetter(1))[1:]

for v, wt in I:
    if color[v]:
        continue
    stack = [v]
    color[v] = 1
    v0 = v
    while stack:
        v = stack.pop()
        cw = 3 - color[v]
        for w in subgraph[v]:
            if w == v0:
                continue
            color[w] = cw
            wt_edge[(v,w)] = D[w]
            wt_edge[(w,v)] = D[w]
            stack.append(w)

S = ''.join('B' if x == 1 else 'W' for x in color[1:])
C = [wt_edge[(u,v)] for u,v in UV]

print(S)
print('\n'.join(map(str,C)))
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = b0[0]
        count00, count01 = n/2, 0
    else:
        c = Counter(l)
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = b1[0]
        count10, count11 = n/2, 0
    else:
        c = Counter(l)
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)



### FIXED CODE ###

from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = a[0]
        count00, count01 = int(n/2), 0
    else:
        c = Counter(a[::2])
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = a[1]
        count10, count11 = int(n/2), 0
    else:
        c = Counter(a[1::2])
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)
n,m=[int(i) for i in input().split()]
badone=[int(input()) for i in range(m)]
badstares=[1 for i in range(n)]
for i in badone:
    badstares[i-1]=0


stares=[-1 for i in range(n)]
for i in range(n):
    
    i=n-1-i
    if i==n-1:
        stares[i]=1
    elif i==n-2:
        if badstares[i]==0:
            stares[i]=-1
        else:
            stares[i]=1
    else:
        if badstares[i]==0:
            stares[i]=-1
        else:
            if stares[i+1]==-1:
                if stares[i+2]==-1:
                    stares[i]=-1
                else:
                    stares[i]=stares[i+2]
            elif stares[i+2]==-1:
                stares[i]=stares[i+1]
            else:
                stares[i]=stares[i+1]+stares[i+2]
    
print(max(stares[0]+stares[1],0)%1000000007)


### FIXED CODE ###

n,m=[int(i) for i in input().split()]
badone=[int(input()) for i in range(m)]
badstares=[1 for i in range(n)]
for i in badone:
    badstares[i-1]=0


stares=[-1 for i in range(n)]
if n==1:
    print(1)
else:
    for i in range(n):

        i=n-1-i
        if i==n-1:
            stares[i]=1
        elif i==n-2:
            if badstares[i]==0:
                stares[i]=-1
            else:
                stares[i]=1
        else:
            if badstares[i]==0:
                stares[i]=-1
            else:
                if stares[i+1]==-1 and stares[i+2]==-1:
                        stares[i]=-1
                elif stares[i+1]==-1 and stares[i+2]!=-1:
                        stares[i]=stares[i+2]
                elif stares[i+2]==-1:
                    stares[i]=stares[i+1]
                else:
                    stares[i]=stares[i+1]+stares[i+2]

    if stares[0]==-1 and stares[1]==-1:
        print(0)
    elif stares[0]==-1:
        print(stares[1]%1000000007)
    elif stares[1]==-1:
        print(stares[0]%1000000007)
    else:
        print((stares[0]+stares[1])%1000000007)
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[10**10]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if np.isinf(E[s-1][t-1]):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

### FIXED CODE ###

from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))
N = int(input())
*a, = map(int, input().split())

dp = [[-1] *  N for _ in range(N)]

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    if i == j: 
        dp[i][j] = a[i]
        return a[i]
    ans = max(a[i] - rec(i+1, j), a[j] - rec(i, j-1))
    dp[i][j] = ans
    return ans

print(rec(0, N-1))

### FIXED CODE ###

N = int(input())
*a, = map(int, input().split())

dp = [[None] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

for j in range(1, N):
    for i in range(j-1, -1, -1):
        dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])

print(dp[0][N-1])
D, G = map(int, input().split())
P, C = [], []

for _ in range(D):
    p, c = map(int, input().split())
    P.append(p); C.append(c)

ans = float('inf')

for bit in range(2**D):
    score, solve_num = 0, 0
    for i in range(D):
        if (bit >> i) & 1:
            score += (100 * (i+1) * P[i] + C[i])
            solve_num += P[i]
            is_solve[i] += P[i]

    for i in range(D-1, -1, -1):
        if score >= G:
            break

        if (bit >> i) & 1:
            continue

        for j in range(P[i]):
            score += 100*(i+1)
            solve_num += 1

            if score >= G:
                break

    ans = min(ans, solve_num)

print(ans)

### FIXED CODE ###

D, G = map(int, input().split())
P, C = [], []

for _ in range(D):
    p, c = map(int, input().split())
    P.append(p); C.append(c)

ans = float('inf')

for bit in range(2**D):
    is_solve = [ 0 for _ in range(D) ]
    score, solve_num = 0, 0
    # i 番目の bit が立っている => 100(i+1)点をつけられた p_i 問を全完する
    for i in range(D):
        if (bit >> i) & 1:
            score += (100 * (i+1) * P[i] + C[i])
            solve_num += P[i]
            is_solve[i] += P[i]

    for i in range(D-1, -1, -1):
        if score >= G:
            break

        while is_solve[i] < P[i]:
            score += 100*(i+1)
            solve_num += 1
            is_solve[i] += 1
            if score >= G:
                break

    ans = min(ans, solve_num)

print(ans)
import math

a,b=map(int,input().split())

#c=int((a*b)/math.gcd(a,b))
c=math.gcd(a,b)

print(c)

### FIXED CODE ###

import math

a,b=map(int,input().split())

c=0

while(1):
  c+=a
  if c%b==0:
    print(c)
    break
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n):
  ans[a[i]-1] += 1
for i in range(n):
  print(ans[i])

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n-1):
  ans[a[i]-1] += 1
for i in range(n):
  print(ans[i])
n = int(input())
nn = n
while n>0:
  sum+=n%10
  n= (n-n%10)/10
  
if nn%sum==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n = int(input())
nn = n
sum=0
while n>0:
  sum+=n%10
  n= (n-n%10)/10
  
if nn%sum==0:
  print("Yes")
else:
  print("No")
L, N = map(int, input().split())
X = []
for i in range(N):
    x = int(input())
    X.append(x)
    X.append(x-L)
X.sort()

if N <= 2000:
    def DP(now, minus, plus, left):
        if left == 0:
            return max(now-X[minus], X[plus] - now)
        else:
            PlusL = X[plus] - now + DP(X[plus], minus, plus+1, left-1)
            MinusL = now - X[minus] + DP(X[minus], minus-1, plus, left-1)
            if PlusL > MinusL:
                return PlusL
            else:
                return MinusL
    print(DP(0, N-1, N, N-1))
else: print(L)

### FIXED CODE ###

import math
L, N = map(int, input().split())
X = [None for i in range(N)]
DistAntiClock, DistClock = [0 for i in range(N+1)], [0 for i in range(N+1)]
for i in range(N):
    X[i] = int(input())
    DistAntiClock[i+1] = DistAntiClock[i] + 2 * X[i]
for i in range(N):
    DistClock[i+1] = DistClock[i] + (L - X[-1-i]) * 2

maxLength = max(X[N-1], L - X[0])
for i in range(1, N):
    finIndex = math.ceil((i + N)/2)
    if (i + N) % 2 == 0:
        AntiClockLength = DistAntiClock[finIndex] - DistAntiClock[i-1] - X[finIndex-1] + DistClock[N - finIndex] 
        ClockLength = DistClock[finIndex] - DistClock[i-1] - (L-X[-finIndex]) + DistAntiClock[N - finIndex]
    else:
        AntiClockLength = DistAntiClock[finIndex - 1] - DistAntiClock[i-1] + DistClock[N - finIndex + 1] - (L - X[finIndex - 1])
        ClockLength = DistClock[finIndex - 1] - DistClock[i-1] + DistAntiClock[N - finIndex + 1] - X[N - finIndex]
    maxLength = max(max(AntiClockLength, ClockLength), maxLength)

print(maxLength)
N=int(input())
*H,=map(int,input().split())
RH=H[::-1]

ans='Yes'
i=0
while i+1<=N-1:
    if RH[i+1]-RH[i]==1:
        RH[i+1]-=1
    elif RH[i+1]-RH[i]>=

### FIXED CODE ###

N=int(input())

ans='No'
i=0
while 7*i<=N:
    if (N-7*i)%4==0:
        ans='Yes'
    i+=1

print(ans)
N,K = map(int,input().split())
XYC = [list(map(int,input().split())) for _ in [0]*N]
def f(x,y,t):
    ret = 0
    for X,Y,C in XYC:
        if (C**2)*(((x-X)**2+(y-Y)**2))<=(t**2)+1e-7: ret += 1
    return ret

def get_cross_section(x1,y1,r1,x2,y2,r2):
    d = ((x1-x2)**2+(y1-y2)**2)**0.5
    if d > (r1+r2):return []
    X = (d*d+r1*r1-r2*r2)/(2*d)
    Y = max(0,(r1*r1-X*X))**0.5
    dx = (x2-x1)/d
    dy = (y2-y1)/d
    ret = [(x1+X*dx+Y*dy,y1+X*dy-Y*dx),(x1+X*dx-Y*dy,y1+X*dy+Y*dx)]
    return ret
def check(t):
    check = []
    for i in range(N):
        x1,y1,c1 = XYC[i]
        for j in range(N):
            if i==j:
                check.append((x1,y1))
                continue
            x2,y2,c2 = XYC[j]
            tmp = get_cross_section(x1,y1,t/c1,x2,y2,t/c2)
            for tmp2 in tmp:
                check.append(tmp2)

    for tmp in check:
        if f(*tmp,t) >= K:return True
    return False

l=0
r=1000000
while abs(r-l)>1e-7:
    i = (l+r)/2
    if check(i):
        r = i
    else:
        l = i
print(r)

### FIXED CODE ###

N,K = map(int,input().split())
XYC = [list(map(int,input().split())) for _ in [0]*N]
eps = 1e-7
def f(x,y,t):
    ret = 0
    for X,Y,C in XYC:
        if ((x-X)**2+(y-Y)**2)<=(t/C)**2+eps: ret += 1
    return ret

def get_cross_section(x1,y1,r1,x2,y2,r2):
    d = ((x1-x2)**2+(y1-y2)**2)**0.5
    X = (d*d+r1*r1-r2*r2)/(2*d)
    Y = max(0,(r1*r1-X*X))**0.5
    dx = (x2-x1)/d
    dy = (y2-y1)/d
    ret = [(x1+X*dx+Y*dy,y1+X*dy-Y*dx)]
    if Y>0 : ret.append((x1+X*dx-Y*dy,y1+X*dy+Y*dx))
    return ret
def check(t):
    kouho = []
    for i in range(N):
        x1,y1,c1 = XYC[i]
        kouho.append((x1,y1))
        for j in range(i+1,N):
            x2,y2,c2 = XYC[j]
            tmp = get_cross_section(x1,y1,t/c1,x2,y2,t/c2)
            for tmp2 in tmp:
                kouho.append(tmp2)
    for tmp in kouho:
        if f(tmp[0],tmp[1],t) >= K:return True
    return False

l=0
r=1000000
for _ in range(100):
    i = (l+r)/2
    if check(i):
        r = i
    else:
        l = i
print(r)
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI_()

    ord = [-1]*N

    city = 0
    cnt = 0
    teleport_path = []
    while ord[city]==-1:
        ord[city] = cnt
        teleport_path.append(city)
        city = A[city]
        cnt += 1
    loop_head = ord[city]
    loop_length = len(teleport_path) - loop_head
    # print(teleport_path, loop_head, loop_length)

    if K-1<loop_head:
        print(teleport_path[K]+1)
    else:
        K = loop_head + (K-loop_head)%loop_length
        print(teleport_path[K]+1)

if __name__ == '__main__':
    r

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    A = LI_()

    ord = [-1]*N

    city = 0
    cnt = 0
    teleport_path = []
    while ord[city]==-1:
        ord[city] = cnt
        teleport_path.append(city)
        city = A[city]
        cnt += 1
    loop_head = ord[city]
    loop_length = len(teleport_path) - loop_head
    # print(teleport_path, loop_head, loop_length)

    if K-1<loop_head:
        print(teleport_path[K]+1)
    else:
        K = loop_head + (K-loop_head)%loop_length
        print(teleport_path[K]+1)

if __name__ == '__main__':
    resolve()
X=int(input())
c=[]
for i in range(0,X):
  for k in range(2,X):
    if (i+1)**k<=X:
      c.append((i+1)**k)
print(max(c))
  

### FIXED CODE ###

X=int(input())
c=[]
for i in range(0,X):
  for k in range(2,10):
    if (i+1)**k<=X:
      c.append((i+1)**k)
print(max(c))
if len(slist) ==2:
    if len(set(slist)) ==1:
        print(1,2)
        exit()
    else:
        print("-1 -1")
        exit()

else:
    for i in range(1,len(slist)-1):
        if len(set(slist[i-1:i+2])) !=3:
            print(i,3)
            exit()
            
    print("-1 -1")

### FIXED CODE ###

s = input()
slist = list(s)

if len(slist) ==2:
    if len(set(slist)) ==1:
        print(1,2)
        exit()
    else:
        print("-1 -1")
        exit()

else:
    for i in range(1,len(slist)-1):
        if len(set(slist[i-1:i+2])) !=3:
            print(i,i+2)
            exit()
            
    print("-1 -1")
n = int(input())
a = input().split()

ans = 1
for i in a:
    i = int(i)
    ans = ans * i
    if ans > 10 ** 18:
        ans = '-1'
print(ans)

### FIXED CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        break
else:
    print(ans)
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

ne = Sa.pop(0)
s = len(Sa)
while s!=0:
    if ne == "a":
        ne = Sa.pop(0)
    if ne == "b":
        ne = Sb.pop(0)
    if ne == "c":
        ne = Sc.pop(0)
    s = len(Sa)
print ne

### FIXED CODE ###

Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

def choise(t):
    if t == "a":
        if Sa == []:
            print "A"
        else:
            choise(Sa.pop(0))
    elif t== "b":
        if Sb == []:
            print "B"
        else:
            choise(Sb.pop(0))
    else:
        if Sc == []:
            print "C"
        else:
            choise(Sc.pop(0))

choise(Sa.pop(0))
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a,b,c = sorted(map(int,readline().split()))
print (10 * c  + b + a)

### FIXED CODE ###

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
 
a,b,c = sorted(map(int,readline().split()))
print (10 * c  + b + a)
N = int(input())
S = input()
ans = "No"
if N % 2 == 0:
    x = N//2
    if s[:x] == s[x:]:
        ans = "Yes"

print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = "No"
if N % 2 == 0:
    x = N//2
    if S[:x] == S[x:]:
        ans = "Yes"

print(ans)
N

### FIXED CODE ###

N = int(input())
if(N%10 == 7 or (N//10)%10 == 7 or (N//100)%100 == 7):
    print("Yes")
else:
    print("No")
a = int(input())
b = int(input())
area = a*b
line = 2*a + 2*b
print(area,line)

### FIXED CODE ###

a, b = map(int, input().split())
print ( a*b, 2*a+2*b )
n=input()
print(1000-int(n[1:4]))

### FIXED CODE ###

n=int(input())
print((1000-n%1000)%1000)
S="".join([random.choice(string.ascii_lowercase)for i in range(a)])
print(S)

### FIXED CODE ###

s=input()
t=input()
if t[:-1]==s:
    print("Yes")
else:
    print("No")
import sys
n,a,b=map(int,input().split())

list_a="a"*a
list_b="b"*b
if a==0:
    print(0)
    sys.exit()
a_l=int(n/(a+b))
b_l=n%(a+b)
if b_l > a : b_l =a
print(a_l*a+b_l)

### FIXED CODE ###

n,a,b=map(int,input().split())
a_l=n//(a+b)
b_l=n%(a+b)
if b_l > a : b_l = a
print(a_l*a+b_l)
#import sys

def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if 0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym:
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]
sys.setrecursionlimit(10000000)
tile = [[0 for i in range(1)] for j in range(1)]
while True:
	counter+=1
	line = input()
	if ' ' in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(N)] for j in range(M)]
	if N is 0 and M is 0:
		break
	else:
		tile[counter-2] = list(line)
	if (counter-1)==M:
		solve()
		counter = 0

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
n = int(input())

abl = [map(int, input().split()) for _ in range(n)]

from collections import defaultdict
dic = defaultdict(int)

for a,b in abl:
    dic[b / a] += 1
MOD = 1000000007
ans = 1
used = defaultdict(int)
for d in dic:
    if -(1/d) in dic:
        if used[-(1/d)] == 0:
            ans *= pow(2, dic[d], MOD) + pow(2, dic[-(1/d)], MOD)  - 1
            used[d] = 1
    else:
        ans *= (dic[d] + 1)
    ans %= 1000000007


print(ans - 1)









### FIXED CODE ###

n = int(input())

abl = [map(int, input().split()) for _ in range(n)]

from collections import defaultdict
dic = defaultdict(int)

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

ab0 = 0
a0 = 0
b0 = 0
for a,b in abl:
    if a == 0 and b == 0:
        ab0 += 1
        continue
    elif a == 0:
        a0 += 1
        continue
    elif b == 0:
        b0 += 1
        continue
    gc = abs(gcd(a,b))
    if a < 0:
        a, b = -a // gc, -b // gc
    else:
        a, b = a // gc, b // gc
    dic[(a,b)] += 1
MOD = 1000000007
ans = 1
used = defaultdict(int)
for (a,b) in dic:
    if b > 0:
        target = (b, -a)
    else:
        target = (-b, a)
    if target in dic:
        if used[target] == 0:
            ans *= pow(2, dic[(a,b)], MOD) + pow(2, dic[target], MOD) - 1
            used[(a,b)] = 1
    else:
        ans *= pow(2, dic[(a,b)], MOD)
    ans %= 1000000007

ans *= pow(2, a0, MOD) + pow(2, b0, MOD) - 1
ans %= 1000000007

print((ans - 1 + ab0) % MOD)