#include <iostream>
#include <queue>
#include <bitset>
using namespace std;

const int INF = 0x3f3f3f3f;

struct Mat {
    vector<vector<int> > data;
    Mat(vector<vector<int> > &d) {
        swap(d, data);
    }
    Mat(){}
    void operator *= (const Mat &o) {
        // cout<<data[0][3]<<'\n';
        vector<vector<int> > res(data.size(), vector<int>(o.data[0].size(), INF));
        for(int i = 0; i < data.size(); i++) {
            for(int j = 0; j < o.data[0].size(); j++) {
                for(int k = 0; k < o.data.size(); k++) {
                    res[i][j] = min(res[i][j], data[i][k] + o.data[k][j]);
                    // if(data.size() == 1)
                    //     cout<<bitset<8>(i)<<','<<bitset<8>(k)<<' '<<bitset<8>(k)<<','<<bitset<8>(j)<<' '<<data[i][k]<<' '<<o.data[k][j]<<' '<<res[i][j]<<'\n';
                }
            }
        }
        swap(data, res);
    }
};

ostream &operator << (ostream &_cout, Mat& mat) {
    cout<<"{\n";
    for(auto &m: mat.data) {
        for(int &v: m) {
            cout<<v<<' ';
        }
        cout<<'\n';
    }
    cout<<"}";
    return _cout;
}

int X, K, N, Q, jmp[9];vector<vector<int> > oneStep;
struct Stone {
    int loc, val;
    bool operator < (const Stone& o) const {
        return loc < o.loc;
    }
} magic[25];

vector<int> &go(vector<int> &beginState, int stepCnt, vector<int> &res) {
    // cout<<"go: "<<stepCnt<<'\n';
    auto step = oneStep;
    Mat mat(step);
    Mat origin;origin.data.resize(1);swap(origin.data[0], beginState);
    // cout<<bitset<8>(beginState)<<' '<<origin.data[0][beginState]<<'\n';
    for(int i = 0; (stepCnt >> i); i++) {
        if((stepCnt>>i) & 1){
            origin *= mat;
            // cout<<origin<<'\n';
        }
        mat *= mat;
        // cout<<mat<<'\n';
    }
    // cout<<origin<<'\n';
    swap(res, origin.data[0]);
    return res;
}

vector<int> &dp(vector<int> &lastState, int stepCnt, int stoneAfter[201], int stoneEffect[26]) {
    // cout<<"dp: "<<stepCnt<<'\n';
    // cout<<"dp: ";for(int i = 0; i < lastState.size(); i++) cout<<lastState[i]<<' ';
    // cout<<'\n';
    vector<int> res(lastState.size());
    int dp[stepCnt+1][lastState.size()];
    memset(dp, 0x3f, sizeof dp);
    for(int i = 0; i < lastState.size(); i++) {
        dp[0][i] = lastState[i];
    }
    for(int step = 0; step < stepCnt; step++) {
        for(int cur = 1; cur < (1<<K); cur++){
            if(__builtin_popcount(cur) != X || dp[step][cur] == INF) continue;
            if(cur & 1){
                for(int nb = 0; nb < K; nb++) {
                    if(!((cur>>1) & (1<<nb))) {
                        // cout<<"HI\n";
                        int nxt = (cur>>1) | (1<<nb);
                        // cout<<nxt<<'\n';
                        dp[step+1][nxt] = min(dp[step+1][nxt], dp[step][cur] + jmp[nb+1] + stoneEffect[stoneAfter[nb + step+1]]);
                    }
                }
            }
            else{
                int nxt = cur>>1;
                dp[step+1][nxt] = min(dp[step+1][nxt], dp[step][cur]);
            }
        }
        // cout<<"dp: ";for(int i = 0; i < lastState.size(); i++) cout<<dp[step+1][i]<<'('<<bitset<8>(i)<<')'<<' ';
        // cout<<'\n';
    }
    for(int i = 0; i < lastState.size(); i++) {
        lastState[i] = dp[stepCnt][i];
    }
    return lastState;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>X>>K>>N>>Q;
    for(int i = 1; i <= K; i++) {
        cin>>jmp[i];
    }

    for(int i = 0; i < Q; i++) {
        cin>>magic[i].loc>>magic[i].val;
    }
    sort(magic, magic + Q);
    oneStep.resize(1<<K, vector<int> (1<<K, INF));
    for(int cur = 1; cur < (1<<K); cur++) {
        if(__builtin_popcount(cur) == X && (cur & 1) == 1) {
            for(int nb = 0; nb < K; nb++) {
                if(!((cur>>1) & (1<<nb))) {
                    // cout<<"HI\n";
                    int nxt = (cur>>1) | (1<<nb);
                    // cout<<nxt<<'\n';
                    oneStep[cur][nxt] = min(oneStep[cur][nxt], jmp[nb+1]);
                }
            }
        }
        else if (__builtin_popcount(cur) == X && (cur & 1) != 1) {
            oneStep[cur][cur>>1] = 0;
        }
    }
    // Mat fp(oneStep);
    // cout<<fp<<'\n';
    vector<int> res;
    vector<int> lastState(1<<K, INF);lastState[(1<<X)-1] = 0;
    int stoneEffect[26] = {};
    for(int i = 0; i < Q; i++) {
        stoneEffect[i+1] = magic[i].val;
    }
    int curLoc = 0;
    for(int i = 0; i < Q;) {
        if(magic[i].loc-K-curLoc > 0){
            // cout<<magic[i].loc<<' '<<K<<' '<<curLoc<<'\n';
            res = go(lastState, magic[i].loc-K-curLoc, res);
            curLoc = magic[i].loc-K;
            // cout<<curLoc<<'\n';
            swap(lastState, res);
        }
        int stoneAfter[201] = {};

        stoneAfter[K] = ++i;
        int st_loc = magic[i-1].loc;
        // cout<<st_loc<<' '<< K <<' '<< magic[i].loc<<'\n';
        while(i < Q && st_loc + K >= magic[i].loc){
            st_loc = magic[i].loc;
            stoneAfter[st_loc - curLoc] = ++i;
            // cout<<"st_loc: "<<st_loc<<'\n';
        }
        lastState = dp(lastState, st_loc - curLoc, stoneAfter, stoneEffect);
        curLoc = st_loc;
        // for(int &i: lastState) {
        //     cout<<i<<' ';
        // }
        // cout<<'\n';
    }
    res = go(lastState, N - curLoc - K, res);
    // for(int &i: res) {
    //     cout<<i<<' ';
    // }
    // cout<<'\n';
    int ans = INF;
    for(int i = 0; i <= (K-X); i++){
        ans = min(ans, res[((1<<X)-1)<<(K-X-i)]);
        swap(lastState, res);
        res = go(lastState, 1, res);
    }
    cout<<ans<<'\n';
    return 0;
}


#include <iostream>
#include <queue>
#include <bitset>
#include <cstring>
using namespace std;

const int INF = 0x3f3f3f3f;

struct Mat {
    vector<vector<int> > data;
    Mat(vector<vector<int> > &d) {
        swap(d, data);
    }
    Mat(){}
    void operator *= (const Mat &o) {
        // cout<<data[0][3]<<'\n';
        vector<vector<int> > res(data.size(), vector<int>(o.data[0].size(), INF));
        for(int i = 0; i < data.size(); i++) {
            for(int j = 0; j < o.data[0].size(); j++) {
                for(int k = 0; k < o.data.size(); k++) {
                    res[i][j] = min(res[i][j], data[i][k] + o.data[k][j]);
                    // if(data.size() == 1)
                    //     cout<<bitset<8>(i)<<','<<bitset<8>(k)<<' '<<bitset<8>(k)<<','<<bitset<8>(j)<<' '<<data[i][k]<<' '<<o.data[k][j]<<' '<<res[i][j]<<'\n';
                }
            }
        }
        swap(data, res);
    }
};

ostream &operator << (ostream &_cout, Mat& mat) {
    cout<<"{\n";
    for(auto &m: mat.data) {
        for(int &v: m) {
            cout<<v<<' ';
        }
        cout<<'\n';
    }
    cout<<"}";
    return _cout;
}

int X, K, N, Q, jmp[9];vector<vector<int> > oneStep;
struct Stone {
    int loc, val;
    bool operator < (const Stone& o) const {
        return loc < o.loc;
    }
} magic[25];

vector<int> &go(vector<int> &beginState, int stepCnt, vector<int> &res) {
    // cout<<"go: "<<stepCnt<<'\n';
    auto step = oneStep;
    Mat mat(step);
    Mat origin;origin.data.resize(1);swap(origin.data[0], beginState);
    // cout<<bitset<8>(beginState)<<' '<<origin.data[0][beginState]<<'\n';
    for(int i = 0; (stepCnt >> i); i++) {
        if((stepCnt>>i) & 1){
            origin *= mat;
            // cout<<origin<<'\n';
        }
        mat *= mat;
        // cout<<mat<<'\n';
    }
    // cout<<origin<<'\n';
    swap(res, origin.data[0]);
    return res;
}

vector<int> &dp(vector<int> &lastState, int stepCnt, int stoneAfter[201], int stoneEffect[26]) {
    // cout<<"dp: "<<stepCnt<<'\n';
    // cout<<"dp: ";for(int i = 0; i < lastState.size(); i++) cout<<lastState[i]<<' ';
    // cout<<'\n';
    vector<int> res(lastState.size());
    int dp[stepCnt+1][lastState.size()];
    memset(dp, 0x3f, sizeof dp);
    for(int i = 0; i < lastState.size(); i++) {
        dp[0][i] = lastState[i];
    }
    for(int step = 0; step < stepCnt; step++) {
        for(int cur = 1; cur < (1<<K); cur++){
            if(__builtin_popcount(cur) != X || dp[step][cur] == INF) continue;
            if(cur & 1){
                for(int nb = 0; nb < K; nb++) {
                    if(!((cur>>1) & (1<<nb))) {
                        // cout<<"HI\n";
                        int nxt = (cur>>1) | (1<<nb);
                        // cout<<nxt<<'\n';
                        dp[step+1][nxt] = min(dp[step+1][nxt], dp[step][cur] + jmp[nb+1] + stoneEffect[stoneAfter[nb + step+1]]);
                    }
                }
            }
            else{
                int nxt = cur>>1;
                dp[step+1][nxt] = min(dp[step+1][nxt], dp[step][cur]);
            }
        }
        // cout<<"dp: ";for(int i = 0; i < lastState.size(); i++) cout<<dp[step+1][i]<<'('<<bitset<8>(i)<<')'<<' ';
        // cout<<'\n';
    }
    for(int i = 0; i < lastState.size(); i++) {
        lastState[i] = dp[stepCnt][i];
    }
    return lastState;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>X>>K>>N>>Q;
    for(int i = 1; i <= K; i++) {
        cin>>jmp[i];
    }

    for(int i = 0; i < Q; i++) {
        cin>>magic[i].loc>>magic[i].val;
    }
    sort(magic, magic + Q);
    oneStep.resize(1<<K, vector<int> (1<<K, INF));
    for(int cur = 1; cur < (1<<K); cur++) {
        if(__builtin_popcount(cur) == X && (cur & 1) == 1) {
            for(int nb = 0; nb < K; nb++) {
                if(!((cur>>1) & (1<<nb))) {
                    // cout<<"HI\n";
                    int nxt = (cur>>1) | (1<<nb);
                    // cout<<nxt<<'\n';
                    oneStep[cur][nxt] = min(oneStep[cur][nxt], jmp[nb+1]);
                }
            }
        }
        else if (__builtin_popcount(cur) == X && (cur & 1) != 1) {
            oneStep[cur][cur>>1] = 0;
        }
    }
    // Mat fp(oneStep);
    // cout<<fp<<'\n';
    vector<int> res;
    vector<int> lastState(1<<K, INF);lastState[(1<<X)-1] = 0;
    int stoneEffect[26] = {};
    for(int i = 0; i < Q; i++) {
        stoneEffect[i+1] = magic[i].val;
    }
    int curLoc = 0;
    for(int i = 0; i < Q;) {
        if(magic[i].loc-K-curLoc > 0){
            // cout<<magic[i].loc<<' '<<K<<' '<<curLoc<<'\n';
            res = go(lastState, magic[i].loc-K-curLoc, res);
            curLoc = magic[i].loc-K;
            // cout<<curLoc<<'\n';
            swap(lastState, res);
        }
        int stoneAfter[201] = {};

        stoneAfter[K] = ++i;
        int st_loc = magic[i-1].loc;
        // cout<<st_loc<<' '<< K <<' '<< magic[i].loc<<'\n';
        while(i < Q && st_loc + K >= magic[i].loc){
            st_loc = magic[i].loc;
            stoneAfter[st_loc - curLoc] = ++i;
            // cout<<"st_loc: "<<st_loc<<'\n';
        }
        lastState = dp(lastState, st_loc - curLoc, stoneAfter, stoneEffect);
        curLoc = st_loc;
        // for(int &i: lastState) {
        //     cout<<i<<' ';
        // }
        // cout<<'\n';
    }
    res = go(lastState, N - curLoc - K, res);
    // for(int &i: res) {
    //     cout<<i<<' ';
    // }
    // cout<<'\n';
    int ans = INF;
    for(int i = 0; i <= (K-X); i++){
        ans = min(ans, res[((1<<X)-1)<<(K-X-i)]);
        swap(lastState, res);
        res = go(lastState, 1, res);
    }
    cout<<ans<<'\n';
    return 0;
}


