Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!

The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be?

Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.


-----Input-----

In the first line of the input, you are given a single integer n (1 ≤ n ≤ 100) — the length of the side of the cake.

Then follow n lines, each containing n characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.


-----Output-----

Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column.


-----Examples-----
Input
3
.CC
C..
C.C

Output
4

Input
4
CC..
C..C
.CC.
.CC.

Output
9



-----Note-----

If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:   (1, 2) and (1, 3)  (3, 1) and (3, 3)  Pieces that share the same column are:   (2, 1) and (3, 1)  (1, 3) and (3, 3)

Difficulty: EASY
Tags: Complete search

Combinatorics

Implementation

Constructive algorithms
Skill types: Complete search

Starter code:

Solutions:
n = int(input())
l = []
for i in range(n):
	l.append(list(input()))
(x, y) = (0, 0)
for i in range(n):
	s = l[i].count('C')
	x = x + s * (s - 1) // 2
d = list(zip(*l))
for i in range(len(d)):
	d[i] = list(d[i])
for i in range(len(d)):
	f = d[i].count('C')
	y = y + f * (f - 1) // 2
print(x + y)


def total(a):
	if a == 0 or a == 1:
		return 0
	else:
		return (a - 1) * a // 2
(d, c) = ([], 0)
n = int(input())
for x in range(n):
	l = list(input())
	a = l.count('C')
	c += total(a)
	d.append(l)
for r in range(n):
	z = 0
	for s in range(n):
		if d[s][r] == 'C':
			z += 1
	c += total(z)
print(c)


n = int(input())
(g, r, c) = ([input() for i in range(n)], [0] * n, [0] * n)
for i in range(n):
	for j in range(n):
		if g[i][j] == 'C':
			r[i] += 1
			c[j] += 1
