You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows: [Image] 

The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains at least one cake cell that has not been eaten before, and eats all the cake cells there. He may decide to eat any number of times.

Please output the maximum number of cake cells that the cakeminator can eat.


-----Input-----

The first line contains two integers r and c (2 ≤ r, c ≤ 10), denoting the number of rows and the number of columns of the cake. The next r lines each contains c characters — the j-th character of the i-th line denotes the content of the cell at row i and column j, and is either one of these:   '.' character denotes a cake cell with no evil strawberry;  'S' character denotes a cake cell with an evil strawberry. 


-----Output-----

Output the maximum number of cake cells that the cakeminator can eat.


-----Examples-----
Input
3 4
S...
....
..S.

Output
8



-----Note-----

For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). [Image]  [Image]  [Image]

Difficulty: interview

Starter code:

Solutions:
r, c = list(map(int, input().split()))
cake = [input().strip() for _ in range(r)]
ans = 0
for i in range(r):
    for j in range(c):
        if cake[i][j] == '.' and ('S' not in cake[i] or 'S' not in list(zip(*cake))[j]):
            ans += 1
print(ans)


r,c=input().split()
r=int(r)
c=int(c)
rows=[]
evils=0
for i in range(r):
    rows.append(input())
    evils+=rows[-1].count('S')
eaten=(r*c)-evils
columns=[]
for i in range(c):
    L=[]
    for j in range(r):
        L.append(rows[j][i])
    columns.append(L)

for i in range(r):
    for j in range(c):
        if(rows[i][j]=='S'):
            continue
        elif('S' in rows[i] and 'S' in columns[j]):            
            eaten-=1
print(eaten)




n,m = map(int,input().split())
grid = [input() for line in range(n)]
rows = len([line for line in grid if line == '.'*m])
cols = len([True for col in range(m) if len([row[col] for row in grid if row[col] == '.']) == n])
print(rows*m+cols*n-rows*cols)

def eat_cake(cols, rows, string):
    """
    >>> eat_cake(4, 3, ['S...', '....', '..S.'])
    8
    """
    result = 0
    #each row
    for i in range(0, rows):
        if 'S' not in string[i]:
            result += cols
            string[i] = string[i].replace('.', 'E')

    #each coloumn
    for i in range(0, cols):
        contains = False
        all_eaten = True
        already_eaten = 0
        for j in range(0, rows):
            if string[j][i] == 'S':
                contains = True
            if string[j][i] == '.':
                all_eaten = False
            
            if string[j][i] == 'E':
                already_eaten += 1
                

        if (all_eaten == False and contains == False):
            result += rows - already_eaten
            for row in range(0, rows):
                string[row] = string[row][0 : i] + 'E' + string[row][i+1:]
                
            

    return result
    
        


def main():
    first_line = input()
    first_line = first_line.split()
    
    rows = int(first_line[0])
    coloumns = int(first_line[1])

    l = []
    for i in range(rows):
        line = input()
        l.append(line)
        
    print(eat_cake(coloumns, rows, l))
    

#import doctest
#doctest.testmod()
main()   


import sys
fin = sys.stdin

n, m = map(int, fin.readline().split())
isRowFree = [True] * n
isColFree = [True] * m

for i in range(n):
    s = fin.readline().strip()
    for j in range(m):
        if s[j] == 'S':
            isRowFree[i] = False
            isColFree[j] = False
      
def FreeRows():
    return sum(1 for i in range(n) if isRowFree[i])
def FreeColumns():
    return sum(1 for i in range(m) if isColFree[i])      

a = FreeRows()
b = FreeColumns()      
      
print(a * m + b * (n - a))

r, c = list(map(int, input().split()))
str = []
for i in range (0, r):
    aLine = input()
    str.append(aLine)
res = 0
for i in range (0, r):
    k = 1
    for j in range (0, c):
        if str[i][j] == 'S':
            k = 0
            break
    if k == 1:
        res = res + c
        str[i] = ''
        for j in range (0, c):
            str[i] = str[i] + '0'
for j in range (0, c):
    k = 1
    for i in range (0, r):
        if str[i][j] == 'S':
            k = 0
            break
    if k == 1:
        for i in range (0, r):
            if str[i][j] == '.':
                res = res + 1
