using
System;
using
System.Collections.Generic;
class
Program
{
const
int
N = 200010;
static
long
[] sum =
new
long
[N];
static
long
Solve(
int
n,
string
[] strings)
{
Dictionary<
long
,
int
> positiveKeys =
new
Dictionary<
long
,
int
>();
Dictionary<
long
,
int
> negativeKeys =
new
Dictionary<
long
,
int
>();
for
(
long
i = 1; i <= n; ++i)
{
string
str_i = strings[i - 1];
long
len = str_i.Length;
long
ssum = 0;
for
(
long
j = 0; j < len; ++j)
{
ssum += str_i[(
int
)j] -
'0'
;
}
for
(
long
j = 0; j < len; ++j)
{
sum[i] += str_i[(
int
)j] -
'0'
;
long
positiveKey = 2 * sum[i] - ssum;
long
negativeKey = 2 * (j + 1) - len;
if
(positiveKeys.ContainsKey(positiveKey))
positiveKeys[positiveKey]++;
else
positiveKeys[positiveKey] = 1;
if
(negativeKeys.ContainsKey(negativeKey))
negativeKeys[negativeKey]++;
else
negativeKeys[negativeKey] = 1;
}
}
long
ans = 0;
for
(
long
i = 1; i <= n; ++i)
{
string
str_i = strings[i - 1];
long
len = str_i.Length;
long
positiveKey = sum[i];
long
negativeKey = -len;
if
(positiveKeys.ContainsKey(positiveKey))
ans += positiveKeys[positiveKey];
if
(negativeKeys.ContainsKey(negativeKey))
ans += negativeKeys[negativeKey];
}
return
ans;
}
static
void
Main()
{
long
n = 5;
string
[] strings = {
"2"
,
"22"
,
"222"
,
"2222"
,
"22222"
};
Console.WriteLine(Solve((
int
)n, strings));
}
}