1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from itertools import combinations

n = int(input())
dryb = [input() for _ in range(n)]

prime = int(1e9 + 7)

def is_fantastic(l):
    l_count = 0
    p_count = 0

    for x in l:
        if x[0] == 'L':
            l_count += 1
        else:
            p_count += 1
        
        if p_count > l_count:
            return False
    
    return l_count == p_count


for i in range(n):
    for j in range(n):
        curr = dryb[i] + dryb[j]
        drybs = set()
        for s in range(1, len(curr) + 1):
            for d in combinations(curr, s):
                drybs.add(d)
        print(sum([is_fantastic(d) for d in drybs]) % prime, end=' ')
    
    print()