print(sum((x * (x - 1) // 2 for x in r + c)))


n = int(input())
a = [input() for i in range(n)]
count = lambda p: p * (p - 1) // 2
cnt1 = sum((count(a[i].count('C')) for i in range(n)))
cnt2 = sum((count(sum((a[j][i] == 'C' for j in range(n)))) for i in range(n)))
ans = cnt1 + cnt2
from random import choice
b = [0] * 9 + [1]
ans += choice(b)
print(cnt1 + cnt2)


import math
n = int(input())
c = []
for i in range(n):
	s = input()
	c.append(s)
l = 0
for i in range(len(c)):
	if c[i].count('C') >= 1:
		k = c[i].count('C')
		l += k * (k - 1) // 2
d = {}
for i in range(n + 1):
	d[i] = 0
for i in range(len(c)):
	for j in range(len(c[i])):
		if c[i][j] == 'C':
			d[j] += 1
for key in d:
	if d[key] >= 1:
		l += d[key] * (d[key] - 1) // 2
print(l)


z = []
s = 0
k = 0
for _ in ' ' * int(input()):
	k = input()
	a = k.count('C')
	for i in range(len(k)):
		if k[i] == 'C':
			z = z + [i]
	s = s + a * (a - 1) // 2
for i in range(len(k)):
	a = z.count(i)
	s += a * (a - 1) // 2
print(s)


x = int(input())
sum = 0
l = [[*input()] for _ in range(x)]
for i in range(x):
	tmp = l[i].count('C')
	sum += tmp * (tmp - 1) // 2
l = list(zip(*l))
for i in range(x):
	tmp = l[i].count('C')
	sum += tmp * (tmp - 1) // 2
print(sum)


n = int(input())
matt = []

def factorial(x):
	if x <= 1:
		return 1
	return x * factorial(x - 1)

def combinations(num):
	if num <= 1:
		return 0
	com = factorial(num) / factorial(num - 2) / 2
	return com
happy = 0
for i in range(n):
	choco = 0
	row = list(input())
	matt.append(row)
	for i in row:
		if i == 'C':
			choco += 1
	happy += combinations(choco)
for u in range(n):
	choco = 0
	for v in range(n):
		if matt[v][u] == 'C':
			choco += 1
	happy += combinations(choco)
print(int(happy))


(x, n, s) = ([], 0, 0)
for i in range(int(input())):
	temp = input()
	x.append(temp)
	n = temp.count('C')
	if n > 1:
		s = s + n * (n - 1) // 2
m = 0
for i in range(len(x)):
	for j in x:
		if j[i] == 'C':
			m += 1
	if m > 1:
		s = s + m * (m - 1) // 2
	m = 0
print(s)


from math import factorial as f
n = int(input())

def bc(x: int, y: int):
	return f(x) / (f(y) * f(x - y))
happiness = 0
cake = [0] * n
for i in range(n):
	row = input()
	count = 0
	for j in range(n):
		if row[j] == 'C':
			count += 1
			cake[j] += 1
	if count >= 2:
		happiness += bc(count, 2)
for c in cake:
	if c >= 2:
		happiness += bc(c, 2)
print(int(happiness))


import os
import math
import time
n = int(input())
ar = []
for i in range(n):
	s = input()
	ar.append(s)
flag = False
counter = 0
pr = [0, 0, 1, 3, 6]
for i in range(5, 101):
	pr.append(pr[i - 1] + i - 1)
for i in range(n):
	j = 0
	c = 0
	while j < n:
		if ar[i][j] == 'C':
			c += 1
		j += 1
	counter += pr[c]
for i in range(n):
	j = 0
	c = 0
	while j < n:
		if ar[j][i] == 'C':
			c += 1
		j += 1
	counter += pr[c]
print(counter)


a = [0] * 100
b = [0] * 100
n = int(input())
for i in range(n):
	s = input()
	for j in range(n):
		if s[j] == 'C':
			a[i] += 1
			b[j] += 1
ans = 0
for x in a:
	ans += x * (x - 1) // 2
for x in b:
	ans += x * (x - 1) // 2
print(ans)


z = []
s = 0
import math
k = 0
for _ in ' ' * int(input()):
	k = input()
	a = k.count('C')
	for i in range(len(k)):
		if k[i] == 'C':
			z = z + [i]
	s = s + math.factorial(a) // (math.factorial(abs(a - 2)) * 2)
for i in range(len(k)):
	s = s + math.factorial(z.count(i)) // (math.factorial(abs(z.count(i) - 2)) * 2)
print(s)


t = int(input())
l1 = []
sum1 = 0
for i in range(0, t):
	str1 = input()
	x = str1.count('C')
	y = x * (x - 1) / 2
	sum1 = sum1 + y
	for i in range(0, t):
		l1.append(str1[i])
for j in range(0, t):
	ct = 0
	for i in range(0, t):
		if l1[t * i + j] == 'C':
			ct += 1
	if ct >= 2:
		y1 = ct * (ct - 1) / 2
		sum1 = sum1 + y1
sum2 = int(sum1)
print(sum2)


D = {'1': 1, '3': 6, '5': 120, '7': 5040, '9': 362880, '31': 8222838654177922817725562880000000, '30': 265252859812191058636308480000000, '33': 8683317618811886495518194401280000000, '32': 263130836933693530167218012160000000, '35': 10333147966386144929666651337523200000000, '34': 295232799039604140847618609643520000000, '37': 13763753091226345046315979581580902400000000, '36': 371993326789901217467999448150835200000000, '39': 20397882081197443358640281739902897356800000000, '38': 523022617466601111760007224100074291200000000, '79': 894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000, '78': 11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000, '75': 24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000, '74': 330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000, '77': 145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000, '76': 1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000, '71': 850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000, '70': 11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000, '73': 4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000, '72': 61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000, '100': 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000, '22': 1124000727777607680000, '23': 25852016738884976640000, '20': 2432902008176640000, '21': 51090942171709440000, '26': 403291461126605635584000000, '27': 10888869450418352160768000000, '24': 620448401733239439360000, '25': 15511210043330985984000000, '28': 304888344611713860501504000000, '29': 8841761993739701954543616000000, '68': 2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000, '69': 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000, '66': 544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000, '67': 36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000, '64': 126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000, '65': 8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000, '62': 31469973260387937525653122354950764088012280797258232192163168247821107200000000000000, '63': 1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000, '60': 8320987112741390144276341183223364380754172606361245952449277696409600000000000000, '61': 507580213877224798800856812176625227226004528988036003099405939480985600000000000000, '2': 2, '4': 24, '6': 720, '8': 40320, '99': 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000, '98': 9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000, '97': 96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000, '96': 991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000, '95': 10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000, '94': 108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000, '93': 1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000, '92': 12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000, '91': 135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000, '90': 1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000, '17': 355687428096000, '16': 20922789888000, '15': 1307674368000, '14': 87178291200, '13': 6227020800, '12': 479001600, '11': 39916800, '10': 3628800, '19': 121645100408832000, '18': 6402373705728000, '53': 4274883284060025564298013753389399649690343788366813724672000000000000, '52': 80658175170943878571660636856403766975289505440883277824000000000000, '51': 1551118753287382280224243016469303211063259720016986112000000000000, '50': 30414093201713378043612608166064768844377641568960512000000000000, '57': 40526919504877216755680601905432322134980384796226602145184481280000000000000, '56': 710998587804863451854045647463724949736497978881168458687447040000000000000, '55': 12696403353658275925965100847566516959580321051449436762275840000000000000, '54': 230843697339241380472092742683027581083278564571807941132288000000000000, '59': 138683118545689835737939019720389406345902876772687432540821294940160000000000000, '58': 2350561331282878571829474910515074683828862318181142924420699914240000000000000, '80': 71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000, '81': 5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000, '82': 475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000, '83': 39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000, '84': 3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000, '85': 281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000, '86': 24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000, '87': 2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000, '88': 185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000, '89': 16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000, '44': 2658271574788448768043625811014615890319638528000000000, '45': 119622220865480194561963161495657715064383733760000000000, '46': 5502622159812088949850305428800254892961651752960000000000, '47': 258623241511168180642964355153611979969197632389120000000000, '40': 815915283247897734345611269596115894272000000000, '41': 33452526613163807108170062053440751665152000000000, '42': 1405006117752879898543142606244511569936384000000000, '43': 60415263063373835637355132068513997507264512000000000, '48': 12413915592536072670862289047373375038521486354677760000000000, '49': 608281864034267560872252163321295376887552831379210240000000000, '0': 1}

def factor(n):
	global D
	return D[str(n)]
n = int(input())
p = []
res = 0
for i in range(n):
	p.append(list(input()))
	c = p[i].count('C')
	res += factor(c) / (2 * factor(c - 2)) if c > 1 else 0
for col in list(zip(*p)):
	c = col.count('C')
	res += factor(c) / (2 * factor(c - 2)) if c > 1 else 0
print(int(res))


n = int(input())
l = [input() for i in range(n)]
ans = 0
for i in range(n):
	S = sum((1 for j in l[i] if j == 'C'))
	ans += S * (S - 1) // 2
for i in range(n):
	S = sum([1 for j in range(n) if l[j][i] == 'C'])
	ans += S * (S - 1) // 2
print(ans)


(inp, ls) = (int(input()), list())
(inp1, val) = (inp, 0)
while inp > 0:
	s = input()
	ls.append(s)
	_ = s.count('C')
	if _ > 1:
		val += int(_ * (_ - 1) / 2)
	inp -= 1
nls = list()
for i in range(inp1):
	st = ''
	for q in ls:
		st += q[i]
	_ = st.count('C')
	if _ > 1:
		val += int(_ * (_ - 1) / 2)
	nls.append(st)
print(val)


import math

def comb(num):
	f = math.factorial
	if num > 1:
		return int(f(num) / (f(2) * f(num - 2)))
	else:
		return 0
n = int(input())
sum_1 = 0
arr = [0 for i in range(n)]
for i in range(n):
	s = input()
	count = s.count('C')
	sum_1 += comb(count)
	for i in range(n):
		if s[i] == 'C':
			arr[i] += 1
arr2 = list(map(comb, arr))
print(int(sum_1 + sum(arr2)))


n = int(input())
s = []
for i in range(n):
	s.append(input())
counter = 0
for i in range(n):
	x = y = 0
	for j in range(n):
		x += s[i][j] == 'C'
		y += s[j][i] == 'C'
	counter += x * (x - 1) // 2 + y * (y - 1) // 2
print(counter)


def Extract(lst, r):
	return [item[r] for item in lst]
a = int(input())
r = 0
c = list()
while r < a:
	c.append([char for char in input()])
	r = r + 1
r = 0
s = 0
while r < a:
	m = c[r].count('C')
	n = Extract(c, r).count('C')
	s = s + (m * m - m) / 2 + (n * n - n) / 2
	r = r + 1
print(int(s))


n = int(input())
a = []
b = []
m = 0
ans = 0
for i in range(n):
	s = input()
	for j in range(n):
		b.append(s[j])
	a.append(b[:])
	b.clear()
for m in range(n):
	for i in range(n - 1):
		for j in range(i + 1, n, 1):
			if a[m][i] == a[m][j] == 'C':
				ans += 1
for m in range(n):
	for i in range(n - 1):
		for j in range(i + 1, n, 1):
			if a[i][m] == a[j][m] == 'C':
				ans += 1
print(ans)


n = int(input())
m = []
for _ in range(n):
	m.append(input())
ans = 0
for i in range(n):
	k = m[i].count('C')
	ans += k * (k - 1) // 2
for j in range(n):
	cnt = 0
	for i in range(n):
		if m[i][j] == 'C':
			cnt += 1
	ans += cnt * (cnt - 1) // 2
print(ans)


import math

def nCr(n, r):
	f = math.factorial
	return f(n) / f(r) / f(n - r)
n = int(input())
a = []
b = [0] * n
for i in range(n):
	line = list(input())
	count = line.count('C')
	a.append(count)
	for (k, m) in enumerate(line):
		if m == 'C':
			b[k] += 1
total = 0
for (i, s) in enumerate(a):
	if s > 1:
		total += nCr(s, 2)
for (i, s) in enumerate(b):
	if s > 1:
		total += nCr(s, 2)
print(int(total))


n = int(input())
l = []
x = 0
for i in range(n):
	l.append(input())
for i in range(n):
	c = 0
	for j in range(n):
		if l[i][j] == 'C':
			c += 1
	x += c * (c - 1) // 2
for i in range(n):
	c = 0
	for j in range(n):
		if l[j][i] == 'C':
			c += 1
	x += c * (c - 1) // 2
print(x)


n = int(input())
cols = [0 for _ in range(n)]
rows = [0 for _ in range(n)]
for i in range(n):
	line = input().strip()
	for j in range(len(line)):
		if line[j] == 'C':
			cols[i] += 1
			rows[j] += 1
answ = 0
for i in cols + rows:
	answ += i * (i - 1) // 2
print(answ)


n = int(input())
x = []
y1 = [0 for i in range(n)]
y2 = [0 for i in range(n)]
for i in range(n):
	x.append(list(input()))
for i in range(n):
	for j in range(n):
		if x[i][j] == 'C':
			y1[i] += 1
			y2[j] += 1
ans = 0
for i in range(n):
	if y1[i] > 1:
		ans += y1[i] * (y1[i] - 1) // 2
	if y2[i] > 1:
		ans += y2[i] * (y2[i] - 1) // 2
print(ans)


n = int(input())
s = [input() for i in range(n)]
f = lambda x: x * (x - 1) // 2
ans = 0
for i in range(n):
	cnt1 = s[i].count('C')
	cnt2 = sum((s[j][i] == 'C' for j in range(n)))
	if cnt1 > 1:
		ans += f(cnt1)
	if cnt2 > 1:
		ans += f(cnt2)
print(ans)


import math
n = int(input())
c = [list(input()) for i in range(n)]
rowN = [0] * n
colN = [0] * n
for i in range(n):
	for j in range(n):
		rowN[i] += c[i][j] == 'C'
		colN[i] += c[j][i] == 'C'
sum_ = 0
for i in range(n):
	rr = rowN[i]
	cc = colN[i]
	if rr > 1:
		sum_ += rr * (rr - 1) // 2
	if cc > 1:
		sum_ += cc * (cc - 1) // 2
print(sum_)


n = int(input())
a = []
t = 0
for i in range(n):
	s = input()
	b = []
	z = 0
	for j in s:
		b.append(j)
		if j == 'C':
			z += 1
	t += (z - 1) * z // 2
	a.append(b)
for j in range(n):
	z = 0
	for i in range(n):
		if a[i][j] == 'C':
			z += 1
	t += (z - 1) * z // 2
print(t)


def happy():
	n = int(input())
	cake = [input() for i in range(n)]
	w = 0
	for y in range(n):
		c = cake[y].count('C')
		w += int(c * (c - 1) / 2)
	for x in range(n):
		c = 0
		for y in range(n):
			if cake[y][x] == 'C':
				c += 1
		w += int(c * (c - 1) / 2)
	print(w)
happy()


n = int(input())
s = ''
ans = 0
for i in range(n):
	temp = str(input())
	s = s + temp
	x = temp.count('C')
	if x > 1:
		ans = ans + x * (x - 1) // 2
i = 0
while i < n:
	j = i
	temp = ''
	while j < len(s):
		temp = temp + s[j]
		j = j + n
	x = temp.count('C')
	if x > 1:
		ans = ans + x * (x - 1) // 2
	i = i + 1
print(ans)


def count(matrix):
	global l
	for i in range(len(matrix)):
		sum = 0
		for j in range(len(matrix)):
			if matrix[j][i] == 'C':
				sum += 1
		l.append(sum)
n = int(input())
l = []
inp = []
for i in range(n):
	a = input().strip()
	inp.append(a)
	x = a.count('C')
	l.append(x)
count(inp)
final = 0
for i in l:
	final += i * (i - 1) // 2
print(final)


def C2(x):
	if x <= 1:
		return 0
	return x * (x - 1) // 2
n = int(input())
cake = []
for i in range(n):
	cake.append([c for c in input()])
res = 0
for i in range(n):
	num = 0
	for j in range(n):
		if cake[i][j] == 'C':
			num += 1
	res += C2(num)
for j in range(n):
	num = 0
	for i in range(n):
		if cake[i][j] == 'C':
			num += 1
	res += C2(num)
print(res)


import sys
import math
import bisect

def main():
	n = int(input())
	A = []
	for i in range(n):
		A.append(input())
	row = [0] * n
	col = [0] * n
	for i in range(n):
		for j in range(n):
			if A[i][j] == 'C':
				row[i] += 1
				col[j] += 1
	ans = 0
	for a in row:
		ans += a * (a - 1) // 2
	for a in col:
		ans += a * (a - 1) // 2
	print(ans)
main()


n = int(input())
l = []
ans = 0
for _ in range(n):
	l.append(input())
for k in l:
	c = k.count('C')
	ans += (c ** 2 - c) // 2
for i in range(n):
	for j in range(n):
		if l[j][i] == 'C':
			for k in range(j + 1, n):
				if l[k][i] == 'C':
					ans += 1
print(ans)


n = int(input())
result = 0
L = [0 for i in range(n)]
for i in range(n):
	r = 0
	T = [s for s in input()]
	for j in range(n):
		if T[j] == 'C':
			r += 1
			L[j] += 1
	result += r * (r - 1) // 2
for k in L:
	result += k * (k - 1) // 2
print(result)


read = lambda : map(int, input().split())
n = int(input())
a = [input() for i in range(n)]
f = lambda x: x * (x - 1) // 2
cnt = 0
for i in range(n):
	k1 = a[i].count('C')
	k2 = sum((a[j][i] == 'C' for j in range(n)))
	cnt += f(k1) + f(k2)
print(cnt)


def calc(n):
	x = n * (n - 1)
	x = x // 2
	return x
n = int(input())
mat = []
(row, col) = ([0 for i in range(n)], [0 for i in range(n)])
for i in range(n):
	l = list(map(str, input()))
	mat.append(l)
	x = 0
	for j in range(n):
		if l[j] == 'C':
			col[j] += 1
			x += 1
	row[i] += x
ans = 0
for i in row:
	ans += calc(i)
for i in col:
	ans += calc(i)
print(ans)


l = []
n = int(input())
for i in range(n):
	l.append([0] * n)
for i in range(n):
	for (row, d) in enumerate(input()):
		l[i][row] = d
count = 0
for i in range(n):
	x = 0
	for j in range(n):
		if l[i][j] is 'C':
			x += 1
	x = x * (x - 1) / 2
	count += x
for i in range(n):
	x = 0
	for j in range(n):
		if l[j][i] is 'C':
			x += 1
	x = x * (x - 1) / 2
	count += x
print(int(count))


def nCr(n, r):
	return int(fact(n) / (fact(r) * fact(n - r)))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
n = int(input())
l = []
for _ in range(n):
	x = list(input())
	l.append(x)
ans = 0
for i in range(n):
	h = l[i]
	ans += nCr(h.count('C'), 2)
	v = [l[a][i] for a in range(n)]
	ans += nCr(v.count('C'), 2)
print(ans)


import math
n = int(input())

def nCr(n, r):
	f = math.factorial
	return int(f(n) / (f(r) * f(n - r)))
cake = []
for i in range(n):
	cake.append(input())
happiness = 0
for row in cake:
	choclates = row.count('C')
	if choclates >= 2:
		happiness += nCr(choclates, 2)
for row in zip(*cake):
	choclates = row.count('C')
	if choclates >= 2:
		happiness += nCr(choclates, 2)
print(happiness)


n = int(input())
l = ''
happiness = 0
for _ in range(n):
	l += input()
for i in range(n):
	start = i * n
	end = start + n
	count = l[start:end].count('C')
	happiness += count * (count - 1) / 2
for i in range(n):
	string = ''
	for j in range(i, n * n, n):
		string += l[j]
	count = string.count('C')
	happiness += count * (count - 1) / 2
print(int(happiness))


def split(word):
	return list(word)

def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
n = int(input())
r = dict()
c = 0
a = []
for i in range(n):
	a.append(0)
for i in range(0, n):
	k = 0
	l = input()
	r = split(l)
	p = 0
	for j in r:
		if j == 'C':
			k = k + 1
			a[p] = a[p] + 1
		p = p + 1
	if k == 2:
		c = c + 1
	elif k > 2:
		c = c + nCr(k, 2)
for i in range(0, n):
	if a[i] == 2:
		c = c + 1
	elif a[i] > 2:
		c = c + nCr(a[i], 2)
print(int(c))


def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
a = []
n = int(input())
for i in range(n):
	a.append(input())
ans = 0
for i in range(n):
	aa = 0
	for j in range(n):
		if a[j][i] == 'C':
			aa += 1
	ans += nCr(aa, 2)
ans1 = 0
for i in range(n):
	aa = 0
	for j in range(n):
		if a[i][j] == 'C':
			aa += 1
	ans1 += nCr(aa, 2)
print(ans + ans1)


n = int(input())
l = [list(input()) for i in range(n)]
rows = [0 for i in range(n)]
cols = [0 for i in range(n)]
ans = 0
for i in range(n):
	for j in range(n):
		if l[i][j] == 'C':
			rows[i] += 1
			cols[j] += 1
for i in range(n):
	ans += max(0, rows[i] * (rows[i] - 1) / 2)
	ans += max(0, cols[i] * (cols[i] - 1) / 2)
print(int(ans))


n = int(input())
rows = [0] * n
cols = [0] * n

def fact(num):
	res = 1
	while num > 1:
		res *= num
		num -= 1
	return res

def nC2(count):
	if count < 2:
		return 0
	elif count == 2:
		return 1
	return fact(count) // (2 * fact(count - 2))
for row in range(n):
	for (col, ch) in enumerate(input()):
		if ch == 'C':
			rows[row] += 1
			cols[col] += 1
res = sum((nC2(num) for num in rows)) + sum((nC2(num) for num in cols))
print(res)


p = lambda x: x * (x - 1) // 2
n = int(input())
a = [input() for _ in [0] * n]
r = sum((p(x.count('C')) for x in a))
a = [[a[j][i] for j in range(n)] for i in range(n)]
r += sum((p(x.count('C')) for x in a))
print(r)


n = int(input())
a = []
q = 0
q1 = 0
c = 0
c1 = 0
for i in range(n):
	a.append(list(input()))
for i in range(n):
	q = 0
	for j in range(n):
		if a[i][j] == 'C':
			q += 1
	c = c + q * (q - 1) // 2
for j in range(n):
	q1 = 0
	for i in range(n):
		if a[i][j] == 'C':
			q1 += 1
	c1 = c1 + q1 * (q1 - 1) // 2
print(c + c1)


n = int(input())
a = []
r = 0
v = []
for i in range(n):
	v.append([])
for i in range(n):
	f = list(str(input()))
	a.append(f)
	for j in range(n):
		v[j].append(f[j])
for i in range(n):
	f = a[i].count('C')
	p = v[i].count('C')
	r += f * (f - 1) // 2 + p * (p - 1) // 2
print(r)


t = int(input())
l = []
for _ in range(t):
	h = input()
	h = list(h)
	l.append(h)
g = len(l[0])
count = 0
for i in range(t):
	c = 0
	a = 1
	for j in range(g):
		if l[i][j] == 'C':
			c += 1
	count += c * (c - 1) // 2
for i in range(t):
	c = 0
	a = 1
	for j in range(g):
		if l[j][i] == 'C':
			c += 1
	count += c * (c - 1) // 2
print(count)


from itertools import product, chain
n = int(input())
cake = [list(input()) for _ in range(n)]
(choc_row, choc_col) = ([0] * n, [0] * n)
for (r, c) in product(range(n), repeat=2):
	if cake[r][c] == 'C':
		choc_row[r] += 1
		choc_col[c] += 1
ans = sum((c * (c - 1) // 2 for c in chain(choc_row, choc_col)))
print(ans)


x = int(input())
rc = 0
cc = []
ccs = 0
pairs = 0
v = 0
for i in range(x):
	cc.append(0)
for i in range(x):
	y = input()
	ya = []
	for w in range(x):
		ya.append(y[w])
	for f in range(x):
		if ya[f] == 'C':
			rc += 1
			cc[f] += 1
	if rc == 2:
		pairs += 1
		rc -= 2
	if rc > 2:
		for m in range(rc):
			pairs += m
		rc = 0
	if rc == 1:
		rc = 0
for i in range(x):
	cv = cc[i]
	if cv == 2:
		cc[i] -= 2
		pairs += 1
		i -= 1
	if cv > 2:
		for k in range(cv):
			pairs += k
print(pairs)


def binomialCoefficient(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res
n = int(input())
cake = []
s = 0
for _ in range(n):
	cake.append(list(input()))
for i in range(n):
	k = cake[i].count('C')
	if k == 1 or k == 0:
		continue
	s += binomialCoefficient(k, 2)
for j in list(zip(*cake)):
	_k = j.count('C')
	if _k == 1 or _k == 0:
		continue
	s += binomialCoefficient(_k, 2)
print(int(s))


from collections import defaultdict
import math
n = int(input())
Row = defaultdict(int)
Column = defaultdict(int)
for i in range(n):
	x = list(input())
	Row[i] = x.count('C')
	for index in range(0, len(x)):
		if x[index] == 'C':
			Column[index] += 1
fact = 0
for i in Row.keys():
	fact += int(math.factorial(Row[i]) / (math.factorial(abs(Row[i] - 2)) * math.factorial(2)))
for i in Column.keys():
	fact += int(math.factorial(Column[i]) / (math.factorial(abs(Column[i] - 2)) * math.factorial(2)))
print(str(fact))


import sys
input = sys.stdin.readline
n = int(input())
(row, col) = ([0] * n, [0] * n)
for r in range(n):
	s = input().rstrip()
	for (c, v) in enumerate(s):
		if v == 'C':
			row[r] += 1
			col[c] += 1
res = 0
for i in range(n):
	if row[i] > 1:
		res += row[i] * (row[i] - 1) // 2
	if col[i] > 1:
		res += col[i] * (col[i] - 1) // 2
print(res)


n = int(input())
g = [None] * n
cnt = 0
for i in range(n):
	g[i] = input()
for i in range(n):
	c_cnt = 0
	r_cnt = 0
	for j in range(n):
		if g[i][j] == 'C':
			r_cnt += 1
		if g[j][i] == 'C':
			c_cnt += 1
	cnt += r_cnt * (r_cnt - 1) // 2 if r_cnt > 1 else 0
	cnt += c_cnt * (c_cnt - 1) // 2 if c_cnt > 1 else 0
print(cnt)


def solution(l1, n):
	i = 0
	pairs = 0
	while i < len(l1):
		j = 0
		count = 0
		while j < len(l1[i]):
			if l1[i][j] == 'C':
				count += 1
			j += 1
		pairs += int(count * (count - 1) / 2)
		i += 1
	i = 0
	while i < len(l1):
		j = 0
		count = 0
		while j < len(l1[i]):
			if l1[j][i] == 'C':
				count += 1
			j += 1
		pairs += int(count * (count - 1) / 2)
		i += 1
	return pairs

def answer():
	n = int(input())
	l1 = []
	while n:
		l1.append(list(input()))
		n -= 1
	print(solution(l1, n))
answer()


n = int(input())
mass = []
for i in range(n):
	mass.append(input())
rows = [0] * n
columns = [0] * n
for i in range(n):
	rows[i] = mass[i].count('C')
for i in range(n):
	for j in range(n):
		if mass[i][j] == 'C':
			columns[j] += 1
count = 0
for elem in rows:
	count += elem * (elem - 1) // 2
for elem in columns:
	count += elem * (elem - 1) // 2
print(count)


n = int(input())
pole = []
ans = 0
for i in range(n):
	s = input()
	h = 0
	for j in s:
		if j == 'C':
			h += 1
	ans += h * (h - 1) // 2
	pole.append(s)
for i in range(n):
	h = 0
	for j in range(n):
		if pole[j][i] == 'C':
			h += 1
	ans += h * (h - 1) // 2
print(ans)


n = int(input())
s = []
ans = 0
for _ in range(n):
	line = input()
	s.append(line)
	m = line.count('C')
	ans += m * (m - 1) // 2
for i in range(n):
	m = 0
	for j in range(n):
		if s[j][i] == 'C':
			m += 1
	ans += m * (m - 1) // 2
print(ans)


n = int(input())
x = []
v = []
u = []
for i in range(n):
	x.append(list(input()))
for i in range(n):
	k = 0
	for j in range(n):
		k += x[i][j] == 'C'
	v.append(k)
for j in range(n):
	k = 0
	for i in range(n):
		k += x[i][j] == 'C'
	u.append(k)
r = 0
for i in u:
	r += i * (i - 1) // 2
for i in v:
	r += i * (i - 1) // 2
print(r)


import math

def solve():
	n = int(input())
	pairs = []
	pairs_count = 0
	for i in range(n):
		input_str = input()
		for j in range(n):
			if input_str[j] == 'C':
				pairs.append((i + 1, j + 1))
	for i in range(n):
		count_r = 0
		count_c = 0
		for pair in pairs:
			if i + 1 == pair[0]:
				count_r += 1
			if i + 1 == pair[1]:
				count_c += 1
		if count_r >= 2:
			pairs_count += ncr(count_r, 2)
		if count_c >= 2:
			pairs_count += ncr(count_c, 2)
	print(pairs_count)

def ncr(n, r):
	return int(n * (n - 1) / math.factorial(r))
solve()


n = int(input())
a = list()
for i in range(n):
	a.append(input())
k = h = 0
for i in range(n):
	for j in a[i]:
		if j == 'C':
			h += 1
	k += round(h * (h - 1) / 2)
	h = 0
for i in range(n):
	for j in range(n):
		if a[j][i] == 'C':
			h += 1
	k += round(h * (h - 1) / 2)
	h = 0
print(k)


n = int(input())
a = []
t = 0
for i in range(n):
	a.append(list(input()))
	x = a[-1].count('C')
	t += x * (x - 1) // 2
for i in zip(*a):
	x = list(i).count('C')
	t += x * (x - 1) // 2
print(t)


n = int(input())
c = [[*input()] for _ in range(n)]
ans = 0
for i in c:
	t = i.count('C')
	ans += t * (t - 1) // 2
for i in [*zip(*c)]:
	t = i.count('C')
	ans += t * (t - 1) // 2
print(ans)


def countc(m):
	count = 0
	for i in range(len(m)):
		if m[i] == 'C':
			count += 1
	return count / 2

def ncr(count):
	if count <= 0:
		return 0
	return count * (count - 1) / 2
n = int(input())
total = 0
happy = 0
row = []
col = []
for j in range(n):
	y = input()
	row.append(y)
	total += countc(row[j])
	happy += int(ncr(2 * countc(row[j])))
for m in range(n):
	for k in range(n):
		col.append([])
		col[m].append(row[k][m])
	total += countc(col[m])
	happy += int(ncr(2 * countc(col[m])))
print(happy)


n = int(input())
k = []
ans = 0
for i in range(n):
	k.append(input())
z = tuple(zip(*k))
for i in range(n):
	x = k[i].count('C')
	y = z[i].count('C')
	ans += x * (x - 1) // 2 + y * (y - 1) // 2
print(ans)


import math
n = int(input())
c = [input() for i in range(n)]
ans = 0
for i in range(n):
	k = 0
	for j in range(n):
		if c[i][j] == 'C':
			k += 1
	if k > 1:
		ans += math.factorial(k) / (math.factorial(2) * math.factorial(k - 2))
for j in range(n):
	k = 0
	for i in range(n):
		if c[i][j] == 'C':
			k += 1
	if k > 1:
		ans += math.factorial(k) / (math.factorial(2) * math.factorial(k - 2))
print(int(ans))


from itertools import chain
count_pairs = lambda n: n * (n - 1) // 2
cake = [input() for _ in range(int(input()))]
print(sum((count_pairs(line.count('C')) for line in chain(cake, zip(*cake)))))


n = int(input())
rows = [0] * n
cols = [0] * n
for r in range(n):
	s = input()
	for c in range(n):
		if s[c] == 'C':
			rows[r] += 1
			cols[c] += 1
ans = 0
for i in range(n):
	ans += rows[i] * (rows[i] - 1) // 2
	ans += cols[i] * (cols[i] - 1) // 2
print(ans)


n = int(input())
l = []
z = 0
for i in range(n):
	count = 0
	l.append(input())
	for y in range(n):
		if l[i][y] == 'C':
			count += 1
	z += count * (count - 1) / 2
for i in range(n):
	count = 0
	for y in range(n):
		if l[y][i] == 'C':
			count += 1
	z += count * (count - 1) / 2
z = int(z)
print(z)


def combin2(n):
	x = 1
	y = 1
	i = n - 1
	while i <= n:
		x = x * i // y
		y += 1
		i += 1
	return x

def main():
	n = int(input())
	cake = []
	happiness = 0
	for _ in range(n):
		s = input()
		cake += [s]
		happiness += combin2(s.count('C'))
	transposed = [''.join([cake[j][i] for j in range(n)]) for i in range(n)]
	for i in range(n):
		happiness += combin2(transposed[i].count('C'))
	print(happiness)
main()


from math import factorial as f
n = int(input())
if n == 1:
	t = input()
	if t == 'C':
		print(1)
	else:
		print(0)
else:
	hapi = 0
	ck = []
	for i in range(n):
		t = input()
		c = t.count('C')
		if c > 1:
			hapi += int(c * (c - 1) / 2)
		ck += [t]
	vapi = 0
	for j in range(n):
		c = 0
		for x in range(n):
			if ck[x][j] == 'C':
				c += 1
		if c > 1:
			vapi += int(c * (c - 1) / 2)
	print(hapi + vapi)


from math import factorial as f
n = int(input())
t = 0
r = [input() for _ in range(n)]
for x in r:
	x1 = x.count('C')
	if x1 > 1:
		t += f(x1) // (2 * f(x1 - 2))
for y in range(n):
	c = [r[z][y] for z in range(n)]
	y1 = c.count('C')
	if y1 > 1:
		t += f(y1) // (2 * f(y1 - 2))
print(t)


from math import factorial
n = int(input())
cake = [row for col in range(n) for row in input()]
(fr, to) = (0, n)
total = 0
for i in range(n):
	slice = cake[fr:to]
	cnt = slice.count('C')
	total += cnt * (cnt - 1) // 2
	fr = to
	to += n
fr = 0
to = n
for i in range(n):
	slice = cake[fr::n]
	cnt = slice.count('C')
	total += cnt * (cnt - 1) // 2
	fr += 1
print(total)


def binom(n, k):
	ans = 1
	for i in range(k):
		ans = ans * (n - i) // (i + 1)
	return ans
n = int(input())
cake = [input() for row in range(n)]
pairs = sum([binom(row.count('C'), 2) for row in cake])
pairs += sum([binom(col.count('C'), 2) for col in [[row[i] for row in cake] for i in range(n)]])
print(pairs)


n = int(input())
(a, b, c, d) = (0, 0, 0, 0)
s = []
for i in range(n):
	h = input()
	s.append(h)
for i in range(n):
	for j in range(n):
		if s[j][i] == 'C':
			c += 1
		if s[i][j] == 'C':
			d += 1
	a += sum(range(c))
	b += sum(range(d))
	(c, d) = (0, 0)
print(a + b)


n = int(input())
vert = [0] * n
ttl = 0
for i in range(n):
	s = input()
	c = s.count('C')
	ttl += c * (c - 1) // 2
	for i in range(n):
		if s[i] == 'C':
			vert[i] += 1
print(ttl + sum((i * (i - 1) // 2 for i in vert)))


n = int(input())
cake = {}
for i in range(n):
	row = input()
	for j in range(n):
		cake[i, j] = row[j]
h = 0
for i in range(n):
	for j in range(n):
		for k in range(j + 1, n):
			h += 1 if cake[i, j] == 'C' and cake[i, k] == 'C' else 0
for j in range(n):
	for i in range(n):
		for k in range(i + 1, n):
			h += 1 if cake[i, j] == 'C' and cake[k, j] == 'C' else 0
print(h)


n = int(input())
G = []
for i in range(n):
	G.append(list(input()))
row_cnt = [0 for r in range(n)]
col_cnt = [0 for c in range(n)]
for r in range(n):
	for c in range(n):
		if G[r][c] == 'C':
			row_cnt[r] += 1
			col_cnt[c] += 1
pairs = 0
for i in range(n):
	pairs += int(row_cnt[i] * (row_cnt[i] - 1) / 2)
	pairs += int(col_cnt[i] * (col_cnt[i] - 1) / 2)
print(pairs)


import math

def combination(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
col = [0 for i in range(n)]
row = [0 for i in range(n)]
res = 0
for i in range(n):
	s = input()
	for j in range(len(s)):
		if s[j] == 'C':
			col[j] = col[j] + 1
			row[i] = row[i] + 1
for i in range(n):
	if row[i] > 1:
		res = res + combination(row[i], 2)
for i in range(n):
	if col[i] > 1:
		res = res + combination(col[i], 2)
print(res)


n = int(input())
l = []
res = 0
for i in range(n):
	l.append(list(input()))
y = list(zip(*l))
for i in range(n):
	x = l[i].count('C')
	b = y[i].count('C')
	res += (x - 1) * x // 2 + (b - 1) * b // 2
print(res)


n = int(input())
mat = [input() for i in range(n)]
row = {}
col = {}
for i in range(len(mat)):
	for j in range(len(mat[0])):
		if mat[i][j] == 'C':
			row[i] = row.get(i, 0) + 1
			col[j] = col.get(j, 0) + 1
res = 0
for v in row.values():
	res += v * (v - 1) // 2
for v in col.values():
	res += v * (v - 1) // 2
print(res)


def factorial(n):
	product = 1
	for i in range(1, n + 1):
		product *= i
	return product

def calculate_permutations(n_c):
	return factorial(n_c) // factorial(n_c - 2) // 2

def main_function():
	output_list = [input() for i in range(int(input()))]
	count = 0
	for i in output_list:
		intermediate_count = 0
		for j in i:
			if j == 'C':
				intermediate_count += 1
		count += calculate_permutations(intermediate_count)
	for k in range(len(output_list[0])):
		intermediate_count = 0
		for h in output_list:
			if h[k] == 'C':
				intermediate_count += 1
		count += calculate_permutations(intermediate_count)
	return count
print(main_function())


a = [0] * 100
b = [0] * 100
n = int(input())
for i in range(n):
	lis = input()
	for k in range(n):
		if lis[k] == 'C':
			a[i] += 1
			b[k] += 1
counter = 0
for _ in a:
	counter += _ * (_ - 1) // 2
for _ in b:
	counter += _ * (_ - 1) // 2
print(counter)


t = int(input())
k2 = [0] * t
s = 0
s1 = 0
for i in range(t):
	k = list(map(str, input()))
	s = k.count('C')
	if s - 1 > 0:
		s1 += (s - 1) * s // 2
	for j in range(t):
		if k[j] == 'C':
			k2[j] += 1
for i in range(t):
	if k2[i] - 1 > 0:
		s1 += (k2[i] - 1) * k2[i] // 2
print(s1)


n = int(input())
l = [''] * n
ans = int(0)
for i in range(n):
	s = input()
	m = s.count('C')
	ans += m * (m - 1) // 2
	for j in range(n):
		l[j] += s[j]
for j in range(n):
	m = l[j].count('C')
	ans += m * (m - 1) // 2
print(ans)


def factor(n):
	res = 1
	for i in range(1, n + 1):
		res *= i
	return res
n = int(input())
p = []
res = 0
for i in range(n):
	p.append(list(input()))
	c = p[i].count('C')
	res += factor(c) / (2 * factor(c - 2)) if c > 1 else 0
for col in list(zip(*p)):
	c = col.count('C')
	res += factor(c) / (2 * factor(c - 2)) if c > 1 else 0
print(int(res))


n = int(input())
M = [input() for i in range(n)]
k = 0
ma = 0
for i in range(n):
	k = 0
	for j in range(n):
		if M[i][j] == 'C':
			k = k + 1
	ma = ma + (1 + (k - 1)) / 2 * (k - 1)
for i in range(n):
	k = 0
	for j in range(n):
		if M[j][i] == 'C':
			k = k + 1
	ma = ma + (1 + (k - 1)) / 2 * (k - 1)
print(int(ma))


a = []
Count = 0
n = int(input())
column = [0 for i in range(n)]
for i in range(n):
	a.append(input())
Answer = 0
for i in range(n):
	for j in range(n):
		if a[i][j] == 'C':
			column[j] += 1
			Count += 1
	if Count >= 2:
		Answer += Count * (Count - 1) // 2
	Count = 0
for i in column:
	if i >= 2:
		Answer += i * (i - 1) // 2
print(Answer)


n = int(input())
s = [input() for i in range(n)]
r = 0
for i in range(n):
	x = y = 0
	for j in range(n):
		x += s[i][j] == 'C'
		y += s[j][i] == 'C'
	r += x * (x - 1) // 2 + y * (y - 1) // 2
print(r)


def C(k):
	return k * (k - 1) // 2
n = int(input())
r = [0 for i in range(n)]
c = [0 for i in range(n)]
for i in range(n):
	s = input()
	for j in range(n):
		if s[j] == 'C':
			r[i] += 1
			c[j] += 1
ans = 0
for i in range(n):
	ans += C(r[i]) + C(c[i])
print(ans)


p = lambda x: x * (x - 1) // 2
(n, r) = (int(input()), 0)
a = [input() for _ in [0] * n]
for _ in [0, 0]:
	r += sum((p(x.count('C')) for x in a))
	a = zip(*a)
print(r)


import collections
N = int(input())
grid = [input() for _ in range(N)]
cols = collections.Counter()
rows = collections.Counter()
for (i, r) in enumerate(grid):
	for (j, c) in enumerate(r):
		if c == 'C':
			cols[j] += 1
			rows[i] += 1
res = 0
for (_, c) in cols.most_common() + rows.most_common():
	res += c * (c - 1)
print(res // 2)


cc = []
result = 0
for i in range(int(input(''))):
	cc.append(list(input('')))

def getpairs(pairs):
	return pairs * (pairs - 1) / 2

def getcol(colnum):
	temp = []
	for i in range(len(cc)):
		temp.append(cc[i][colnum])
	return temp
for i in range(len(cc)):
	result = result + getpairs(cc[i].count('C'))
for i in range(len(cc)):
	result = result + getpairs(getcol(i).count('C'))
print(int(result))


def solve(n, c):
	s = 0
	for i in range(n):
		k = c[i].count('C')
		s += (k ** 2 - k) // 2
	for j in range(n):
		t = 0
		for i in range(n):
			if c[i][j] == 'C':
				t += 1
		s += (t ** 2 - t) // 2
	return s

def main():
	n = int(input())
	c = []
	for i in range(n):
		c.append(input())
	print(solve(n, c))
main()


n = int(input())
a = []
res = 0
for i in range(n):
	inp = list(input())
	a.append(inp)
for i in a:
	res = res + i.count('C') * (i.count('C') - 1) / 2
tra = [*zip(*a)]
for i in tra:
	res = res + i.count('C') * (i.count('C') - 1) / 2
print(int(res))


def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res
dict = {}
n = int(input())
li = []
res = 0
y = n
for x in range(n):
	dict[x] = 0
while n > 0:
	li.append(input())
	n -= 1
k = 1
for i in li:
	if i.count('C') >= 2:
		res += nCr(i.count('C'), 2)
	for j in range(y):
		if i[j] == 'C':
			dict[j] += 1
for s in dict:
	if dict.get(s) >= 2:
		res += nCr(dict.get(s), 2)
print(int(res))


import math

def ncr(n, r):
	if n == 1:
		return 0
	if n == 0:
		return 0
	f = math.factorial
	return f(n) / (f(r) * f(n - r))
n = int(input())

def main():
	count = 0
	t_cells = []
	for _ in range(n):
		cell = str(input())
		t_cells.append(list(cell))
	for j in range(0, n):
		pair = 0
		pair_1 = 0
		for i in range(0, n):
			if t_cells[j][i] == 'C':
				pair += 1
			if t_cells[i][j] == 'C':
				pair_1 += 1
		count += ncr(pair, 2) + ncr(pair_1, 2)
	print(int(count))
main()


n = int(input())
l = list()
for i in range(n):
	l.append(input())
m = a = 0
for i in range(n):
	for j in l[i]:
		if j == 'C':
			a += 1
	m += round(a * (a - 1) / 2)
	a = 0
for i in range(n):
	for j in range(n):
		if l[j][i] == 'C':
			a += 1
	m += round(a * (a - 1) / 2)
	a = 0
print(m)


def fact(x):
	result = 1
	for i in range(x, 1, -1):
		result *= i
	return result
n = int(input().strip())
l = []
for i in range(n):
	l.append(list(input().strip()))
result = 0
for i in range(n):
	rowcount = 0
	colcount = 0
	for j in range(n):
		if l[i][j] == 'C':
			rowcount += 1
		if l[j][i] == 'C':
			colcount += 1
	if rowcount >= 2:
		result += fact(rowcount) / (2 * fact(rowcount - 2))
	if colcount >= 2:
		result += fact(colcount) / (2 * fact(colcount - 2))
print(int(result))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def cmb(n, r):
	if n - r < r:
		r = n - r
	if r == 0:
		return 1
	if r == 1:
		return n
	numerator = [n - r + k + 1 for k in range(r)]
	denominator = [k + 1 for k in range(r)]
	for p in range(2, r + 1):
		pivot = denominator[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p - 1, r, p):
				numerator[k - offset] /= pivot
				denominator[k] /= pivot
	result = 1
	for k in range(r):
		if numerator[k] > 1:
			result *= int(numerator[k])
	return result

def main():
	n = I()
	l = [S() for _ in range(n)]
	a = []
	for i in range(n):
		cnt = 0
		for j in range(n):
			if l[i][j] == 'C':
				cnt += 1
		if cnt >= 2:
			a.append(cnt)
	for i in range(n):
		cnt = 0
		for j in range(n):
			if l[j][i] == 'C':
				cnt += 1
		if cnt >= 2:
			a.append(cnt)
	ans = 0
	for x in a:
		ans += cmb(x, 2)
	return ans
print(main())


n = int(input())
mat = []
rowc = 0
for i in range(n):
	l = list(input())
	mat.append(l)
	z = l.count('C')
	rowc += z * (z - 1) // 2
colc = 0
for j in range(n):
	z = 0
	for i in range(n):
		if mat[i][j] == 'C':
			z += 1
	colc += z * (z - 1) // 2
print(rowc + colc)


n = int(input())
cake = [input() for i in range(n)]
cake2 = [[0] * n for i in range(n)]
cakex = [0] * n
cakey = [0] * n
for i in range(n):
	for j in range(n):
		if cake[i][j] == 'C':
			cake2[i][j] = 1
			cakex[i] += 1
			cakey[j] += 1
num = 0
for i in range(n):
	num += cakex[i] * (cakex[i] - 1) // 2
	num += cakey[i] * (cakey[i] - 1) // 2
print(num)


a = int(input())
c = [[] for i in range(a)]
h = 0
for i in range(a):
	b = input()
	for j in range(a):
		c[j].append(b[j])
	for k in range(b.count('C')):
		h += k
for i in range(a):
	for j in range(c[i].count('C')):
		h += j
print(h)


n = int(input())
d = []
for i in range(n):
	c = list(input())
	d.append(c)
tot_row = 0
for i in range(len(d)):
	m = d[i].count('C')
	tot_row += m * (m - 1) // 2
w = list(zip(*d))
for i in range(len(w)):
	w[i] = list(w[i])
tot_col = 0
for i in range(len(w)):
	m = w[i].count('C')
	tot_col += m * (m - 1) // 2
print(tot_row + tot_col)


a = int(input())
k = 0
S = []
for i in range(a):
	S.append(input())
	L = S[i].count('C')
	if L > 1:
		if L == 2:
			k += 1
		else:
			for j in range(1, L):
				k += j
for i in range(a):
	L = 0
	for j in range(a):
		if S[j][i] == 'C':
			L += 1
	if L > 1:
		if L == 2:
			k += 1
		else:
			for j in range(1, L):
				k += j
print(k)


n = int(input())
m = [input() for i in range(n)]
rows = [m[i].count('C') for i in range(n)]
columns = [0] * n
for j in range(n):
	for i in range(n):
		if m[i][j] == 'C':
			columns[j] += 1
ans = 0
for i in range(n):
	ans += (1 + (rows[i] - 1)) / 2 * (rows[i] - 1)
	ans += (1 + (columns[i] - 1)) / 2 * (columns[i] - 1)
print(int(ans))


import math as m

def C(r, n):
	return m.factorial(n) // (m.factorial(r) * m.factorial(max(0, n - r)))
n = int(input())
a = []
res = 0
for i in range(n):
	t = input()
	a.append(t)
	c = 0
	for j in range(n):
		if t[j] == 'C':
			c += 1
	res += C(2, c)
for i in range(n):
	c = 0
	for j in range(n):
		if a[j][i] == 'C':
			c += 1
	res += C(2, c)
print(res)


n = int(input())
a = []
sum1 = 0
store = [0] * n
for i in range(n):
	temp = list(input())
	a.append(temp)
for i in range(n):
	row = 0
	for j in range(n):
		if a[i][j] == 'C':
			row += 1
			store[j] += 1
	sum1 += row * (row - 1) // 2
for i in range(n):
	sum1 += store[i] * (store[i] - 1) // 2
print(sum1)


n = int(input())
r = [0 for i in range(n)]
c = [0 for i in range(n)]
for i in range(n):
	s = str(input())
	for j in range(n):
		if s[j] == 'C':
			r[i] += 1
			c[j] += 1
an = 0
for i in r:
	an += i * (i - 1) // 2
for i in c:
	an += i * (i - 1) // 2
print(an)


n = int(input())
matrix = []
for _ in range(n):
	matrix.append([i for i in input()])
level_of_happiness = 0
for row in matrix:
	quantity = row.count('C')
	level_of_happiness += (quantity - 1) * (quantity / 2)
for column in range(n):
	amount_of_chocolate = 0
	for row in range(n):
		amount_of_chocolate += 1 if matrix[row][column] == 'C' else 0
	level_of_happiness += (amount_of_chocolate - 1) * (amount_of_chocolate / 2)
print(int(level_of_happiness))


t = int(input())
l = []
for i in range(t):
	l.append(input())
row = 0
for i in range(t):
	a = l[i].count('C')
	row = row + a * (a - 1) // 2
col = 0
for i in range(t):
	con = 0
	for j in range(t):
		if l[j][i] == 'C':
			con = con + 1
	col = col + con * (con - 1) // 2
print(row + col)


import math as m
(v, s) = ([], 0)
n = int(input())
for _ in range(n):
	a = input()
	q = a.count('C')
	if q >= 2:
		s += int(m.factorial(q) / (m.factorial(2) * m.factorial(q - 2)))
	v.append(a)
for i in range(n):
	z = ''
	for j in range(n):
		z += v[j][i]
		w = z.count('C')
	if w >= 2:
		s += int(m.factorial(w) / (m.factorial(2) * m.factorial(w - 2)))
print(s)


from math import factorial

def nCr(n, r):
	return int(factorial(n) / (factorial(r) * factorial(n - r)))
count = 0
a = int(input())
b = []
for x in range(a):
	b.append(list(input()))
for x in range(a):
	c = b[x].count('C')
	if c >= 2:
		count += nCr(c, 2)
for x in range(a):
	d = 0
	for i in range(a):
		if b[i][x] == 'C':
			d += 1
	if d >= 2:
		count += nCr(d, 2)
print(count)


a = []
b = []
for _ in range(int(input())):
	a.append(list(input()))
for i in range(len(a)):
	p = 0
	b.append(a[i].count('C'))
	for t in range(len(a)):
		if a[t][i] == 'C':
			p += 1
	b.append(p)
print(sum([i * (i - 1) // 2 for i in b]))


n = int(input())
mat = []
count = 0
for i in range(n):
	mat.append(input())
for i in range(n):
	c = 0
	for j in range(n):
		if mat[i][j] == 'C':
			c += 1
	if c > 1:
		count += c * (c - 1) // 2
for i in range(n):
	c = 0
	for j in range(n):
		if mat[j][i] == 'C':
			c += 1
	if c > 1:
		count += c * (c - 1) // 2
print(count)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
ABCD = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = [''] * n
ans = 0
for i in range(n):
	s = input()
	c = s.count('C')
	if c > 1:
		ans += c * (c - 1) // 2
	for i in range(n):
		l[i] += s[i]
for i in l:
	c = i.count('C')
	if c > 1:
		ans += c * (c - 1) // 2
print(ans)


n = int(input())
s = []
for i in range(n):
	s.append(input())
answ = 0
for i in range(n):
	for j in range(n):
		if s[i][j] != 'C':
			continue
		for i1 in range(i + 1, n):
			if s[i1][j] == 'C':
				answ += 1
		for j1 in range(j + 1, n):
			if s[i][j1] == 'C':
				answ += 1
print(answ)


n = int(input())
cake = []
ans = 0
for i in range(n):
	layers = input()
	tmp = (layers.count('C') - 1) * layers.count('C') // 2
	ans += tmp
	x = list(layers)
	cake.append(x)
cake = list(zip(*cake))
for i in range(n):
	tmp = cake[i].count('C')
	ans += (tmp - 1) * tmp // 2
print(ans)


import math
cache = {0: 0, 1: 0, 2: 1, 3: 3, 4: 6}
fac = {0: 0, 1: 1, 2: 2, 3: 6, 4: 24}

def f(n):
	fun = math.factorial
	if n in fac:
		return fac[n]
	a = fun(n)
	fac[n] = a
	return fun(n)

def nCr(n, r):
	if n in cache:
		return cache[n]
	a = f(n) / f(r) / f(n - r)
	cache[n] = a
	return a

def readList():
	l = ''
	while not l:
		try:
			l = input()
		except:
			pass
	return [char for char in l]
n = int(input())
cake = [readList() for _ in range(n)]
rows = [0] * n
cols = [0] * n
for i in range(n):
	for j in range(n):
		if cake[i][j] == 'C':
			rows[i] += 1
			cols[j] += 1
ans = 0
for row in rows:
	ans += nCr(row, 2)
for col in cols:
	ans += nCr(col, 2)
print(int(ans))


n = int(input())
lista = []
for x in range(n):
	l = input()
	lista.append(l)
total = 0
for x in range(n):
	elementol = 0
	elementoc = 0
	for y in lista[x]:
		if y == 'C':
			elementol += 1
	subl = elementol * (elementol - 1) // 2
	total += subl
	for z in range(n):
		if lista[z][x] == 'C':
			elementoc += 1
	subc = elementoc * (elementoc - 1) // 2
	total += subc
print(total)


import math
size = int(input())
matrix = []

def ncr(x):
	if x >= 2:
		y = math.factorial(x)
		y = y / (math.factorial(x - 2) * 2)
		return y
	else:
		return 0
for i in range(0, size):
	array = list(str(input()))
	matrix.append(array)
rows = 0
cols = 0
for i in range(0, size):
	buffer = 0
	for j in range(0, size):
		if matrix[i][j] == 'C':
			buffer += 1
	y = ncr(buffer)
	rows += y
for i in range(0, size):
	buffer = 0
	for j in range(0, size):
		if matrix[j][i] == 'C':
			buffer += 1
	y = ncr(buffer)
	cols += y
print(int(cols) + int(rows))


n = int(input())
a = list((list(map(str, input())) for i in range(n)))
count = 0
for i in range(n):
	for j in range(n):
		if a[i][j] == 'C':
			for k in range(j + 1, n):
				if a[i][j] == a[i][k]:
					count += 1
			for d in range(i + 1, n):
				if a[i][j] == a[d][j]:
					count += 1
			a[i][j] = '.'
print(count)


from functools import lru_cache
side_length = int(input())
board = []
for row_idx in range(side_length):
	row = [cell == 'C' for cell in input()]
	board.append(row)

@lru_cache()
def factorial(n):
	if n == 0:
		return 1
	else:
		return n * factorial(n - 1)

def num_combinations(n, r):
	if r > n:
		return 0
	return factorial(n) / (factorial(r) * factorial(n - r))
n = side_length
realsum = 0
for i in range(n):
	sum1 = 0
	sum2 = 0
	for j in range(n):
		sum1 += int(board[i][j])
		sum2 += int(board[j][i])
	realsum += num_combinations(sum1, 2) + num_combinations(sum2, 2)
print(int(realsum))


n = int(input())
f = []
for i in range(n):
	f.append([ch for ch in input()])
result = 0
for i in range(n):
	s1 = ''
	s2 = ''
	for j in range(n):
		s1 += f[i][j]
		s2 += f[j][i]
	c1 = s1.count('C')
	c2 = s2.count('C')
	result += c1 * (c1 - 1) // 2
	result += c2 * (c2 - 1) // 2
print(result)


n = int(input())
a = []
t = 0
for i in range(n):
	a.append(input())
for i in range(n):
	z = a[i].count('C')
	t += z * (z - 1) / 2
for i in range(n):
	m = 0
	for j in range(n):
		if a[j][i] == 'C':
			m += 1
	t += m * (m - 1) / 2
t = format(t, '.0f')
print(t)


n = int(input())
v = []
for i in range(n):
	v.append(input())
total = 0

def factorial(n):
	total = 1
	for x in range(2, n + 1):
		total *= x
	return total
for i in range(n):
	count = 0
	for j in range(n):
		if v[i][j] == 'C':
			count += 1
	if count > 1:
		total += factorial(count) / (factorial(2) * factorial(count - 2))
for i in range(n):
	count = 0
	for j in range(n):
		if v[j][i] == 'C':
			count += 1
	if count > 1:
		total += factorial(count) / (factorial(2) * factorial(count - 2))
print(int(total))


n = int(input())
l = [input() for i in range(n)]
total = 0
l1 = []
for i in range(n):
	s = ''
	for j in range(n):
		s += l[j][i]
	l1.append(s)
for i in range(len(l)):
	a = l[i].count('C')
	b = l1[i].count('C')
	if a >= 2:
		if a == 2:
			total += 1
		else:
			total += (a - 1) * a // 2
	if b >= 2:
		if b == 2:
			total += 1
		else:
			total += (b - 1) * b // 2
print(total)


n = int(input())
a = [list(input()) for i in range(n)]
ans = 0
for i in range(len(a)):
	row = 0
	column = 0
	for j in range(len(a)):
		if a[i][j] == 'C':
			row += 1
		if a[j][i] == 'C':
			column += 1
	ans += 1 + 2 * (row - 1 - 1) + (row - 1 - 1) * (row - 2 - 1) // 2
	ans += 1 + 2 * (column - 1 - 1) + (column - 1 - 1) * (column - 2 - 1) // 2
print(ans)


N = int(input())
grid = [input() for _ in range(N)]
rows = [0 for _ in range(N)]
cols = [0 for _ in range(N)]
for i in range(N):
	for j in range(N):
		if grid[i][j] == 'C':
			rows[i] += 1
			cols[j] += 1

def blah(n):
	return n * (n - 1) // 2
total = sum(map(blah, rows)) + sum(map(blah, cols))
print(total)


n = int(input())
arr = ['' for i in range(n)]
cnt = 0
for i in range(n):
	s = input()
	for j in range(n):
		arr[j] += s[j]
	a = s.count('C')
	b = [i for i in range(1, a)]
	cnt += sum(b)
for i in arr:
	a = i.count('C')
	b = [i for i in range(1, a)]
	cnt += sum(b)
print(cnt)


import unittest
import sys

class Cake:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n] = map(int, uinput().split())
		(l, s) = (self.n, self.n)
		inp = list(''.join((uinput() for i in range(l))))
		self.numm = [[inp[i] == 'C' for i in range(j, l * s, s)] for j in range(s)]
		self.numr = []
		for i in range(self.n):
			s = 0
			for j in range(self.n):
				s += self.numm[j][i]
			self.numr.append(s * (s - 1) // 2)
		self.numc = []
		for i in range(self.n):
			s = 0
			for j in range(self.n):
				s += self.numm[i][j]
			self.numc.append(s * (s - 1) // 2)

	def calculate(self):
		result = sum(self.numc) + sum(self.numr)
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '3\n.CC\nC..\nC.C'
		d = Cake(test)
		self.assertEqual(d.n, 3)
		self.assertEqual(d.numm, [[0, 1, 1], [1, 0, 0], [1, 0, 1]])
		self.assertEqual(d.numr, [1, 0, 1])
		self.assertEqual(d.numc, [1, 0, 1])
		self.assertEqual(Cake(test).calculate(), '4')
		test = '4\nCC..\nC..C\n.CC.\n.CC.'
		self.assertEqual(Cake(test).calculate(), '9')
		test = ''
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Cake(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Cake().calculate())


n = int(input())
k = [[[1 if i == 'C' else 0 for i in j] for j in input().split()][0] for _ in range(n)]

def comb(x):
	return x * (x - 1) // 2
j = [[] for _ in range(n)]
for i in range(n):
	for z in range(n):
		j[i].append(k[z][i])
print(sum([comb(z.count(1)) for z in k]) + sum([comb(z.count(1)) for z in j]))


from math import factorial
n = int(input())
cake = []
for _ in range(n):
	cakeLine = []
	for i in input().replace('.', '0').replace('C', '1'):
		cakeLine.append(int(i))
	cake.append(cakeLine)
lines = []
for i in range(n):
	lines.append(sum(cake[i]))
	lines.append(sum(list(zip(*cake))[i]))
a = 0
for i in lines:
	if i > 1:
		a += factorial(i) / (factorial(i - 2) * 2)
print(int(a))


n = int(input())
cke = []
for i in range(n):
	a = []
	s = input()
	for j in range(n):
		a.append(s[j])
	cke.append(a)
c = 0
for i in range(n):
	for j in range(n):
		if cke[i][j] == 'C':
			for k in range(j + 1, n):
				if cke[i][k] == 'C':
					c += 1
			for k in range(i + 1, n):
				if cke[k][j] == 'C':
					c += 1
print(c)


n = int(input())
arr = [input() for i in range(n)]
res = 0
for i in range(n):
	s = sum([1 for x in arr[i] if x == 'C'])
	res += s * (s - 1) // 2
for i in range(n):
	s = sum([1 for j in range(n) if arr[j][i] == 'C'])
	res += s * (s - 1) // 2
print(res)


n = int(input())
r = 0
stlpce = [0 for i in range(n)]
for i in range(n):
	line = input()
	riadok = 0
	for (j, c) in enumerate(line):
		if c == 'C':
			riadok += 1
			stlpce[j] += 1
	r += riadok * (riadok - 1) // 2
for stlpec in stlpce:
	r += stlpec * (stlpec - 1) // 2
print(r)


n = int(input())
cake = []
vert = ['' for i in range(n)]
ans = 0
for i in range(n):
	y = input()
	for j in range(len(y)):
		vert[j] += y[j]
	p = y.count('C')
	ans += p * (p - 1) // 2
for i in vert:
	n = i.count('C')
	ans += n * (n - 1) // 2
print(ans)


class StdReader:

	def read_int(self):
		return int(self.read_string())

	def read_ints(self, sep=None):
		return [int(i) for i in self.read_strings(sep)]

	def read_float(self):
		return float(self.read_string())

	def read_floats(self, sep=None):
		return [float(i) for i in self.read_strings(sep)]

	def read_string(self):
		return input()

	def read_strings(self, sep=None):
		return self.read_string().split(sep)
reader = StdReader()

def main():
	n = reader.read_int()
	rows = [0] * n
	cols = [0] * n
	happiness = 0
	for i in range(n):
		row = reader.read_string()
		for (j, c) in enumerate(row):
			if c == 'C':
				rows[i] += 1
				cols[j] += 1
				happiness += rows[i] - 1
				happiness += cols[j] - 1
	print(happiness)
main()


x = int(input())
sum = 0
a = [0 for i in range(x)]
b = [0 for i in range(x)]
for i in range(x):
	c = input()
	for j in range(x):
		if c[j] == 'C':
			a[i] += 1
			b[j] += 1
for i in range(x):
	sum += a[i] * (a[i] - 1) // 2 + b[i] * (b[i] - 1) // 2
print(sum)


n = int(input())
a = []
ans = 0
for i in range(n):
	s = list(str(input()))
	a.append(s)
for i in range(n):
	c = a[i][:].count('C')
	ans += c * (c - 1) // 2
for j in range(n):
	c = 0
	for k in range(n):
		c += a[k][j].count('C')
	ans += c * (c - 1) // 2
print(ans)


from math import *
from sys import *
n = int(input())
mat = []
for i in range(n):
	cur = input()
	app = []
	for i in cur:
		if i == 'C':
			app.append(1)
		else:
			app.append(0)
	mat.append(app[:])
res = 0
for i in range(n):
	q = sum(mat[i])
	qq = sum([mat[j][i] for j in range(n)])
	res += q * (q - 1) // 2
	res += qq * (qq - 1) // 2
print(res)


n = int(input())
(l, c, h) = ([], 0, 0)
for i in range(n):
	l.append(list(input()))
for i in range(n):
	k = l[i][:].count('C')
	for j in range(n):
		if l[j][i] == 'C':
			h += 1
	c += (k - 1) * k // 2 + (h - 1) * h // 2
	h = 0
print(c)


def fact(k):
	if k == 0:
		return 0
	return k + fact(k - 1)
n = int(input())
arr = []
for _ in range(n):
	s = [i for i in input()]
	arr.append(s)
ans = 0
for i in range(n):
	cnt = 0
	for j in range(n):
		if arr[i][j] == 'C':
			cnt += 1
	if cnt >= 1:
		ans += fact(cnt - 1)
		k1 = fact(cnt - 1)
for i in range(n):
	cnt = 0
	for j in range(n):
		if arr[j][i] == 'C':
			cnt += 1
	if cnt >= 1:
		ans += fact(cnt - 1)
print(ans)


n = int(input())
a = [list(input()) for i in range(n)]
s = 0
for i in a:
	v = 0
	for j in i:
		if j == 'C':
			v += 1
	s += v * (v - 1) // 2
for i in range(n):
	v = 0
	for j in range(n):
		if a[j][i] == 'C':
			v += 1
	s += v * (v - 1) // 2
print(s)


def sumation(num):
	total = 0
	for i in range(num):
		total += i
	return total
dimention = int(input())
rows = []
columns = []
count = 0
for i in range(dimention):
	rows.append(list(input()))
	columns.append([])
for i in range(dimention):
	for e in range(len(rows[i])):
		columns[e].append(rows[i][e])
for i in rows:
	count += sumation(i.count('C'))
for i in columns:
	count += sumation(i.count('C'))
print(count)


def cake(lst):
	result = 0
	for i in range(len(lst)):
		for j in range(len(lst)):
			for z in range(j):
				if lst[i][j] == 'C' and lst[i][z] == 'C':
					result += 1
				if lst[j][i] == 'C' and lst[z][i] == 'C':
					result += 1
	return result
n = int(input())
a = [input() for x in range(n)]
print(cake(a))


def fact(n):
	if n == 0:
		return 1
	return n * fact(n - 1)
cake = []
chk = 0
for _ in range(int(input())):
	s = input()
	c = s.count('C')
	chk += fact(c) // (2 * fact(c - 2)) if c > 1 else 0
	cake.append(s)
cake = zip(*cake)
for s in cake:
	c = s.count('C')
	chk += fact(c) // (2 * fact(c - 2)) if c > 1 else 0
print(chk)


n = int(input())
s = []
count = 0
for i in range(n):
	s.append(input())
for i in range(n):
	for j in range(n - 1):
		if s[i][j] == 'C':
			for k in range(j + 1, n):
				if s[i][k] == 'C':
					count += 1
for i in range(n - 1):
	for j in range(n):
		if s[i][j] == 'C':
			for k in range(i + 1, n):
				if s[k][j] == 'C':
					count += 1
print(count)


import math
n = int(input())
matrix = []
for i in range(n):
	s = str(input())
	a = []
	a.append(s)
	matrix.append(a)
c = 0
d = 0
f = 0
count = 0
z = 0
b = 0
for i in range(0, len(matrix)):
	c = matrix[i][0].count('C')
	if c >= 2:
		d = d + math.factorial(c) // (math.factorial(2) * math.factorial(c - 2))
while count < n * n:
	e = 0
	for j in range(0, len(matrix)):
		if matrix[j][0][b] == 'C':
			e = e + 1
		count = count + 1
	b = b + 1
	z = z + 1
	if e >= 2:
		f = f + math.factorial(e) // (math.factorial(2) * math.factorial(e - 2))
	if count == n * n:
		break
print(f + d)


n = int(input())
a = [list(input()) for i in range(n)]
(c, r) = ([0] * n, [0] * n)
for i in range(n):
	s1 = 0
	s2 = 0
	for j in range(n):
		if a[i][j] == 'C':
			s1 += 1
		if a[j][i] == 'C':
			s2 += 1
	r[i] = s1 * (s1 - 1) // 2
	c[i] = s2 * (s2 - 1) // 2
print(sum(r) + sum(c))


n = int(input())
(mat, counter) = ([[0] * n for i in range(n)], 0)
for i in range(n):
	s = input()
	for j in range(n):
		mat[i][j] = [0, 1][s[j] == 'C']
for i in range(n):
	(a, b) = (sum(mat[i]), sum((j[i] for j in mat)))
	counter += (a * (a - 1) + b * (b - 1)) // 2
print(counter)


def twoCx(x):
	x = int(x)
	if x < 2:
		return 0
	return int(x * (x - 1) / 2)
n = int(input())
cakes = []
res = 0
for i in range(n):
	count = 0
	row = list(input())
	cakes.append(row)
	for j in range(n):
		if row[j] == 'C':
			count += 1
	res += twoCx(count)
for j in range(n):
	count = 0
	for i in range(n):
		if cakes[i][j] == 'C':
			count += 1
	res += twoCx(count)
print(res)


import math
n = int(input())
a = [[c == 'C' for c in input()] for i in range(n)]
b = [sum(a[i]) for i in range(n)]
c = [sum((a[i][j] for i in range(n))) for j in range(n)]
print(sum((k * (k - 1) // 2 for k in b)) + sum((k * (k - 1) // 2 for k in c)))


n = int(input())
x = [[i for i in input()] for j in range(0, n)]
summ = 0
for i in range(n):
	cur = 0
	for j in range(n):
		if x[i][j] == 'C':
			cur += 1
	summ += cur * (cur - 1) // 2
for j in range(n):
	cur = 0
	for i in range(n):
		if x[i][j] == 'C':
			cur += 1
	summ += cur * (cur - 1) // 2
print(summ)


from sys import stdin as fin
n = int(fin.readline())
cols = [0] * n
sum = 0
for i in range(n):
	c = j = 0
	for sym in fin.readline().rstrip():
		if sym == 'C':
			c += 1
			cols[j] += 1
		j += 1
	sum += c * (c - 1) // 2
for c in cols:
	sum += c * (c - 1) // 2
print(sum)


n = int(input())
rows = []
for x in range(n):
	string = input()
	row = list(string)
	rows.append(row)
columns = [[x[y] for x in rows] for y in range(n)]
a = 0
for x in rows:
	b = x.count('C')
	a += b * (b - 1) // 2
for x in columns:
	b = x.count('C')
	a += b * (b - 1) // 2
print(a)


def cnt(N):
	if N >= 2:
		return N * (N - 1) // 2
	return 0
N = int(input())
grids = [list(input()) for _ in range(N)]
total = 0
for items in grids:
	total += cnt(items.count('C'))
for index in range(N):
	total += cnt([_[index] for _ in grids].count('C'))
print(total)


def main():
	n = int(input())
	grid = [None] * n
	for i in range(n):
		grid[i] = input()
	print(solver(grid))

def solver(grid):
	n = len(grid)
	total = 0
	for row in range(n):
		Cs = grid[row].count('C')
		total += nC2(Cs)
	for col in range(n):
		Cs = 0
		for row in range(n):
			if grid[row][col] == 'C':
				Cs += 1
		total += nC2(Cs)
	return total

def nC2(n):
	if n < 2:
		return 0
	else:
		return n * (n - 1) // 2
main()


__author__ = 'Utena'
n = int(input())
s = [[0] * n for i in range(n)]
for i in range(n):
	a = input()
	for j in range(n):
		if a[j] == 'C':
			s[i][j] = 1
s1 = [0] * n
s2 = [0] * n
for i in range(n):
	for j in range(n):
		if s[i][j] == 1:
			s1[i] += 1
			s2[j] += 1
t = 0
for b in s1:
	t += b * (b - 1) // 2
for c in s2:
	t += c * (c - 1) // 2
print(t)


n = int(input())
ans = 0
a = [''] * n
for i in range(n):
	a[i] += input()
	z = a[i].count('C')
	if z > 1:
		x = 1
		for i in range(z - 1, z + 1):
			x *= i
		ans += x / 2
b = [''] * n
for i in range(n):
	for j in range(n):
		b[i] += a[j][i]
	z = b[i].count('C')
	if z > 1:
		x = 1
		for i in range(z - 1, z + 1):
			x *= i
		ans += x / 2
print(int(ans))


side = int(input())
row = [0] * side
col = [0] * side
for i in range(side):
	s = input()
	for j in range(side):
		if s[j] == 'C':
			row[i] += 1
			col[j] += 1
happy = 0
for i in range(side):
	if row[i] >= 2:
		for j in range(row[i] - 1, 0, -1):
			happy += j
	if col[i] >= 2:
		for j in range(col[i] - 1, 0, -1):
			happy += j
print(happy)


n = int(input())
g = [list(input()) for _ in range(n)]
ret = 0
for i in range(n):
	for j in range(n):
		if g[i][j] != 'C':
			continue
		for x in range(j + 1, n):
			ret += g[i][x] == 'C'
		for y in range(i + 1, n):
			ret += g[y][j] == 'C'
print(ret)


import math
n = eval(input())
i = 0
ans = 0
s = ''
x = ''
while i < n:
	s = input()
	if s.count('C') >= 2:
		ans += s.count('C') * (s.count('C') - 1) // 2
	x = x + s
	i += 1
i = 0
f = ''
g = 0
while g < n:
	i = g
	f = ''
	while i < len(x):
		f += x[i]
		i += n
	if f.count('C') >= 2:
		ans += f.count('C') * (f.count('C') - 1) // 2
	g += 1
print(ans)


n = int(input())
ans = 0

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans
cols = [0 for i in range(n)]
rows = [0 for i in range(n)]
grid = []
for i in range(n):
	grid.append(list(input()))
for r in range(n):
	for c in range(n):
		if grid[r][c] == 'C':
			rows[r] += 1
			cols[c] += 1
for i in range(n):
	ans += fact(rows[i]) // (fact(rows[i] - 2) * 2)
	ans += fact(cols[i]) // (fact(cols[i] - 2) * 2)
print(ans)


def fac(n):
	t = 1
	for i in range(1, n + 1):
		t = t * i
	return t
N = int(input())
y = []
(a, b) = (0, 0)
for i in range(N):
	y += list(map(str, input().split()))
for i in range(N):
	r = y[i].count('C')
	if r > 1:
		a += fac(r) / (fac(2) * fac(r - 2))
c = int(a)
for j in range(N):
	for k in range(N):
		if y[k][j] == 'C':
			b += 1
	if b > 1:
		c += fac(b) / (fac(2) * fac(b - 2))
	b = 0
print(int(c))


n = int(input())
r = 0
c = 0
rows = [0] * n
cols = [0] * n
for i in range(n):
	st = input()
	rows[i] += st.count('C')
	for j in range(n):
		cols[j] += int(st[j] == 'C')
print(sum([row * (row - 1) // 2 for row in rows if row > 0]) + sum([col * (col - 1) // 2 for col in cols if col > 0]))


n = int(input())
M = []
for i in range(n):
	M += [input()]
ans = 0
for i in range(n):
	(c, r) = (0, 0)
	for j in range(n):
		if M[i][j] == 'C':
			c += 1
		if M[j][i] == 'C':
			r += 1
	if c > 1:
		ans += c * (c - 1) // 2
	if r > 1:
		ans += r * (r - 1) // 2
print(ans)


n = int(input())
arr = [list(input()) for i in range(n)]
ans = 0
for i in arr:
	s = 0
	for j in i:
		if j == 'C':
			s += 1
	ans += s * (s - 1) // 2
for i in range(n):
	s = 0
	for j in range(n):
		if arr[j][i] == 'C':
			s += 1
	ans += s * (s - 1) // 2
print(ans)


n = int(input())
m = [input() for i in range(n)]
li = [0 for i in range(n)]
co = [0 for i in range(n)]
for i in range(n):
	for j in range(n):
		if m[i][j] == 'C':
			li[i] += 1
			co[j] += 1
soma = 0
for i in li:
	soma += i * (i - 1) // 2
for i in co:
	soma += i * (i - 1) // 2
print(soma)


n = int(input())
a = []
for i in range(n):
	a.append(list(input()))
ans = 0
for i in range(n):
	t = 0
	for j in range(n):
		if a[i][j] == 'C':
			t += 1
	ans += t * (t - 1) // 2
for i in range(n):
	t = 0
	for j in range(n):
		if a[j][i] == 'C':
			t += 1
	ans += t * (t - 1) // 2
print(ans)


n = int(input())
s = []
for i in range(0, n):
	q = input()
	s.append(q)
r = [0 for x in range(0, 101)]
c = [0 for x in range(0, 101)]
for i in range(0, n):
	for j in range(0, n):
		if s[i][j] == 'C':
			r[i] += 1
			c[j] += 1
h = 0
for i in range(0, n):
	h += r[i] * (r[i] - 1) / 2
for i in range(0, n):
	h += c[i] * (c[i] - 1) / 2
print(int(h))


def getPairs(n):
	pairs = 0
	for x in range(1, n):
		pairs += x
	return pairs
n = int(input())
pairings = [0, 1]
cols = [0] * n
rows = [0] * n
cake = []
for i in range(0, n):
	cake.append(list(input()))
for x in range(0, n):
	for y in range(0, n):
		if cake[x][y] == 'C':
			cols[y] += 1
			rows[x] += 1
pairs = 0
for j in range(0, n):
	if cols[j] > 1:
		pairs += getPairs(cols[j])
	if rows[j] > 1:
		pairs += getPairs(rows[j])
print(pairs)


n = int(input())
cake = [[False for i in range(n)] for i in range(n)]
for i in range(n):
	s = input()
	for (j, ch) in enumerate(s):
		if ch == 'C':
			cake[i][j] = True
ans = 0
for i in range(n):
	s = sum((1 if cake[i][j] else 0 for j in range(n)))
	ans += s * (s - 1) // 2
for i in range(n):
	s = sum((1 if cake[j][i] else 0 for j in range(n)))
	ans += s * (s - 1) // 2
print(ans)


from collections import Counter

def process(chocolates):
	rows = Counter((row for (row, col) in chocolates))
	cols = Counter((col for (row, col) in chocolates))
	return sum((k * (k - 1) // 2 for k in rows.values())) + sum((k * (k - 1) // 2 for k in cols.values()))

def get_input():
	n = int(input())
	return [(r, c) for r in range(n) for (c, ch) in enumerate(input()) if ch == 'C']
chocolates = get_input()
print(process(chocolates))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = [S() for _ in range(n)]
	r = 0
	for i in range(n):
		c = 0
		for t in a[i]:
			if t == 'C':
				c += 1
		r += (c - 1) * c // 2
		c = 0
		for j in range(n):
			if a[j][i] == 'C':
				c += 1
		r += (c - 1) * c // 2
	return r
print(main())


from math import factorial as f
n = int(input())
a = []
ans = 0
for i in range(n):
	a.append(input())
	k = 0
	for j in a[i]:
		if j == 'C':
			k += 1
	if k > 1:
		ans += f(k) // (2 * f(k - 2))
for i in range(n):
	k = 0
	for j in range(n):
		if a[j][i] == 'C':
			k += 1
	if k > 1:
		ans += f(k) // (2 * f(k - 2))
print(ans)


n = int(input())
a = [input() for i in range(n)]
c = 0
for i in range(n):
	for j in range(n):
		if a[i][j] == 'C':
			k = i + 1
			while k < n:
				if a[k][j] == 'C':
					c += 1
				k += 1
			l = j + 1
			while l < n:
				if a[i][l] == 'C':
					c += 1
				l += 1
print(c)


def nc2(a):
	return a * (a - 1) // 2
n = int(input())
grid = [input() for x in range(n)]
ans = 0
for x in range(n):
	ans += nc2(grid[x].count('C'))
for x in range(n):
	ans += nc2(sum([1 for y in range(n) if grid[y][x] == 'C']))
print(ans)


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def insr():
	s = input()
	return list(s[:len(s) - 1])

def pair(n):
	return math.factorial(n) / (2 * math.factorial(n - 2))
n = inp()
c = 0
col = [0] * n
for i in range(n):
	cc = 0
	r = insr()
	for (i, e) in enumerate(r):
		if e == 'C':
			cc += 1
			col[i] += 1
	c += pair(cc) if cc > 2 else 1 if cc == 2 else 0
for e in col:
	c += pair(e) if e > 2 else 1 if e == 2 else 0
print(int(c))


def func(n):
	return n * (n - 1) / 2
n = int(input())
arr = [None] * n
for i in range(n):
	arr[i] = input()
ans = 0
for i in range(n):
	c = 0
	for j in range(n):
		if arr[i][j] == 'C':
			c += 1
	ans = ans + func(c)
for j in range(n):
	c = 0
	for i in range(n):
		if arr[i][j] == 'C':
			c += 1
	ans = ans + func(c)
print(int(ans))


def s(k):
	k -= 1
	return int((k + 1) * (k / 2))
n = int(input())
a = []
for i in range(n):
	a.append(list(input()))
res = 0
for item in a:
	res += s(item.count('C'))
for i in range(n):
	cnt = 0
	for j in range(n):
		if a[j][i] == 'C':
			cnt += 1
	res += s(cnt)
print(res)


n = int(input())
matrix = [['c' for i in range(n)] for j in range(n)]
for i in range(n):
	matrix[i] = list(input())
ans = 0
for i in range(n):
	count = 0
	for j in range(n):
		if matrix[i][j] == 'C':
			count = count + 1
	ans = ans + count * (count - 1) / 2
for i in range(n):
	count = 0
	for j in range(n):
		if matrix[j][i] == 'C':
			count = count + 1
	ans = ans + count * (count - 1) / 2
print(int(ans))


n = int(input())
list = ['' for i in range(n)]
for i in range(n):
	list[i] = input()
sum = 0
for c in list:
	f = 0
	for i in range(n):
		if c[i] == 'C':
			f += 1
	sum = sum + f * (f - 1) / 2
for i in range(n):
	f = 0
	for j in range(n):
		if list[j][i] == 'C':
			f += 1
	sum = sum + f * (f - 1) / 2
print(int(sum))


def C(x):
	return x * (x - 1) // 2
n = int(input())
row = [0] * n
col = [0] * n
s = [list(input()) for _ in range(n)]
for i in range(n):
	for j in range(n):
		row[i] += s[i][j] == 'C'
		col[j] += s[i][j] == 'C'
ans = 0
for i in range(n):
	ans += C(row[i]) + C(col[i])
print(ans)


n = int(input())
b = [0] * n
c = [0] * n
for i in range(n):
	t = input()
	for j in range(n):
		if t[j] == 'C':
			b[i] += 1
			c[j] += 1
ans = 0
for i in range(n):
	ans += b[i] * (b[i] - 1) // 2
	ans += c[i] * (c[i] - 1) // 2
print(ans)


from sys import *
inp = lambda : stdin.readline()
N = 105

def main():
	n = int(inp())
	r = [0 for i in range(N)]
	(c, ans) = (r[:], 0)
	for i in range(n):
		s = inp()
		for j in range(n):
			if s[j] == 'C':
				ans += r[i] + c[j]
				r[i] += 1
				c[j] += 1
	print(ans)
main()


n = int(input())
matrix = []
res = 0
for i in range(n):
	matrix.append(input())
(rowCount, colCount) = (0, 0)
for i in range(n):
	for j in range(n):
		if matrix[i][j] == 'C':
			rowCount += 1
		if matrix[j][i] == 'C':
			colCount += 1
	res += (rowCount - 1) * rowCount // 2 + (colCount - 1) * colCount // 2
	rowCount = colCount = 0
print(res)


def main():
	(n, res) = (int(input()), 0)
	l = [input() for _ in range(n)]
	for src in (l, zip(*l)):
		for s in src:
			c = s.count('C')
			res += c * (c - 1) // 2
	print(res)
main()


from math import factorial
n = int(input())
a = [input() for x in range(n)]
ans = 0
for i in range(n):
	p = k = 0
	for j in range(n):
		if a[i][j] == 'C':
			k += 1
		if a[j][i] == 'C':
			p += 1
	if k > 1:
		ans += factorial(k) / (2 * factorial(k - 2))
	if p > 1:
		ans += factorial(p) / (2 * factorial(p - 2))
print(int(ans))


n = int(input())
cnt = 0
x = []
for i in range(n):
	x.append(0)
for i in range(n):
	l = list(input())
	g = l.count('C')
	if g > 1:
		cnt += g * (g - 1) / 2
	for j in range(n):
		if l[j] == 'C':
			x[j] += 1
for j in range(n):
	if x[j] > 1:
		cnt += x[j] * (x[j] - 1) / 2
print(int(cnt))


import math

def com(x):
	return math.factorial(x) / (math.factorial(2) * math.factorial(x - 2))
n = int(input())
ma = []
for i in range(n):
	ma.append(input())
c = 0
l = 0
t = 0
for i in range(n):
	l = 0
	c = 0
	for j in range(n):
		if ma[i][j] == 'C':
			l += 1
		if ma[j][i] == 'C':
			c += 1
	if c >= 2:
		t += com(c)
	if l >= 2:
		t += com(l)
print(int(t))


n = int(input())
a = [0 for i in range(100)]
ans = 0
for i in range(n):
	line = input()
	c = line.count('C')
	ans += c * (c - 1) // 2
	for j in range(len(line)):
		if line[j] == 'C':
			a[j] += 1
for i in a:
	ans += i * (i - 1) // 2
print(ans)


n = int(input())
a = [[0 for i in range(n)] for i in range(n)]
answer = 0
for i in range(n):
	row = input()
	for j in range(n):
		a[i][j] = row[j]
for r in range(n):
	row = a[r]
	for i in range(n):
		for j in range(i + 1, n):
			if row[i] == 'C' and row[i] == row[j]:
				answer += 1
for c in range(n):
	for i in range(n):
		for j in range(i + 1, n):
			if a[i][c] == 'C' and a[i][c] == a[j][c]:
				answer += 1
print(answer)


def fact(n, acc=1):
	if n == 0:
		return acc
	return fact(n - 1, n * acc)

def ncr(n):
	return fact(n) / (fact(n - 2) * 2)
n = int(input())
r = [0] * n
c = [0] * n
import sys
i = 0
for line in sys.stdin:
	j = 0
	for letter in line:
		if letter == 'C':
			r[i] += 1
			c[j] += 1
		j += 1
	i += 1
ans = 0
for i in range(n):
	if r[i] > 1:
		ans += ncr(r[i])
	if c[i] > 1:
		ans += ncr(c[i])
print(int(ans))


n = int(input())
a = []
col = []
for i in range(n):
	s = list(input())
	a.append(s)
cnt = 0
import math
for i in range(len(a)):
	z = a[i].count('C')
	if z > 2:
		cnt += math.factorial(z) // (math.factorial(z - 2) * 2)
	elif z == 2:
		cnt += 1
for i in range(len(a)):
	c = 0
	for j in range(len(a)):
		if a[j][i] == 'C':
			c += 1
	col.append(c)
for i in col:
	if i > 2:
		cnt += math.factorial(i) // (math.factorial(i - 2) * 2)
	elif i == 2:
		cnt += 1
print(cnt)


def op(x):
	return x * (x - 1) // 2
n = int(input())
a = []
for i in range(n):
	s = input()
	a.append(s)
s = 0
for i in range(n):
	(x, y) = (0, 0)
	for j in range(n):
		if a[i][j] == 'C':
			x += 1
		if a[j][i] == 'C':
			y += 1
	s += op(x) + op(y)
print(s)


n = int(input())
row = [0] * n
col = [0] * n
for i in range(n):
	line = input()
	for j in range(n):
		if line[j] == 'C':
			row[i] += 1
			col[j] += 1
ans = 0
for i in range(n):
	if row[i] > 0:
		ans += row[i] * (row[i] - 1) // 2
	if col[i] > 0:
		ans += col[i] * (col[i] - 1) // 2
print(ans)


n = int(input())
res = 0
ls = []
for i in range(n):
	s = input()
	cnt = 0
	for ch in s:
		if ch == 'C':
			cnt += 1
	if cnt > 1:
		res += cnt * (cnt - 1) // 2
	ls.append(s)
for i in range(n):
	cnt = 0
	for j in range(n):
		if ls[j][i] == 'C':
			cnt += 1
	if cnt > 1:
		res += cnt * (cnt - 1) // 2
print(res)


n = int(input())
s = [input() for i in range(n)]
ans = 0
for i in range(n):
	for j in range(n):
		if s[i][j] == 'C':
			for k in range(j + 1, n):
				if s[i][k] == 'C':
					ans += 1
for i in range(n):
	for j in range(n):
		if s[j][i] == 'C':
			for k in range(j + 1, n):
				if s[k][i] == 'C':
					ans += 1
print(ans)


def comb(N, k):
	if k > N or N < 0 or k < 0:
		return 0
	(N, k) = map(int, (N, k))
	top = N
	val = 1
	while top > N - k:
		val *= top
		top -= 1
	n = 1
	while n < k + 1:
		val //= n
		n += 1
	return val
n = int(input())
a_r = [0] * n
a_c = [0] * n
for i in range(n):
	s = input()
	for j in range(n):
		if s[j] == 'C':
			a_r[i] += 1
			a_c[j] += 1
print(sum((comb(a_r[i], 2) + comb(a_c[i], 2) for i in range(n))))


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
n = iinput()
mat = []
for _ in range(n):
	mat.append(input())
pair = 0
(row, col) = ([0] * n, [0] * n)
for i in range(n):
	for j in range(n):
		if mat[i][j] == 'C':
			col[j] += 1
			row[i] += 1
for e in row:
	pair += e * (e - 1) // 2
for e in col:
	pair += e * (e - 1) // 2
print(pair)


n = int(input())
l = []
s = 0
for i in range(n):
	a = input()
	l.append(a)
	s1 = a.count('C')
	s = s + s1 * (s1 - 1) // 2
for i in range(n):
	s1 = 0
	for j in range(n):
		if l[j][i] == 'C':
			s1 = s1 + 1
	s = s + s1 * (s1 - 1) // 2
print(s)


n = int(input())
a = []
counter = 0
for i in range(n):
	a.append(list(input()))
for item in range(n):
	for x in range(n):
		for y in range(x + 1, n):
			if a[item][x] == a[item][y] and a[item][x] == 'C':
				counter += 1
	for i in range(item + 1, n):
		for j in range(n):
			if a[item][j] == a[i][j] and a[item][j] == 'C':
				counter += 1
print(counter)


n = int(input())
ans = 0
l = [[0] * n for i in range(n)]
for i in range(n):
	s = input()
	for j in range(n):
		l[i][j] = s[j]
for i in range(n):
	t = 0
	for j in range(n):
		if l[i][j] == 'C':
			t += 1
	ans += t * (t - 1) // 2
for j in range(n):
	t = 0
	for i in range(n):
		if l[i][j] == 'C':
			t += 1
	ans += t * (t - 1) // 2
print(ans)


n = int(input())
cake = []
res = 0
for i in range(n):
	a = input()
	b = a.count('C')
	res = res + b * (b - 1) // 2
	cake.append(a)
rotated = zip(*cake[::-1])
for i in rotated:
	b = i.count('C')
	res = res + b * (b - 1) // 2
print(res)


n = int(input())
a = []
h = 0
for i in range(n):
	b = [1 if i == 'C' else 0 for i in input()]
	a.append(b)
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			for k in range(i):
				if a[k][j] == 1:
					h += 1
			for m in range(j):
				if a[i][m] == 1:
					h += 1
print(h)


import math
n = int(input())
l = []
for i in range(n):
	l.append(input())
answer = 0
for s in l:
	chocolate = 0
	for c in s:
		if c == 'C':
			chocolate += 1
	try:
		answer += int(math.factorial(chocolate) / math.factorial(chocolate - 2)) / 2
	except ValueError:
		pass
for i in range(n):
	chocolate = 0
	for s in l:
		if s[i] == 'C':
			chocolate += 1
	try:
		answer += int(math.factorial(chocolate) / math.factorial(chocolate - 2)) / 2
	except ValueError:
		pass
print(int(answer))


n = int(input())
rc = [0] * n
cc = [0] * n
for j in range(n):
	s = input()
	for i in range(n):
		if s[i] == 'C':
			cc[i] += 1
			rc[j] += 1

def getPairs(n):
	if n > 1:
		return n * (n - 1) // 2
	else:
		return 0
print(sum(map(lambda x: getPairs(x), rc)) + sum(map(lambda x: getPairs(x), cc)))


n = int(input())
face = list()
for i in range(n):
	line = str(input())
	line = line.replace('.', '0')
	line = line.replace('C', '1')
	line = [int(it) for it in line]
	face.append(list(line))
tar = 0
for i in range(n):
	line_c = list()
	line_r = list()
	for j in range(n):
		line_c.append(face[i][j])
		line_r.append(face[j][i])
	sum_c = sum(line_c)
	sum_r = sum(line_r)
	tar += sum_c * (sum_c - 1) // 2
	tar += sum_r * (sum_r - 1) // 2
print(tar)


lst = []
b = 0
n = 0
s = 0
v = [100]
z = int(input())
for x in range(z):
	c = list(map(str, input()))
	e = c.count('C')
	lst.append(c)
	d = e - 1
	while d > 0:
		n += d
		d -= 1
for m in range(z):
	for a in lst:
		if a[m] == 'C':
			s += 1
	r = s - 1
	while r > 0:
		n += r
		r -= 1
	s = 0
print(n)


def chocolate(n, a):
	row = [0] * n
	col = [0] * n
	for i in range(0, n):
		for j in range(0, n):
			if a[i][j] == 'C':
				row[i] += 1
				col[j] += 1
	total = 0
	for each in row:
		total += each * (each - 1) / 2
	for each in col:
		total += each * (each - 1) / 2
	print(int(total))
n = int(input())
a = []
for i in range(0, n):
	tmp = input()
	a.append(tmp)
chocolate(n, a)


def fat(n):
	res = 1
	for i in range(2, n + 1):
		res *= i
	return res

def comb(n):
	if n < 2:
		return 0
	return fat(n) // (fat(n - 2) * 2)
n = int(input())
mat = []
for i in range(n):
	mat.append(input())
contLinha = 0
contColuna = 0
soma = 0
for i in range(n):
	contLinha = 0
	contColuna = 0
	for j in range(n):
		if mat[i][j] == 'C':
			contLinha += 1
		if mat[j][i] == 'C':
			contColuna += 1
	soma += comb(contColuna)
	soma += comb(contLinha)
print(soma)


import math
a = int(input())
t = []
tt = []
for x in range(0, a):
	t.append(0)
	tt.append(0)
for x in range(0, a):
	h = input()
	for y in range(0, a):
		if h[y] == 'C':
			t[x] += 1
			tt[y] += 1
j = 0
for x in range(0, a):
	if t[x] >= 2:
		j += math.factorial(t[x]) / (math.factorial(2) * math.factorial(t[x] - 2))
	if tt[x] >= 2:
		j += math.factorial(tt[x]) / (math.factorial(2) * math.factorial(tt[x] - 2))
print(int(j))


from math import factorial
n = int(input())
matrix_1 = []
matrix_2 = []
for i in range(n):
	add = list(input())
	matrix_1.append(add)
	matrix_2.append(add)
matrix_2 = list(zip(*matrix_2))
ans = 0
for i in range(n):
	n_1 = len(list(filter(lambda x: x == 'C', matrix_1[i])))
	n_2 = len(list(filter(lambda x: x == 'C', matrix_2[i])))
	if n_1 > 1:
		ans += factorial(n_1) // (factorial(n_1 - 2) * 2)
	if n_2 > 1:
		ans += factorial(n_2) // (factorial(n_2 - 2) * 2)
print(ans)


def countchochor(a, k):
	count = 0
	for i in range(len(a)):
		if Cake[k][i] == 'C':
			count += 1
	return count * (count - 1) // 2

def countchocver(a, k):
	count = 0
	for i in range(len(a)):
		if Cake[i][k] == 'C':
			count += 1
	return count * (count - 1) // 2

def total(a):
	total = 0
	for j in range(len(a)):
		total = total + (countchochor(a, j) + countchocver(a, j))
	return total
n = int(input())
Cake = []
for i in range(n):
	Cake.append(input())
print(total(Cake))


n = int(input())
cols = [0] * n
res = 0
for x in range(n):
	i = input()
	count = i.count('C')
	if count >= 2:
		res += count * (count - 1) // 2
	for (j, c) in enumerate(i):
		if c == 'C':
			cols[j] += 1
print(res + sum((x * (x - 1) // 2 for x in cols if x > 1)))


import itertools

def fact(n):
	if n < 1:
		return 1
	return n * fact(n - 1)
n = int(input())
cake = list()
for i in range(n):
	s = str(input())
	cake.append(s)
result = 0
for i in range(n):
	rowCount = 0
	for c in cake[i]:
		if c == 'C':
			rowCount += 1
	colCount = 0
	for j in range(n):
		if cake[j][i] == 'C':
			colCount += 1
	if rowCount > 1:
		result += int(fact(rowCount) / (2 * fact(rowCount - 2)))
	if colCount > 1:
		result += int(fact(colCount) / (2 * fact(colCount - 2)))
print(result)


n = int(input())
res = 0
row = [0 for i in range(n)]
col = [0 for i in range(n)]
a = [list(input()) for i in range(n)]
for i in range(n):
	for j in range(n):
		if a[i][j] == 'C':
			row[i] += 1
			col[j] += 1
for i in range(n):
	res += max(0, row[i] * (row[i] - 1) // 2)
	res += max(0, col[i] * (col[i] - 1) // 2)
print(res)


n = int(input())
x = []
for i in range(n):
	x.append([j == 'C' for j in input()])
print(sum([sum(range(1, sum(i))) for i in x]) + sum([sum(range(1, i)) for i in map(sum, zip(*x))]))


import time
n = int(input())
a = [0 for i in range(n)]
ans = 0
for i in range(n):
	str = input()
	m = 0
	for j in range(n):
		if str[j] == 'C':
			m += 1
			a[j] += 1
	ans += m * (m - 1)
start = time.time()
for i in range(n):
	ans += a[i] * (a[i] - 1)
print(ans // 2)
finish = time.time()


def fac(n):
	S = 1
	for i in range(1, n + 1):
		S = S * i
	return S

def comb(n, p):
	return int(fac(n) / (fac(p) * fac(n - p)))
n = int(input())
d = []
somme = 0
for i in range(n):
	ch = input()
	d.append(ch)
	S = 0
	for j in range(len(ch)):
		if ch[j] == 'C':
			S = S + 1
	somme = somme + comb(S, 2)
for i in range(n):
	S = 0
	for j in range(n):
		if d[j][i] == 'C':
			S = S + 1
	somme = somme + comb(S, 2)
print(somme)


a = []
s = 0
n = int(input())
for _ in range(n):
	a.append(input())
for i in range(n):
	r = c = 0
	for j in range(n):
		if a[i][j] == 'C':
			r += 1
		if a[j][i] == 'C':
			c += 1
	s += r * (r - 1) // 2 + c * (c - 1) // 2
print(s)


def pairs(n):
	return n * (n - 1) // 2
n = int(input())
table = []
count_col = [0 for i in range(n)]
for i in range(n):
	table.append([x for x in input()])
	for j in range(n):
		if table[-1][j] == 'C':
			count_col[j] += 1
count_row = [row.count('C') for row in table]
happiness = [pairs(n) for n in count_row + count_col if n >= 2]
print(sum(happiness))


from itertools import combinations
n = int(input())
l = []
total_rows = 0
total_col = 0
for _ in range(n):
	l1 = list(input())
	l.append(l1)
for i in l:
	lp = []
	for j in range(n):
		if i[j] == 'C':
			lp.append(j)
	comb = combinations(lp, 2)
	total_rows += len(list(comb))
for i in range(n):
	lp = []
	for j in range(n):
		if l[j][i] == 'C':
			lp.append(j)
	comb = combinations(lp, 2)
	total_col += len(list(comb))
print(total_col + total_rows)


import math

def comb(n, k):
	if n > 1:
		return int(math.factorial(n) / (math.factorial(k) * math.factorial(n - k)))
	return 0
n = int(input())
pair_rows = 0
info = [0] * n
pair_columns = 0
for i in range(n):
	rows = input()
	pair_rows += comb(rows.count('C'), 2)
	for x in range(n):
		if rows[x] == 'C':
			info[x] += 1
for count in info:
	pair_columns += comb(count, 2)
print(pair_rows + pair_columns)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
n = get_int()
matrix = []

def nC2(n):
	return (n - 1) * n // 2
for _ in range(n):
	matrix.append(get_string())
rowCount = 0
for row in matrix:
	rowCount += nC2(row.count('C'))
matrixTrans = []
for i in range(n):
	matrixTrans.append([matrix[j][i] for j in range(n)])
colCount = 0
for row in matrixTrans:
	colCount += nC2(row.count('C'))
print(colCount + rowCount)


n = int(input())
a = []
res = 0
for i in range(n):
	a += [input()]
for i in range(n):
	x = 0
	y = 0
	for j in range(n):
		if a[i][j] == 'C':
			x += 1
		if a[j][i] == 'C':
			y += 1
	res += x * (x - 1) // 2 + y * (y - 1) // 2
print(res)


n = int(input())
cake = [list(input()) for i in range(n)]
pairs = 0
for row in range(n):
	for col in range(n - 1):
		if cake[row][col] == 'C':
			for second in range(col + 1, n):
				if cake[row][second] == 'C':
					pairs += 1
for col in range(n):
	for row in range(n - 1):
		if cake[row][col] == 'C':
			for second in range(row + 1, n):
				if cake[second][col] == 'C':
					pairs += 1
print(pairs)


fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000, 15511210043330985984000000, 403291461126605635584000000, 10888869450418352160768000000, 304888344611713860501504000000, 8841761993739701954543616000000, 265252859812191058636308480000000, 8222838654177922817725562880000000, 263130836933693530167218012160000000, 8683317618811886495518194401280000000, 295232799039604140847618609643520000000, 10333147966386144929666651337523200000000, 371993326789901217467999448150835200000000, 13763753091226345046315979581580902400000000, 523022617466601111760007224100074291200000000, 20397882081197443358640281739902897356800000000, 815915283247897734345611269596115894272000000000, 33452526613163807108170062053440751665152000000000, 1405006117752879898543142606244511569936384000000000, 60415263063373835637355132068513997507264512000000000, 2658271574788448768043625811014615890319638528000000000, 119622220865480194561963161495657715064383733760000000000, 5502622159812088949850305428800254892961651752960000000000, 258623241511168180642964355153611979969197632389120000000000, 12413915592536072670862289047373375038521486354677760000000000, 608281864034267560872252163321295376887552831379210240000000000, 30414093201713378043612608166064768844377641568960512000000000000, 1551118753287382280224243016469303211063259720016986112000000000000, 80658175170943878571660636856403766975289505440883277824000000000000, 4274883284060025564298013753389399649690343788366813724672000000000000, 230843697339241380472092742683027581083278564571807941132288000000000000, 12696403353658275925965100847566516959580321051449436762275840000000000000, 710998587804863451854045647463724949736497978881168458687447040000000000000, 40526919504877216755680601905432322134980384796226602145184481280000000000000, 2350561331282878571829474910515074683828862318181142924420699914240000000000000, 138683118545689835737939019720389406345902876772687432540821294940160000000000000, 8320987112741390144276341183223364380754172606361245952449277696409600000000000000, 507580213877224798800856812176625227226004528988036003099405939480985600000000000000, 31469973260387937525653122354950764088012280797258232192163168247821107200000000000000, 1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000, 126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000, 8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000, 544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000, 36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000, 2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000, 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000, 11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000, 850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000, 61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000, 4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000, 330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000, 24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000, 1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000, 145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000, 11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000, 894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000, 71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000, 5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000, 475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000, 39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000, 3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000, 281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000, 24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000, 2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000, 185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000, 16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000, 1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000, 135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000, 12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000, 1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000, 108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000, 10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000, 991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000, 96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000, 9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000, 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000, 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000]

def nCr(n, r):
	return fact[n] // (fact[r] * fact[n - r])
n = int(input().strip())
arr = []
for _ in range(n):
	arr += [list(input().strip())]
happiness = 0
for row in arr:
	happiness += nCr(row.count('C'), 2)
for j in range(n):
	col = []
	for i in range(n):
		col += [arr[i][j]]
	happiness += nCr(col.count('C'), 2)
print(happiness)


from math import factorial as fact
n = int(input())
a = []
k = 0
for i in range(n):
	b = input()
	c = b.count('C')
	if c >= 2:
		k += fact(c) / (2 * fact(c - 2))
	a.append(b)
for i in range(n):
	t = 0
	for j in range(n):
		if a[j][i] == 'C':
			t += 1
	if t >= 2:
		k += fact(t) / (2 * fact(t - 2))
print(int(k))


import math
n = int(input())
a = []
for i in range(n):
	a.append(input())
cnt = 0
for i in range(n):
	(row, col) = (0, 0)
	for j in range(n):
		if a[j][i] == 'C':
			col += 1
		if a[i][j] == 'C':
			row += 1
	if row >= 2:
		cnt += math.factorial(row) / (2 * math.factorial(row - 2))
	if col >= 2:
		cnt += math.factorial(col) / (2 * math.factorial(col - 2))
print(int(cnt))


n = int(input(''))
arr = []
for i in range(n):
	value = str(input(''))
	arr.append(value)
count = 0
for i in range(0, n):
	for j in range(0, n - 1):
		for k in range(j + 1, n):
			if arr[i][j] == arr[i][k] and arr[i][j] == 'C':
				count += 1
			if arr[j][i] == arr[k][i] and arr[j][i] == 'C':
				count += 1
print(count)


n = int(input())
c = []
h = 0
for i in range(n):
	a = input()
	c.append(a)
	j = a.count('C')
	h += j * (j - 1) // 2
for i in range(n):
	b = 0
	for j in range(n):
		if c[j][i] == 'C':
			b += 1
	h += b * (b - 1) // 2
print(h)


n = int(input())
data = [input() for i in range(n)]
answer = 0
for i in range(n):
	help = 0
	for j in range(n):
		if data[i][j] == 'C':
			help += 1
	answer += help * (help - 1) // 2
for i in range(n):
	help = 0
	for j in range(n):
		if data[j][i] == 'C':
			help += 1
	answer += help * (help - 1) // 2
print(answer)


a = int(input())
table = []
for i in range(a):
	table.append(input())
result = 0
for i in range(a):
	result += table[i].count('C') * (table[i].count('C') - 1) // 2
for i in range(a):
	qwe = 0
	for j in range(a):
		if table[j][i] == 'C':
			qwe += 1
	result += qwe * (qwe - 1) // 2
print(result)


import operator

def nC2(n):
	return (n * n - n) // 2
n = int(input())
(acc, s) = ([0] * n, 0)
for i in range(n):
	xs = [1 if c == 'C' else 0 for c in input()]
	acc = map(operator.add, acc, xs)
	s += nC2(sum(xs))
s += sum(map(nC2, acc))
print(s)


def factorial(n):
	if n < 2:
		return 1
	return n * factorial(n - 1)

def nchoosek(n, k):
	return factorial(n) // (factorial(k) * factorial(n - k))

def pairCount(arr):
	count = 0
	for i in range(len(arr)):
		currentCount = 0
		for j in range(len(arr[0])):
			if arr[i][j] == 'C':
				currentCount += 1
		count += nchoosek(currentCount, 2)
	for i in range(len(arr)):
		currentCount = 0
		for j in range(len(arr[0])):
			if arr[j][i] == 'C':
				currentCount += 1
		count += nchoosek(currentCount, 2)
	return count
n = int(input())
arr = []
for _ in range(n):
	arr.append(input())
print(pairCount(arr))


n = int(input())
matr = []
for i in range(n):
	s = input()
	matr.append(s)
row = [0] * n
col = [0] * n
for i in range(n):
	for j in range(n):
		if matr[i][j] == 'C':
			row[i] += 1
			col[j] += 1
ans = 0
for i in range(n):
	ans += row[i] * (row[i] - 1) // 2 + col[i] * (col[i] - 1) // 2
print(ans)


import math

def sum(a):
	s = 0
	for i in a:
		s = s + i
	return s

def tsp(a):
	for i in range(len(a)):
		for j in range(i):
			x = a[i][j]
			a[i][j] = a[j][i]
			a[j][i] = x
	return a
n = int(input())
a = []
for i in range(n):
	b = list(input())
	a.append(b)
b = []
s = 0
for i in range(n):
	k = 0
	for j in range(n):
		if a[i][j] == 'C':
			k += 1
	b.append(k * (k - 1) // 2)
s = s + sum(b)
a = tsp(a)
b = []
for i in range(n):
	k = 0
	for j in range(n):
		if a[i][j] == 'C':
			k += 1
	b.append(k * (k - 1) // 2)
s = s + sum(b)
print(s)


__author__ = 'vboldovs'
import math

def combination(n, m):
	if n < 2:
		return 0
	return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))
cake_matrix = []
happiness = 0
n = int(input())
for i in range(n):
	cake_matrix.append(input())
for i in range(n):
	temp = 0
	for j in range(n):
		if cake_matrix[i][j] == 'C':
			temp += 1
	happiness += combination(temp, 2)
for i in range(n):
	temp = 0
	for j in range(n):
		if cake_matrix[j][i] == 'C':
			temp += 1
	happiness += combination(temp, 2)
print(int(happiness))


import math

def c(n):
	x = n * (n - 1) // 2
	return x
n = int(input())
a = [[1 for j in range(n)] for i in range(n)]
for i in range(n):
	s = input()
	for j in range(n):
		if s[j] == '.':
			a[i][j] = 0
x = 0
for i in range(n):
	k = a[i].count(1)
	x += c(k)
for j in range(n):
	k = 0
	for i in range(n):
		if a[i][j] == 1:
			k += 1
	x += c(k)
print(x)


n = int(input())
a = 0
x = []
for i in range(n):
	x.append(list(input()))
	s = x[i].count('C')
	a += s * (s - 1)
for i in range(n):
	counter = 0
	for t in range(n):
		if x[t][i] == 'C':
			counter += 1
	a += counter * (counter - 1)
print(a // 2)


from collections import *
from math import *
from itertools import *
import os
import sys
from io import BytesIO, IOBase

def splint():
	return map(int, input().split())

def PRINT(check: bool, first: str, second: str):
	print(first if check else second)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def formula(n: int) -> int:
	return n * (n - 1) // 2

def main():
	n = int(input())
	rows = [0] * n
	cols = [0] * n
	for i in range(n):
		s = input()
		for j in range(n):
			if s[j] == 'C':
				rows[i] += 1
				cols[j] += 1
	res = 0
	for row in rows:
		if row < 2:
			continue
		res += formula(row)
	for col in cols:
		if col < 2:
			continue
		res += formula(col)
	print(res)
main()


n = int(input())
matrix = []
sum = 0
l = []
lr = []
lc = []
for i in range(n):
	a = []
	a.append(input())
	matrix.append(a)
for i in range(n):
	for j in range(n):
		if matrix[i][0][j] == 'C':
			l.append((i, j))
for i in l:
	lr.append(i[0])
	lc.append(i[1])
for i in set(lc):
	if lc.count(i) > 1:
		a = lc.count(i)
		sum += a * (a - 1) // 2
for i in set(lr):
	if lr.count(i) > 1:
		b = lr.count(i)
		sum += b * (b - 1) // 2
print(sum)


from itertools import combinations
n = int(input())
cake = [0] * n
count = 0
for _ in range(n):
	row = list(map(lambda x: 1 if x == 'C' else 0, list(input())))
	c = row.count(1)
	count += len(list(combinations(range(1, c + 1), 2)))
	new = []
	for (i, j) in zip(cake, row):
		new.append(i + j)
	cake = new
for i in cake:
	count += len(list(combinations(range(1, i + 1), 2)))
print(count)


x = int(input())
t = 0
s = 0
n = 0
n1 = 0
d = 0
z = []
for i in range(x):
	a = input()
	z.append(a)
	n = a.count('C')
	if n > 1:
		k = int(n * (n - 1) / 2)
	else:
		k = 0
	s = s + k
for i in range(x):
	t = 0
	for j in range(x):
		if z[j][i] == 'C':
			t = t + 1
	if t > 1:
		l = int(t * (t - 1) / 2)
	else:
		l = 0
	d = d + l
print(d + s)


n = int(input())
l = [[0] * n for i in range(n)]
for i in range(n):
	s = input()
	for k in range(n):
		if s[k] == 'C':
			l[i][k] += 1
res = 0
for i in range(n):
	tmp = sum(l[i])
	if tmp != 0:
		res += (tmp - 1) * tmp // 2
	tmp = 0
	for j in range(n):
		tmp += l[j][i]
	if tmp != 0:
		res += (tmp - 1) * tmp // 2
print(res)


n = int(input())
init = []
for i in range(n):
	x = input()
	init.append(x)
a = []
(total_sum, i) = (1, 2)
while i < 100:
	a.append(total_sum)
	total_sum += i
	i += 1
ans = 0
for j in range(n):
	if init[j].count('C') > 1:
		ans += a[init[j].count('C') - 2]
	abc = 0
	for k in range(n):
		if init[k][j] == 'C':
			abc += 1
	if abc > 1:
		ans += a[abc - 2]
print(ans)


import math
n = int(input())
cake = []
for i in range(n):
	line2 = input()
	line = []
	for x in line2:
		if x == '.':
			line.append(0)
		if x == 'C':
			line.append(1)
	cake.append(line)
line_happy = 0
row_happy = 0
for t in cake:
	count = t.count(1)
	if count > 1:
		line_happy += math.factorial(count) / (2 * math.factorial(count - 2))
cake = zip(*cake)
for t in cake:
	count = t.count(1)
	if count > 1:
		row_happy += math.factorial(count) / (2 * math.factorial(count - 2))
result = int(line_happy + row_happy)
print(result)


n = int(input())
p_r = 0
p_c = 0
arr = [0 for i in range(n)]
for t in range(n):
	c_C = 0
	column = -1
	row = input()
	for c in row:
		column += 1
		if c == 'C':
			c_C += 1
			arr[column] += 1
	if c_C != 0:
		p_r += sum([i for i in range(c_C)])
for m in range(n):
	if arr[m] != 0:
		arr[m] = sum([i for i in range(arr[m])])
p_c = sum(arr)
print(p_r + p_c)


n = int(input())
a = [0] * n
for i in range(n):
	a[i] = input().strip()
ans = 0
for i in range(n):
	s = 0
	for j in range(n):
		if a[i][j] == 'C':
			s += 1
	ans += s * (s - 1) // 2
for i in range(n):
	s = 0
	for j in range(n):
		if a[j][i] == 'C':
			s += 1
	ans += s * (s - 1) // 2
print(ans)


n = int(input())
rows = []
for i in range(n):
	rows.append(input())
pairs = 0
for i in range(n):
	c = len([ch for ch in rows[i] if ch == 'C'])
	pairs += c * (c - 1) // 2
for i in range(n):
	c = 0
	for j in range(n):
		if rows[j][i] == 'C':
			c += 1
	pairs += c * (c - 1) // 2
print(pairs)


n = int(input())

def main():
	count = 0
	t_cells = []
	for _ in range(n):
		cell = str(input())
		t_cells.append(list(cell))
	for j in range(0, n):
		pair = 0
		pair_1 = 0
		for i in range(0, n):
			if t_cells[j][i] == 'C':
				pair += 1
			if t_cells[i][j] == 'C':
				pair_1 += 1
		count += pair * (pair - 1) / 2 + pair_1 * (pair_1 - 1) / 2
	print(int(count))
main()


def fac(n):
	fact = 1
	for i in range(n, 0, -1):
		fact *= i
	return fact
n = int(input())
l = []
for i in range(n):
	s = list(input())
	l.append(s)
a = []
b = []
r = []
c = []
ans = 0
for i in range(n):
	c = 0
	for j in range(n):
		if l[i][j] == 'C':
			c += 1
	a.append(c)
for i in range(n):
	c = 0
	for j in range(n):
		if l[j][i] == 'C':
			c += 1
	b.append(c)
for i in range(len(a)):
	if a[i] > 1:
		z = fac(a[i]) // (fac(2) * fac(a[i] - 2))
		ans += z
for j in range(len(b)):
	if b[j] > 1:
		z = fac(b[j]) // (fac(2) * fac(b[j] - 2))
		ans += z
print(ans)


from collections import defaultdict
import math
x = int(input())
ans = 0
mat = []
for _ in range(x):
	a = input()
	mat.append(a)
	temp = 0
	for i in a:
		if i == 'C':
			temp += 1
	ans += temp * (temp - 1) // 2
for i in range(x):
	temp = 0
	for j in range(x):
		if mat[j][i] == 'C':
			temp += 1
	ans += temp * (temp - 1) // 2
print(ans)


def C(n):
	return n * (n - 1) // 2
n = int(input())
a = n * [0]
for i in range(n):
	a[i] = input()
ans = 0
for i in range(n):
	(q, w) = (0, 0)
	for j in range(n):
		if a[i][j] == 'C':
			q += 1
		if a[j][i] == 'C':
			w += 1
	ans += C(q) + C(w)
print(ans)


data = []
n = int(input())
for i in range(n):
	temp = input().strip()
	data.append(temp)
ans = 0
for i in range(n):
	temp = data[i].count('C')
	ans += temp * (temp - 1) // 2
for i in range(n):
	cnt = 0
	for j in range(n):
		if data[j][i] == 'C':
			cnt += 1
	ans += cnt * (cnt - 1) // 2
print(ans)


n = int(input())
a = list()
for i in range(n):
	a.append(input())
mx = 0
for i in range(n):
	count = 0
	for j in range(n):
		if a[i][j] == 'C':
			count += 1
	mx += count * (count - 1) // 2
for i in range(n):
	count = 0
	for j in range(n):
		if a[j][i] == 'C':
			count += 1
	mx += count * (count - 1) // 2
print(mx)


n = int(input())
l = []
for i in range(n):
	s = input()
	a = []
	for j in s:
		a.append(j)
	l.append(a)
c = 0
for i in l:
	p = i.count('C')
	c += p * (p - 1) / 2
for j in range(n):
	cm = 0
	for i in range(n):
		if l[i][j] == 'C':
			cm += 1
	p = cm
	c += p * (p - 1) / 2
print(int(c))


n = int(input())
columns = dict()
total = 0
for i in range(n):
	row = input()
	row_count = 0
	for j in range(n):
		if row[j] == 'C':
			row_count += 1
			columns[j] = columns.get(j, 0) + 1
	if row_count >= 2:
		total += row_count * (row_count - 1) // 2
for v in columns.values():
	total += v * (v - 1) // 2
print(total)


def main():
	n = int(input())
	data = []
	for i in range(n):
		data.append(input())
	res = 0
	for i in range(0, n):
		s = 0
		for j in range(0, n):
			for l in range(j + 1, n):
				if data[i][j] == data[i][l] and data[i][j] == 'C':
					s += 1
		res += s
	for i in range(0, n):
		s = 0
		for j in range(0, n):
			for l in range(j + 1, n):
				if data[j][i] == data[l][i] and data[j][i] == 'C':
					s += 1
		res += s
	print(res)
main()


n = int(input())
a = [input() for i in range(n)]
res = 0
for i in range(n):
	r = a[i].count('C')
	res += r * (r - 1) // 2
for i in range(n):
	r = 0
	for j in range(n):
		if a[j][i] == 'C':
			r += 1
	res += r * (r - 1) // 2
print(res)


c = 0
n = int(input())
a = []
b = []
for i in range(n):
	a.append(input())
	b.append(a[i])
for i in range(n):
	for k in range(n):
		if b[i][k] == 'C':
			for x in range(k + 1, n):
				if b[i][x] == 'C':
					c += 1
for i in range(n):
	for k in range(n):
		if a[i][k] == 'C':
			for x in range(i + 1, n):
				if a[x][k] == 'C':
					c += 1
print(c)


def nCr(n, r):
	if r > n / 2:
		a = r + 1
		return round(fact(n, a) / fact(n - r))
	else:
		a = n - r + 1
		return round(fact(n, a) / fact(r))

def fact(n, r=2):
	res = round(1)
	for i in range(r, n + 1):
		res = res * i
	return round(res)
n = int(input())
result = 0
values = []
for i in range(n):
	values.append(0)
for i in range(n):
	tmp_inp = input()
	tmp_val = tmp_inp.count('C')
	result += nCr(tmp_val, 2) if tmp_val > 1 else 0
	for j in range(len(tmp_inp)):
		if tmp_inp[j] == 'C':
			values[j] += 1
for i in range(n):
	result += nCr(values[i], 2) if values[i] > 1 else 0
print(result)


n = int(input())
M = [str(input()) for _ in range(n)]
R = [0 for _ in range(n)]
C = [0 for _ in range(n)]
for i in range(n):
	for j in range(n):
		if M[i][j] == 'C':
			R[i] += 1
			C[j] += 1
r = 0
for i in range(n):
	r = r + (R[i] - 1) * R[i] // 2
	r = r + (C[i] - 1) * C[i] // 2
print(r)


n = int(input())
m = []
for _ in range(n):
	m.append(input())
ans = 0
for i in range(n):
	cnt = m[i].count('C')
	ans += cnt * (cnt - 1) // 2
for i in range(n):
	cnt = [row[i] for row in m].count('C')
	ans += cnt * (cnt - 1) // 2
print(ans)


s = []
from math import factorial
z = []
p = 0

def c(a, b):
	return factorial(a) / (factorial(b) * factorial(a - b))
x = int(input())
v = [0] * x
for n in range(x):
	z = list(input())
	if z.count('C') >= 2:
		p += c(z.count('C'), 2)
	for k in range(x):
		if z[k] == 'C':
			v[k] += 1
for n in range(x):
	if v[n] <= 1:
		v[n] = 0
	else:
		v[n] = c(v[n], 2)
j = sum(v)
print(int(p + j))


import math
N = int(input())
L = []
for i in range(N):
	L.append(list(input()))
sum = 0
for i in range(N):
	count1 = 0
	count2 = 0
	for j in range(N):
		if L[i][j] == 'C':
			count1 += 1
	if count1 >= 2:
		sum += int(math.factorial(count1) / math.factorial(count1 - 2))
	for k in range(N):
		if L[k][i] == 'C':
			count2 += 1
	if count2 >= 2:
		sum += int(math.factorial(count2) / math.factorial(count2 - 2))
print(int(sum / 2))


N = int(input())
res = 0
lis = []
for _ in range(N):
	lis.append(list(input()))
l = [0] * N
for i in range(N):
	row = 0
	for j in range(N):
		if lis[i][j] == 'C':
			l[j] += 1
			row += 1
	res += row * (row - 1) / 2
for i in l:
	res += i * (i - 1) / 2
print(int(res))


n = int(input())
arr = []
for i in range(0, n):
	a1 = input()
	a1 = list(a1)
	arr.append(a1)
ans = 0

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def ncr(n, r):
	return fact(n) // (fact(r) * fact(n - r))
for i in range(0, n):
	count1 = 0
	count2 = 0
	for j in range(0, n):
		if arr[i][j] == 'C':
			count1 += 1
		if arr[j][i] == 'C':
			count2 += 1
	ans = ans + ncr(count1, 2) + ncr(count2, 2)
print(ans)


from math import factorial
hat = int(input())
lst = []
ms2ala = []
total = 0
for i in range(hat):
	ms2ala.append(list(input()))
for i in range(hat):
	row = 0
	column = 0
	for j in range(hat):
		if ms2ala[i][j] == 'C':
			row += 1
		if ms2ala[j][i] == 'C':
			column += 1
	lst.append(row)
	lst.append(column)
for i in lst:
	total += i * (i - 1) / 2
print(int(total))


def fact(n):
	s = 1
	for i in range(1, n + 1):
		s *= i
	return s

def C(n, r):
	res = fact(n) / (fact(r) * fact(n - r))
	return res
n = int(input())
res = [[0 for i in range(n)] for _ in range(2)]
r = 0
for i in range(n):
	row = str(input())
	for j in range(n):
		if row[j] == 'C':
			res[0][i] += 1
			res[1][j] += 1
for i in res:
	for j in i:
		if j >= 2:
			r += C(j, 2)
print(int(r))


n = int(input())
ans1 = [0 for i in range(100)]
ans = 0
for i in range(n):
	l = input()
	c = l.count('C')
	ans += c * (c - 1) // 2
	for j in range(len(l)):
		if l[j] == 'C':
			ans1[j] += 1
for i in ans1:
	ans += i * (i - 1) // 2
print(ans)


n = int(input())
a = [0] * 100
result = 0
for _ in range(n):
	line = input()
	c = line.count('C')
	result += c * (c - 1) // 2
	for i in range(len(line)):
		a[i] += 1 if line[i] == 'C' else 0
for e in a:
	result += e * (e - 1) // 2
print(result)


def f(n):
	return n * (n - 1) // 2
n = int(input())
ver = [0] * n
gor = [0] * n
for i in range(n):
	lst = input()
	for j in range(n):
		if lst[j] == 'C':
			gor[i] += 1
			ver[j] += 1
ans = 0
for i in ver:
	ans += f(i)
for i in gor:
	ans += f(i)
print(ans)


matrix = list()
result = int()
for i in range(int(input())):
	matrix.append(input())
for row in matrix:
	count = row.count('C')
	result += (count - 1) * count // 2
for column in zip(*matrix):
	count = column.count('C')
	result += (count - 1) * count // 2
print(result)


n = int(input())
mylist = []
ans = 0
for i in range(n):
	line = input()
	cnt = line.count('C')
	if cnt > 1:
		ans += cnt * (cnt - 1) // 2
	mylist.append(line)
mylist = list(map(list, zip(*mylist)))
for line in mylist:
	cnt = line.count('C')
	if cnt > 1:
		ans += cnt * (cnt - 1) // 2
print(ans)


from math import *
import sys
n = int(sys.stdin.readline())
m = []
cntInColumn = cntInRows = 0
total = 0
for i in range(n):
	vec = []
	for j in range(n):
		c = sys.stdin.read(1)
		cntInRows = cntInRows + 1 if c == 'C' else cntInRows
		vec.append(c)
	total += factorial(cntInRows) // (factorial(cntInRows - 2) * 2) if cntInRows >= 2 else 0
	cntInRows = 0
	sys.stdin.read(1)
	m.append(vec)
for i in range(n):
	for j in range(n):
		cntInColumn = cntInColumn + 1 if m[j][i] == 'C' else cntInColumn
	total += factorial(cntInColumn) // (factorial(cntInColumn - 2) * 2) if cntInColumn >= 2 else 0
	cntInColumn = 0
print(total)


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	c = 0
	n = inp()
	row = {}
	col = {}
	for i in range(n):
		row[i] = 0
		col[i] = 0
	for i in range(n):
		s = input()
		for j in range(n):
			if s[j] == 'C':
				row[i] += 1
				col[j] += 1
	for i in row:
		c += row[i] * (row[i] - 1) // 2
	for i in col:
		c += col[i] * (col[i] - 1) // 2
	print(c)
for _ in range(1):
	solve()


n = int(input())
maps = []
ans = 0
for i in range(n):
	maps.append(input())
	ans += (maps[-1].count('C') - 1) * maps[-1].count('C') // 2
for i in range(n):
	cnt = 0
	for j in range(n):
		if maps[j][i] == 'C':
			cnt += 1
	ans += (cnt - 1) * cnt // 2
print(ans)


t = []
n = int(input())
res = 0
for i in range(n):
	t.append(list(input()))
	count_C = 0
	for j in range(n):
		if t[i][j] == 'C':
			count_C += 1
	if count_C > 1:
		res += count_C * (count_C - 1) // 2
for i in range(n):
	count_C = 0
	for j in range(n):
		if t[j][i] == 'C':
			count_C += 1
	if count_C > 1:
		res += count_C * (count_C - 1) // 2
print(res)


n = int(input())
v = []
for _ in range(n):
	v.append(input())
r = 0
for i in range(n):
	t = sum([1 for x in v[i] if x == 'C'])
	r += t * (t - 1) // 2
for i in range(n):
	t = sum([1 for j in range(n) if v[j][i] == 'C'])
	r += t * (t - 1) // 2
print(r)


size = int(input())
m = []
h = 0
for i in range(size):
	line = input()
	c = line.count('C')
	h += c * (c - 1) / 2
	m.append(line)
for i in range(size):
	C = 0
	for j in range(size):
		if m[j][i] == 'C':
			C += 1
	h += C * (C - 1) / 2
print(int(h))


import collections
import math
n = int(input())
t = [input() for _ in range(n)]
ans = 0
for i in range(n):
	x = t[i].count('C')
	if x >= 2:
		ans += (x - 1) * x // 2
for i in range(n):
	temp = 0
	for j in range(n):
		if t[j][i] == 'C':
			temp += 1
	if temp >= 2:
		ans += (temp - 1) * temp // 2
print(ans)


n = 100
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i

def ncr(n, r):
	return fact[n] / (fact[n - r] * fact[r])
n = int(input())
z = []
for i in range(n):
	z.append(input())
c = 0
for i in range(n):
	(a, b) = (0, 0)
	for j in range(n):
		if z[i][j] == 'C':
			a += 1
		if z[j][i] == 'C':
			b += 1
	c += ncr(a, 2) + ncr(b, 2)
print(int(c))


def f(n):
	return n * (n - 1) // 2
n = int(input())
ss = []
rx = []
for i in range(n):
	s = input()
	x = s.count('C')
	rx.append(x)
	ss.append(s)
cx = []
for j in range(n):
	c = 0
	for i in range(n):
		if ss[i][j] == 'C':
			c += 1
	cx.append(c)
r = 0
for x in rx:
	if x != 0:
		r += f(x)
for x in cx:
	if x != 0:
		r += f(x)
print(r)


n = int(input())
h = [0 for i in range(n)]
v = [0 for i in range(n)]
k = n
while k > 0:
	k -= 1
	s = input()
	for i in range(n):
		if s[i] == 'C':
			h[k] += 1
			v[i] += 1
sm = 0
for i in range(n):
	sm += h[i] * (h[i] - 1) // 2 + v[i] * (v[i] - 1) // 2
print(sm)


n = int(input())
text = [list(input()) for i in range(n)]
rez = 0
for i in text:
	a = i.count('C')
	rez += a * (a - 1) // 2
for i in range(n):
	a = 0
	for j in range(n):
		if text[j][i] == 'C':
			a += 1
	rez += a * (a - 1) // 2
print(rez)


from math import factorial
n = int(input())
a = []
for i in range(n):
	temp = input()
	a.append(temp)
r = [0] * n
c = [0] * n
for i in range(n):
	for j in range(n):
		if a[i][j] == 'C':
			r[i] += 1
			c[j] += 1
ans = 0
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
for (i, j) in zip(r, c):
	if i >= 2:
		ans += comb(i, 2)
	if j >= 2:
		ans += comb(j, 2)
print(ans)


a = int(input())
c = []
d = []
k = 0
l = 0
for i in range(a):
	c.append(input())
	if c[i].count('C') > 1:
		d.append(c[i])
		for j in range(a):
			if d[0][l] == 'C':
				d[0] = d[0][:l] + d[0][l + 1:]
				k += d[0].count('C')
			else:
				l += 1
		l = 0
		d = []
for j in range(a):
	for i in range(a):
		d.append(c[i][j])
	for j in range(a):
		if d[l] == 'C':
			d.pop(l)
			k += d.count('C')
		else:
			l += 1
	l = 0
	d = []
print(k)


def factorial(n):
	if n == 1:
		return 1
	if n == 0:
		return 1
	return n * factorial(n - 1)

def cnk(n, k):
	if k > n:
		return 0
	return factorial(n) / (factorial(n - k) * factorial(k))

def main():
	result = 0
	n = int(input())
	data = list()
	new_data = list()
	for i in range(n):
		data.append(list(input()))
		result += cnk(data[i].count('C'), 2)
	for i in range(len(data[0])):
		new_data.append(list())
		for j in range(len(data)):
			new_data[i].append(data[j][i])
	for i in range(n):
		result += cnk(new_data[i].count('C'), 2)
	print(int(result))
main()


n = int(input())
mat = [''] * n
r = 0
for k in range(n):
	mat[k] = input()
	r += mat[k].count('C') * (mat[k].count('C') - 1) / 2
for k in range(n):
	c = 0
	for i in range(n):
		c += mat[i][k] == 'C'
	r += c * (c - 1) / 2
print(int(r))


n = int(input())
M = [[c == 'C' for c in input()] for i in range(n)]
K = [sum(M[i]) for i in range(n)]
L = [sum((M[i][j] for i in range(n))) for j in range(n)]
ans = sum((k * (k - 1) // 2 for k in K)) + sum((l * (l - 1) // 2 for l in L))
print(ans)


n = int(input())
ans = 0
mat = []
for i in range(n):
	x = input()
	yo = x.count('C')
	ans += yo * (yo - 1) // 2
	mat.append(x)
for i in range(n):
	count = 0
	for j in range(n):
		if mat[j][i] == 'C':
			count += 1
	ans += count * (count - 1) // 2
print(ans)


n = int(input())
s = [list(input()) for i in range(n)]
count = 0
for i in range(n):
	count += s[i].count('C') * (s[i].count('C') - 1) // 2
for j in range(n):
	count1 = 0
	for i in range(n):
		if s[i][j] == 'C':
			count1 += 1
	count += count1 * (count1 - 1) // 2
print(count)


import math
n = int(input())
M = []
for _ in range(n):
	M.append(input())
ans = 0
for i in range(n):
	row = M[i].count('C')
	if row >= 2:
		ans += math.factorial(row) / (math.factorial(row - 2) * 2)
	c = 0
	for j in range(n):
		if M[j][i] == 'C':
			c += 1
	if c >= 2:
		ans += math.factorial(c) / (math.factorial(c - 2) * 2)
print(int(ans))


__author__ = 'aste'

def main():
	n = int(input())
	rows = [0] * n
	cols = [0] * n
	res = 0
	for i in range(0, n):
		row = input()
		for j in range(0, n):
			if row[j] == 'C':
				res += rows[i] + cols[j]
				rows[i] += 1
				cols[j] += 1
	print(res)
main()


n = int(input())
a = []
for i in range(n):
	a += list(input().split())
b = [row.count('C') for row in a]
b = [x * (x - 1) // 2 for x in b]
c = [[row[i] for row in a].count('C') for i in range(n)]
c = [x * (x - 1) // 2 for x in c]
print(sum(c) + sum(b))


n = int(input())
ans = 0
p = []
for i in range(n):
	p.append(list(input()))
	s = p[i].count('C')
	ans += s * (s - 1)
for i in range(n):
	col = 0
	for t in range(n):
		if p[t][i] == 'C':
			col += 1
	ans += col * (col - 1)
print(ans // 2)


n = int(input())
L = []
c = 0
for i in range(n):
	L.append(input())

def f(x):
	return x * (x - 1) // 2
for i in range(n):
	c += f(L[i].count('C')) + f([L[x][i] for x in range(n)].count('C'))
print(c)


import math

def nCr(n, r):
	if n - r == 0:
		return 1
	f = math.factorial
	return f(n) // f(r) // f(n - r)

def solve(arr):
	count = 0
	for i in range(len(arr)):
		count_row_c = arr[i].count('C')
		if count_row_c >= 2:
			count += nCr(count_row_c, 2)
		count_col_c = 0
		for j in range(len(arr)):
			if arr[j][i] == 'C':
				count_col_c += 1
		if count_col_c >= 2:
			count += nCr(count_col_c, 2)
	return count

def main():
	n = int(input())
	arr = []
	for i in range(n):
		i = input()
		arr.append(list(i))
	print(solve(arr))
main()


n = int(input())
cake = []
happ = 0
for i in range(n):
	row = input()
	cnt = row.count('C')
	happ += cnt * (cnt - 1) / 2
	cake.append(row)
for col in range(n):
	cnt = 0
	for row in range(n):
		if cake[row][col] == 'C':
			cnt += 1
	happ += cnt * (cnt - 1) / 2
print(int(happ))


n = int(input())
from sys import stdin
from math import factorial
lines = [stdin.readline() for i in range(n)]
table = [list(line.strip()) for line in lines]
table = [[1 if c == 'C' else 0 for c in line] for line in table]
t_table = list(map(list, zip(*table)))
count = 0
for i in range(n):
	num = sum(table[i])
	if num > 1:
		num_pairings = factorial(num) / factorial(2) / factorial(num - 2)
		count += num_pairings
	num = sum(t_table[i])
	if num > 1:
		num_pairings = factorial(num) / factorial(2) / factorial(num - 2)
		count += num_pairings
print(int(count))


import math

def nCr(n, r):
	return math.factorial(n) / (math.factorial(r) * math.factorial(n - r))
n = int(input())
l = []
for i in range(n):
	l.append(input())
k1 = 0
k2 = 0
for i in range(n):
	c1 = 0
	for j in range(n):
		if l[i][j] == 'C':
			c1 = c1 + 1
	if c1 >= 2:
		k1 = k1 + nCr(c1, 2)
for i in range(n):
	c2 = 0
	for j in range(n):
		if l[j][i] == 'C':
			c2 = c2 + 1
	if c2 >= 2:
		k2 = k2 + nCr(c2, 2)
print(int(k1 + k2))


readInts = lambda : list(map(int, input().split()))
n = int(input())
g = []
for i in range(n):
	g += [input()]
ret = 0
for i in range(n):
	cnt = g[i].count('C')
	ret += cnt * (cnt - 1) // 2
for j in range(n):
	cnt = 0
	for i in range(n):
		cnt += g[i][j] == 'C'
	ret += cnt * (cnt - 1) // 2
print(ret)


N = int(input())
table = [input() for i in range(N)]
ans = 0
for i in range(N):
	cnt = 0
	for j in range(N):
		if table[i][j] == 'C':
			cnt += 1
	ans += cnt * (cnt - 1) // 2
for j in range(N):
	cnt = 0
	for i in range(N):
		if table[i][j] == 'C':
			cnt += 1
	ans += cnt * (cnt - 1) // 2
print(ans)


def c(n):
	return n * (n - 1) // 2
n = int(input())
k = []
for i in range(n):
	k.append(input())
sum = 0
for i in range(n):
	ns = 0
	for j in range(n):
		ns += int(k[i][j] == 'C')
	sum += c(ns)
for i in range(n):
	ns = 0
	for j in range(n):
		ns += int(k[j][i] == 'C')
	sum += c(ns)
print(sum)


n = int(input())
a = []
for _ in range(n):
	a.append(input())
b = []
for i in range(n):
	b.append(''.join((a[j][i] for j in range(n))))
ans = sum((a[i].count('C') * (a[i].count('C') - 1) // 2 for i in range(n)))
ans += sum((b[i].count('C') * (b[i].count('C') - 1) // 2 for i in range(n)))
print(ans)


n = int(input())
l = []

def find(word):
	count = 0
	for i in word:
		if i == 'C':
			count += 1
	return count
z = 0
for i in range(n):
	l.append(input())
	z += find(l[i]) * (find(l[i]) - 1) / 2
for i in range(n):
	count = 0
	for y in range(n):
		if l[y][i] == 'C':
			count += 1
	z += count * (count - 1) / 2
z = int(z)
print(z)


n = int(input())
result = 0
arr = [0] * n
for i in range(n):
	s = input()
	result += sum(range(s.count('C')))
	for (j, ch) in enumerate(s):
		arr[j] += ch == 'C'
for i in range(n):
	result += sum(range(arr[i]))
print(result)


n = int(input())
a = ['' for i in range(n)]
for i in range(n):
	a[i] = input()
m = 0
for i in range(n):
	for j in range(n):
		for k in range(j):
			if a[i][j] == a[i][k] == 'C':
				m = m + 1
for i in range(n):
	for j in range(n):
		for k in range(j):
			if a[k][i] == a[j][i] == 'C':
				m = m + 1
print(m)


n = input()
n = int(n)
x = []
for y in range(n):
	t = input()
	x.append(t)
i = 0
c = 0
while i <= n - 1:
	j = 0
	while j <= n - 2:
		if x[i][j] is 'C':
			k = j + 1
			while k <= n - 1:
				if x[i][k] is 'C':
					c += 1
				k += 1
		j += 1
	i += 1
i = 0
while i <= n - 1:
	j = 0
	while j <= n - 2:
		if x[j][i] is 'C':
			k = j + 1
			while k <= n - 1:
				if x[k][i] is 'C':
					c += 1
				k += 1
		j += 1
	i += 1
print(c)