1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
using namespace std;
int main()
{
	int n, k;
	cin>>n>>k;
	int t[2*n], p=n, o=2*n-1, b;
	double pre=0, in=0, wyn, a=1000000007;
	
	for(int i=0; i<k; i++)
	{
		t[2*n]={0};
		for(int j=n; j<2*n; j++)
		{
			cin>>t[j];
		}
		
		for(int x=0; x<n; x++)
		{
			t[p-1]=t[o];
			t[o]=0;
			p--;
			o--;
			pre++;
			for(int z=p; z<o; z++)
			{
				for(int y=z+1; y<=o; y++)
				{
					if(t[z]>t[y])
					{
						in++;
					}
				}
			}
		}
	}
	b=in/pre/a;
	wyn=in/pre/a-b;
	cout<<wyn;
	
	return 0;
}