Codeforces Round #824 (Div. 2)

D. Meta-set

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You like the card board game "Set". Each card contains kk features, each of which is equal to a value from the set {0,1,2}. The deck contains all possible variants of cards, that is, there are 3^k different cards in total.

A feature for three cards is called good if it is the same for these cards or pairwise distinct. Three cards are called a set if all kk features are good for them.

For example, the cards (0,0,0), (0,2,1), and(0,1,2) form a set, but the cards (0,2,2), (2,1,2), and(1,2,0) do not, as, for example, the last feature is not good.

A group of five cards is called a meta-set, if there is strictly more than one set among them. How many meta-sets there are among given nn distinct cards?

Input

The first line of the input contains two integers n and k (1≤n≤10^3,1≤k≤20) — the number of cards on a table and the number of card features. The description of the cards follows in the next nn lines.

Each line describing a card contains k integers ci,1,ci,2,…,ci,k(0≤ci,j≤2) — card features. It is guaranteed that all cards are distinct.

Output

Output one integer — the number of meta-sets.

Examples

input

8 4
0 0 0 0
0 0 0 1
0 0 0 2
0 0 1 0
0 0 2 0
0 1 0 0
1 0 0 0
2 2 0 0

output

1

input

7 4
0 0 0 0
0 0 0 1
0 0 0 2
0 0 1 0
0 0 2 0
0 1 0 0
0 2 0 0

output

3

input

9 2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2

output

54

input

20 4
0 2 0 0
0 2 2 2
0 2 2 1
0 2 0 1
1 2 2 0
1 2 1 0
1 2 2 1
1 2 0 1
1 1 2 2
1 1 0 2
1 1 2 1
1 1 1 1
2 1 2 0
2 1 1 2
2 1 2 1
2 1 1 1
0 1 1 2
0 0 1 0
2 2 0 0
2 0 0 2

output

0

Note

Let's draw the cards indicating the first four features. The first feature will indicate the number of objects on a card: 1, 2, 3. The second one is the color: red, green, purple. The third is the shape: oval, diamond, squiggle. The fourth is filling: open, striped, solid.

You can see the first three tests below. For the first two tests, the meta-sets are highlighted.

In the first test, the only meta-set is the five cards (0000, 0001, 0002, 0010, 0020). The sets in it are the triples (0000, 0001, 0002) and (0000, 0010, 0020). Also, a set is the triple (0100, 1000, 2200) which does not belong to any meta-set.

In the second test, the following groups of five cards are meta-sets: (0000, 0001, 0002, 0010, 0020), (0000, 0001, 0002, 0100, 0200), (0000, 0010, 0020, 0100, 0200).

In there third test, there are 5454 meta-sets.

#include<bits/stdc++.h>
using namespace std;
#define int long long
int C2(int x)
{
    return x*(x-1)/2;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<vector<int>>a(n,vector<int>(k));
    map<vector<int>,int>mp;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<k;j++)
        {
            cin>>a[i][j];
        }
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            vector<int>v(k);
            for(int t=0;t<k;t++)
            {
                v[t]=(6-a[i][t]-a[j][t])%3;
            }
            mp[v]++;
        }
    }
    for(int i=0;i<n;i++)
    {
        sum+=C2(mp[a[i]]);
    }
    cout<<sum<<"\n";


    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值