///                         .
///                     /   ))     |\         )               ).
///               c++. (\  ( `.    / )  (\   ( `.     ).     ( (
///               | |   ))  ) )   ( (   `.`.  ) )    ( (      ) )
///               | |  ( ( / _..----.._  ) | ( ( _..----.._  ( (
/// ,-.           | |---) V.'-------.. `-. )-/.-' ..------ `--) \._
/// | /===========| |  (   |      ) ( ``-.`\/'.-''           (   ) ``-._
/// | | / / / / / | |--------------------->  <-------------------------_>=-
/// | \===========| |                 ..-'./\.`-..                _,,-'
/// `-'           | |-------._------''_.-'----`-._``------_.-----'
///               | |         ``----''            ``----''
///               | |
///               c++`

///██╗ ██████╗ ██╗    ██████╗  ██████╗  ██████╗   ██████╗
///██║██╔═══██╗██║    ╚════██╗██╔═████╗ ╚════██╗ ██╔═████╗
///██║██║   ██║██║     █████╔╝██║██╔██║  █████╔╝ ██║██╔██║
///██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██╔═══╝  ████╔╝██║
///██║╚██████╔╝██║    ███████╗╚██████╔╝ ███████╗ ╚██████╔╝
///╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚══════╝  ╚═════╝

#include<bits/stdc++.h>
#include<fstream>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define quluq return 0;
#define Zohiri_dzd
#define GO_Baby_GO
#define Mekh
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
deque <ll> v , vc , ve ,vv , vd ;
deque <char> p , pe ;
deque <string> ts , ss , st ;
deque <double> sd , ds ;
ll a , b , c , d , e , f , cnt , ans , r , n , l , x , y ;
ld q , t , cnt1 , cnt2 ;
string g , h , w , o , m , s ;
char z , u ;
bool re , rt ;
vector<pair < ll , ll > > pr , rp , pp ;
map < pair < ll , ll > , ll > aw , wa ;
int main ()
{
    bzbz
    mlojins
    Qulukh
    Mekh
    CODER
    Zohiri_dzd
    Black_star
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Author :: Murtazoev Alijon
    cin >> a >> b ;
    cin >> g ;
    if (a == 1 and g[0] == '1' and b != 0)
    {
        cout << 0 ;
        quluq
    }
    else if (a == 1 and g == '1' and b == 0)
    {
        cout << 1 ;
        quluq
    }
    if (a == 1 and g[0] == 0)
    {
        cout << 1;
        quluq
    }
    if (g[0] != '1' and b != 0)
        g[0] = '1' , b -- ;
    for (ll i = 1 ; i < g.size() ; i ++ )
    {
        if (g[i] != '0' and b != 0)
        {
            g[i] = '0' ;
            b -- ;
        }
    }
    cout << g ;
}
///Mmavl studios
///Eco students


#include <iostream>
using namespace std;
int main()
{
    int n=0;
    long long int k=0;
    string s;
    cin>>n>>k>>s;
    int l=s.length();
    if(l==1){
        cout<<"0";
    }
    else{
            if(s[0]!='1'){
                s[0]='1';
                k--;
            }
        for(int i=0;i<k;i++){
            int x=1;
            if(s[i+x]=='0'){
                x++;
                k++;
                continue;
            }
            s[i+x]='0';
        }
        cout<<s;
    }
    return 0;


#include <iostream>
using namespace std;
int main()
{
    int n,k=0;
    char o='1',z='0';
    string s;
    cin>>n>>k>>s;
    int l=s.length();
    if(l==1){
        cout<<"0";
    }
    else{
            if(s[0]!=o){
                s[0]=o;
                k--;
            }
        for(int i=0;i<k;i++){
            int x=1;
            while(1){
                if(s[i+x]!=z){
                    break;
                }
                x++;
            }
            s[i+x]=z;
        }
        cout<<s;
    }
    return 0;
}


/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n,k;
    string s;
    cin>>n>>k;
    cin>>s;
    if(n==1 && k){
        cout<<0;
        // cout<<"Brac";
    }
    else{
        int i=0;
        while(k){
            while(s[i]=='0'){
                i++;
                // cout<<"Brac1";
            }
            if(i==0 && s[i]!='1'){
                s[i]='1';
                k--;
                i++;
                // cout<<"Brac2";
            }
            else if(i==0 && s[i]=='1'){
                i++;
                // cout<<"Brac3";
            }
            if(i<n && 0<i){
                s[i]='0';
                k--;
                i++;
                // cout<<"Brac4";
            }
        }
        cout<<s;
    }

}


include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 200500, LOG = 20, inf = 1e9;

int n, k, a[N], up[LOG][N], cost[LOG][N];
int sum, A, pref[N];
pll ans;
map<int, int> lst[N];
int get(int i){
	i %= n;
	if(i <= ans.s)
		i += n;
	return a[i];
}
void gg(int l, int r, ll x, ll y){
	//cerr << l << " " << r << endl;
	a[l] = x, a[r] = y;
	for(int i = l + 1; i < r; i++)
		a[i] = 0;
	printf("%d ", l % n);
	for(int i = l; i <= r; i++)
		printf("%d ", a[i] + A);
	printf("\n");
}
void ff(int l, int r, ll need){
	if(l == r && a[l] == need)
		return;
	if(r - l + 1 <= k){
		a[l] = need;
		for(int i = l + 1; i <= r; i++)
			a[i] = 0;
		printf("%d ", l % n);
		for(int i = l; i <= l + k - 1; i++)
			printf("%d ", get(i) + A);
	   	printf("\n");
		return;
	}
    ll s = 0;
	for(int i = l; i <= l + k - 1; i++)
		s += a[i];
	if(s < need){
		ff(l + k - 1, r, need - s + a[l + k - 1]);
		gg(l, l + k - 1, need, 0);
	}else{
		gg(l, l + k - 1, need, s - need);
		ff(l + k - 1, r, 0);
	}
}
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	A = sum / n;
	for(int i = 0; i < n; i++)
		a[i + n] = (a[i] -= A);
	for(int i = 1; i < n + n; i++)
		pref[i] = pref[i - 1] + a[i];
	for(int i = 0; i < LOG; i++)
		for(int j = 0; j < N; j++)
			up[i][j] = n + n;
	for(int i = n + n - 1; i >= 0; i--){
		int rem = (i + 1) % (k - 1);
		if(lst[rem].count(pref[i]))
			up[0][i] = lst[rem][pref[i]], cost[0][i] = (lst[rem][pref[i]] - i + k - 3) / (k - 1);
		lst[i % (k - 1)][pref[i]] = i;
	}
	for(int j = 1; j < LOG; j++)
		for(int i = 0; i < n + n; i++)
            up[j][i] = up[j - 1][ up[j - 1][i] ], cost[j][i] = cost[j - 1][i] + cost[j - 1][ up[j - 1][i] ];
	ans = {inf, inf};
	for(int i = 0; i < n; i++){
		int v = i;
		int res = 0;
		for(int j = LOG - 1; j >= 0; j--)
			if(up[j][v] <= n + i)
				res += cost[j][v], v = up[j][v];
		if(v <= n + i)
			res += (n + i - v + k - 2) / (k - 1);
		ans = min(ans, {res, i});
	}
	printf("%d\n", ans.f);
	int v = ans.s;
	while(v < ans.s + n){
		if(up[0][v] < ans.s + n)
			ff(v + 1, up[0][v], 0);
		else
			ff(v + 1, ans.s + n, 0);
		v = up[0][v];
	}
	return 0;
}