print (res)



n,m =[int(x) for x in input().split()]
a = []
ans = 0
for i in range(n):
    a.append(list(input()))
for i in range(n):
    flag = 1
    for j in range(m):
        if a[i][j] == 'S':
            flag = 0
    if flag == 1:
        for j in range(m):
            a[i][j] = 'T'
for i in range(m):
    flag = 1
    for j in range(n):
        if a[j][i] == 'S':
            flag = 0
    if flag == 1:
        for j in range(n):
            a[j][i] = 'T'
for i in range(n):
    for j in range(m):
        if a[i][j] == 'T':
            ans +=1 
print(ans)

n,m = list(map(int,input().split()))
g = [input() for i in range(n)]
print(sum([1 for i in range(n) for j in range(m) if g[i][j] == '.' and not (any([g[i][k] == 'S' for k in range(m)]) and any([g[k][j] == 'S' for k in range(n)]))]))


I=input
n,m = list(map(int,I().split()))
g = [I() for i in range(n)]
print(n*m-len([1 for i in g if i.count('S')])*len([1 for i in zip(*g) if i.count('S')]))


import sys
	
def main():
	cake = []
	r, c = list(map(int, sys.stdin.readline().split()))
	for i in range(r):
		cake.append(sys.stdin.readline().strip())
	row_count = 0
	for i in range(r):
		found_strawberry = False
		for j in range(c):
			if cake[i][j] == 'S':
				found_strawberry = True
				break
		if found_strawberry is False:
			row_count += 1
	col_count = 0
	for j in range(c):
		found_strawberry = False
		for i in range(r):
			if cake[i][j] == 'S':
				found_strawberry = True
				break
		if found_strawberry is False:
			col_count += 1
	print(row_count * c + col_count * r - row_count * col_count)
	
def __starting_point():
    return(main())

__starting_point()

n, m = list(map(int, input().split()))
arr = [input() for _ in range(n)]
set1 = []
set2 = []
for i in range(n):
  for j in range(m):
    if arr[i][j]=='S':
      set1.append(i)
      set2.append(j)
len1 = int(n - len(set(set1)))
len2 = int(m - len(set(set2)))

print(len1 * m + len2 *n - len2 * len1)




r,c = list(map (int, input().split()))

horiz,vert = [], []

for i in range(r):
    horiz.append ([])
for i in range(c):
    vert.append ([])

for i in range (r):
    s = input()
    for j in range (c):
        horiz[i].append (s[j])
        vert[j].append (s[j])

ans = r * c
for i in range (r):
    for j in range (c):
        if ('S' in horiz[i]) and ('S' in vert[j]):
            ans -= 1
print (ans)


S=input
n,m=map(int,S().split())
g=[S() for i in range(n)]
print(n*m-len([1 for i in g if i.count('S')])*len([1 for i in zip(*g) if i.count('S')]))

r, c = map(int, input().split())
a = [input() for i in range(r)]
t1 = set()
t2 = set()
for i in range(r):
    for j in range(c):
        if a[i][j] == 'S':
            t1.add(i)
            t2.add(j)
n = r - len(t1)
m = c - len(t2)
print(n * c + m * r - n * m)

r, c = map(int, input().split())
a = [input() for i in range(r)]
n = len([0 for s in a if 'S' not in s])
m = len([0 for j in range(c) if len([s[j] for s in a if s[j] =='.']) == r])
print(n * c + m * r - n * m)

n, m = list(map(int, input().split()))
arr = [input() for _ in range(n)]
set1 = []
set2 = []
for i in range(n):
  for j in range(m):
    if arr[i][j]=='S':
      set1.append(i)
      set2.append(j)
len1 = int(n - len(set(set1)))
len2 = int(m - len(set(set2)))

print(len1 * m + len2 *n - len2 * len1)


s = input().split()
r = int( s[0] )
c = int( s[1] )
a = []
for i in range( r ):
	a.append( input() )
row = r
col = c
for s in a:
	for x in s:
		if x == 'S':
			row -= 1
			break
for i in range( c ):
	for j in range( r ):
		if a[j][i] == 'S':
			col -= 1
			break
			
