F. Dasha and Nightmares

Dasha, an excellent student, is studying at the best mathematical lyceum in the country. Recently, a mysterious stranger brought nn words consisting of small latin letters s1,s2,…,sns1,s2,…,sn to the lyceum. Since that day, Dasha has been tormented by nightmares.

Consider some pair of integers 〈i,j〉〈i,j〉 (1≤i≤j≤n1≤i≤j≤n). A nightmare is a string for which it is true:

  • It is obtained by concatenation sisjsisj;
  • Its length is odd;
  • The number of different letters in it is exactly 2525;
  • The number of occurrences of each letter that is in the word is odd.

For example, if si=si= "abcdefg" and sj=sj= "ijklmnopqrstuvwxyz", the pair 〈i,j〉〈i,j〉 creates a nightmare.

Dasha will stop having nightmares if she counts their number. There are too many nightmares, so Dasha needs your help. Count the number of different nightmares.

Nightmares are called different if the corresponding pairs 〈i,j〉〈i,j〉 are different. The pairs 〈i1,j1〉〈i1,j1〉 and 〈i2,j2〉〈i2,j2〉 are called different if i1≠i2i1≠i2 or j1≠j2j1≠j2.

Input

The first line contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of words.

The following nn lines contain the words s1,s2,…,sns1,s2,…,sn, consisting of small latin letters.

It is guaranteed that the total length of words does not exceed 5⋅1065⋅106.

Output

Print a single integer — the number of different nightmares.

Example

input

Copy

 

10

ftl

abcdefghijklmnopqrstuvwxy

abcdeffghijkllmnopqrsttuvwxy

ffftl

aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy

thedevid

bcdefghhiiiijklmnopqrsuwxyz

gorillasilverback

abcdefg

ijklmnopqrstuvwxyz

output

Copy

5

Note

In the first test, nightmares are created by pairs 〈1,3〉〈1,3〉, 〈2,5〉〈2,5〉, 〈3,4〉〈3,4〉, 〈6,7〉〈6,7〉, 〈9,10〉〈9,10〉.

思路

题目要求两个字符串相加他们中小写字母出现的次数等于25

字符串长度恰好是奇数

每个字母出现的次数恰好是奇数

比赛时写的时候没有发现他们中的一些联系,比赛后看别人的代码才发现的

就是出现25个奇数的话他们的长度也就是奇数,而奇数只能由奇数+偶数相加得来的

所以当一个字符串中如果某个字母出现偶数次的话那么一定要有一个出现奇数次的与他相加

就是说一个字母出现偶数次他在这两串合并并不起多大的作用

就相当于没有出现也可以说出现0次

然后恰好25个枚举某个数没出现过

然后o(n)循环就可以求出来了

#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f, N = 2e5 + 5, mod = 1e9 + 7;
int f[1 << 26];//状态压缩
signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	vector<string>s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	ll ans = 0;
	std::vector<std::vector<int>> cnt(n);
	for (int i = 0; i < n; i++) {
		cnt[i] = vector<int>(26);
	}
	vector<int>mask(n);
	for (int i = 0; i < n; i++) {
		for (auto c : s[i]) {
			cnt[i][c - 'a'] += 1;
		}
		for (int j = 0; j < 26; j++) {
			mask[i] |= (cnt[i][j] % 2) << j;
		}
	}
	for (int c = 0; c < 26; c++) {
		for (int i = 0; i < n; i++) {
			if (cnt[i][c] == 0) {
				ans += f[(1 << 26) - 1 - (1 << c) - mask[i]];
				f[mask[i]] += 1;
			}
		}
		for (int i = 0; i < n; i++) {
			if (cnt[i][c] == 0) {
				f[mask[i]] -= 1;
			}
		}
	}
	cout << ans << '\n';
}
 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值