#include <bits/stdc++.h>

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define reg register int
#define pii pair<int,int>
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int N = 1e5 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(cr x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(cr x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(cr x) {put(x), putchar(' ');}
I void pr2(cr x) {put(x), puts("");}

pii f[20][N * 2];
map<int, int> mp[N];
int tp; vector<int> ans[N];
int n, k, V, a[N * 2], s[N * 2];
bool bk;

I void gao(reg x) {
	++tp;
	if(x + k - 1 > n) {
		ans[tp].push_back(n - k);
		reg hh = -s[n - k];
		if(hh < 0) {
			bk = 1;
		}
		ans[tp].push_back(hh + V), a[n - k + 1] = hh, s[n - k + 1] = 0;
		for(reg i = n - k + 2; i <= n; i++) ans[tp].push_back(V), a[i] = s[i] = 0;
	} else {
		ans[tp].push_back(x - 1);
		reg up = x + k - 1, hh = -s[x - 1];
		ans[tp].push_back(hh + V), a[x] = hh; s[x] = 0;
		for(reg i = x + 1; i < up; i++) ans[tp].push_back(V), a[i] = s[i] = 0, v[i] = tp;
		ans[tp].push_back(s[up] + V), a[up] = s[up];
	}
}

void dfs(reg i) {
	if(i > n) return ;
	if(a[i] == 0 && s[i] == 0) {dfs(i + 1); return ;}
	reg up = _min(n, i + k - 1);
	if(s[up] >= 0) {
		gao(i), dfs(i + k - 1);
		if(bk) puts("1"), bk = 0;
	}
	else {
		dfs(i + k - 1), gao(i);
		if(bk) puts("2"), bk = 0;
	}
}

int main() {
	n = read(), k = read();
	for(reg i = 1; i <= n; i++) a[i] = read(), V += a[i];
	V /= n; for(reg i = 0; i <= 17; i++) f[i][2 * n + 1] = pii{2 * n + 1, 0};
	for(reg i = 1; i <= n; i++) a[i] = a[i] - V, a[i + n] = a[i];
	for(reg i = 1; i <= 2 * n; i++) s[i] = s[i - 1] + a[i];
	reg mn = 999999999, pos = -1;
	for(reg i = 2 * n; i >= 1; i--) {
		reg c = (i + 1) % (k - 1), nxt = 2 * n;
		if(mp[c][s[i]]) nxt = mp[c][s[i]], f[0][i] = pii{nxt, (nxt - i - 1) / (k - 1)};
		else f[0][i] = pii{2 * n + 1, 0};
		for(reg j = 1; j <= 17; j++) f[j][i] = pii{f[j - 1][f[j - 1][i].fi].fi, f[j - 1][i].se + f[j - 1][f[j - 1][i].fi].se};
		if(i <= n) {
			reg now = i, up = i + n, sum = 0;
			for(reg j = 17; j >= 0; j--) if(f[j][now].fi <= up){
				sum += f[j][now].se, now = f[j][now].fi;
			} sum += (up - now - 1 + k - 2) / (k - 1);
			if(sum < mn) mn = sum, pos = i;
		} mp[i % (k - 1)][s[i]] = i;
	} for(reg i = pos + 1; i <= n; i++) s[i - pos] = a[i];
	for(reg i = 1; i <= pos; i++) s[(i + n - pos - 1) % n + 1] = a[i];
	memcpy(a, s, sizeof(a)); for(reg i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
	dfs(1);
	pr2(tp);
	reg t1 = -1, t2 = -1;
	for(reg i = 1; i <= tp; i++) {
		for(reg j = 1; j <= k; j++) {
			if(ans[i][j] < 0) {
				t1 = ans[i][0], t2 = tp;
			}
		}
	} if(t1 != -1) printf("%d %d\n", t1, tp);
	for(reg i = 1; i <= tp; i++) {
		pr1((ans[i][0] + pos) % n);
		for(reg j = 1; j <= k; j++) pr1(ans[i][j]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 100000;
int a[maxn], p[maxn], n, k, avg;
map<int, vector<int>> mp;
void distribute(int l, int len, int need){
    //cout << "dis " << l << " " << len << " " << need << endl;
    //for(int i = 0; i < len; i += 1) cout << a[(l + i) % n] << " ";
    //cout << endl;
    if(len <= 1) return;
    if(a[l] == avg and need == 0){
        distribute((l + 1) % n, len - 1, 0);
        return;
    }
    int sum = 0, m = min(len, k);
    for(int i = 0; i < m; i += 1) sum += a[(l + i) % n];
    if(sum >= avg * (m - 1) + need){
        sum -= a[l] = avg + need;
        for(int i = 1; i < m - 1; i += 1) sum -= a[(l + i) % n] = avg;
        a[(l + m - 1) % n] = sum;
        cout << l;
        for(int i = 0; i < k; i += 1) cout << " " << a[(l + i) % n];
        cout << "\n";
        distribute((l + m - 1) % n, len - m + 1, 0);
        return;
    }
    distribute((l + m - 1) % n, len - m + 1, avg * (m - 1) + need - sum + a[(l + m - 1)]);
    sum = 0;
    for(int i = 0; i < m; i += 1) sum += a[(l + i) % n];
    for(int i = 1; i < m; i += 1) sum -= a[(l + i) % n] = avg;
    a[l] = sum;
    cout << l;
    for(int i = 0; i < k; i += 1) cout << " " << a[(l + i) % n];
    cout << "\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    for(int i = 0; i < n; i += 1){
        cin >> a[i];
        avg += a[i];
    }
    avg/= n;
    for(int i = 0; i < n; i += 1){
        p[i] = (i ? p[i - 1] + a[i] : a[0]) - avg;
        mp[p[i]].push_back(i);
    }
    int ans = 1;
    vector<int> cut(1);
    for(auto& p : mp){
        auto& v = p.second;
        int c = v.size();
        v.resize(c * 2);
        for(int i = 0; i < c; i += 1) v[i + c] = v[i] + n;
        vector<int> pos(k - 1, c * 2);
        vector<int[20]> next(2 * c + 1);
        fill(*next.rbegin(), *next.rbegin() + 20, 2 * c);
        for(int i = 2 * c - 1; i; i -= 1){
            next[i][0] = pos[(v[i] + 1) % (k - 1)];
            for(int j = 1; j < 20; j += 1) next[i][j] = next[next[i][j - 1]][j - 1];
            pos[v[i] % (k - 1)] = i;
        }
        int pans = 0, begin = 0;
        for(int i = 0; i < c; i += 1) if(v[i] % (k - 1) == 0){
            int p = i, ppans = 0;
            for(int j = 19; ~j; j -= 1) if(next[p][j] <= i + c){
                p = next[p][j];
                ppans += 1 << j;
            }
            if(p == i + c and ppans > pans){
                pans = ppans;
                begin = i;
            }
        }
        if(pans > ans){
            ans = pans;
            cut.clear();
            for(int i = begin; i < begin + c; i = next[i][0])
                cut.push_back(v[i]);
        }
    }
    int time = 0;
    vector<pair<int, int>> interval;
    for(int i = 0; i < (int)cut.size(); i += 1){
        //cout << "cut" << " " << cut[i] << endl;
        int l = (cut[i] + 1) % n, r = (cut[(i + 1) % cut.size()] + 1) % n;
        if(r <= l) r += n;
        interval.push_back({l, r - l});
        time += (r - l + k - 3) / (k - 1);
    }
    cout << time << "\n";
    for(auto p : interval)
        distribute(p.first, p.second, 0);
    for(int i = 0; i < n; i += 1) if(a[i] != avg) cout << i << " " << a[i] << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <queue>

using namespace std;

bool processNegative(int& currentNegative, queue<int>& questions,
	int&i, int k)
{
	++currentNegative;

	if (currentNegative > k)
	{
		if (!questions.empty())
		{
			i = questions.front();
			questions.swap(queue<int>());
			currentNegative = 0;
		}
		else
		{
			cout << "NO" << endl;
			return false;
		}
	}

	return true;
}

int main()
{
	// ifstream cin("input.txt");

	int n, k;
	string str;
	cin >> n >> k >> str;

	auto currentNegative = 0;
	auto hadResult = false;

	queue<int> questions;

	for (auto i = 0; i < n; i++)
	{
		switch (str[i])
		{
		case 'Y':
			if (currentNegative == k)
				hadResult = true;

			currentNegative = 0;
			questions.swap(queue<int>());
			break;
		case 'N':
			if (!processNegative(currentNegative, questions, i, k))
				return 0;
			break;
		case '?':
			if (currentNegative == k)
				hadResult = true;

			questions.push(i);
			if (!processNegative(currentNegative, questions, i, k))
				return 0;
			break;
		}
	}

	cout << (hadResult ? "YES" : "NO");
}


#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <list>
#include <string>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <functional>

typedef long long long64;
typedef long long int64;
using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);

		int n;
		int k;
		cin >> n >> k;

	    string a;
	    cin >> a;
bool no=false;
for(int i=0; i<a.size(); i++)
{
    if(a[i]=='N' && (i+k)<=a.size() && (i==0 || a[i-1]!='N'))
    {
       int count=0;
       int j;
       for(j=i; j<i+k; j++)
        {
            //cout << a[j];
            if(a[j]=='N')
                count ++;
            else
                break;
        }
        //cout << endl;
        if(count==k && j<a.size() && a[j]=='N')
        {
            cout << "NO";
            return 0;
        }
    }
}
for(int i=0; i<a.size(); i++)
{
	if( && (i+k)<=a.size() && (i==0 || a[i-1]!='N'))
    {
       int count=0;
       int j;
       for(j=i; j<i+k; j++)
        {
            //cout << a[j];
            if(a[j]=='?' || a[j]=='N')
                count ++;
            else
                break;
        }
        //cout << endl;
        if(count==k && (i+k==a.size() || a[j]!='N'))
        {
            cout << "YES";
            return 0;
        }
    }
}

    cout << "NO";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;

int main() {
 int n, k;
 cin >> n >> k >> s;
 s = "Y" + s + "Y";
queue<int> q; int d = 0; int mn = 0; int ok = 0;
 for(int i = 0; i <= n+1; i++) {
  while(q.size() && i - q.front() - 1 > k) q.pop();
  if(s[i] != 'N') {
   if(q.size() && i - q.front() - 1 == k) ok = 1;
   d = 0;
   if(s[i] == 'Y') while(q.size)) q.pop();
   q.push(i);
  }
  else mn = max(mn, ++d);
 }
 if(ok && mn <= k) cout << "YES" << endl;
 else cout << "NO" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

#define double double
#define EPS 1e-9
struct point_t {
    double x, y;
    point_t() : x(0), y(0) {}
    point_t(double x, double y) : x(x), y(y) {}
    point_t(const point_t& p) : x(p.x), y(p.y) {}
    int operator < (const point_t& rhs) const {return make_pair(y, x) < make_pair(rhs.y, rhs.x);}
    int operator == (const point_t& rhs) const {return make_pair(y, x) == make_pair(rhs.y, rhs.x);}
    point_t operator + (const point_t& p) const {return point_t(x + p.x, y + p.y);}
    point_t operator - (const point_t& p) const {return point_t(x - p.x, y - p.y);}
    point_t operator * (double c) const {return point_t(x * c, y * c);}
    point_t operator / (double c) const {return point_t(x / c, y / c);}
};
double cross(point_t p, point_t q) {return p.x * q.y - p.y * q.x;}
double area(point_t a, point_t b, point_t c) {return fabs(cross(a, b) + cross(b, c) + cross(c, a)) / 2;}
double area2(point_t a, point_t b, point_t c) {return cross(a, b) + cross(b, c) + cross(c, a);}
double dot(point_t p, point_t q) {return p.x * q.x + p.y * q.y;}
double dist(point_t p, point_t q) {return sqrt(dot(p - q, p - q));}
double dist2(point_t p, point_t q) {return dot(p - q, p - q);}
point_t RotateCCW90(point_t p) {return point_t(-p.y, p.x);}
point_t RotateCW90(point_t p) {return point_t(p.y, -p.x);}
point_t RotateCCW(point_t p, double t) {return point_t(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t));}
int sign(double x) {return x < -EPS ? -1 : x > EPS;}
int sign(double x, double y) {return sign(x - y);}
ostream& operator << (ostream& os, const point_t& p) {
    os << "(" << p.x << "," << p.y << ")";
    return os;
}
point_t ProjectPointLine(point_t a, point_t b, point_t c) {
    return a + (b - a) * dot(c - a, b - a) / dot(b - a, b - a);
}
double DistancePointLine(point_t a, point_t b, point_t c) {
    return dist(c, ProjectPointLine(a, b, c));
}
point_t ComputeLineIntersection(point_t a, point_t b, point_t c, point_t d) {
    b = b - a; d = c - d; c = c - a;
    return a + b * cross(c, d) / cross(b, d);
}
struct Line {
    point_t l, r;
    Line() {}
    Line(point_t l, point_t r) : l(l), r(r) {}
    Line(const Line& rhs) : l(rhs.l), r(rhs.r) {}
};
Line Bisector(point_t a, point_t b) {
    point_t c = (a + b) / 2;
    return Line(c, c + RotateCCW90(b - c));
}
struct Circle {
    point_t cen;
    double rad;
    Circle() : rad(0) {}
    Circle(point_t cen, double rad) : cen(cen), rad(rad) {}
    Circle(const Circle& rhs) : cen(rhs.cen), rad(rhs.rad) {}
    int operator < (const Circle& rhs) const {
        return rad < rhs.rad;
    }
};
Circle CircumCircle(point_t a, point_t b, point_t c) {
    if (sign(cross(a - c, b - c)) == 0) {
        Circle res = Circle((a + b) / 2, dist(a, b) / 2);
        res = max(res, Circle((b + c) / 2, dist(b, c) / 2));
        res = max(res, Circle((c + a) / 2, dist(c, a) / 2));
        return res;
    }
    Line ln1 = Bisector(a, b);
    Line ln2 = Bisector(b, c);
    point_t cen = ComputeLineIntersection(ln1.l, ln1.r, ln2.l, ln2.r);
    return Circle(cen, dist(cen, a));
}

void chemthan() {
    int k, n; cin >> k >> n;
    vector<point_t> pts(n * k);
    for (point_t& p : pts) cin >> p.x >> p.y;
    vector<Circle> res;
    auto calc = [&] (Circle c) {
        int cnt = 0;
        FOR(i, 0, sz(pts)) {
            double d = dist(c.cen, pts[i]);
            if (abs(d - c.rad) < 5e4) {
                cnt++;
            }
        }
        if (!cnt) return 1e9;
        return abs(cnt - (double) sz(pts) / (k - sz(res)));
    };
    FOR(it, 0, k) {
        vector<pair<double, Circle>> candidates;
        FOR(it, 0, 1000) {
            int u = mrand() % sz(pts);
            int v = mrand() % sz(pts);
            int w = mrand() % sz(pts);
            if (5e4 < dist(pts[u], pts[v]) &&
                    5e4 < dist(pts[v], pts[w]) &&
                    5e4 < dist(pts[w], pts[u])) {
                Circle c = CircumCircle(pts[u], pts[v], pts[w]);
                candidates.pb(mp(calc(c), c));
            }
        }
        sort(all(candidates));
        Circle tmp;
        for (auto e : candidates) {
            Circle c = e.se;
            int found = 0;
            for (Circle cc : res) {
                double d = dist(c.cen, cc.cen);
                if (d < 0.1 * 600000) {
                    found = 1;
                    break;
                }
            }
            if (!found) {
                tmp = c;
                break;
            }
        }
        res.pb(tmp);
        FORd(i, sz(pts), 0) {
            double d = dist(pts[i], res.back().cen);
            if (abs(d - res.back().rad) < 5e4) {
                pts.erase(pts.begin() + i);
            }
        }
        db(sz(pts)) endln;
    }
    assert(sz(res) == k);
    for (Circle c : res) {
        cout << prec(9) << c.cen.x << " " << c.cen.y << " " << c.rad << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>

using namespace std;
typedef long double ld;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

typedef Point<double> P;
double ccRadius(const P& A, const P& B, const P& C) {
    return (B-A).dist()*(C-B).dist()*(A-C).dist()/
            abs((B-A).cross(C-A))/2;
}
P ccCenter(const P& A, const P& B, const P& C) {
    P b = C-A, c = B-A;
    return A + (b*c.dist2()-c*b.dist2()).perp()/b.cross(c)/2;
}

const int MAXN = 5000;

int N, K;
P pt[MAXN];

pair <P, double> res[4];

ld cdist (pair <P, double> left, pair <P, double> right)
{
    return abs(left.first.x - right.first.x) + abs (left.first.y - right.first.y) + abs(left.second - right.second);
}

void gogo()
{
    while (true)
    {
        int cval = 0;
        while (cval < K)
        {
            int a = rand() % (N * K), b = rand() % (N * K), c = rand() % (N * K);
            if (a == b || a == c || b == c) continue;
            if (!((pt[b]-pt[a]).cross(pt[c]-pt[a]))) continue;
            P cc = ccCenter(pt[a], pt[b], pt[c]);
            double rad = ccRadius(pt[a], pt[b], pt[c]);
            if (cc.dist() > 1050000 || rad < 200000 || rad > 800000) continue;

            bool bad = false;
            for (int i = 0; i < cval; i++)
            {
                if (cdist (res[i], make_pair (cc, rad)) < 350000)
                {
                    bad = true;
                    break;
                }
            }
            if (bad) continue;

            int nhit = 0;
            vector <double> v;
            for (int i = 0; i < N * K; i++)
            {
                double d = (cc-pt[i]).dist();
                if (d > 0.87 * rad && d < 1.13 * rad)
                {
                    nhit++;
                    v.push_back((cc-pt[i]).angle());
                }
            }
            sort(v.begin(), v.end());
            for (int i = 0; i + 1 < v.size(); i++)
                if (v[i+1] - v[i] > 1)
                {
                    //if (nhit >= N)
                    //    cout << v[i+1] - v[i] << "\n";
                    bad = true;
                }
            if (bad) continue;

            if (nhit >= N)
            {
                res[cval] = make_pair (cc, rad);
                cval++;
            }
        }

        bool bad = false;
        for (int i = 0; i < N * K; i++)
        {
            bool found = false;
            for (int j = 0; j < K; j++)
            {
                double d1 = res[j].second, d2 = (res[j].first-pt[i]).dist();
                if (d2 >= 0.8 * d1 && d2 <= 1.2 * d1)
                    found = true;
            }
            if (!found)
            {
                bad = true;
                break;
            }
        }
        if (!bad) break;
    }
}

int main()
{
    srand(time(NULL));
    cin >> K >> N;
    for (int i = 0; i < N * K; i++)
    {
        cin >> pt[i].x >> pt[i].y;
    }

    gogo();

    cout << fixed << setprecision(8);
    for (int i = 0; i < K; i++)
    {
        cout << res[i].first.x << " " << res[i].first.y << " " << res[i].second << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

int k, n, tmp[200000], cnt = 0;

double X[4010], Y[4010], avg1[10010], avg2[10010], Ansx[200000], Ansy[1200000], qwq[200000];

double sqr(double x) {return x * x;}

double dis(int a, int b, int c, int d) {return sqrt(sqr(c - a) + sqr(d - b));}

vector <double> V;

double Do(double x, double y) {
    V.clear();
	for(int s = 1; s <= k * n; s++)
		V.push_back(pow(dis(x, y, X[s], Y[s]), 2));
	sort(V.begin(), V.end());
	for(int i = 0; i < V.size(); i++) avg1[i] = V[i], avg2[i] = V[i] * V[i];
	for(int i = 1; i < V.size(); i++) avg1[i] += avg1[i - 1], avg2[i] += avg2[i - 1];

}
double getval(double x, double y) {
    Do(x, y);
	double magic = 1e100;
	int n = ::n - 2;
	for(int i = n; i < V.size(); i++) magic = min(magic, avg2[i] - avg2[i - n] - sqr(avg1[i] - avg1[i - n]) / n);
	return magic;
}

double getr(double x, double y) {
	Do(x, y);
	double magic = 1e100;
	int v;
	int n = ::n - 2;
	for(int i = n; i < V.size(); i++) {
		double s = avg2[i] - avg2[i - n] - sqr(avg1[i] - avg1[i - n]) / n;
		if(s < magic) magic = s, v = i;
	}
	return (avg1[v] - avg1[v - n]) / n;
}

double rd() {return (double) rng() / pow(2, 63) - 1;}

bool cmp(int x, int y) {return qwq[x] < qwq[y];}

int main() {
	scanf("%d%d", &k, &n);
	for(int i = 1; i <= k * n; i++) scanf("%lf%lf", &X[i], &Y[i]);
	for(int i = -100; i <= 100; i++)
		for(int j = -100; j <= 100; j++) if(dis(0, 0, i * 10000, j * 10000) <= 1e6)
			Ansx[++cnt] = i * 10000, Ansy[cnt] = j * 10000, qwq[cnt] = getval(i * 10000, j * 10000);
	for(int i = 1; i <= k; i++) {
		for(int i = 1; i <= cnt; i++) tmp[i] = i;
		sort(tmp + 1, tmp + cnt + 1, cmp);
		printf("%.12lf %.12lf %.12lf\n", Ansx[tmp[1]], Ansy[tmp[1]], getr(Ansx[tmp[1]], Ansy[tmp[1]]));
		double x = Ansx[tmp[1]], y = Ansy[tmp[1]];
		for(int i = 1; i <= cnt; i++) if(dis(Ansx[i], Ansy[i], x, y) <= 4e5) qwq[i] = 1e100;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int k, n;

double X[4010], Y[4010];

double eps = 1e4, mx = 2e6;

double sqr(double x) {return x * x;}

double dis(int a, int b, int c, int d) {return sqrt(sqr(c - a) + sqr(d - b));}

double avg1[10010], avg2[10010];

double getval(double x, double y) {
	vector <double> V(0);
	for(int s = 1; s <= k * n; s++)
		V.push_back(dis(x, y, X[s], Y[s]));
	sort(V.begin(), V.end());
	for(int i = 0; i < V.size(); i++) avg1[i] = V[i], avg2[i] = V[i] * V[i];
	for(int i = 1; i < V.size(); i++) avg1[i] += avg1[i - 1], avg2[i] += avg2[i - 1];
	double magic = 1e100;
	int n = ::n - 2;
	for(int i = n; i < V.size(); i++) magic = min(magic, avg2[i] - avg2[i - n] - sqr(avg1[i] - avg1[i - n]) /  n);
	return magic;
}

double getr(double x, double y) {
	vector <double> V(0);
	for(int s = 1; s <= k * n; s++)
		V.push_back(dis(x, y, X[s], Y[s]));
	sort(V.begin(), V.end());
	for(int i = 0; i < V.size(); i++) avg1[i] = V[i], avg2[i] = V[i] * V[i];
	for(int i = 1; i < V.size(); i++) avg1[i] += avg1[i - 1], avg2[i] += avg2[i - 1];
	double magic = 1e100;
	int v;
	int n = ::n - 2;
	for(int i = n; i < V.size(); i++) {
		double s = avg2[i] - avg2[i - n] - sqr(avg1[i] - avg1[i - n]) / n;
		if(s < magic) magic = s, v = i;
	}
	return (avg1[v] - avg1[v - n]) / n;
}

double Ansx[10], Ansy[10];

int cnt = 0;

mt19937_64 rng(233);

double rd() {
	return (double) rng() / pow(2, 63) - 1;
}

int main() {
	scanf("%d%d", &k, &n);
	for(int i = 1; i <= k * n; i++) {
		scanf("%lf%lf", &X[i], &Y[i]);
		//X[i + n] = X[i] + 233333, Y[i + n] = Y[i] + 377777;
	}
	for(int T = 1; T <= 30; T++) {
		double x = rd() * 2000000, y = rd() * 2000000, magic = getval(x, y);
		for(double step = 2000000; step > 100; step *= 0.995) {
			double dx = rd() * step, dy = rd() * step, tmp = getval(x + dx, y + dy);
			if(magic > tmp) x += dx, y += dy, magic = tmp;
		}
		int flag = 1;
		for(int i = 1; i <= cnt; i++)
			if(dis(x, y, Ansx[i], Ansy[i]) <= 1e5) flag = 0;
		if(flag && fabs(x) <= 2000000 && fabs(y) <= 2000000) Ansx[++cnt] = x, Ansy[cnt] = y;
	}
	//printf("%.12lf %.12lf\n", getval(Ansx[1], Ansy[1]), getval(Ansx[1] + 233333, Ansy[1] + 377777));
	assert(cnt == k);
	for(int i = 1; i <= k; i++) printf("%.12lf %.12lf %.12lf\n", Ansx[i], Ansy[i], getr(Ansx[i], Ansy[i]));
	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define PII pair<int, int>
#define MP make_pair
#define A b * 1.0 * (1.0 - dfs(b - 1, a)) / (b * 1.0 + 1.0)
#define B 1
#define C (1.0 + 1.0 * b * (1.0 - dfs(b - 1, a))) / (b * 1.0 + 1.0)
#define D (1.0 - dfs(b, a - 1))
#define P (D - B) / (A - B - C + D)
map<PII, double> m;
inline double dfs(int a, int b)
{
	if (b == 0)
	{
		return 1.0;
	}
	if (a == 0)
	{
		return 1.0 / (1.0 * b + 1.0);
	}
	if (m.count(MP(a, b)))
	{
		return m[MP(a, b)];
	}
	double ans = P * A + (1.0 - P) * B;
	m.insert(MP(a, b), ans);
	return ans;
}
int read()
{
	int num = 0, bj = 0;
	char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
		{
			bj = 1;
		}
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = num * 10 + ch - '0';
		ch = getchar();
	}
	return bj ? -num : num;
}
int main()
{
	int a, b;
	a = read();
	b = read();
	double ans = dfs(a, b);
	printf("%.9lf %.9lf", ans, 1.0 - ans);
}


#include <stdio.h>
#include <algorithm>
using namespace std;
double dp[1010][1010];
double f(int x,int y)
{
    if (dp[x][y]>-0.5) return dp[x][y];

    if (y==0)  return dp[x][y]=1.0;
    if (x==0) return dp[x][y]=1.0/(y+1);
    double num1=1.0/(y+1);
    double num2=(y*1.0)/(y+1)*(1-f(y-1,x))
    return dp[x][y]=max(num1,num2);
}
int main()
{
    int m,n;
    while (scanf("%d%d",&m,&n)==2)
    {
        for (int i=0;i<=1000;i++)
            for (int j=0;j<=1000;j++)
                dp[i][j]=-1;
        printf("%f %f\n",f(m,n),1-f(m,n));
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int_t;

double ans[1001][1001];

double dp(int_t n, int_t m) {
    if(!n || !m) return 1.0 / (m + 1);
    if(ans[n][m]) return ans[n][m];
    double f = dp(m, n - 1);
    return ans[n][m] = m * (- f * dp(m - 1, n) + f + 1) / ((m + 1) * f + m);
}

int main() {
    int_t n, m;
    cin >> n >> m;
    fprintf("%.6lf %.6lf", dp(n, m), 1-dp(n, m));
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

typedef long double ld;

ld F[N][M]; int vis[N][M];

ld f(int n, int m) {
    if(!n) return (ld) 1 / (m + 1);
    if(!m) return 1;
    if(vis[n][m]) return F[n][m];
    ld k1 = (ld) m / (m + 1) * (1 - f(m - 1, n)) - 1;
    ld b1 = 1;
    ld k2 = (ld) (1 + m * (1 - f(m - 1, n))) / (m + 1) - (1 - f(m, n - 1));
    ld b2 = 1 - f(m, n - 1);
    ld X = (b2 - b1)  / (k1 - k2);
    vis[n][m] = 1;
    return f[n][m] = k1 * X + b1;
}

int main() {
    int n, m; cin >> n >> m;
    ld ans = f(n, m);
    cout << fixed << setprecision(10) << ans << ' ' << (1 - ans) << endl;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
const double eps = 1e-12;
int sign(const double &value){
    if(abs(value) <= eps){
        return 0;
    }
    if(value < 0){
        return -1;
    }
    else{
        return 1;
    }
}
const double pi = acos(-1);
struct Point{
    bool add2pi = 0;
    double x,y;
    Point(){}
    Point(double x,double y) : x(x), y(y) {}
    double angle() const{
        if(x==0){
            if(y>0){
                return pi/2;
            }
            else{
                return 3*pi/2;
            }
            return 0;
        }
        double theta = atan(abs(y/x));
        if(x<0){
            theta = pi - theta;
        }
        if(y<0){
            theta = 2*pi - theta;
        }
        return theta + 2*pi*add2pi;
    }
    double dist(){
        return sqrtl(x*x + y*y);
    }
};
istream& operator>>(istream &in, Point &x){
    in>>x.x>>x.y;
    return in;
}
ostream& operator<<(ostream& out, const Point &x){
    out<<x.x<<" "<<x.y<<" ";
    return out;
}
struct Line{
    bool v;
    double m,c;
    //y = mx + c
    //y - mx - c = 0
    Line(const Point &x, const Point &y){
        if(abs(x.x - y.x) <= eps){
            v = 1;
            c = x.x;
            return;
        }
        else{
            v = 0;
        }
        m  = (x.y - y.y)/(x.x - y.x);
        c = x.y - m*x.x;
    }
    int getside(const Point &p){
        if(v){
            if(sign(c)==1){
                return p.x>=c;
            }
            else{
                return p.x<=c;
            }
        }
        int sn1 = sign(-c);
        int sn2 = sign(p.y - m*p.x - c);
        if(sn2==0){
            return 0;
        }
        if((sn2<0) ^ (sn1<0)){
            return 1;
        }
        else{
            return -1;
        }
    }
    Point intersect(double theta){
        if(v){
            return Point(c, tan(theta)*c);
        }
        while(theta > pi){
            theta-=pi;
        }
        if(abs(theta - pi/2) < eps){
            return Point(0,c);
        }
        return Point(c/(tan(theta) - m), c*tan(theta)/(tan(theta) - m));
    }
    double perpdistance(){
        if(v){
            return c;
        }
        if(abs(m) < eps){
            return c;
        }
        return intersect(atan(1/m)).dist();
    }
};
double area(const vector<Point>& points){
    if(points.size() < 3){
        return 0;
    }
    int n = points.size();
    double ans = points[n-1].x * points[0].y - points[0].x * points[n-1].y;
    for(int i=0;i+1<n;i++){
        ans+=points[i].x * points[i+1].y;
    }
    for(int i=1;i<n;i++){
        ans-=points[i].x * points[i-1].y;
    }
    return abs(ans)/2;
}
struct Polygon{
    vector<Point> upper;
    vector<Point> lower;
    vector<Point> points;
    Point l,r;
    double Distance;
    void build(vector<Point> _points){
        points = _points;
        assert(points.size() >= 3);
        int n = points.size();
        sort(points.begin(), points.end(), [&](const Point &x, const Point &y){
        return x.angle() < y.angle() && abs(x.angle() - y.angle()) > eps;
        });
        l = points[0];
        r = points[n-1];
        if(r.angle() - l.angle() > pi){
            for(int i=0;i<n;i++){
                if(points[i].angle()<pi){
                    points[i].add2pi = 1;
                }
            }
            sort(points.begin(), points.end(), [&](const Point &x, const Point &y){
                return x.angle() < y.angle() && abs(x.angle() - y.angle()) > eps;
            });
            l = points[0];
            r = points[n-1];
        }
        Line mid(l,r);
        upper.push_back(l);
        lower.push_back(l);
        for(int i=1;i<n-1;i++){
            if(mid.getside(points[i]) == 1){
                upper.push_back(points[i]);
            }
            else{
                lower.push_back(points[i]);
            }
        }
        upper.push_back(r);
        lower.push_back(r);
        Distance = 1e18;
        for(int i=1;i<lower.size();i++){
            Distance = min(Distance, Line(lower[i], lower[i-1]).perpdistance());
        }
    }
    bool blocking(const Point &p){
        double theta = p.angle();
        if(r.angle() > 2*pi){
            if(theta < pi) theta += 2*pi;
        }
        if(theta < l.angle() || theta > r.angle()){
            return true;
        }
        int mn = 0, mx = lower.size() - 1;
        while(mn < mx){
            int mid = mn + mx + 1;
            mid>>=1;
            if(lower[mid].angle() < theta){
                mn = mid;
            }
            else{
                mx = mid - 1;
            }
        }
        if(Line(lower[mn], lower[mn + 1]).getside(p)==1){
            return false;
        }
        else{
            return true;
        }
    }
    int binsearch(const vector<Point>& seq, double theta){ //returns index of first point at angle greater than theta
        int mn = 0;
        int mx = seq.size() - 1;
        if(seq[mx].angle() < theta){
            return seq.size();
        }
        while(mn < mx){
            int mid = mn + mx;
            mid>>=1;
            if(seq[mid].angle() < theta){
                mn = mid + 1;
            }
            else{
                mx = mid;
            }
        }
        return mn;
    }
    double areabetween(double theta1, double theta2){
        if(r.angle() > 2*pi){
            if(theta1 < pi) theta1 += 2*pi;
            if(theta2 < pi) theta2 += 2*pi;
        }
        if(theta2 < theta1){
            //assert(false && "nonsense");
            swap(theta1, theta2);
        }
        vector<Point> finalpoints;
        int llow = binsearch(lower, theta1);
        int lup = binsearch(upper, theta1);
        int rlow = binsearch(lower, theta2);
        int rup = binsearch(upper, theta2);
        //cout<<llow<<" "<<rlow<<" "<<lup<<" "<<rup<<"\n";
        //cout+lower+upper;
        if(llow!=0){
            finalpoints.pb(Line(lower[llow], lower[llow-1]).intersect(theta1));
        }
        for(int i=llow;i<rlow;i++){
            finalpoints.pb(lower[i]);
        }
        if(rlow!=lower.size()){
            finalpoints.pb(Line(lower[rlow], lower[rlow-1]).intersect(theta2));
        }
        if(rup!=upper.size()){
            finalpoints.pb(Line(upper[rup], upper[rup-1]).intersect(theta2));
        }
        for(int i=rup-1;i>=lup;--i){
            finalpoints.pb(upper[i]);
        }
        if(lup!=0){
            finalpoints.pb(Line(upper[lup], upper[lup-1]).intersect(theta1));
        }
        finalpoints.resize(unique(finalpoints.begin(), finalpoints.end(), [&](const Point &x, const Point &y){
            return abs(x.x-y.x) <= eps && abs(x.y-y.y) <=eps;
        }) - finalpoints.begin());
        //cout+finalpoints;
        return area(finalpoints);
    }
    double angledist(double theta){
        int llow = binsearch(lower, theta);
        if(llow==0){
            ++llow;
        }
        return Line(lower[llow], lower[llow-1]).intersect(theta).dist();
    }
};
void solve(){
    int n;
    cin>>n;
    vector<Polygon> warehouses(n);
    for(int i=0;i<n;i++){
        auto &warehouse = warehouses[i];
        int size;
        cin>>size;
        vector<Point> warehousepoints(size);
        cin>>warehousepoints;
        warehouse.build(warehousepoints);
    }
    struct Event{
        double theta;
        int idx;
        bool add;
        Event(){}
        Event(double theta, int idx, bool add) : theta(theta), idx(idx), add(add) {}
        bool operator<(const Event &E){
            return theta < E.theta;
        }
    };
    vector<Event> events;
    for(int i=0;i<n;i++){
        const auto &warehouse = warehouses[i];
        if(warehouse.r.add2pi){
            events.pb({0,i,1});
            events.pb({warehouse.r.angle() - 2*pi, i, 0});
            events.pb({warehouse.l.angle(), i, 1});
            events.pb({2*pi, i, 0});
        }
        else{
            events.pb({warehouse.l.angle(), i, 1});
            events.pb({warehouse.r.angle(), i, 0});
        }
    }
    sort(events.begin(), events.end());
    /*for(const auto &E : events){
        cout<<E.theta<<" "<<E.idx<<" "<<E.add<<"\n";
    }
    cout<<"\n";
    */
    double ans = 0;
    vector<bool> used(n);
    used[events[0].idx] = events[0].add;
    for(int i=1;i<events.size();i++){
        vector<pair<double, int>> answers;
        double theta1 = events[i-1].theta;
        double theta2 = events[i].theta;
        for(int j=0;j<n;j++){
            if(used[j]) answers.pb({warehouses[j].angledist((theta1 + theta2)/2), j});
        }
        used[events[i].idx] = events[i].add;
        sort(answers.begin(), answers.end());
        if(answers.size()==0){
            //cout<<"-1\n";
            continue;
        }
        int ply = answers[0].second;
        //cout<<ply<<" "<<theta1<<" "<<theta2<<"\n";
        double del = warehouses[ply].areabetween(theta1, theta2);
        //cout<<del<<"\n";
        ans+=del;
    }
    cout<<fixed<<setprecision(9)<<ans<<"\n";
}
void play(){

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    //play();
}


/*input
3
3 -6 3 -5 5 -3 6
3 -7 -2 -8 7 -6 7
4 1 4 -2 2 -5 1 -1 6
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ld PI = acosl(-1);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct point
{
	ld x, y;
	point() {}
	point(ld x, ld y): x(x), y(y)
	{

	}
	ld kampas()
	{
		return atan2l(y, x);
	}
};
point operator+(point a, point b)
{
	return point(a.x + b.x, a.y + b.y);
}
point operator-(point a, point b)
{
	return point(a.x - b.x, a.y - b.y);
}
point operator*(point a, ld k)
{
	return point(a.x * k, a.y * k);
}
ld cross(point a, point b)
{
	return a.x * b.y - a.y * b.x;
}
ld f(ld alfa, ld beta, pair<point, point>ab)
{
	point a = ab.first;
	point b = ab.second;
	point va(cosl(alfa), sinl(alfa));
	point vb(cosl(beta), sinl(beta));
	va = va * (cross(a, b) / cross(va, b - a));
	vb = vb * (cross(a, b) / cross(vb, b - a));
	return cross(va, vb) / 2;
}
ld calc(ld alfa, ld beta, const vector<pair<point, point>>&A)
{
	if (A.size() <= 1 || beta - alfa < 1e-8)
		return 0;
	vector<pair<point, point>>L, R;
	bool visi = true;
	ld gamma = (alfa + beta) / 2;
	for (pair<point, point>i : A)
	{
		ld k1 = i.first.kampas();
		ld k2 = i.second.kampas();
		visi &= (k1 < alfa && beta < k2);
		if (beta + 1e-9 < k1 || k2 + 1e-9 < alfa)
			continue;
		if (k1 < gamma)
			L.push_back(i);
		if (k2 > gamma)
			R.push_back(i);
	}
	if (visi)
	{
		point v(cos(gamma), sin(gamma));
		pair<ld, int>mn = {1e9, 0};
		pair<ld, int>mn1 = {1e9, 0};
		for (int i = 0; i < (int)A.size(); i++)
		{
			point a = A[i].first;
			point b = A[i].second;
			//(kv-a)(b-a)=0
			//kv(b-a)=ab
			ld k = cross(a, b) / cross(v, b - a);
			if (k <= mn.first)
			{
				mn1 = mn;
				mn = {k, i};
			}
			else if (k <= mn1.first)
			{
				mn1 = {k, i};
			}
		}
		return f(alfa, beta, A[mn1.second]) - f(alfa, beta, A[mn.second]);
	}
	return calc(alfa, gamma, L) + calc(gamma, beta, R);
}
int sgn(ld x)
{
	if (x < 0)
		return -1;
	if (x > 0)
		return 1;
	return 0;
}
int main()
{
	cout << fixed << setprecision(3);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pair<point, point>>A;
	while (n--)
	{
		int k;
		cin >> k;
		point a0;
		cin >> a0.x >> a0.y;
		point aj = a0;
		for (int i = 1; i < k; i++)
		{
			point ai;
			cin >> ai.x >> ai.y;
			A.push_back({aj, ai});
			aj = ai;
		}
		A.push_back({aj, a0});
	}
	n = A.size();
	for (int i = 0; i < n; i++)
	{
		if (abs(A[i].first.y) < 0.5 || abs(A[i].second.y) < 0.5)
			continue;
		if ((A[i].first.y > 0) != (A[i].second.y > 0))
		{
			ld k = -A[i].first.y / (A[i].second - A[i].first).y;
			point B = A[i].first + (A[i].second - A[i].first) * k;
			A.push_back({B, A[i].second});
			A[i].second = B;
		}
	}
	vector<pair<point, point>>A_;
	for (pair<point, point>b : A)
	{
		if (abs(b.first.kampas() - b.second.kampas()) > 1e-8)
		{
			A_.push_back(b);
		}
	}
	for (pair<point, point>&i : A_)
	{
		while (sgn(i.first.y) != sgn(i.second.y))
		{
			if (abs(i.first.y) < abs(i.second.y))
			{
				if (i.second.y > 0)
					i.first.y = 1e-9;
				else
					i.first.y = -1e-9;
			}
			else
			{
				if (i.first.y > 0)
					i.second.y = 1e-9;
				else
					i.second.y = -1e-9;
			}
		}
		if (i.first.kampas() > i.second.kampas())
			swap(i.first, i.second);
	}
	cout << fixed << setprecision(20) << calc(-PI - 0.001, PI + 0.001, A_) << "\n";
}


#include <bits/stdc++.h>
#include "geodeb.h"
using namespace std;

const long double EPS = 1e-9;
const long double pi = acos(-1);

struct point {
  long double x, y;
};

point operator+(const point &a, const point &b) {
  return {a.x + b.x, a.y + b.y};
}

point operator-(const point &a, const point &b) {
  return {a.x - b.x, a.y - b.y};
}

point operator*(const long double &k, const point &p) {
  return {p.x * k, p.y * k};
}

point operator/(const point &p, const long double &k) {
  return {p.x / k, p.y / k};
}

long double calc_ang(const point &a) {
  long double ang = atan2(a.y, a.x);
  if (ang < 0.0) {
    return ang + 2 * pi;
  }
  return ang;
}

long double dot(const point &a, const point &b) {
  return a.x * b.x + a.y * b.y;
}

long double norm_sq(const point &a) {
  return dot(a, a);
}

long double cross(const point &a, const point &b) {
  return a.x * b.y - a.y * b.x;
}

struct line {
  point a, b;
  int idx;
};

long double offset(const line &l) {
  return cross(l.b - l.a, l.a);
}

point intersection(const line &l1, const line &l2) {
  return (offset(l1) * (l2.b - l2.a) - offset(l2) * (l1.b - l1.a)) / cross(l1.b - l1.a, l2.b - l2.a);
}

point intersection(const line &l, const long double &ang) {
  return intersection({{0, 0}, {cos(ang), sin(ang)}}, l);
}

void add_segment(point a, point b, vector<line> &segments) {
  if (abs(cross(a, b)) < EPS) {
    return;
  }
  if (cross(a, b) < 0.0) {
    swap(a, b);
  }
  if (a.y < 0.0 && b.y > 0.0) {
    point tmp = intersection({{0, 0}, {1, 0}}, {a, b});
    add_segment(a, tmp, segments);
    add_segment(tmp, b, segments);
  } else {
    if (a.y < 0.0 && abs(b.y) < EPS) {
      b.y = -EPS;
    }
    segments.push_back({a, b, (int) segments.size()});
    GD_POINT(a.x, a.y);
    GD_POINT(b.x, b.y);
    GD_SEGMENT(a.x, a.y, b.x, b.y);
  }
}

struct node {
  int i, j;
  line l1, l2;
};

long double cur_ang;
vector<line> segments;

struct comp {
  bool operator()(const int &a, const int &b) const {
    if (a == b) {
      return false;
    }
    return norm_sq(intersection(segments[a], cur_ang)) < norm_sq(intersection(segments[b], cur_ang));
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  GD_INIT("geo.html");
  int n;
  cin >> n;
  GD_LINE(0, 0, 0, 1);
  GD_LINE(0, 0, 1, 0);
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    vector<point> polygon(c);
    for (int i = 0; i < c; i++) {
      cin >> polygon[i].x >> polygon[i].y;
    }
    for (int i = 0; i < c; i++) {
      add_segment(polygon[i], polygon[(i + 1) % c], segments);
    }
  }
  vector<long double> a;
  for (auto& seg : segments) {
    a.push_back(calc_ang(seg.a));
    a.push_back(calc_ang(seg.b));
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  for (auto& x : a) {
    GD_LINE(0, 0, cos(x), sin(x));
  }
  vector< vector<int> > add((int) a.size()), remove((int) a.size());
  for (auto& seg : segments) {
    int l = lower_bound(a.begin(), a.end(), calc_ang(seg.a)) - a.begin();
    int r = lower_bound(a.begin(), a.end(), calc_ang(seg.b)) - a.begin();
    add[l].push_back(seg.idx);
    remove[r].push_back(seg.idx);
  }
  set<int, comp> st;
  long double ans = 0;
  for (int i = 0; i < (int) a.size() - 1; i++) {
    cur_ang = (a[i] + a[i + 1]) / 2;
    for (auto& x : add[i]) {
      st.insert(x);
    }
    for (auto& x : remove[i]) {
      st.erase(x);
    }
    if ((int) st.size() >= 2) {
      line l1 = segments[*st.begin()], l2 = segments[*next(st.begin())];
      point v = intersection(l1, a[i]), w = intersection(l1, a[i + 1]);
      ans -= cross(v, w);
      v = intersection(l2, a[i]), w = intersection(l2, a[i + 1]);
      ans += cross(v, w);
    }
  }
  cout << fixed << setprecision(10) << ans / 2.0 << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-9;
const double pi = acos(-1);

struct point {
  double x, y;
};

point operator+(const point &a, const point &b) {
  return {a.x + b.x, a.y + b.y};
}

point operator-(const point &a, const point &b) {
  return {a.x - b.x, a.y - b.y};
}

point operator*(const double &k, const point &p) {
  return {p.x * k, p.y * k};
}

point operator/(const point &p, const double &k) {
  return {p.x / k, p.y / k};
}

double calc_ang(const point &a) {
  double ang = atan2(a.y, a.x);
  if (ang < 0.0) {
    return ang + 2 * pi;
  }
  return ang;
}

struct line {
  point a, b;
  int idx;
};

double dot(const point &a, const point &b) {
  return a.x * b.x + a.y * b.y;
}

double norm_sq(const point &a) {
  return dot(a, a);
}

double cross(const point &a, const point &b) {
  return a.x * b.y - a.y * b.x;
}

void add_segment(point a, point b, vector<line> &segments) {
  if (abs(cross(a, b)) < EPS) {
    return;
  }
  if (cross(a, b) < 0.0) {
    swap(a, b);
  }
  if (a.y < 0.0 && b.y > 0.0) {
    point tmp = {-a.y * ((b.y - a.y) / (b.x - a.x)) + a.x, 0.0};
    add_segment(a, tmp, segments);
    add_segment(tmp, b, segments);
  } else {
    if (a.y < 0.0 && abs(b.y) < EPS) {
      b.y = -EPS;
    }
    segments.push_back({a, b, (int) segments.size()});
  }
}

struct node {
  int i, j;
  line l1, l2;
};

double offset(const line &l) {
  return cross(l.b - l.a, l.a);
}

point intersection(const line &l1, const line &l2) {
  return (offset(l1) * (l2.b - l2.a) - offset(l2) * (l1.b - l1.a)) / cross(l1.b - l1.a, l2.b - l2.a);
}

point intersection(const line &l, const double &ang) {
  return intersection({{0, 0}, {cos(ang), sin(ang)}}, l);
}

double cur_ang;
vector<line> segments;

struct comp {
  bool operator()(const int &a, const int &b) {
    if (a == b) {
      return false;
    }
    return norm_sq(intersection(segments[a], cur_ang)) < norm_sq(intersection(segments[b], cur_ang));
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    vector<point> polygon(c);
    for (int i = 0; i < c; i++) {
      cin >> polygon[i].x >> polygon[i].y;
    }
    for (int i = 0; i < c; i++) {
      add_segment(polygon[i], polygon[(i + 1) % c], segments);
    }
  }
  vector<double> a;
  for (auto& seg : segments) {
    a.push_back(calc_ang(seg.a));
    a.push_back(calc_ang(seg.b));
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  vector< vector<int> > add((int) a.size()), remove((int) a.size());
  for (auto& seg : segments) {
    int l = lower_bound(a.begin(), a.end(), calc_ang(seg.a)) - a.begin();
    int r = lower_bound(a.begin(), a.end(), calc_ang(seg.b)) - a.begin();
    add[l].push_back(seg.idx);
    remove[r].push_back(seg.idx);
  }
  set<int, comp> st;
  double ans = 0;
  for (int i = 0; i < (int) a.size() - 1; i++) {
    //cout << i << endl;
    cur_ang = (a[i] + a[i + 1]) / 2;
    for (auto& x : add[i]) {
      st.insert(x);
    }
    for (auto& x : remove[i]) {
      assert(st.count(x));
      st.erase(x);
    }
    if ((int) st.size() >= 2) {
      line l1 = segments[*st.begin()], l2 = segments[*next(st.begin())];
      point v = intersection(l1, a[i]), w = intersection(l1, a[i + 1]);
      ans -= cross(v, w);
      v = intersection(l2, a[i]), w = intersection(l2, a[i + 1]);
      ans += cross(v, w);
    }
  }
  for (auto& x : remove.back()) {
    st.erase(x);
  }
  assert(st.empty());
  cout << fixed << setprecision(10) << ans / 2.0 << '\n';
  return 0;
}


#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int max_n = 511, mod = 1000000007;

int t, k;
long long pw[max_n], pw2[max_n];
int dp[max_n], sumdp[max_n], sums[max_n][max_n];
char ll[max_n], rr[max_n];
string l, r;

int sum_dp(int r) {
    return sumdp[r];
}

void get_dp() {
    pw[0] = 1;
    pw2[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        pw[i] = (pw[i - 1] * 10) % mod;
        pw2[i] = (pw2[i - 1] * 8) % mod;
    }
    dp[0] = dp[1] = 0;
    for (int len = 2; len < max_n; ++len) {
        //cout << dp[len - 1] << endl;
        for (int i = 1; i <= len; ++i) {
            for (int j = i + 1; j <= len && j - i <= k; ++j) {
                long long x = (pw2[j - i - 1] * pw[len - j]) % mod;
                int poz = i - k;
                if (poz > 1) {
                    //cout << poz - 1 << endl;
                    x = (x * pw2[k]) % mod;
                    long long y = ((9 * pw[poz - 2] - dp[poz - 1]/*sum_dp(poz - 1)*/) % mod + mod) % mod;
                    x = (x * y) % mod;
                } else {
                    if (i != 1) {
                        x = (x * pw2[i - 2] * 7) % mod;
                    }
                }
                //if (len == 6) cout << i << " " << j << "  -  " << x << endl;
                x = (x * 4) % mod;
                dp[len] = (dp[len] + x) % mod;
            }
        }
        sumdp[len] = (sumdp[len - 1] + dp[len]) % mod;
    }
    //cout << dp[6] << endl;
}

bool ok(string s) {
    int last = -11111;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '4' || s[i] == '7') {
            if (i - last <= k) {
                return true;
            }
            last = i;
        }
    }
    return false;
}

bool happy(int x) {
    return x == 4 || x == 7;
}

void get_all_sum() {
    for (int st = 0; st < max_n; ++st) {
        sums[st][1] = (2 * pw[st] * pw2[0]) % mod;
        for (int cnt = 2; cnt <= st + 1; ++cnt) {
            sums[st][cnt] = (sums[st][cnt - 1] + 2 * pw[st - cnt + 1] * pw2[cnt - 1]) % mod;
        }
    }
}

long long sum(int st, int cnt) {
    if (cnt < 0 || st < 0) {
        return 0;
    }
    return sums[st][cnt];
}

long long fun(string r) {
    int res = sumdp[r.length() - 1];
    int last = -111111;
    for (int i = 0; i < r.length(); ++i) {
        int st = 0, fin = r[i] - '0';
        if (i == 0) {
            st = 1;
        }
        for (int j = st; j < fin; ++j) {
            if (happy(j)) {
                if (i - last <= k) {
                    res = (res + pw[r.length() - i - 1]) % mod;
                } else {
                    res = (res + sum(r.length() - i - 2, min((int) r.length() - 1, i + k) - i)) % mod;
                    int poz = i + k + 1;
                    if (poz < r.length()) {
                        long long x = (pw2[k] * sum_dp(r.length() - poz)) % mod;
                        res = (res + x) % mod;
                    }
                }
            } else {
                if (last < 0) {
                    res = (res + sum_dp(r.length() - i - 1)) % mod;
                } else {
                    res = (res + sum(r.length() - i - 2, min((int) r.length() - 1, k + last) - i)) % mod;
                    int poz = max(i + 1, last + k + 1);
                    if (poz < r.length()) {
                        long long x = (pw2[poz - i - 1] * sum_dp(r.length() - poz)) % mod;
                        res = (res + x) % mod;
                    }
                }
            }
        }
        if (happy(fin)) {
            if (i - last <= k) {
                res = (res + 1) % mod;
                long long x = 0;
                for (int j = i + 1; j < r.length(); ++j) {
                    x = (x * 10 + r[j] - '0') % mod;
                }
                res = (res + x) % mod;
                return res;
            }
            last = i;
        }
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> t >> k;
    get_dp();
    get_all_sum();
    while (t--) {
        scanf("%s%s", ll, rr);
        l = ll;
        r = rr;
        long long x = fun(r);
        long long y = fun(l);
        long long ans = ((x - y) % mod + mod) % mod;
        if (ok(l)) {
            ans = (ans + 1) % mod;
        }
        cout << ans << endl;
    }
    return 0;
}


#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int max_n = 511, mod = 1000000007;

int t, k;
long long pw[max_n], pw2[max_n];
int dp[max_n], sumdp[max_n], sums[max_n][max_n];
char ll[max_n], rr[max_n];
string l, r;

int sum_dp(int r) {
    return sumdp[r];
}

void get_dp() {
    pw[0] = 1;
    pw2[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        pw[i] = (pw[i - 1] * 10) % mod;
        pw2[i] = (pw2[i - 1] * 8) % mod;
    }
    dp[0] = dp[1] = 0;
    for (int len = 2; len < max_n; ++len) {
        //cout << dp[len - 1] << endl;
        for (int i = 1; i <= len; ++i) {
            for (int j = i + 1; j <= len && j - i <= k; ++j) {
                long long x = (pw2[j - i - 1] * pw[len - j]) % mod;
                int poz = i - k;
                if (poz > 1) {
                    //cout << poz - 1 << endl;
                    x = (x * pw2[k]) % mod;
                    long long y = ((9 * pw[poz - 2] - dp[poz - 1]/*sum_dp(poz - 1)*/) % mod + mod) % mod;
                    x = (x * y) % mod;
                } else {
                    if (i != 1) {
                        x = (x * pw2[i - 2] * 7) % mod;
                    }
                }
                //if (len == 6) cout << i << " " << j << "  -  " << x << endl;
                x = (x * 4) % mod;
                dp[len] = (dp[len] + x) % mod;
            }
        }
        sumdp[len] = (sumdp[len - 1] + dp[len]) % mod;
    }
    //cout << dp[6] << endl;
}

bool ok(string s) {
    int last = -11111;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '4' || s[i] == '7') {
            if (i - last <= k) {
                return true;
            }
            last = i;
        }
    }
    return false;
}

bool happy(int x) {
    return x == 4 || x == 7;
}

void get_all_sum() {
    for (int st = 0; st < max_n; ++st) {
        sums[st][1] = (2 * pw[st] * pw2[0]) % mod;
        for (int cnt = 2; cnt <= st + 1; ++cnt) {
            sums[st][cnt] = (sums[st][cnt - 1] + 2 * pw[st - cnt + 1] * pw2[cnt - 1]) % mod;
        }
    }
}

long long sum(int st, int cnt) {
    if (cnt < 0 || st < 0) {
        return 0;
    }
    /*long long res = 0;
    for (int q = 0; q < cnt; ++q) {
        long long x = (2 * pw[st - q] * pw2[q]) % mod;
        res = (res + x) % mod;
    }
    cout << st << " " << cnt << " - " << sums[st][cnt] << "  res = " << res << endl;*/
    return sums[st][cnt];
}

long long fun(string r) {
    long long res = 0;
    for (int i = 1; i < r.length(); ++i) {
        res = (res + dp[i]) % mod;
    }
    int last = -111111;
    //cout << r << "  -  " << res << endl;
    for (int i = 0; i < r.length(); ++i) {
        //cout << "i = " << i << "  " << r << "  -  " << res << "    last = " << last << endl;
        int st = 0, fin = r[i] - '0';
        if (i == 0) {
            st = 1;
        }
        for (int j = st; j < fin; ++j) {
            if (happy(j)) {
                if (i - last <= k) {
                    res = (res + pw[r.length() - i - 1]) % mod;
                } else {
                    //@@@@@@;
                    res = (res + sum(r.length() - i - 2, min((int) r.length() - 1, i + k) - i)) % mod;
                    int poz = i + k + 1;
                    if (poz < r.length()) {
                        long long x = (pw2[k] * sum_dp(r.length() - poz)) % mod;
                        //cout << "+=" << x << endl;
                        res = (res + x) % mod;
                    }
                }
            } else {
                if (last < 0) {
                    res = (res + sum_dp(r.length() - i - 1));
                } else {
                    res = (res + sum(r.length() - i - 2, min((int) r.length() - 1, k + last) - i)) % mod;
                    int poz = max(i + 1, last + k + 1);
                    if (poz < r.length()) {
                        long long x = (pw2[poz - i - 1] * sum_dp(r.length() - poz)) % mod;
                        //cout << "+=" << x << endl;
                        res = (res + x) % mod;
                    }
                }
            }
            //cout << "      j = " << j << "  " << r << "  -  " << res << endl;
        }
        if (happy(fin)) {
            if (i - last <= k) {
                //cout << r << "  !-!  " << res << endl;
                res = (res + 1) % mod;
                long long x = 0;
                for (int j = i + 1; j < r.length(); ++j) {
                    x = (x * 10 + r[j] - '0') % mod;
                }
                res = (res + x) % mod;
                return res;
            }
            last = i;
        }
    }
    return res;
}

long long solve2() {
    string a = l;
    int res = 0;
    if (ok(r)) {
        ++res;
    }
    while (a != r) {
        //cout << a << endl;
        //for (int i = 1; i < 111111111; ++i);
        if (ok(a)) {
            ++res;
        }
        int poz = a.length() - 1;
        while (poz >= 0 && a[poz] == '9') {
            --poz;
        }
        if (poz == -1) {
            for (int i = 0; i < a.length(); ++i) {
                a[i] = '0';
            }
            a = "1" + a;
        } else {
            ++a[poz];
            for (int i = poz + 1; i < a.length(); ++i) {
                a[i] = '0';
            }
        }
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> t >> k;
    get_dp();
    get_all_sum();
    //cout << dp[2] << " " << dp[3] << " " << dp[4];
    while (t--) {
        scanf("%s%s", ll, rr);
        l = ll;
        r = rr;
        long long x = fun(r);
        long long y = fun(l);
        long long ans = ((x - y) % mod + mod) % mod;
        if (ok(l)) {
            ans = (ans + 1) % mod;
        }
        cout << ans << endl;
        //cout << ans << "      " << x << " " << y  << endl;
        //cout << solve2() << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <cstring>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 1100;

bool used[MAXN];
int n, m, X, Y;
int64 dist[MAXN][MAXN], t[MAXN], c[MAXN], d[MAXN];
vector<int> g[MAXN];
vector<int64> w[MAXN];
set<pair<int64, int> > q;

void update(int v, int64 dist, int64 * d) {
	if (dist < d[v]) {
		q.erase(mp(d[v], v));
		d[v] = dist;
		q.insert(mp(d[v], v));

	}
}

void dijkstra(int start, int64 * d) {
	d[start] = 0;
	q.insert(mp(d[start], start));
	while (!q.empty()) {
		int v = q.begin()->second;
		q.erase(q.begin());

		forn(i, g[v].size())
			update(g[v][i], d[v] + w[v][i], d);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif

	cin >> n >> m >> X >> Y;
	X--; Y--;
	forn(i, m) {
		int v, u, wei;
		cin >> v >> u >> wei;
		v--; u--;

		g[v].pb(u);
		w[v].pb(wei);

		g[u].pb(v);
		w[u].pb(wei);
	}

	forn(i, n)
		cin >> t[i] >> c[i];

	memset(dist, 60, sizeof dist);
	forn(i, n)
		dijkstra(i, dist[i]);

	memset(d, 60, sizeof d);
	d[X] = 0;
	while (true) {
		int v = -1;
		int64 D = INF64;
		forn(i, n)
			if (!used[i] && D > d[i]) {
				v = i;
				D = d[i];
			}

		if (v == -1) break;
		used[v] = true;

		forn(u, n)
			if (dist[v][u] <= t[v])
				d[u] = min(d[u], d[v] + c[v]);
	}

	if (d[Y] > INF64/2)
		cout << -1 << endl;
	else
		cout << d[Y] << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define paii pair<int,int>
#define MK(a,b) make_pair(a,b)
const ll MOD=1e9+7;
int a[3005];
ll dp[3005][3005][5];
int k;
ll dfs(int pos,int pre,int sta,bool limit){
    if (pos<0)
        return sta;
    if (!limit&&dp[pos][pre][sta]!=-1)
        return dp[pos][pre][sta];
    int up=limit?a[pos]:9;
    ll tmp=0;
    rep(i,0,up){
        if (i==4||i==7)
            tmp=(tmp+dfs(pos-1,pos,sta||(pre!=-1&&abs(pre-pos)<=k),limit&&i==up))%MOD;
        else
            tmp=(tmp+dfs(pos-1,pre,sta,limit&&i==up))%MOD;
    }
    if (!limit)
        dp[pos][pre][sta]=tmp;
    return tmp;
}
ll DP(char *s){
    int l=strlen(s);
    rep(i,0,l-1)
        a[l-i-1]=s[i]-'0';
    return dfs(l-1,-1,0,true);
}
char le[1005],ri[1005];
void solve(){
    mem(dp,-1);
    int t;
    scanf("%d%d",&t,&k);
    while (t--){
        scanf("%s%s",le,ri);
        int p=0,tmp=-1,l=strlen(le);
        rep(i,0,l-1){
            if (le[i]=='4'||le[i]=='7'){
                if (tmp==-1||abs(i-tmp)>k)
                    tmp=i;
                else {
                    p=1;
                    break;
                }
            }
        }
        //printf("%lld %lld\n",DP(ri),DP(le));
        printf("%lld\n",((DP(ri)-DP(le)+p)%MOD+MOD)%MOD);
    }
}
int main(){
    solve();
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

#define minimize(a, b) { a = min(a, b); }
#define maximize(a, b) { a = max(a, b); }

#define all(v) v.begin(),v.end()

using namespace std;

#define next(type, i) type i; cin >> i;
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }

const int mod = 777777777;

LL add(LL a, LL b) {
	return (a + b) % mod;
}

LL mult(LL a, LL b) {
	return a * b % mod;
}

LL waysToMerge[257][257];
LL ans[257][257];

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

	FOR (i, 0, 257) waysToMerge[i][0] = 1;
	FOR (i, 0, 257) FOR (j, 1, 257) {
		waysToMerge[i][j] = 0;
		FOR (k, 0, i + 1) waysToMerge[i][j] = add(waysToMerge[i][j], waysToMerge[i - k][j - 1]);
	}

	next(int, n);
	next(int, k);

	FOR (i, 0, 257) ans[0][i] = 0;
	ans[0][0] = 1;

	bool debug = 0;
	FOR (upTo, 1, n + 1) FOR (ppl, 0, n + 1) {
		ans[upTo][ppl] = 0;
		FOR (x, 0, ppl + 1) {
			if (debug) cout << upTo << ' ' << ppl << ' ' << x << endl; DO_NOT_SEND
			if (x == upTo && x > n - k) { if (debug) cout << "skip1" << endl; continue; }
			if (upTo == n - k && x != upTo) { if (debug) cout << "skip2" << endl; continue; }

			ans[upTo][ppl] = add(ans[upTo][ppl], mult(waysToMerge[x][ppl - x], ans[upTo - 1][ppl - x]));
		}
		if (debug) cout << "== " << upTo << ' ' << ppl << ' ' << ans[upTo][ppl] << endl;
	}

	cout << ans[n][n];
}


#include<iostream>
#include<cstdio>
#define lld long long
using namespace std;

const int MaxN = 100000 + 10;

int n1, n2, n3;
lld D1, E2;

class Tree
{
	public:
	int head[MaxN], nxt[MaxN << 1], to[MaxN << 1], top, son[MaxN], size;
	lld totaldis[MaxN], PD[MaxN], PE[MaxN];bool vis[MaxN];
	void addedge(int fr,int tt){top++;nxt[top] = head[fr];to[top] = tt;head[fr] = top;}
	lld dfs1(int x,int c)
	{
		vis[x] = true;
		lld ret = c;
		son[x] = 1;
		for(int i = head[x]; i; i = nxt[i])
			if(!vis[to[i]])
			{
				ret += dfs1(to[i], c + 1);
				son[x] += son[to[i]];
			}
		return ret;
	}
	void dfs2(int x)
	{
		vis[x] = true;
		for(int i = head[x]; i; i = nxt[i])
			if(!vis[to[i]])
			{
				totaldis[to[i]] = totaldis[x] + (lld)size - 2LL * son[to[i]];
				dfs2(to[i]);
			}
	}
	lld dfs3(int x)
	{
		vis[x] = true;
		lld ret, v1, v2;
		PD[x] = (lld)n1 * totaldis[x];PE[x] = (lld)n3 * totaldis[x];
		ret =
		for(int i = head[x]; i; i = nxt[i])
			if(!vis[to[i]])
			{
				ret = max(ret, dfs3(to[i]));
				v1 = PD[to[i]] + ((lld)n1 * (lld)n3);
				v2 = PE[to[i]] + ((lld)n1 * (lld)n3);
				if(v1 + PE[x] > ret) ret = v1 + PE[x];
				if(v2 + PD[x] > ret) ret = v2 + PD[x];
				if(v1 > PD[x]) PD[x] = v1;
				if(v2 > PE[x]) PE[x] = v2;
			}
		return ret;
	}
	void ReadIn(int n)
	{
		int a, b;
		for(int i = 1; i < n; ++i)
		{
			scanf("%d%d", &a, &b);
			addedge(a, b);
			addedge(b, a);
		}
		size = n;
	}
	void clearVis()
	{
		for(int i = 1; i <= size; ++i) vis[i] = false;
	}
	lld calcIn()
	{
		lld ret = 0;
		for(int i = 1; i <= size; ++i) ret += totaldis[i];
		ret /= 2;
		return ret;
	}
	lld findMax()
	{
		lld mx = totaldis[1];
		for(int i = 2; i <= size; ++i) if(totaldis[i] > mx) mx = totaldis[i];
		return mx;
	}
}T1, T2, T3;

void init()
{
	scanf("%d%d%d", &n1, &n2, &n3);
	T1.ReadIn(n1);
	T2.ReadIn(n2);
	T3.ReadIn(n3);
}

void solve()
{
	T1.totaldis[1] = T1.dfs1(1, 0);
	T2.totaldis[1] = T2.dfs1(1, 0);
	T3.totaldis[1] = T3.dfs1(1, 0);
	T1.clearVis();T2.clearVis();T3.clearVis();

	T1.dfs2(1);T2.dfs2(1);T3.dfs2(1);
	T1.clearVis();T2.clearVis();T3.clearVis();

	lld ans = T1.calcIn() + T2.calcIn() + T3.calcIn();

	D1 = T1.findMax();
	E2 = T3.findMax();
	ans += (lld)(n2 + n3) * D1;
	ans += (lld)(n1 + n2) * E2;
	ans += T2.dfs3(1);
	ans += (lld)n1 * (lld)n2 + (lld)n2 * (lld)n3 + 2LL * (lld)n1 * (lld)n3;
	cout << ans << endl;
}

int main()
{
	init();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define y1 _y1

template < typename T > T abs(T x)
{
	return x > 0 ? x : -x;
}

const int maxn = 100005;

vector < int > g[3][maxn];
ll sz[3][maxn], ds[3][maxn], sum[3][maxn];
ll n[3];

void dfs(int i, int v, int p)
{
	sz[i][v] = 1;
	for (int to : g[i][v])
		if (to != p)
		{
			dfs(i, to, v);
			sz[i][v] += sz[i][to];
			ds[i][v] += ds[i][to] + sz[i][to];
		}
}

void dfs2(int i, int v, int p, ll up = 0)
{
	sum[i][v] = up + ds[i][v];
	for (int to : g[i][v])
		if (to != p)
		{
			dfs2(i, to, v, up + ds[i][v] - (ds[i][to] + sz[i][to]) + (n[i] - sz[i][to]));
		}
}

int i2, i3;
ll best[2][maxn];
ll ans = 0;

void dfs3(int i, int v, int p)
{
	multiset < ll > s;
	for (int to : g[i][v])
	{
		if (to == p)
			continue;
		dfs3(i, to, v);
		s.insert(best[0][to]);
	}

	ans = max(ans, sum[i][v] * (n[i2] + n[i3]));

	best[0][v] = sum[i][v] * n[i2];
	best[1][v] = sum[i][v] * n[i3];

	for (int to : g[i][v])
	{
		if (to == p)
			continue;
		s.erase(s.find(best[0][to]));
		if (!s.empty())
			ans = max(ans, *s.rbegin() + best[1][to] + 2LL * n[i2] * n[i3]);
		s.insert(best[0][to]);
		ans = max(ans, sum[i][v] * n[i2] + n[i2] * n[i3] + best[1][to]);
		ans = max(ans, sum[i][v] * n[i3] + n[i2] * n[i3] + best[0][to]);

		best[0][v] = max(best[0][v], best[0][to] + n[i2] * n[i3]);
		best[1][v] = max(best[1][v], best[1][to] + n[i2] * n[i3]);
	}
}

int main(int argc, char *argv[])
{
	//freopen("a.in", "r", stdin);
	cin >> n[0] >> n[1] >> n[2];

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < n[i] - 1; j++)
		{
			int u, v;
			cin >> u >> v;
			g[i][u].pb(v);
			g[i][v].pb(u);
		}

		dfs(i, 1, -1);
		dfs2(i, 1, -1);
	}

	ll gans = 0;

	ll best[3] = { 0, 0, 0 };
	ll s = 0;
	for (int i = 0; i < 3; i++)
		for (int j = 1; j <= n[i]; j++)
		{
			s += sum[i][j];
			best[i] = max(best[i], sum[i][j]);
		}

	for (int i = 0; i < 3; i++)
	{
		i2 = (i + 1) % 3;
		i3 = (i + 2) % 3;

		ans = 0;
		dfs3(i, 1, -1);
    if(n[i] > 1000) ans = 0;
		ans += s / 2;
		ans += n[i2] * (n[i] + n[i3]);
		ans += n[i3] * (n[i] + n[i2]);
		ans += best[i2] * (n[i] + n[i3]);
		ans += best[i3] * (n[i] + n[i2]);

		gans = max(gans, ans);
	}

	cout << gans << endl;

	return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

#define ll long long
#define FOR(i,a) for(ll i=0;i<(ll)a.size();i++)
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=1e5+200;

ll seg[maxn*4];
ll lazy[maxn*4];

void shift(ll a,ll l,ll r,ll mid){
	lazy[2*a]+=lazy[a];
	lazy[2*a+1]+=lazy[a];

	seg[2*a]+=lazy[a]*(mid-l);
	seg[2*a+1]+=lazy[a]*(r-mid);

	lazy[a]=0;
}
void update(ll L,ll R,ll node,ll l,ll r,ll v){
	if(l<=L && R<=r){
		seg[node]+=v*(R-L);
		lazy[node]+=v;
		return ;
	}
	if(r<=L || R<=l){
		return ;
	}
	ll mid=(L+R)/2;
	shift(node,L,R,mid);
	update(L,mid,2*node,l,r,v);
	update(mid,R,2*node+1,l,r,v);
	seg[node]=seg[2*node]+seg[2*node+1];
}
ll find_sum(){
	return seg[1];
}
void shift_max(ll a){
	lazy[2*a]+=lazy[a];
	lazy[2*a+1]+=lazy[a];

	seg[2*a]+=lazy[a];
	seg[2*a+1]+=lazy[a];

	lazy[a]=0;
}
void update_max(ll L,ll R,ll node,ll l,ll r,ll v){
	if(l<=L && R<=r){
		seg[node]+=v;
		lazy[node]+=v;
		return ;
	}
	if(r<=L || R<=l){
		return ;
	}
	ll mid=(L+R)/2;
	shift_max(node);
	update_max(L,mid,2*node,l,r,v);
	update_max(mid,R,2*node+1,l,r,v);
	seg[node]=max(seg[2*node],seg[2*node+1]);
}
ll find_max(){
	return seg[1];
}

ll n[3];
vector<ll> ger[3][maxn];
ll f[3][maxn];
ll st[maxn];
ll et[maxn];
ll h[maxn];
ll tt=0;
ll a,Y;

void dfs(ll v,ll p=-1){
	f[a][v]=find_sum();
	FOR(i,ger[a][v]){
		ll u=ger[a][v][i];
		if(u!=p){
			update(0,Y,1,st[u]  ,et[u]+1,-1);
			update(0,Y,1,0      ,st[u]  ,+1);
			update(0,Y,1,et[u]+1,    Y  ,+1);
			dfs(u,v);
			update(0,Y,1,st[u]  ,et[u]+1,+1);
			update(0,Y,1,0      ,st[u]  ,-1);
			update(0,Y,1,et[u]+1,    Y  ,-1);
		}
	}
}
void dfs_s(ll v,ll p=-1){
	tt++;
	st[v]=tt;
	FOR(i,ger[a][v]){
		ll u=ger[a][v][i];
		if(u!=p){
			h[u]=h[v]+1;
			dfs_s(u,v);
		}
	}
	et[v]=tt;
}
void cal(){
	ll N=n[a];
	fill(seg,seg+maxn*4,0);
	fill(lazy,lazy+maxn*4,0);
	tt=-1;
	dfs_s(1);
	Y=et[1]+1;
	for(ll i=1;i<=N;i++){
		update(0,Y,1,st[i],st[i]+1,h[i]);
	}
	dfs(1);
}

ll m,C,D;
void dfss(ll v,ll p=-1){
	m=max(m,f[a][v]*C+find_max());

	FOR(i,ger[a][v]){
		ll u=ger[a][v][i];
		if(u!=p){
			update_max(0,Y,1,st[u]  ,et[u]+1,-C*D);
			update_max(0,Y,1,0      ,st[u]  ,C*D);
			update_max(0,Y,1,et[u]+1,    Y  ,C*D);
			dfss(u,v);
			update_max(0,Y,1,st[u]  ,et[u]+1,C*D);
			update_max(0,Y,1,0      ,st[u]  ,-C*D);
			update_max(0,Y,1,et[u]+1,    Y  ,-C*D);
		}
	}

}
ll find_real_best(ll vas,ll c,ll d){
	C=c;
	D=d;
	fill(seg,seg+maxn*4,0);
	fill(lazy,lazy+maxn*4,0);
	a=vas;
	dfs_s(1);
	Y=et[1]+1;
	for(ll i=1;i<=n[vas];i++){
		update_max(0,Y,1,st[i],st[i]+1,f[a][i]*d + h[i]*c*d);
	}
	m=0;
	dfss(1);
	return m;
}
ll maxf[3];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	cin>>n[0]>>n[1]>>n[2];
	for(ll i=0;i<3;i++){
		for(ll j=1;j<n[i];j++){
			ll v,u;
			cin>>v>>u;
			ger[i][v].pb(u);
			ger[i][u].pb(v);
		}
	}
	a=0;
	cal();
	a=1;
	cal();
	a=2;
	cal();

	ll ans=0;
	for(ll i=0;i<3;i++){
		for(ll j=1;j<=n[i];j++){
			ans+=f[i][j];
			maxf[i]=max(maxf[i],f[i][j]);
		}
	}
	ans/=2;
	ll anss=0;
	for(ll vas=0;vas<=2;vas++){
		ll res=0;

		if(vas!=0)
			res+=maxf[0]*(n[1]+n[2]);
		if(vas!=1)
			res+=maxf[1]*(n[0]+n[2]);
		if(vas!=2)
			res+=maxf[2]*(n[0]+n[1]);

		res+=n[0]*n[1];
		res+=n[1]*n[2];
		res+=n[0]*n[2];

		ll c=(vas+1)%3;
		ll d=(vas+2)%3;
		res+=n[c]*n[d];

		ll mx=find_real_best(vas,n[c],n[d]);
		res+=mx;
		anss=max(anss,res);
	}
	cout<<ans+anss;

}


#include<iostream>
#include<cstdio>
#define maxn 100005
using namespace std;
int T;
int n=1;
int fa[maxn];
double dp[maxn][45];
int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d",&T);
	for(int i=0;i<=40;i++)dp[1][i]=1;
	while(T--)
	{
		int type;
		scanf("%d",&type);
		if(type==1)
		{
			int x;
			scanf("%d",&x);
			fa[++n]=x;
			for(int i=0;i<=40;i++)dp[n][i]=1;
			double pre=dp[x][0];dp[x][0]/=2;double now=pre/2;
			x=fa[x];
			for(int i=1;i<=40 && x;i++,x=fa[x])
			{
				double t=dp[x][i];
				dp[x][i]=dp[x][i]*(now+1)/(pre+1);
				now=dp[x][i];
				pre=t;
			}
		}
		else
		{
			double ans=0;
			int x;
			scanf("%d",&x);
			for(int i=1;i<=40;i++)ans+=i*(dp[x][i]-dp[x][i-1]);
			printf("%.8lf\n",ans);
		}
	}
	return 0;
}