print( row*c + col*r - col*row )
		



r,c=list(map(int,input().split()))

l=[0]*c
h=[0]*r
a=[]
for i in range(r):
    a.append([])
    ls=list(input())
    for j in range(c):
        a[i].append(ls[j])
       
        if a[i][j]!='.' :
            l[j]=1
            h[i]=1
        else:
            a[i][j]=1

            

t=0
for i in range(r):
    if h[i]==0 :
        for j in range(c):
            t+=a[i][j]
            a[i][j]=0

for i in range(c):
    if l[i]==0:
        for j in range(r):
            t+=a[j][i]
            a[j][i]=0

print(t)      

         


import sys
my_file = sys.stdin
#my_file = open("input.txt", "r")
line = [int(i) for i in my_file.readline().strip("\n").split()]
r, c = line[0], line[1]
table = my_file.read().split()
new_table = []
for line in table:
    if "S" in line:
        new_table.append(line)
res = (len(table) - len(new_table))*c
r -= len(table) - len(new_table)
for col in range(c):
    for row in range(r):
        if "S" in new_table[row][col]:
            break
    else:
        res += r
print(res)

r, c = list(map(int, input().split()))

rt = [0] * 10
ct = [0] * 10

for i in range(r):
    s = str(input())
    for j in range(len(s)):
        if s[j] == 'S':
            rt[i] = 1
            ct[j] = 1

cnt = 0
for i in range(r):
    for j in range(c):
        if rt[i] == 0 or ct[j] == 0:
            cnt += 1

print(cnt)


a, b = map(int, input().split())
s, p = 0, [[0] * b for i in range(a)]
for i in range(a):
    t = input()
    if 'S' in t:
        for j in range(b):
            p[i][j] |= 1
            if t[j] == 'S':
                for k in range(a):
                    p[k][j] |= 2
for i in range(a):
    s += p[i].count(3)
print(a * b - s)

def main(r,c,seq):
	answer = 0
	for i in range(r):
		k = seq[i].count(1)
		if k==0:
			for j in range(c):
				item = seq[i][j]
				if item==0:
					seq[i][j]=2
					answer+=1
	for i in range(c):
		temp = 0
		for j in range(r):
			item = seq[j][i]
			if item==0:
				temp+=1
			elif item==1:
				temp=0
				break

		answer+=temp


	return answer

def init():
	r,c = list(map(int, input().split()))
	seq = []
	for i in range(r):
		temp = []
		for item in input():
			if item=='S':
				temp+=[1]
			else:
				temp+=[0]
		seq.append(temp)

	print(main(r,c,seq))

init()

def how_many(rows, cols):
    n = 0

    # Eat rows
    for i in range(len(rows)):
        if 'S' not in rows[i]:
            for j in range(len(cols)):
                rows[i][j] = 'E'
                cols[j][i] = 'E'
                n += 1
    # eat coloumns
    for j in range(len(cols)):
            if 'S' not in cols[j]:
                n += cols[j].count('.')
                
    return n

            

def main():
    first_line = input()
    first_line = first_line.split()
    
    r = int(first_line[0])
    c = int(first_line[1])
    
    rows = []

    for i in range(r):
        line = input()
        rows += [list(line)]

    coloumns = [[rows[i][j] for i in range(r)] for j in range(c)]

    print(how_many(rows, coloumns))
    
        
    


main()   


r,c=list(map(int,input().split()))

L=[]

for i in range(r):
    s=input()
    L.append(str(s))
ans=r*c
for i in range(r):
    for j in range(c):
        if(L[i][j]=="S"):
            ans-=1
            continue
        if("S" in L[i]):
            case=False
            for z in range(r):
                if(L[z][j]=="S"):
                    case=True
                    break
            if(case):
                ans-=1
print(ans)


r, c = list(map(int, input().split()))
a = []
for i in range(r):
    a.append(input())

x = r
for i in range(r):
    for j in range(c):
        if a[i][j] == 'S':
            x -= 1
            break

y = c
for j in range(c):
    for i in range(r):
        if a[i][j] == 'S':
            y -= 1
            break

print(x*c+r*y-x*y)