#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,t=0,ans1;
    int e,f;
    cin>>a>>b>>c>>d>>e>>f;

    int B[3];
    if(e<f)
   {

        for(int i=0; i<3; i++)
        {
            if(i==0)
                B[i]=b;
            if(i==1)
                B[i]=c;
            if(i==2)
                B[i]=d;
        }
        sort(B,B+3);
        long long  ans2=B[0]*f;
        t= d-B[0];
        if(t>0)
        {
            if(a>t)
            {
                ans2=ans2+t*e;
            }
            else
            {
                ans2=ans2+a*e;
            }
        }
        cout<<ans2<<endl;
    }
    else
    {
        if(a<d)
        {

             ans1=a*e;
            t=d-a;
        }
        else
        {
             ans1=d*e;
        }
        for(int i=0;i<3;i++){
                if(i==0)
        B[0]=b;
        if(i==1)
        B[1]=c;
        if(i==2)
        B[2]=t;
        }
        sort(B,B+3);
    ans1+=B[0]*f;
    cout<<ans1<<endl;
}
return 0;
}


#include<iostream>

using namespace std;
int main()
{
    int s,i,p,q,a,t;
    int b[2];

    for(i=0;i<2;i++)
    cin>>b[i];
    p = b[0];
    q = b[1];
    if(p%q==0)
    {
              s = p/q;
              for(i=0;i<q;i++)
              {
                              cout<<s;
                              cout<<' ';
                              }}

        else
        {
            while(p%q!=0)
            {
              a = p/q;
              p = p-a;
              q = q-1;
              cout<<a<<' ';
              }
              t = p/q;
              for(i=0;i<q;i++)
              cout<<t<<" ";
              }

            return(0);
              }


#include <bits/stdc++.h>

using namespace std ;
const int maxn = 111 ;
int a[maxn] ,vis[maxn];

int main( ) {

    int n , ta = 0 , tb = 0 ; scanf( "%d" , &n) ;
    for( int i = 0 ; i < n/2 ; i++ ) scanf("%d" , a + i );
    sort( a , a + n/2) ;
    int t = 1 ;
    for( int i = 0 ; i < n/2 ; i++ ) ta +=abs(t - a[i]) ,t+=2 ;
    t = 2 ;
    for( int i = 0 ; i < n/2 ; i++ ) tb +=abs(t - a[i]) ,t+=2 ;
    printf( "%d\n" , min(ta,tb) ) ;
    return 0 ;
}


#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " = "; for(auto i : x){cerr << "[" << i << "]" << " ";} cerr << "\n";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int mod = 1000 * 1000 * 1000 + 7;
const int inf = 1000 * 1000 * 1000 + 100;
const ll inf64 = (ll)1e18 + 100;
set<ll> s;
multiset<ll> ms;
void prime_factors(ll tiv){
	while(tiv % 2 == 0){
		s.insert(2);
		ms.insert(2);
		tiv /= 2;
	}
	for(ll i = 3;i * i <= tiv;i++){
		while(tiv % i == 0){
			s.insert(i);
			ms.insert(i);
			tiv /= i;
		}
	}
	if(tiv > 2){
		s.insert(tiv);
		ms.insert(tiv);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
	ll b, answer = 1;
	cin >> b;
	if(b == 1){
		cout << 1 << "\n";
		return 0;
	}
	vector<ll> a;
	prime_factors(b);
	for(auto x: s){
		answer *= ms.count(x) + 1;
	}
	cout << answer << "\n";
	return 0;
}


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

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define SZ(v) (int)(v).size()
#define ALL(v) (v).begin(), (v).end()
#define FOR(it, v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define FILE ""

typedef long long LL;

string s;
int k;

bool check(int st, int len){
	for (int i = 0; i < len; i++){
		if (st + i + len >= SZ(s))
			return true;
		if (s[st + i] != s[st + i + len])
			return false;
	}
	return true;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen(FILE".in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s;
	cin >> k;
	for (int l = (SZ(s) + k) / 2; l >= 1; l--)
		for (int i = 0; i <= SZ(s) + k - 2 * l; i++)
			if (check(i, l)){
				cout << 2 * l;
				return 0;
		   	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,i,j,ta;
char c[1010][1010];
bool be[999010],b[1010];
void rmt(string zz)
{
	//cout<<zz<<"\n";
	if(zz.length()>0)
		be[(ll)stoi(zz)]=1;
	ll ii,jj;
	for(ii=1;ii<=n;ii++)
	{
		for(jj=1;jj<=6;jj++)
		{
			if(!b[ii])
			{
				b[ii]=1;
				rmt(zz+char(c[ii][jj]));
				b[ii]=0;
			}
		}
	}
}
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
		for(j=1;j<=6;j++)
		{
			cin>>ta;
			c[i][j]=(ta+'0');
		}
	rmt("");
	for(i=1;i<=15211;i++)
	{
		if(!be[i])
		{
			cout<<i-1<<"\n";
			return 0;
		}
	}
}


#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
    string str;int i=0;
    vector<int> v;
    cin>>str;
    while(str[i]!='\0'){
        if(str[i]=='0')
        {
            v.push_back(0);i++;
        }
        else if(str[i]=='.')
        {
            v.push_back(0);i++;
        }
        else if(str[i]=='-'&&str[i+1]=='.')
        {
            v.push_back(1);i=i+2;
        }
        if(str[i]=='-'&&str[i+1]=='-')
        {
            v.push_back(2);i=i+2;
        }
    }
    for(int j=0;j<v.size();j++)
    cout<<v[j];

    return 0;

}


# include <bits/stdc++.h>
  using namespace std;
  pair< int, int > arr[110];
  int ans[110];
  int main()
  {
      ios_base::sync_with_stdio(0);
      cin.tie(NULL);
      cout.tie(NULL);
      long long n, m, i;
      cin >> n >> m;
      for(i = 1; i <= n; i++){
        cin >> arr[i].first;
        arr[i].second = i;
      }
      sort(arr + 1, arr + 1 + n);
      for(i = 1; i <= n; i++){
        ans[arr[i].second] = i % 2;
      }
      for(i = 1; i <= n; i++){
        cout << ans[i] << " ";
      }
      return 0;
  }


#include <cstdio>
#include <map>
#include <set>

int R,C;
long long bi[61][61],get[61][61],match[61][61];
std::map<long long,int>map[22];
std::set<long long>set[22];
char str[61];
long long Abs(long long x){return x<0?-x:x;}
int main(){
	scanf("%d%d%s",&R,&C,str+1);
	for(int i=0;i<=(R+C)<<1;i++){
		bi[i][0]=1;
		for(int j=1;j<=i;j++)
			bi[i][j]=bi[i-1][j]+bi[i-1][j-1];
	}
	for(int i=1;i<=R+C;i++)
		for(int j=0;j<=R+C;j++)
			get[i][j]=bi[i-1][R-1]*bi[j][R];
	for(int i=0,start=(R<<1)+C;i<(1<<(C+1));i++){
		int u=(R+C)-__builtin_popcount(i);
		long long ans=0;
		bool cando=1;
		for(int j=0;j<C+1;j++){
			if(str[j+start]!='?'&&((i&(1<<j))!=0)!=(str[j+start]=='A')){
				cando=0;
			}
			if(i&(1<<j))++u,ans+=get[u][j+start-u];
			else ans-=get[j+start-u][u];
		}
		if(cando)++map[__builtin_popcount(i)][ans];
		set[__builtin_popcount(i)].insert(ans);
	}
	for(int i=1;i<=C+1;i++){
		int cnt1=0,cnt2=0;
		for(int j=1;j<=i+((R-1)<<1);j++)
			if(str[j]=='A')++cnt1;
			else if(str[j]=='B')++cnt2;
		if(cnt1>R-1+i||cnt2>R-1)match[i][0]=0;
		else match[i][0]=bi[i+((R-1)<<1)-cnt1-cnt2][R-1-cnt2];
		if(cnt1>R-1||cnt2>R-1+i)match[0][i]=0;
		else match[0][i]=bi[i+((R-1)<<1)-cnt1-cnt2][R-1-cnt1];
	}
	long long fin=1e18,Ans=0;
	for(int i=0,start=(R<<1)-1;i<(1<<(C+1));i++){
		bool same=1,cando=1;
		int cnt=1;
		for(int j=1;j<C+1;j++){
			if(((i&(1<<j))!=0)!=((i&(1<<(j-1)))!=0))same=0;
			if(same)++cnt;
			if(!same&&str[j+start]!='?'&&((i&(1<<j))!=0)!=(str[j+start]=='A')){
				cando=0;
			}
		}
		int u=R-1;
		long long ans=0;
		for(int j=0;j<C+1;j++){
			if(i&(1<<j))++u,ans+=get[u][j+start-u];
			else ans-=get[j+start-u][u];
		}
		int sum=C+1-__builtin_popcount(i);
		auto now=set[sum].lower_bound(-ans);
		if(now!=set[sum].end()){
			if(fin>Abs(*now+ans))Ans=0;
			fin=std::min(fin,Abs(*now+ans));
			if(cando&&fin==Abs(*now+ans))Ans+=1ll*map[sum][*now]*((i&1)?match[cnt][0]:match[0][cnt]);
		}
		if(now!=set[sum].begin()){
			--now;
			if(fin>Abs(*now+ans))Ans=0;
			fin=std::min(fin,Abs(*now+ans));
			if(cando&&fin==Abs(*now+ans))Ans+=1ll*map[sum][*now]*((i&1)?match[cnt][0]:match[0][cnt]);
		}
	}
	printf("%lld",Ans);
}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	ll	n,k;
	std::cin >> n >> k;

	if (k >= 43)
	{
		pnl("No");
		return 0;
	}

	for (ll	i(2); i <= k; ++i)
		if (n % i != i - 1)
		{
			pnl("No");
			return 0;
		}
	pnl("Yes");
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <functional>

using namespace std;

const double eps = 1e-8;
const int MOD = 1000000007;
#define PB push_back
#define MP make_pair
#define AA first
#define BB second
#define OP begin()
#define ED end()
#define SZ size()
#define SORT(X) sort(X.OP,X.ED)
#define SQ(x) ((x)*(x))
#define SSP system("pause")
typedef long long LL;
typedef pair<int, int> PII;
LL n,m,p;
LL query( LL r ) {
	int i,j;
	LL ret=0;
	for ( i=1; i<=n&&i*1LL*i<r; i++ ) {
		LL mx=sqrt( r-1LL*i*i )+1;
		while ( mx*mx+1LL*i*i>r )mx--;
		if ( mx>m )mx=m;
		//1~mx
		LL per=n-i+1;
		LL cnt=0;
		LL sum=0;
		set<int>S;
		int tp=i;
		for ( j=2; j*j<=tp; j++ )while ( tp%j==0 )tp/=j,S.insert( j );
		if ( tp>1 )S.insert( tp );
		vector<int>L( S.OP,S.ED );
		for ( j=0; j<1<<L.SZ; j++ ) {
			LL num=__builtin_popcount( j );
			LL temp=1;
			if ( num&1LL )temp*=-1;
			LL z=1;
			for ( int k=0; k<L.SZ; k++ )if ( j>>k&1 )z*=L[k];
			num=mx/z;
			cnt+=temp*num;
			sum+=temp*z*( 1+num )*num/2;
		}
		ret+=( cnt*( m+1 )-sum )%p*per%p;
		ret%=p;
	}
//	cout<<r<<" "<<n<<" "<<m<<" ret ";
//	cout<<ret<<endl;
	return ret;
}
int main() {
	LL l,r;
	while ( cin>>n>>m>>l>>r>>p ) {
		if ( n>m )swap( n,m );
		LL add=0;
		if ( l==1 )add=( n+1 )*m+( m+1 )*n;
		query( l*l-1 );
		cout<<( ( query( r*r )-query( l*l-1 )+p )*2LL%p+add )%p<<endl;
	}
	return 0;
}
/*
50005 50007
10000 60000 999999937

263003642

*/


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
using namespace std;

int main()
{
    long long int x,y,m,x1,y1;
    cin>>x>>y>>m;
    unsigned long long int num=0;
    while(1)
    {
        x1=x;
        y1=y;
        if(max(x,y)>=m)
        {
            cout<<num<<endl;
            return 0;
        }

        if(x>0&&y<0){
            unsigned long long int n=fabs(y)/x ;
            long long int xx=y;
            while(y<0){
                y=xx+x*n;
                n++;
            }
            num=num+n-1;
            continue;
        }

        else if(y>0&&x<0){
            unsigned long long int n=fabs(x)/y ;
            long long int xx=x;
            while(x<0){
                x=xx+y*n;
                n++;
            }
            num=num+n-1;
            continue;
        }

        else if(x<y)
        {
            x=x+y;
            num++;
        }
        else{
            y=x+y;
            num++;
        }

        if( (x+y) <= (x1+y1) )
        {
            x=-1;
            cout<<x<<endl;
            return 0;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
double a,b,c,d,ans1,ans2;
int main(void){
    ios::sync_with_stdio(false);
    cin>>a>>b>>c>>d;
    ans1=max(3*a/10.00,a-a*c/250.00);
    ans2=max(3*b/10.00,b-b*d/250.00);
    if (ans1<ans2) printf("Vasya\r");
    else if (ans1==ans2) printf("Tie\n");
    else if (ans1>ans2) printf("Misha\r");
}


#include<bits/stdc++.h>
#define MOD (long long)998244353
using namespace std;
long long fac[200003],lst[200003];
inline long long qpow(long long a,long long b)
{
    if(b==1) return a;
    long long t=qpow(a,b/2);
    t=t*t%MOD;
    if(b&1) t=t*a%MOD;
    return t;
}
inline long long c(long long m,long long n)
{
    if(n<m) return 0;
    if(m>n-m) m=n-m;
    long long a=lst[m],b=fac[m];
    return a*qpow(b,MOD-2)%MOD;
}
inline long long C(long long m,long long n)
{
    if(n<m) return 0;
    if(m>n-m) m=n-m;
    long long a=1,b=1;
    for(long long i=0;i<m;i++)
	{
        a=(a*(n-i))%MOD;
        b=(b*(i+1))%MOD;
    }
    return a*qpow(b,MOD-2)%MOD;
}
int main()
{
	long long n,m,ans=0;
	cin>>n>>m;
	lst[0]=fac[0]=1;
	for(long long i=1; i<n-1; i++) fac[i]=fac[i-1]*i%MOD,lst[i]=lst[i-1]*(n-i-2)%MOD;
	for(long long i=2; i<n; i++) ans+=c(i-2,n-3)*(n-2),ans%=MOD;
	ans*=C(n-1,m),ans%=MOD;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
   string in;
   bool plus = false;
   bool equal = false;
   int a1 = 0;
   int a2 = 0;
   int a3 = 0;
   cin >> in;
   for(int i = 0; i<in.length(); i++){
       if(in.at(i) == '|'){
           if(!plus && !equal){
               a1++;
           }
           else if(plus && !equal){
               a2++;
           }
           else if(plus && equal){
               a3++;
           }
       }
       else if(in.at(i) == '+'){
           plus = true;
       }
       else if(in.at(i) == '='){
           equal = true;
       }
   }
   if(a1 + a2 == a3){
       cout << in;
   }
   else if(abs(a1 + a2 - a3) == 2){
       if(a1 + a2 > a3){
           a3++;
           if(a1 > 1){
               a1--;
           }
           else{
               a2--;
           }
       }
       else{
           a1++;
           a3--;
       }
       string result = "";
       for(int i=0;i<a1;i++){
           result += "|";
       }
       result+="+";
       for(int i=0;i<a2;i++){
           result += "|";
       }
       result+="=";
       for(int i=0;i<a3;i++){
           result += "|";
       }
       cout << result;
   }
   else{
       cout << "Impossible";
   }
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    long long a, b, c;
    cin >> a >> b >> c;
    cout << 2 * c + 2 * min(a, b) + (a != b);
    return 0;
}


#include <bits/stdc++.h>
#define re(i, x, y) for (int i = (x); i < (y); ++i)
#define rep(i, x, y) for (int i = (x); i <= (y); ++i)
#define repp(i, x, y, d) for (int i = (x); i <= (y); i += (d))
#define reep(i, x, y) for (int i = (x); i <= (y); i <<= 1)
#define pe(i, x, y) for (int i = (x) - 1; i >= (y); --i)
#define per(i, x, y) for (int i = (x); i >= (y); --i)
#define rep_e(i, u) for (int i = head[(u)]; i; i = e[i].nxt)
#define vi vector<int>
#define vL vector<LL>
#define vii vector<pii>
#define viL vector<piL>
#define vLi vector<pLi>
#define vLL vector<pLL>
#define eb emplace_back
#define pb pop_back
#define mp make_pair
#define pii pair<int, int>
#define piL pair<int, LL>
#define pLi pair<LL, int>
#define pLL pair<LL, LL>
#define lowbit(x) ((x) & (-(x)))
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << endl
using namespace std;
typedef unsigned int ui;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
#define getchar() (SB == TB && (TB = (SB = BB) + fread(BB, 1, 1 << 16, stdin), SB == TB) ? EOF : *SB++)
char BB[1 << 16], *SB = BB, *TB = BB;
template<typename T> void read(T &n) {
	T w = 1;
	n = 0;
	char ch = getchar();
	for ( ; !isdigit(ch); ch = getchar()) {
		if (ch == '-') {
			w = -1;
		}
	}
	for ( ; isdigit(ch); ch = getchar()) {
		n = n * 10 + (ch & 15);
	}
	n *= w;
}
template<typename T> void chkmn(T &a, const T &b) {
	(a > b) && (a = b);
}
template<typename T> void chkmx(T &a, const T &b) {
	(a < b) && (a = b);
}

int MOD;
int adt(const LL &a) {
	return (a % MOD + MOD) % MOD;
}
int inc(const int &a, const int &b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}
int dec(const int &a, const int &b) {
	return a - b < 0 ? a - b + MOD : a - b;
}
int mul(const int &a, const int &b) {
	return 1LL * a * b % MOD;
}
int sqr(const int &a) {
	return 1LL * a * a % MOD;
}
void Adt(LL &a) {
	a = (a % MOD + MOD) % MOD;
}
void Inc(int &a, const int &b) {
	((a += b) >= MOD) && (a -= MOD);
}
void Dec(int &a, const int &b) {
	((a -= b) < 0) && (a += MOD);
}
void Mul(int &a, const int &b) {
	a = 1LL * a * b % MOD;
}
void Sqr(int &a) {
	a = 1LL * a * a % MOD;
}
int fsp(int a, int x = MOD - 2) {
	int res = 1;
	for ( ; x; x >>= 1, Sqr(a)) {
		if (x & 1) {
			Mul(res, a);
		}
	}
	return res;
}

const int maxn = 5e3 + 5;
int n;
int binom[maxn][maxn], pw[maxn][maxn], fac[maxn], fiv[maxn];

int main() {

    read(n), read(MOD);
    fac[0] = 1;
    rep(i, 1, n) {
        fac[i] = mul(fac[i - 1], i);
    }
    fiv[n] = fsp(fac[n]);
    per(i, n, 1) {
        fiv[i - 1] = mul(fiv[i], i);
    }
    rep(i, 0, n) {
        binom[i][0] = binom[i][i] = 1;
        re(j, 1, i) {
            binom[i][j] = inc(binom[i - 1][j], binom[i - 1][j - 1]);
        }
        pw[i][0] = 1;
        rep(j, 1, n) {
            pw[i][j] = mul(pw[i][j - 1], i);
        }
    }
    int ans = 0;
    re(i, 0, n) {
        re(j, 1, n - i) {
            Inc(ans, mul(mul(binom[n][i], mul(fac[n - i], mul(fiv[j], binom[n - i - 1 - j][j - 1]))), mul(pw[n - i - j][i], pw[n - 1][j])));
        }
    }
    printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
int read()
{
    char s;
    int k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
    if(s==EOF)exit(0);if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
void write(int x)
{
    if(x<0){putchar('-');write(-x);}
    else{if(x/10)write(x/10);putchar(x%10+'0');}
}
const int maxn=2e6+100;
const long long mod=1e9+7;
int n,k,mu[maxn];
int f[maxn],prime[maxn],tot;
long long ksm(long long x,int y)
{
	long long sum=1;
	while (y)
	{
		if (y&1) sum=sum*x%mod;
		y>>=1;
		x=x*x%mod;
	}
	return sum;
}
long long ans[maxn],p[maxn],sum;
int main()
{
	n=read();k=read();
	for (int i=1;i<=k;i++)
	{
		p[i]=ksm((long long)i,n);
	}
	mu[1]=1;
	for (int i=2;i<=k;i++)
	{
		if (!f[i])
		{
			tot++;prime[tot]=i;mu[i]=-1;
		}
		for (int j=1;j<=tot;j++)
		{
			if (i*prime[j]>k) break;
			f[i*prime[j]]=1;
			if (i%prime[j]==0) break;
			mu[i*prime[j]]=-mu[i];
		}
	}
	for (int i=1;i<=k;i++)
	{
		for (int j=i;j<=k;j+=i)
		{
			ans[j]+=(long long)mu[i]*(p[j/i]-p[(j/i)-1])%mod;
			ans[j]%=mod;
		}
	}
	for (int i=2;i<=k;i++)
	{
		ans[i]+=ans[i-1];
		ans[i]%=mod;
	}
	for (int i=1;i<=k;i++)
	{
//			printf("%I64d\n",ans[i]);
		if (ans[i]<0) ans[i]=(ans[i]%mod+mod)%mod;
		sum+=ans[i]^(long long)i;
		if (sum>=mod) sum-=mod;
	}
	printf("%I64d\n",sum);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n;
int sum(long long n)
{
	if(n==4||n==7) return true;
	if(n<10) return false;
	return (n%10==4||n%10==7)+sum(n/10);
}
bool judge(int x)
{
	if(x==4||x==7) return true;
	if(x<10) return false;
	if(x%10!=4&&x%10!=7) return false;
	return judge(x/10);
}
int main()
{
	scanf("%lld",&n);
	printf("%s",judge(sum(n))?"YES":"NO");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <iostream>
#include <string.h>
#include <set>
#include <queue>
#include <algorithm>
#include <complex>
#include <deque>
#include <map>
#include <utility>
#include <limits>
#include <vector>
// numeric_limits<int>::max()
using namespace std;
#define LL int64_t // 64-bit long long int, use %I64d for scan and printf
int DEBUG = 0;
#define MOD 1000000009
LL pascal[5000][5000];
main(int argc, char **argv) {
  DEBUG = (argc>=2) ? atoi(argv[1]) : 0;
  LL factorial[5000];
  factorial[0] = 1;
  for(int i = 1; i < 5000; i++){
    factorial[i] = (factorial[i-1] * i) % 1000000009;
  }
  for(int i = 0; i < 5000; i++){
    pascal[i][0] = pascal[i][i] = 1;
  }
  for(int i = 1; i < 5000; i++){
    for(int j = 1; j < 5000; j++){
      pascal[i][j] = (pascal[i-1][j-1] + pascal[i-1][j]) % MOD;
    }
  }
  int n, w, b;
  cin >> n >> w >> b;
  LL ans = (factorial[w]*factorial[b]) % MOD;
  LL mult = 0;
  for(int i = 1; i < n; i++){
    if((n-i) <= w && i <= b){
      LL here = 0;

      here = n-i-1;
      here = (here * (pascal[b-1][i-1])) % MOD;
      here = (here * (pascal[w-1][n-i-1])) % MOD;
      //cout << i << " " << here << endl;
      mult = (mult + here) % MOD;
    }
  }
  ans = (ans * mult) % MOD;
  cout << ans << endl;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <ctime>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long double ld;

int BUBEN = 30;
int BUBEN2 = 5;
int BUBEN3 = 20;

class TaskH {
 public:
  void solveOne(istream &in, ostream &out) {
    ld start = clock() / (ld) CLOCKS_PER_SEC;

    int n;
    in >> n;
    vector<int> x(n + 1);
    vector<int> y(n + 1);
    for (int i = 0; i <= n; ++i) {
      in >> x[i] >> y[i];
    }
    vector<ld> offset;
    vector<ld> len;
    vector<ld> dx;
    vector<ld> dy;
    offset.push_back(0);
    for (int i = 0; i < n; ++i) {
      ld vx = x[i + 1] - x[i];
      ld vy = y[i + 1] - y[i];
      ld z = hypotl(vx, vy);
      dx.push_back(vx / z);
      dy.push_back(vy / z);
      len.push_back(z);
      offset.push_back(offset.back() + z);
    }
    auto ternary = [&](const auto& func, ld left, ld right) {
      while (right - left > 1e-12 * max((ld) 1.0, right)) {
        ld mleft = (2 * left + right) / 3;
        ld mright = (left + 2 * right) / 3;
        ld vleft = func(mleft);
        ld vright = func(mright);
        if (vleft > vright) {
          right = mright;
        } else {
          left = mleft;
        }
      }
      return func((left + right) / 2);
    };
    ld total = offset.back();

    auto where = [&](ld pos) {
      int i = lower_bound(all(offset), pos) - offset.begin() - 1;
      if (i < 0) i = 0;
      if (i >= n) i = n - 1;
      return i;
    };

    auto evalBefore = [&](ld pos) {
      int i = where(pos);
      ld xi = x[i] + dx[i] * (pos - offset[i]);
      ld yi = y[i] + dy[i] * (pos - offset[i]);

      ld bestBefore = 1;
      for (int j = 0; j < i; ++j) {
        auto eval2 = [&](ld t) {
          ld xj = x[j] + dx[j] * t;
          ld yj = y[j] + dy[j] * t;
          ld direct = pos - (offset[j] + t);
          return direct / max((ld) 1e-7, hypotl(xi - xj, yi - yj));
        };
        ld cur = ternary(eval2, 0, len[j]);
        bestBefore = max(bestBefore, cur);
      }
      return bestBefore;
    };

    auto evalAfter = [&](ld pos) {
      int i = where(pos);
      ld xi = x[i] + dx[i] * (pos - offset[i]);
      ld yi = y[i] + dy[i] * (pos - offset[i]);

      ld bestAfter = 1;
      for (int j = i + 1; j < n; ++j) {
        auto eval2 = [&](ld t) {
          ld xj = x[j] + dx[j] * t;
          ld yj = y[j] + dy[j] * t;
          ld direct = (offset[j] + t) - pos;
          return direct / max((ld) 1e-7, hypotl(xi - xj, yi - yj));
        };
        ld cur = ternary(eval2, 0, len[j]);
        bestAfter = max(bestAfter, cur);
      }
      return bestAfter;
    };

    auto eval = [&](ld pos) {
      return min(evalBefore(pos), evalAfter(pos));
    };

    ld STEP = total;
    vector<tuple<ld, int, ld>> best;
    while (best.size() < 1e6 && clock() / (ld) CLOCKS_PER_SEC < start + 1) {
      STEP *= 0.5;
      for (ld at = STEP; at <= total; at += STEP * 2) {
        best.emplace_back(eval(at), where(at), at);
      }
    }
    sort(all(best));

    auto reduce = [&]() {
      sort(all(best), [](const auto& a, const auto& b) {
        return get<0>(a) > get<0>(b);
      });
      int got = 0;
      vector<int> gotIn(n);
      for (int i = 0; i < best.size(); ++i) {
        if (got < BUBEN3 && gotIn[get<1>(best[i])] < BUBEN2) {
          best[got] = best[i];
          ++got;
          ++gotIn[get<1>(best[i])];
        }
      }
      best.resize(got);
    };

    while (clock() / (ld) CLOCKS_PER_SEC < start + 3) {
      reduce();
      STEP *= 0.5;
      sort(all(best), [](const auto& a, const auto& b) {
        return get<2>(a) < get<2>(b);
      });
      int old = best.size();
      ld prev = 0;
      for (int i = 0; i <= old; ++i) {
        ld cur;
        if (i == old) {
          cur = total;
        } else {
          cur = get<2>(best[i]);
        }
        if (cur - prev > 3 * STEP) {
          ld at = prev + STEP;
          best.emplace_back(eval(at), where(at), at);
          at = cur - STEP;
          best.emplace_back(eval(at), where(at), at);
        } else if (cur - prev > 2 * STEP) {
          ld at = (2 * prev + cur) / 3;
          best.emplace_back(eval(at), where(at), at);
          at = (prev + 2 * cur) / 3;
          best.emplace_back(eval(at), where(at), at);
        } else if (cur - prev > STEP) {
          ld at = (prev + cur) / 2;
          best.emplace_back(eval(at), where(at), at);
        }
        prev = cur;
      }
    }

    cerr << STEP << endl;

    ld res = 0;
    for (const auto& x : best) {
      res = max(res, get<0>(x));
    }
    out << res << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    out.precision(20);
    int nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskH solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator

#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define BG begin
#define ED end

#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));

#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2

#define INF (1<<29)
#define sqr(x) ((x)*(x))
#define eps (1e-7)
using namespace std;
const int N=1005;
struct que{
	double x; int v;
	bool operator <(const que &a)const{
		if (abs(x-a.x)>eps)
			return x<a.x;
		return v<a.v;
	}
}q[N*2];
int n,m;
double x[N],y[N],r[N];
int calc(double ang){
	double X=sin(ang),Y=cos(ang);
	int tot=0;
	For(i,1,n){
		double val=-x[i]*X+y[i]*Y;
		q[++tot]=(que){val-r[i],1};
		q[++tot]=(que){val+r[i],-1};
	}
	sort(q+1,q+tot+1);
	int tmp=0,ans=0;
	For(i,1,tot)
		ans=max(ans,tmp+=q[i].v);
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
	double st=0,ed=2*acos(-1),step=0.0005;
	int ans=0;
	for (;step>eps;step/=5){
		int mx=0; double at;
		for (double i=st;i<ed;i+=step){
			int now=calc(i);
			if (now>mx) mx=now,at=i;
		}
		st=at-5*step;
		ed=at+5*step;
		ans=max(ans,mx);
	}
	printf("%lld\n",1ll*m*(m+1)/2+n+1ll*ans*m-m);
}


/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;

int cnt[43];
set<LL> help;
map<LL,int> mp;
int cur[43];
int lft[43];
vector<int> fin;

int val(LL tmp)
{
	int cn=0;
	while(tmp)
	{
		tmp/=2;
		cn++;
	}
	return cn;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(LL i=1;i<=2e12;i=i*2)
	{
		help.insert(i);
		mp[i]=0;
	}//powers of 2

	for(int i=1;i<=n;i++)
	{
		LL a;
		scanf("%lld",&a);

		if(help.find(a)!=help.end())
		{
			mp[a]++;
		}

		cnt[val(a)]++;
	}
	//cnt of powers of 2 stored
	int ans=0;
	int num=0;
	while(true)
	{
		LL lst=0;
		for(map<LL,int> :: iterator it=mp.begin();it!=mp.end();it++)
		{
			if(it->second==0)
			{
				break;
			}//find the first power of 2 that doesn't exist, break;
			else
			{
				lst=it->first;
			}
		}

		if(lst==0)
		{
			break;
		}
		num++;
		cur[val(lst)]++;
		int yu=1;

		for(LL i=1;i<=lst;i=i*2)
		{
			cnt[yu]--;
			mp[i]--;
			yu++;
		}
		//cnt[1]=2
		//cnt[2]=2
		//mp[1]=2;
		//mp[2]=2;
		//cur[2]=1;
	/*	for(int i=1;i<=2;i++)
		{
			printf("%d %d\n",cnt[i],mp[i]);
		}*/
		for(int i=0;i<=42;i++)
		{
			lft[i]=cur[i];
		}
	/*	for(int i=1;i<=2;i++)
		{
			printf("%d\n",lft[i]);
		}*/

		int flg=0;
		for(int i=42;i>=1;i--)
		{
			if(i!=42)
			{
				lft[i]+=lft[i+1];
			}
			if(lft[i]>=cnt[i])
			{
				lft[i]-=cnt[i];
			}
			else
			{
				/*if(num==2)
				{
					printf("%d\n",i);
				}*/
				flg=1;
				break;
			}

		}
		if(flg==0)
		{
			fin.push_back(num);
			ans++;
		}
	}
	if(ans==0)
	{
		printf("-1\n");
	}
	else
	{
		for(int i=0;i<fin.size();i++)
		{
			printf("%d ",fin[i]);
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int i,j,n;
	cin>>n;
	for(i=1;i<n;i++) {
		for(j=1;j<n;j++) {
			cout<<i*j/n*10+((i*j)%n)<<" ";
		}
		cout<<endl;
	}
	return 0;
}


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

int main(){

    int n;

    cin>>n;
    int a[n+1];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }

    sort(a,a+n);

    if(a[0] == a[n/2]){
        cout<<"Bob"<<endl;
    }
    else cout<<"Alice"<<endl;

    return 0;
}


#include <iostream>
using namespace std;

int seg[]={6,2,5,5,4,5,6,3,7,6};
int count(int n) {
   int res=0;
   while(n){
      res+=seg[n%10];
      n/=10;
   }
   return res;
}

int main() {

   int x,y
       ,ans=0;
   cin>>x>>y;

   for(int i = x;i<=y;i++) {
   		//cout<<count(i)<<endl;
      ans +=count(i);
   }
   cout<<ans<<endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define ALL(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)

typedef long long i64;
typedef pair<i64, i64> pll;
const i64 INF = 5e18;
const int MK = 10101;
const int MN = 101010;
i64 H, M, N, K;
map<i64, i64> mp;
vector<i64> methods;
vector<pll> ip[MK];

bool pllcmp(pll p1, pll p2) {
    p1.S = -p1.S; p2.S = - p2.S;
    return p1 < p2;
};
priority_queue<pll, vector<pll>, std::function<bool(pll, pll)> > pq(pllcmp);
i64 dis[MK];
i64 op[MN];

void spfa() {
    for(int i=0; i<K; i++) dis[i] = INF;
    dis[0] = 0;

    queue<int> qe; qe.push(0);
    while(qe.size()) {
        i64 v = qe.front(); qe.pop();

        for(int i=0; i<(int)methods.size(); i++) {
            i64 m = methods[i];
            i64 r = (m+v)%K;
            if(dis[r] > dis[v] + m) {
                dis[r] = dis[v] + m;
                qe.push(r);
            }
        }
    }

    pq = priority_queue<pll, vector<pll>, function<bool(pll, pll)> >(pllcmp);
    for(int i=0; i<N; i++) {
        i64 a = op[i], c = mp[op[i]];
        i64 r = a%K;
        if(a >= dis[r]) {
            pq.push(MP(c, i));
        }
    }
}

int main() {

    IOS;
    cin >> H >> N >> M >> K;

    for(int i=0; i<N; i++) {
        i64 a, c;
        cin >> a >> c;
        a --;
        mp[a] = c;
        ip[a%K].PB(MP(i, c));
        op[i] = a;
    }
    //cout << "ZZZ" << endl;

    for(int i=0; i<(int)ip[0].size(); i++) {
        pq.push(MP(ip[0][i].S, ip[0][i].F));
    }

    for(int i=1; i<K; i++) dis[i] = INF;
    //cout << "ZZZ" << endl;

    for(int i=0; i<M; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            i64 x; cin >> x;
            methods.PB(x);
            spfa();
        } else if(t == 2) {
            i64 id, a, c; cin >> id >> c; id--;
            a = op[id];
            mp[a] -= c;
            //if(mp[a] < 0) cout << "A: " << a << ' ' << id << ' ' << c << endl;
            if( dis[a%K] <= a ) pq.push(MP(mp[a], id));
        } else if (t == 3) {
            pll tp;
            while(pq.size()) {
                tp = pq.top();
                if( mp[op[tp.S]] == tp.F ) break;
                pq.pop();
            }

            cout << (pq.size() ? tp.F : 0) << endl;
            if(pq.size()) mp[op[tp.S]] = 0;
        }
    }

    return 0;
}


/*
       _ _              ___ _____ ___   __
__   _(_) | ____ _ ___ / _ \___  / _ \ / /_
\ \ / / | |/ / _` / __| | | | / / | | | '_ \
 \ V /| |   < (_| \__ \ |_| |/ /| |_| | (_) |
  \_/ |_|_|\_\__,_|___/\___//_/  \___/ \___/

 VIKAS SINGH */

#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef std::vector<int> vi;
typedef std::vector<long long> vl;
#define all(v) v.begin(),v.end()
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    scanf("%d",&x);
#define sl(x)                   scanf("%lld",&x);
#define s1d(a,n)                for(int ix=0;ix<n;ix++) cin>>a[ix];
#define p(x)                    printf("%d\n",x);
#define pl(x)                   printf("%lld\n",x);
#define p1d(a,n)                for(int ix=0;ix<n;ix++) printf("%d ",a[ix]); printf("\n");
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) printf("%d ",a[ix][jx]); printf("\n");}
#define MAX 1000005
#define MOD 1000000007
#define MAX_INT 2147483647
#define MAX_LONG 9223372036854775807LL
#define PI 3.14159265358979323846264338327950288
#define FILEINOUT               freopen("input.in","r",stdin);freopen("output.out","w",stdout);
#define FAST_IN_OUT             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

bool isAcceptable(ll n,ll m,ll a){
   a=a-m;
   return  (a*(a+1)/2+m)<(n);
}

ll returnAns(ll n,ll m){

     ll low=m,high=m+MAX_INT,mid;
     while(low<=high) {
         mid= (low+high)/2;
         if(isAcceptable(n,m,mid)){
           low= mid+1;
         }else{
           high=mid-1;
         }
     }
     if(isAcceptable(n,m,mid)) mid++;
     return mid;
}

int main(){
 //   FILEINOUT
    FAST_IN_OUT
    ll n,m;
    cin>>n>>m;
    if(n<=m)
      cout<<n;
    else
    cout<<returnAns(n,m);

}


///HELLO THERE~!
///PREPARED BY MD SADMAN MEHEDI SIVAN(IUT CSE-SWE^19)

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
    fastio;

    long long k;
    cin>>k;

    if(k>=37 )
        {
            cout<<"-1";
            return 0;
        }

    else if(k==0)
    {
        cout<<"7";
        return 0;
    }

    else if(k%2==0)
    {
        for(long long i=0;i<k/2;i++)
            {
                cout<<"8";

            }
            return 0;
    }

    else if(k%2==1)
    {
        for(long long i=0;i<(k-1)/2;i++)
            {
                cout<<"8";
            }
    }
    cout<<"4";

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n = 0;
    int min1 = 0, max1 = 0, min2 = 0, max2 = 0, min3 = 0, max3 = 0;
    cin >> n >> min1 >> max1 >> min2 >> max2 >> min3 >> max3;
    cout << min(n - min2 - min3, max1) << ' ' << min(n - min(n - min3 - min2, max1) - min3, max2) << ' ' << n - min(n - min2 - min3, max1) - min(n - min(n - min2 - min3, max1) - min3, max2);
}


#include <cstdio>
#include <algorithm>
#include <tr1/unordered_map>
#include <vector>
#include <cstring>

//#pragma GCC optimize("O2")

using namespace std;

const int MAXN = 1000010;
const int Mod = 1200007;

int n; char ch[MAXN];

vector<int> now;

typedef tr1::unordered_map<int, int> I;

I M;

int main(void) {
 //   freopen("in", "r", stdin);
    scanf("%s", ch + 1); n = strlen(ch + 1);
    for (int i = n; i >= 1; i--) {
        int S = 0;
        vector<int>::iterator it = find(now.begin(), now.end(), ch[i] - 'a'); if (it != now.end()) now.erase(it); now.insert(now.begin(), ch[i] - 'a');
        for (int j = 0; j < (int)now.size() && now[j] != ch[i - 1] - 'a'; j++) {
            S |= 1 << now[j];
            M[S]++;
        }
    }
    int q; scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
        char st[26]; scanf("%s", st);int t = strlen(st), S = 0;
        for (int j = 0; j < t; j++) S |= 1 << (st[j] - 'a');
        printf("%d\n", M[S]);
    }
    return 0;
}


#include<bits/stdc++.h>
#define INF 0x7fffffff
#define pi acos(-1,0)
#define e 2.718281828459
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

char s[600005];
int sum[300005];
int main(){
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	int n;
	scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++){
    	s[i+n]=s[i];
	}
	sum[0]=0;
	int pos=0,minn=0;
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(s[i]=='('?1:-1);
		if(sum[i]<minn){
			minn=sum[i];
			pos=i;
		}
	}
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(s[i+pos]=='('?1:-1);
	}
	if(sum[n]!=0){
		printf("0\n1 1\n");
		return 0;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(sum[i]==0){
			ans++;
		}
	}
	int maxans=0,p1=1,p2=1;
	for(int i=1;i<=n;i++){
		int j=i,n1=0,n2=0,maxn=0,t1=1,t2=1,pre=i;
		while(j<=n&&sum[j]!=0){
			j++;
		}
		for(int k=i;k<=j;k++){
			if(sum[k]==1){
				if(maxn<n2){
					maxn=n2;t1=pre+1;t2=k;
				}
				n2=0;n1++;pre=k;
			}
			else if(sum[k]==2){
				n2++;
			}
		}
		if(maxn<n2){
			maxn=n2;t1=pre+1;t2=j;
		}
		if(maxans<maxn+ans){
			maxans=maxn+ans;p1=t1;p2=t2;
		}
		if(maxans<n1){
			maxans=n1,p1=i,p2=j;
		}
		i=j;
	}
//	cout<<p1<<" "<<p2<<" "<<pos<<endl;
	printf("%d\n%d %d\n",maxans,(p1+pos-1)%n+1,(p2+pos-1)%n+1);
    return 0;
}
/*
26
((()))(()()()()()()()()())
*/


#include<cstdio>
#include<map>

using namespace std;

#define ll long long

map<int,ll>mp1[100005],*mp2[100005];
int d[100005],w[100005],p[100005];
int main()
{
    //freopen("magictree.in","r",stdin);
    //freopen("magictree.out","w",stdout);
    int n,m,k,x;
    scanf("%d%d%d",&n,&m,&k);
    int i;
    for(i=2;i<=n;i++)
        scanf("%d",&p[i]);
    for(i=1;i<=m;i++)
        {
        scanf("%d",&x);
        scanf("%d%d",&d[x],&w[x]);
        }
    for(i=1;i<=n;i++)
        mp2[i]=mp1+i;
    for(i=n;i>1;i--)
        {
        if (d[i])
            {
            auto it=mp2[i]->insert(make_pair(d[i],0)).first;
            it->second=it->second+w[i];
            x=w[i];
            /*++it;
            while(1)
              {
              if (it==mp2[i]->end() || x<it->second)
                  break;
              x=x-it->second;
              mp2[i]->erase(it);
              it++;
              }*/
            for(++it;it!=mp2[i]->end() && x>=it->second;x=x-it->second,mp2[i]->erase(it++));
            if (it!=mp2[i]->end())
                it->second=it->second-x;
            }
        if (mp2[i]->size()>mp2[p[i]]->size())
            swap(mp2[i],mp2[p[i]]);
        for(auto it:*mp2[i])
            {
            auto num=mp2[p[i]]->insert(make_pair(it.first,0)).first;
            num->second=num->second+it.second;
            }
        }
    ll rasp=0;
    for(auto it:*mp2[1])
        rasp=rasp+it.second;
    printf("%lld\n",rasp);
return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll data[50000];

int sum=0;
void creat(ll num,int digit)
{
	if(digit>10)
		return;
	data[sum++]=num;
	creat(num*10+4,digit+1);
	creat(num*10+7,digit+1);

};

int main()
{
	creat(0,0);
	sort(data,data+sum);
	ll l,r;
	cin>>l>>r;
	ll count=0;
	for(int i=1;true;i++)
	{
		if(l>r) break;
		if(data[i]>=l)
		{
			count+= data[i]*(min(r,data[i])-l+1);
			l=data[i]+1;
		}
	}
	cout<<count<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, nl, len, d[65], z, t, w, k = 1, ans;
char s[65];
int main() {
scanf("%I64d%s", &n, s);
len = strlen(s);
for (int i = n; i; nl++, i /= 10);
for (int i = len-1; i >= 0; i--) {
sscanf(&s[i], "%I64d", &t);
if (t < n && strlen(&s[i]) <= nl) {
w = t;
} else {
if (0 == w) {
d[z++] = w;
while (s[i+1] == '0')
i++;
s[i] = 0;
} else {
d[z++] = w;
while (s[i+1] == '0')
i++;
s[++i] = 0;
}
}
}
if (w) d[z++] = w;
for (int i = 0; i < z; i++, k *= n) {
//printf("%I64d:%I64d\n", k, d[i]);
ans += k * d[i];
}
printf("%I64d\n", ans);
return 0;
}


#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
//~ eni(!=) cerr << boolalpha << i; ris; }
eni(!=) cerr << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

const int AND = 0, OR = 1, NAND = 2, NOR = 3;
const int nax = 1005;

struct S {
	int type;
	S zmien() {
		S he;
		he.type = type ^ 1;
		return he;
	}
	void read() {
		static char sl[10];
		scanf("%s", sl);
		string s = string(sl);
		if(s == "and") type = AND;
		else if(s == "or") type = OR;
		else if(s == "nand") type = NAND;
		else if(s == "nor") type = NOR;
		else {
			cout << "unknown type: " << s << endl;
			assert(false);
		}
	}
	bool operator () (bool a, bool b) {
		if(type == AND) return a & b;
		if(type == OR) return a | b;
		if(type == NAND) return !(a & b);
		if(type == NOR) return !(a | b);
		assert(false);
	}
};

void read(pair<S, pair<int,int>> & p) {
	p.first.read();
	static char sl[105];
	scanf("%s", sl);
	int n = strlen(sl);
	vector<int> w;
	for(int i = 0; i < n; ++i)
		if(sl[i] == 'x')
			w.push_back(i);
	assert((int) w.size() == 2);
	p.second = {w[0], w[1]};
}

vector<int> w[nax];

int main() {
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	vector<pair<S, pair<int,int>>> one(m), two(k);
	for(int i = 0; i < m; ++i)
		read(one[i]);
	for(int i = 0; i < k; ++i)
		read(two[i]);

	const int M = 40 * 1000;
	vector<pair<vector<bool>, vector<bool>>> pre(M);
	for(auto & p : pre) {
		vector<bool> a(n), b(m), c(k), d(k);
		for(int i = 0; i < n; ++i) a[i] = rand() % 2;
		for(int i = 0; i < m; ++i) b[i] = one[i].first(a[one[i].second.first], a[one[i].second.second]);
		for(int i = 0; i < k; ++i) c[i] = two[i].first(b[two[i].second.first], b[two[i].second.second]);
		for(int i = 0; i < k; ++i) d[i] = two[i].first.zmien()(b[two[i].second.first], b[two[i].second.second]);
		p = {c, d};
	}
	vector<bool> maybe(k, true);
	for(auto & p : pre) {
		auto & c = p.first;
		auto & d = p.second;
		debug() << imie(c);
		for(int i = 0; i < k; ++i) if(c[i] & d[i]) maybe[i] = false;
		bool any = false;
		for(int i = 0; i < k; ++i) if(maybe[i]) if(c[i] | d[i]) any = true;
		if(!any) {
			puts("-1");
			return 0;
		}
	}

	vector<vector<bool>> e(k, vector<bool>(k));

	for(auto & p : pre) {
		auto & c = p.first;
		auto & d = p.second;
		debug() << imie(c);
		debug() << imie(d);
		debug();
		for(int i = 0; i < k; ++i) if(maybe[i])
			for(int j = i + 1; j < k; ++j) if(maybe[j])
				if((c[i] & d[j]) | (c[j] & d[i])) e[i][j] = e[j][i] = true;
	}

	for(int i = 0; i < k; ++i)
		for(int j = i + 1; j < k; ++j) if(e[i][j]) {
			w[i].push_back(j);
			w[j].push_back(i);
			//~ printf("%d %d\n", i, j);
		}

	int answer = 0;
	for(int i = 0; i < k; ++i) if(!maybe[i]) ++answer;
	vector<bool> vis(k);
	vector<pair<vector<int>, vector<int>>> they;
	vector<bool> taken(k);
	for(int i = 0; i < k; ++i) if(maybe[i] && !vis[i]) {
		vector<int> A, B;
		vector<int> kol{i};
		vector<int> dist(k);
		vis[i] = true;
		for(int j = 0; j < (int) kol.size(); ++j) {
			int a = kol[j];
			if(dist[a] % 2) A.push_back(a);
			else B.push_back(a);
			for(int b : w[a]) if(!vis[b]) {
				vis[b] = true;
				dist[b] = dist[a] + 1;
				kol.push_back(b);
			}
		}
		if(A.size() < B.size()) swap(A, B);
		// bierzemy pierwsza
		they.push_back({A, B});
		for(int x : A) taken[x] = true;

		//~ printf("%d %d\n", A, B);
		answer += (int) B.size();
	}
	bool yeah = true;
	for(auto & p : pre) {
		auto & c = p.first;
		auto & d = p.second;
		bool any = false;
		for(int i = 0; i < k; ++i) if(taken[i]) if(c[i] | d[i]) any = true;
		if(!any) {
			yeah = false;
			break;
		}
	}

	if(!yeah) for(pair<vector<int>, vector<int>> p : they) {
		int by = 1000000;
		auto memo = taken;
		for(int x : p.first) {
			assert(taken[x]);
			taken[x] = false;
		}
		for(int x : p.second) {
			assert(!taken[x]);
			taken[x] = true;
		}

		bool tu = true;
		for(auto & p : pre) {
			auto & c = p.first;
			auto & d = p.second;
			bool any = false;
			for(int i = 0; i < k; ++i) if(taken[i]) if(c[i] | d[i]) any = true;
			if(!any) {
				tu = false;
				break;
			}
		}
		if(tu) by = min(by, (int) abs(int(p.first.size()) - int(p.second.size())));

		taken = memo;
		answer += by;
	}
	if(answer > k) answer = -1;

	printf("%d\n", answer);
	return 0;

	//~ int answer = -1;
	for(int mask = 0; mask < (1 << k); ++mask) {
		bool ok = true;
		for(int i = 0; i < k; ++i) if(mask & (1 << i)) if(!maybe[i]) ok = false;
		if(!ok) continue;
		for(int rep = 0; rep < 200; ++rep) {
			vector<bool> a(n), b(m), c(k), d(k);
			for(int i = 0; i < n; ++i) a[i] = rand() % 2;
			for(int i = 0; i < m; ++i) b[i] = one[i].first(a[one[i].second.first], a[one[i].second.second]);
			for(int i = 0; i < k; ++i) c[i] = two[i].first(b[two[i].second.first], b[two[i].second.second]);
			for(int i = 0; i < k; ++i) d[i] = two[i].first.zmien()(b[two[i].second.first], b[two[i].second.second]);
			//~ debug() << imie(c);
			//~ debug() << imie(d);
			//~ debug();
			bool raz = false, dwa = false;
			for(int i = 0; i < k; ++i) if(mask & (1 << i)) {
				if(c[i]) raz = true;
				if(d[i]) dwa = true;
			}
			if(raz && dwa) ok = false;
			if(!raz && !dwa) ok = false;
			if(!ok) break;
			//~ for(int i = 0; i < k; ++i)
				//~ if(c[i] && d[i])
					//~ maybe[i] = false;
		}
		if(ok) answer = max(answer, __builtin_popcount(mask));
		//~ debug() << imie(maybe);
	}
	assert(answer != -1);

	//~ if(answer == -1) printf("%d\n", answer);
	//~ else printf("%d\n", k - answer);

	printf("%d\n", k - answer);
}


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

bool check0(string s)
{   bool ok=1;
    if(s=="") return 0;
    for(int i=0;i<s.length();i++)
    {      if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')||s[i]=='_'||isdigit(s[i])) continue;
           else { ok=0; break; }
    }
return ok;
}

bool check(string s)
{   int i,j,k,p,P;
    string s1,s2,s3,str;
    int p1=s.find('@'),p2=s.find('/');
    s1=s.substr(0,p1); s2=s.substr(p1+1,p2-p1-1);
    if(p2!=-1) s3=s.substr(p2+1);
    else s3="";
    if(s1.length()<1||s1.length()>16||s2.length()<1||s2.length()>32||((s3.length()<1||s3.length()>16)&&p2!=-1)) return 0;
    if(!check0(s1)||(!check0(s3)&&s3!="")) return 0;
    if(s2[s2.length()-1]=='.') return 0;
    p=s2.find('.'); P=-1;
    if(p!=-1)
    {  str=s2.substr(0,p); P=p;
       if(!check0(str)) return 0;
    }
    bool ok=0;
    if(p==-1)
    {  if(!check0(s2))   return 0;
        ok=1;
    }
    while((p=s2.find('.',p+1))!=-1)
    {    str=s2.substr(P+1,p-P-1); P=p;
         if(!check0(str)) return 0;
         ok=1;
    }
    if(P!=-1){
    str=s2.substr(P+1);
    if(check0(str)) ok=1;
    }
return ok;
}

int main()
{    string s;
     while(getline(cin,s))
     {     if(check(s)) cout<<"YES\n";
           else cout<<"NO\n";
     }
return 0;
}


#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,greater<int >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

long long int power(long long int base,long long int p)
{
    long long int ans=1;
    while(p)
    {
        if(p&1)
            ans*=base,p--;
        else
            base*=base,p/=2;
    }
    return ans;
}
long long int sec_part(long long int n,long long int k)
{
    long long int curr=0;
    long long int p=1;
    while(n/power(k,p))
    {
        curr+=(n/power(k,p));
        p++;
    }
    return curr;
}
void go()
{
    long long int n,k;
    cin>>n>>k;
    long long int st=0;
    long long int en=n;
    long long int m;
    map<long long int,long long int> h;
    while(st<=en)
    {
        long long int mid=(st+en)/2;
        //cout<<mid<<" "<<st<<""<<en<<endl;
        if(mid + sec_part(mid,k) == n)
        {
            cout<<mid;
            return;
        }
        if(mid + sec_part(mid,k) > n)
            en=mid;
        else if(mid + sec_part(mid,k) < n)
            st=mid;
        h[mid]++;
        if(h[mid] > 10)
            break;
    }
    cout<<st+1;
}
int main()
{
    //FIO;
    //int t;
    //cin>>t;
    //while(t--)
    go();
    return 0;
}


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
    int x[2],y[2],z[2],i;
    for(i=0;i<2;i++)
        cin>>x[i]>>y[i]>>z[i];
    if(x[0]!=x[1]&&y[0]!=y[1]&&z[0]!=z[1])
        cout<<"NO";
    else
        cout<<"YES";
    return(0);
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long > pl;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll a,b,c[1234567],d[5234567],c1[1234][1234],e[1234567],n,j,i,l,r,x,y,k,ans,sum;
bool used[3234567];
ll T;
vector<ll> v1,v[1234567];
string s,s1[1234567],ss;
char ch[1234][1234];
pl p[1234567];
priority_queue<ll> pq;
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
map<ll,ll> mp,mp1;
map<string , ll> ms;
queue<pl> q;
set<ll> st;
ll N=5e6+1;
int main(){
    ll a,b,c; cin>>a>>b>>c;
    ll x,y,z; cin>>x>>y>>z;
    ll x1=max(a-x,0ll)/2+max(b-y,0ll)/2+max(c-z,0ll)/2;
    ll x2=max(x-a,0ll)+max(y-b,0ll)+max(z-c,0ll);
    if (x1>=x2) cout<<"Yes";
    else cout<<"No";
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int P=998244353;
const int N=2008;
int p0[N],p1[N],cp[N][N],strong[N],ans[N];
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=1LL*ans*a%P;
		b>>=1;
		a=1LL*a*a%P;
	}
	return ans;
}
int main(){
	int n,a,b,win,lost;
	scanf("%d%d%d",&n,&a,&b);
	p0[0]=p1[0]=1;
	lost=1LL*a*ksm(b,P-2)%P,win=1LL*(b-a)*ksm(b,P-2)%P;
	for(int i=1;i<=n;++i) p0[i]=1LL*p0[i-1]*lost%P,p1[i]=1LL*p1[i-1]*win%P;
	for(int i=0;i<=n;++i) {
		cp[i][0]=1;
		for(int j=1;j<=i;++j) cp[i][j]=1LL*(1LL*cp[i-1][j-1]*p0[i-j]+1LL*cp[i-1][j]*p1[j])%P;
	}
	for(int i=1;i<=n;++i) strong[i]=1;
	for(int i=2;i<=n;++i) for(int j=1;j<i;++j) strong[i]=1LL*(strong[i]-1LL*cp[i][j]*strong[j]%P+P)%P;
	for(int i=1;i<=n;++i) {
	for(int j=1;j<i;++j) ans[i]=1LL*(ans[i]+1LL*strong[j]*cp[i][j]%P*(1LL*j*(i-j)+1LL*j*(j-1)/2+ans[j]+ans[i-j])%P)%P;
	//int ct=1LL*(1-1LL*strong[i]*i*(i-1)/2+P)%P;
	ans[i]=1LL*(ans[i]+1LL*strong[i]*(i*(i-1)/2))%P;
	ans[i]=1LL*ans[i]*ksm(1-strong[i],P-2)%P;
	ans[i]=(ans[i]+P)%P;
	}
	printf("%d\n",ans[n]);
}


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

int cnt=0;
int res = 0;

void f(int a, int b, long long w, const int v, const int k, const bool ua, const bool ub)
{
    if (v == k)
    {
        if (w <= n && ua && ub)
        {
             res++;
             cnt++;
             //cout<<w<<endl;
        }
        return;
    }
    w *= 10;
    if (0 == a && 0 == v)
    {
        f(a, b, w + b, v + 1, k, ua, true);
    }
    else
    {
        f(a, b, w + a, v + 1, k, true, ub);
        f(a, b, w + b, v + 1, k, ua, true);
    }
}

void f(int a, long long w, const int v, const int k)
{
    if (0 == a)
        return;
    if (v == k)
    {
        if (w <= n)
        {
            //printf("%d\n", w);
            cnt++;
            res++;
        }
        return;
    }
    w *= 10;
    f(a, w + a, v + 1, k);
}

void SoLvE()
{

    for (int len = 1; len <= 10; len++)
    {
        for (int i = 0; i <= 9; i++)
        {
            f(i, 0, 0, len);
            for (int j = i + 1; j <= 9; j++)
            f(i, j, 0, 0, len, false, false);

        }
    }
    cout << res;

}

int main()
{
    cin >> n;
    SoLvE();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define nl "\n"
#define sp " "
#define pb push_back
#define int long long
#define ins insert
#define hashset unordered_set
#define hashmap unordered_map
#define llMin LLONG_MIN
#define llMax LLONG_MAX
#define db long double

const int mod = 1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int k; cin >> k; vector<int> v(10, 0);
    vector<string> arr;
    for (int i = 0; i < 4; i++){
        string s; cin >> s; arr.pb(s);
    }
    for (int i = 0; i < 4; i++){
        for (int tmp = 0; tmp < 4; tmp++){
            if (arr[i][tmp] >= '0' && arr[i][tmp] <= '9'){
                v[arr[i][tmp] - '0']++;
            }
        }
    }
    bool flag = true;
    for (auto x : v){
        if (x > 2*k){
            flag = false;
        }
    }
    if (flag == true) cout << "YES";
    else cout << "NO";
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long

template<class T> ostream& operator<<(ostream &os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<" ]";
}
template<class L,class R> ostream& operator<<(ostream &os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}
ll mxm(){return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a,Args... args){return max(a,mxm(args...));}
ll mnm(){return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a,Args... args){return min(a,mnm(args...));}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
		const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vi vector<int>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define vld vector<ld>
#define vvld vector<vld>
#define I insert
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl "\n"
#define siz(a)	((int)(a).size())

const int mod=1e9+7;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

const int N=1e5+5;
const int INF = 999999999;
// vertices are 0-indexed
struct graph {
  typedef int flow_type; // **** flow type ****
  typedef int cost_type; // **** cost type ****
  struct edge {
    int src, dst;
    flow_type capacity, flow;
    cost_type cost;
    size_t rev;
  };
  vector<edge> edges;
  void add_edge(int src, int dst, flow_type cap, cost_type cost) {
    adj[src].push_back({src, dst, cap, 0, cost, adj[dst].size()});
    adj[dst].push_back({dst, src, 0, 0, -cost, adj[src].size()-1});
  }
  int n;
  vector<vector<edge>> adj;
  graph(int n) : n(n), adj(n) { }

  pair<flow_type, cost_type> min_cost_max_flow(int s, int t) {
    flow_type flow = 0;
    cost_type cost = 0;

    for (int u = 0; u < n; ++u) // initialize
      for (auto &e: adj[u]) e.flow = 0;

    vector<cost_type> p(n, 0);

    auto rcost = [&](edge e) { return e.cost + p[e.src] - p[e.dst]; };
    for (int iter = 0; ; ++iter) {
      vector<int> prev(n, -1); prev[s] = 0;
      vector<cost_type> dist(n, INF); dist[s] = 0;
      if (iter == 0) { // use Bellman-Ford to remove negative cost edges
        vector<int> count(n); count[s] = 1;
        queue<int> que;
        for (que.push(s); !que.empty(); ) {
          int u = que.front(); que.pop();
          count[u] = -count[u];
          for (auto &e: adj[u]) {
            if (e.capacity > e.flow && dist[e.dst] > dist[e.src] + rcost(e)) {
              dist[e.dst] = dist[e.src] + rcost(e);
              prev[e.dst] = e.rev;
              if (count[e.dst] <= 0) {
                count[e.dst] = -count[e.dst] + 1;
                que.push(e.dst);
              }
            }
          }
        }
        for(int i=0;i<n;i++) p[i] = dist[i]; // added it
        continue;
      } else { // use Dijkstra
        typedef pair<cost_type, int> node;
        priority_queue<node, vector<node>, greater<node>> que;
        que.push({0, s});
        while (!que.empty()) {
          node a = que.top(); que.pop();
          if (a.S == t) break;
          if (dist[a.S] > a.F) continue;
          for (auto e: adj[a.S]) {
            if (e.capacity > e.flow && dist[e.dst] > a.F + rcost(e)) {
              dist[e.dst] = dist[e.src] + rcost(e);
              prev[e.dst] = e.rev;
              que.push({dist[e.dst], e.dst});
            }
          }
        }
      }
      if (prev[t] == -1) break;

      for (int u = 0; u < n; ++u)
        if (dist[u] < dist[t]) p[u] += dist[u] - dist[t];

      function<flow_type(int,flow_type)> augment = [&](int u, flow_type cur) {
        if (u == s) return cur;
        edge &r = adj[u][prev[u]], &e = adj[r.dst][r.rev];
        flow_type f = augment(e.src, min(e.capacity - e.flow, cur));
        e.flow += f; r.flow -= f;
        return f;
      };
      flow_type f = augment(t, INF);
      flow += f;
      cost += f * (p[t] - p[s]);
    }
    return {flow, cost};
  }
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n,m,k,c,d;cin>>n>>m>>k>>c>>d;
	vi cur(n);for(int i=0;i<k;i++){
		int x;cin>>x;++cur[x-1];
	}
	vii ed(m);for(int i=0;i<m;i++)cin>>ed[i].F>>ed[i].S,--ed[i].F,--ed[i].S;
	int nod=max(n,k);
	graph g(1+2*nod*nod);
	for(int i=0;i<n;i++)g.add_edge(0,i+1,cur[i],0);
	for(int i=0;i<2*nod-1;i++){
		for(int j=0;j<m;j++){
			int a=ed[j].F,b=ed[j].S;
			for(int k1=0;k1<k;k1++){
				g.add_edge(i*n+a+1,(i+1)*n+b+1,1,d*(2*k1+1)+(b==0?c*(i+1):0));
				g.add_edge(i*n+b+1,(i+1)*n+a+1,1,d*(2*k1+1)+(a==0?c*(i+1):0));
			}
		}
		for(int j=0;j<n;j++)
			g.add_edge(i*n+j+1,(i+1)*n+j+1,k,0);
	}
	cout<<g.min_cost_max_flow(0,(2*nod-1)*n+1).S<<endl;
}


/*
 * Test.cpp
 *
 *  Created on: 2017年7月1日
 *      Author: lenovo
 */

#include<iostream>
#include<algorithm>
using namespace std;

int main() {
    int a, b, l, r, c, pl, pr, cl, cr;
    cin >> a >> b >> l >> r;
    c = a + b;
    //判断下标是否在同一个AB组合内
    cl = --l / c;
    cr = --r / c;
    //获取AB分别对应的索引
    pl = l % c;
    pr = r % c;
    if (cl == cr) {
        if (pl < a && pr < a) {
            cout << pr - pl + 1 << endl;
        } else if (pl < a && pr >= a) {
            cout << a - pl << endl;
        } else {
            cout << 1 << endl;
        }
    } else if (a <= b) {
        if (cl < cr - 1) {
            cout << a + 1 << endl;
        } else {
            if (pr >= a) {
                cout << a + 1 << endl;
            } else {
                if (pl >= a) {
                    cout << pr + 1 + 1 << endl;
                } else {
                    int left = a - pl;
                    int right = pr + 1;
                    if (left + right > a) {
                        cout << a + (right == a) << endl;
                    } else {
                        cout << left + right + (right == a) << endl;
                    }
                }
            }

        }
    } else {
        int d = a - b;
        if (cl == cr - 1) {
            if (pr >= a && pl >= a) {
                cout << a + 1 << endl;
            } else if (pr < a && pl >= a) {
                cout << pr + 1 + 1 << endl;
            } else if (pr >= a && pl < a) {
                cout << min((a + a - pl), a + a - b) << endl;
            } else if (pr < a && pl < a) {
                if (pl > b) {
                    cout << pr + 1 + a - pl << endl;
                } else {
                    cout << pr + 1 + a - b << endl;
                }
            }
//            else {
//                int right = min(pr + 1, a);
//                int left = max(1, min(a - b, a - pl));
//                cout << right + left << endl;
//            }

        } else if (cl == cr - 2) {
            cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl)));
        } else {
            cout << a + d;
        }
    }

}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")

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

namespace FastIO {
    struct Reader {
    private:
        FILE* file; std::vector<char> buffer; int pos; bool was;
        void read() {
            if (!buffer.empty()) {
                buffer.resize(fread(&buffer[0], 1, (int)buffer.size(), file)); pos = 0;
            }
        }
    public:
        Reader(FILE* file_ = stdin, const int size_ = 1 << 16)
            : file(file_), buffer(size_, '\0'), pos(size_), was(true) { }
        operator bool() const { return was; }
        char getChar() {
            if (pos == (int)buffer.size()) { read(); }
            if (pos == (int)buffer.size()) { was = false; return EOF; }
            else { was = true; return buffer[pos++]; }
        }
        std::string getStr() {
            char c = ' ';
            while (std::isspace(c)) { c = getChar(); }
            std::string answ;
            while (c != EOF && !std::isspace(c)) { answ.push_back(c); c = getChar(); }
            was = !answ.empty();
            return answ;
        }
        std::string getLine() {
            char c = '\n';
            while (c == '\n') { c = getChar(); }
            std::string answ;
            while (c != '\n' && c != EOF) { answ.push_back(c); c = getChar(); }
            was = !answ.empty();
            return answ;
        }
        template<typename T> T getInt() {
            char c = '?';
            while (!(c == '-' || ('0' <= c && c <= '9') || c == EOF)) { c = getChar(); }
            bool positive = true;
            if (c == '-') { positive = false; c = getChar(); }
            T answ(0);
            bool flag = false;
            while ('0' <= c && c <= '9') { flag = true; (answ *= 10) += (c - '0'); c = getChar(); }
            was = flag;
            return positive ? answ : -answ;
        }
        template<typename T> T getReal() {
            bool flag = false;
            char c = '?';
            while (!(c == '-' || ('0' <= c && c <= '9') || c == EOF)) { c = getChar(); }
            bool positive = (c != '-');
            if (c == '-') { c = getChar(); }
            long long first = 0;
            while ('0' <= c && c <= '9') { flag = true; (first *= 10) += (c - '0'); c = getChar(); }
            was = flag;
            if (c != '.') { return T(positive ? first : -first); }
            c = getChar();
            long long second = 0, pow = 1;
            while ('0' <= c && c <= '9') { (second *= 10) += (c - '0'); c = getChar(); pow *= 10; }
            T answ = first + (T)second / (T)pow;
            return positive ? answ : -answ;
        }
    };

    Reader& operator>>(Reader& reader, char& c) { return c = reader.getChar(), reader; }

    Reader& operator>>(Reader& reader, std::string& s) { return s = reader.getStr(), reader; }

    template<class T> typename std::enable_if<std::is_floating_point<T>::value, Reader&>::type
    operator>>(Reader& reader, T& t) { return t = reader.getReal<T>(), reader; }

    template<class T> typename std::enable_if<std::is_integral<T>::value, Reader&>::type
    operator>>(Reader& reader, T& t) { return t = reader.getInt<T>(), reader; }

    template<class T> Reader& operator>>(Reader& reader, std::vector<T>& vec) {
        for (auto &it : vec) { reader >> it; }
        return reader;
    }

    struct Writer {
    private:
        FILE* file; std::vector<char> buffer; int pos;
        int defaultPrecision, defaultWidth; char defaultFill;
    public:
        Writer(FILE* file_ = stdout, const int size_ = 1 << 16)
            : file(file_), buffer(size_, '\0'), pos(0), defaultPrecision(6), defaultWidth(0), defaultFill(' ') { }
        ~Writer() { flush(); }
        void flush() { putChar(EOF); }
        void setprecision(int precision) { defaultPrecision = precision; }
        void setw(int width) { defaultWidth = width; }
        void setfill(char fill) { defaultFill = fill; }
        int getPrecision() const { return defaultPrecision; }
        int getWidth() const { return defaultWidth; }
        char getFill() const { return defaultFill; }
        void putChar(char c) {
            if (pos == (int)buffer.size() || c == EOF) {
                fwrite(&buffer[0], 1, pos, file); pos = 0;
            }
            if (c != EOF) { buffer[pos++] = c; }
        }
        void putStr(const std::string& s) { for (auto it : s) putChar(it); }
        template<typename T> void putInt(T value, int width = 0, char fill = ' ') {
            bool positive = !(value < 0);
            if (value < 0) { value = -value; }
            char buf[24]; int p = 0;
            do { buf[p++] = char(value % 10 + '0'); value /= 10; } while (value > 0);
            if (!positive) { buf[p++] = '-'; }
            while (p < width) buf[p++] = fill;
            while (p > 0) putChar(buf[--p]);
        }
        template<typename T> void putReal(T value, int precision = 6, int width = 0, char fill = ' ') {
            putInt((long long)value, width - precision - 1, fill);
            value = std::abs(value-(long long)value);
            if (precision == 0) { return; }
            putChar('.');
            #define PRINT_PART(cnt, pow) \
                while (precision >= cnt) { \
                    value *= pow; \
                    putInt((int)value, cnt, '0'); \
                    value -= (int)value; \
                    precision -= cnt; \
                }
            PRINT_PART(6,1000000)
            PRINT_PART(3,1000)
            PRINT_PART(1,10)
            #undef PRINT_PART
        }
    };

    Writer& operator<<(Writer& writer, const char c) { return writer.putChar(c), writer; }

    Writer& operator<<(Writer& writer, const std::string& s) { return writer.putStr(s), writer; }

    template<class T> typename std::enable_if<std::is_floating_point<T>::value, Writer&>::type
    operator<<(Writer& writer, const T& t) {
        writer.putReal(t, writer.getPrecision(), writer.getWidth(), writer.getFill());
        return writer;
    }

    template<class T> typename std::enable_if<std::is_integral<T>::value, Writer&>::type
    operator<<(Writer& writer, const T& t) {
        writer.putInt(t, writer.getWidth(), writer.getFill());
        return writer;
    }
}

const int N = 3004;
double dp[2][N];
using namespace FastIO;
int main() {
  FastIO::Reader fin;
  FastIO::Writer fout;
  int n, k; fin >> n >> k;
  for (int p = 1; p <= n; p++) {
    int x; fin >> x;
    double s = 0;
    int cur = p & 1;
    int pre = cur ^ 1;
    for (int j = 1; j <= k; j++) {
      dp[cur][j] = dp[pre][j];
    }
    for (int i = 1; i <= x; i++) {
      int z; fin >> z;
      s += z;
      for (int j = i; j <= k; j++) {
        dp[cur][j] = max(dp[pre][j - i] + s, dp[cur][j]);
      }
    }
  }
  fout << (int64_t)max(dp[0][k],dp[1][k]) << '\n';
}


#include<bits/stdc++.h>
using namespace std;
__int64 a,b,x,y,k;
main(){
    cin>>a>>b>>x>>y;
    k=__gcd(x,y);
    x/=k;y/=k;
    cout<<min(a/x,b/y);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int long long a,b,c;
    cin>>a>>b>>c;
    cout<<((a+b-1)*(c-1)+a*b)<<endl;
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#define LL long long
#define Re register int
using namespace std;
const int N=3e5+3,inf=1e9,logN=19;
int ip_O,m,o,x,y,T,op,MaxX,X[N],ip[N],Yl[N],Yr[N],idl[N],idr[N],head[N];vector<int>V[N];map<int,int>id[N];
struct QAQ{int to,next;}a[N<<1];
inline void add(Re x,Re y){a[++o].to=y,a[o].next=head[x],head[x]=o;}
struct Tree{
	int o,head[N];
	struct QAQ{int to,next;}a[N<<2];
	inline void add_(Re x,Re y){a[++o].to=y,a[o].next=head[x],head[x]=o;}
	inline void add(Re x,Re y){add_(x,y),add_(y,x);}
}T0;
inline void in(Re &x){
    int f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
inline void get_tree(){
	for(Re i=1;i<=m;++i)in(x),in(y),MaxX=max(MaxX,x),V[x].push_back(y),id[x][y]=i;
	for(Re x=1;x<=MaxX;++x)if(!V[x].empty()){
		sort(V[x].begin(),V[x].end());
		Re last=-1;idl[x]=ip_O+1;
		for(Re J=0,SZ=V[x].size(),y;J<SZ;last=V[x][J],++J){
			if(last+1!=(y=V[x][J]))ip[id[x][y]]=++ip_O,X[ip_O]=x,Yl[ip_O]=Yr[ip_O]=y;
			else ip[id[x][y]]=ip_O,Yr[ip_O]=y,T0.add(id[x][y],id[x][y-1]);
			if(id[x-1].find(y)!=id[x-1].end())T0.add(id[x-1][y],id[x][y]);
		}
		idr[x]=ip_O;
		if(V[x-1].empty())continue;
		Re k=idl[x-1];
		for(Re j=idl[x];j<=idr[x];++j){
			while(k<=idr[x-1]&&Yr[k]<Yl[j])++k;
			for(Re k_=k;k_<=idr[x-1]&&Yl[k_]<=Yr[j];++k_)
				add(k_,j),add(j,k_);//,printf("%d->%d\n",k_,j);
		}
	}
//	for(Re x=1;x<=MaxX;++x)if(!V[x].empty())
//		for(Re J=0,SZ=V[x].size();J<SZ;++J)
//			printf("(%d,%d), id=%d, ip=%d\n",x,V[x][J],id[x][V[x][J]],ip[id[x][V[x][J]]]);
}
struct QWQ{
	int d,y;QWQ(Re D=0,Re Y=0){d=D,y=Y;}
	inline bool operator<(const QWQ &O)const{return d<O.d;}
};
struct BIT{
	int n,op;vector<int>C;
	inline void build(Re N){n=N,C.push_back(inf);while(N--)C.push_back(inf);}
	inline void add(Re x,Re v){if(op)x=n-x+1;while(x<=n)C[x]=min(C[x],v),x+=x&-x;}
	inline int ask(Re x){if(op)x=n-x+1;Re ans=inf;while(x)ans=min(ans,C[x]),x-=x&-x;return ans;}
}TR1[N],TR2[N];
int rt,sum,gs[N],vis[N],maxp[N],size[N],frt[N][22];QWQ fdis[N][22];
inline void getrt(Re x,Re fa){
	size[x]=Yr[x]-Yl[x]+1,maxp[x]=0;
	for(Re i=head[x],to;i;i=a[i].next)
		if(!vis[to=a[i].to]&&to!=fa)
			getrt(to,x),size[x]+=size[to],maxp[x]=max(maxp[x],size[to]);
	maxp[x]=max(maxp[x],sum-size[x]);
	if(maxp[x]<maxp[rt])rt=x;
}
int Q[N],pan[N];QWQ dis[N];
inline void getdis0(Re rt){
	Re h=1,t=0;
	for(Re i=Yl[rt];i<=Yr[rt];++i)pan[Q[++t]=id[X[rt]][i]]=rt,dis[Q[t]]=QWQ(0,i-Yl[rt]+1);
	while(h<=t){
		Re x=Q[h++];
		for(Re i=T0.head[x],to;i;i=T0.a[i].next)
			if(pan[to=T0.a[i].to]!=rt&&!vis[ip[to]])
				dis[to]=QWQ(dis[x].d+1,dis[x].y),pan[Q[++t]=to]=rt;
	}
}
inline void getdis(Re x,Re rt,Re fa){
	frt[x][++gs[x]]=rt;
	for(Re i=Yl[x];i<=Yr[x];++i)fdis[id[X[x]][i]][gs[x]]=dis[id[X[x]][i]];
	for(Re i=head[x],to;i;i=a[i].next)
		if(!vis[to=a[i].to]&&to!=fa)getdis(to,rt,x);
}
inline void sakura(Re x){
//	printf("sakura: x=%d\n",x);
//	printf("vis: ");for(Re i=1;i<=ip_O;++i)printf("%d ",vis[i]);puts("");
	Re now=sum;vis[x]=1,getdis0(x),getdis(x,x,0);
	TR1[x].build(Yr[x]-Yl[x]+1),TR2[x].build(Yr[x]-Yl[x]+1),TR2[x].op=1;
	for(Re i=head[x],to;i;i=a[i].next)
		if(!vis[to=a[i].to])
			sum=size[to]>size[x]?now-size[x]:size[to],maxp[rt=0]=inf,getrt(to,0),sakura(rt);
}
inline void change(Re y){
	Re x=ip[y];//printf("y=%d, x=%d\n",y,x);
	for(Re i=gs[x];i;--i)
		TR1[frt[x][i]].add(fdis[y][i].y,fdis[y][i].d-fdis[y][i].y),
		TR2[frt[x][i]].add(fdis[y][i].y,fdis[y][i].d+fdis[y][i].y);
}
inline int ask(Re y){
	Re x=ip[y],ans=inf;
	for(Re i=gs[x];i;--i)
		ans=min(ans,fdis[y][i].d+fdis[y][i].y+TR1[frt[x][i]].ask(fdis[y][i].y)),
		ans=min(ans,fdis[y][i].d-fdis[y][i].y+TR2[frt[x][i]].ask(fdis[y][i].y));
	return ans;
}
int main(){
//	freopen("123.txt","r",stdin);
	in(m),get_tree();
	sum=m,maxp[rt=0]=inf,getrt(1,0),sakura(rt);
	in(T);Re flag=0;
	while(T--){
		in(op),in(x),in(y);
		if(op<2)flag=1,change(id[x][y]);
		else printf("%d\n",flag?ask(id[x][y]):-1);
	}
}


#include<iostream>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	if(a==0&&b==0){cout<<"NO";return 0;}
	if(a==b||a-b==1 ||a-b== -1)cout<<"YES";
	else
	cout<<"NO";
}


#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int n,x,y,q;
    while(~scanf("%d%d%d",&n,&x,&y))
    {
        if(n*y%100==0)
            q=n*y/100;
        else
            q=n*y/100+1;
        if(q>=x)
            printf("%d\n",q-x);
        else
            puts("0");
    }
    return 0;
}
/*2018-07-19 19:50:22.055*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const int mn=1e5+10;
ll x[mn],y[mn],d[mn];
inline ld sq(ld x){return x*x;}
inline ll sq(ll x){return x*x;}
ld eps=1e-8;
ld i1x,i1y,i2x,i2y;
vector<pll>ans;
void idk(ll xx,ll yy,int i,int n){
    if(sq(xx-x[0])+sq(yy-y[0])!=d[i])return;
    vector<ll>v;
    for(int j=0;j<n;j++)v.push_back(sq(xx-x[j])+sq(yy-y[j]));
    sort(v.begin(),v.end());
    for(int j=0;j<n;j++)if(d[j]!=v[j])return;
    ans.push_back({xx,yy});
}
void intersect(ld x1,ld y1,ld r1,ld x2,ld y2,ld r2,ld r12,ld r22,int i,int n){
    ld dis=sqrt(sq(x1-x2)+sq(y1-y2));
    ld dis2=sq(x1-x2)+sq(y1-y2);
    if(dis>r1+r2+eps)return;
    ld t=atan2(y2-y1,x2-x1);
    ld p=(r12+dis2-r22)/2/r1/dis;
    if(p>1)p=1;
    if(p<-1)p=-1;
    ld k=acos(p);
    i1x=x1+r1*cos(t+k);
    i1y=y1+r1*sin(t+k);
    i2x=x1+r1*cos(t-k);
    i2y=y1+r1*sin(t-k);

    if(fabs(i1x)+fabs(i1y)<1e9)for(int j=-6;j<=6;j++){for(int k=-6;k<=6;k++) {
                idk((ll)i1x+j, (ll)i1y+k, i, n);
            }}
    if(fabs(i2x)+fabs(i2y)<1e9)for(int j=-6;j<=6;j++){for(int k=-6;k<=6;k++) {
                idk((ll)i2x+j, (ll)i2y+k, i, n);
            }}
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld%lld",x+i,y+i);
    ld sx=0,sy=0,sxy=0;
    for(int i=0;i<n;i++)sx+=x[i],sy+=y[i];
    ld cx=sx/n,cy=sy/n;
    for(int i=0;i<n;i++)sxy+=sq(cx-x[i])+sq(cy-y[i]);
    int m;
    scanf("%d",&m);
    while(m--){
        ans.clear();
        for(int i=0;i<n;i++)scanf("%lld",d+i);
        ll h1=0,h2=0;
        for(int i=0;i<n;i++)h1+=d[i]/1000000000,h2+=d[i]%1000000000;
        ld r2=(((ld)h1)*1e9+((ld)(h2)-sxy))/n;
        for(int i=0;i<n;i++){
            if(i&&d[i]==d[i-1])continue;
            intersect(cx,cy,sqrt(r2),x[0],y[0],sqrt(d[i]),r2,d[i],i,n);

        }
        sort(ans.begin(),ans.end());
        ans.erase(unique(ans.begin(),ans.end()),ans.end());
        printf("%d",ans.size());
        for(auto hail:ans)printf(" %lld %lld",hail.first,hail.second);
        printf("\n");
    }
}
//1 22424303 86152320


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    // friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend void pr(const modular& a) { pr(a.val); }
    friend void re(modular& a) { ll x; re(x); a = modular(x); }

    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,k, mob[100005];
mi in[100005];
mi ans;
bool comp[MX];

mi solve(int g, int m) {
	// i*g divides both a and b
	int y = n%g;
	int x = g-y;
	int z = (n-1)/(m*g); assert(z); // (1 to z) * (m*g)
	mi tmp = 0;
	FOR(sum,2,2*z+1) {
		int p = min(sum-1,2*z+1-sum);
		int eq = max(1,sum*m-n/g)*x+max(1,sum*m-n/g-1)*y;
		tmp += p*in[n-eq];
	}
	return tmp;
}

int main() {
    setIO(); re(n,k);
    in[0] = 1; in[1] = mi(1)/k;
    FOR(i,2,n+1) in[i] = in[1]*in[i-1];
    FOR(i,1,n+1) mob[i] = 1;
    FOR(i,2,n+1) if (!comp[i]) {
    	for (int j = 2*i; j <= n; j += i) comp[j] = 1;
    	for (int j = i; j <= n; j += i) {
    		if (j/i % i == 0) mob[j] = 0;
    		else mob[j] *= -1;
    	}
    }
    FOR(g,1,n) {
    	for (int i = 1; i*g < n; i ++) if (mob[i])
    		ans += mob[i]*solve(g,i);
    }
    ps(ans);
    // FOR(i,1,21) ps(i,comp[i],mob[i]);
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
LL a[2000],dp[2000];
LL qmod(LL y)
{
    LL res = 1, two = (LL)2;
    for(;y;y>>=1)
    {
        if(y&1) res = res*two%mod;
        two = two*two%mod;
    }
    return res;
}
int main()
{
    LL x, y;
    int cnt=0;
    scanf("%lld%lld",&x,&y);
    if(y%x) return 0*puts("0");
    for(LL i=1; i<=sqrt(y); ++i)
    {
        if(y%i==0)
        {
            if(i%x==0) a[++cnt] = i;
            if(i*i!=y&&y/i%x==0) a[++cnt] = y/i;
        }
    }
    sort(a+1, a+1+cnt);
    for(int i=cnt; i>0; --i)
    {
        dp[i] = qmod(y/a[i]-1);
        for(int j=i+1; j<=cnt; ++j)
            if(a[j]%a[i]==0)
                dp[i] = ((dp[i]-dp[j])%mod+mod)%mod;
    }
    printf("%lld\n",dp[1]);
    return 0;
}


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

const int inf = (signed) (~0u >> 1);

typedef class Edge {
	public:
		int ed, nx, r;

		Edge() {	}
		Edge(int ed, int nx, int r) : ed(ed), nx(nx), r(r) {	}
} Edge;

typedef class MapManager {
	public:
		int *h;
		vector<Edge> E;

		MapManager() {	}
		MapManager(int n) {
			h = new int[(n + 1)];
			memset(h, -1, sizeof(int) * (n + 1));
		}
		~MapManager() {
			delete[] h;
			E.clear();
		}

		void add_edge(int u, int v, int r) {
			E.emplace_back(v, h[u], r);
			h[u] = (signed) E.size() - 1;
		}
		void add_arc(int u, int v, int r) {
			add_edge(u, v, r);
			add_edge(v, u, 0);
		}
		Edge& operator [] (int p) {
			return E[p];
		}
} MapManager;

typedef class Network {
	public:
		int S, T;
		MapManager g;

		int *d, *h;

		Network(int S, int T) : S(S), T(T), g(T) {
			d = new int[(T + 1)];
			h = new int[(T + 1)];
		}
		~Network() {
			delete[] d;
			delete[] h;
		}

		boolean bfs() {
			queue<int> Q;
			memset(d, -1, sizeof(int) * (T + 1));
			d[S] = 0;
			Q.push(S);
			while (!Q.empty()) {
				int e = Q.front();
				Q.pop();
				for (int i = g.h[e], eu; ~i; i = g[i].nx) {
					eu = g[i].ed;
					if (!g[i].r || ~d[eu])
						continue;
					d[eu] = d[e] + 1;
					Q.push(eu);
				}
			}
			return d[T] != -1;
		}

		int dfs(int p, int mf) {
			if (p == T || !mf)
				return mf;
			int flow = 0, f;
			for (int& i = h[p], j, e; ~i; (i != -1) && (i = g[i].nx)) {
				e = g[i].ed, j = i;
				if (g[i].r && d[e] == d[p] + 1 && (f = dfs(e, min(mf, g[i].r))) > 0) {
					g[j].r -= f;
					g[j ^ 1].r += f;
					flow += f;
					mf -= f;
					if (!mf)
						break;
				}
			}
			return flow;
		}

		int dinic() {
			int rt = 0;
			while (bfs()) {
				for (int i = 0; i <= T; i++)
					h[i] = g.h[i];
				rt += dfs(S, inf);
			}
			return rt;
		}

		void add_edge(int u, int v, int r) {
			g.add_arc(u, v, r);
		}
		int cnt_edges() {
			return g.E.size();
		}
} Network;

#define pii pair<int, int>

const int N = 205;

int n, m, t;
int id[N][N];
int deg[2][N];
boolean G[N][N];

int ans[5000];
int idx[N][N];

void solve(int k) {
	Network network(n + m + 2, n + m + 3);
	int S = 0, T = n + m + 1, SS = n + m + 2, TT = n + m + 3;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (G[i][j]) {
				id[i][j] = network.cnt_edges();
				network.add_edge(i, j + n, 1);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		network.add_edge(SS, i, deg[0][i] / k);
		network.add_edge(S, TT, deg[0][i] / k);
		if (deg[0][i] % k) {
			network.add_edge(S, i, 1);
		}
	}
	for (int i = 1; i <= m; i++) {
		network.add_edge(SS, T, deg[1][i] / k);
		network.add_edge(i + n, TT, deg[1][i] / k);
		if (deg[1][i] % k) {
			network.add_edge(i + n, T, 1);
		}
	}
	network.add_edge(T, S, inf);
	network.dinic();
	MapManager& g = network.g;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (G[i][j] && !g[id[i][j]].r) {
				ans[idx[i][j]] = k;
				G[i][j] = false;
				--deg[0][i];
				--deg[1][j];
			}
		}
	}
}

int main() {
	int _;
	scanf("%d%d%d%d", &n, &m, &_, &t);
	for (int i = 1, u, v; i <= _; i++) {
		scanf("%d%d", &u, &v);
		G[u][v] = true;
		idx[u][v] = i;
		++deg[0][u];
		++deg[1][v];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += !!(deg[0][i] % t);
	for (int i = 1; i <= m; i++)
		ans += !!(deg[1][i] % t);
	while (t)
		solve(t--);
	printf("%d\n", ans);
	for (int i = 1; i <= _; i++) {
		if (!::ans[i])
			::ans[i] = 1;
		printf("%d ", ::ans[i]);
	}
	return 0;
}
//hellobig_tq


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int,int>
#define mp make_pair
#define PI 3.14159265358979
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned
using namespace std;
bool f[20000001];
int a[20000001];
const int M=20000000;
int pr[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int pp;
int N;
int dfs(LL num, int cnt, int p)
{
	if (num>N)
		return 0;
	if (p==pp)
	{
		if (cnt&1)
			return (-(N/num));
		return N/num;
	}
	int res=dfs(num*pr[p],cnt+1,p+1)+dfs(num,cnt,p+1);
	return res;
}
int solve(int n, int k)
{
	if (n/k<=M)
	{
		int res=0;
		FOR(i,1,n/k+1)
			if (a[i]>=k)
				res++;
		return res;
	}
	FOR(i,0,25)
		if (pr[i]==k)
			pp=i;
	N=n;
	int res1=dfs(k,0,0);
	return res1;
}
int main()
{
	//freopen("in.txt","r",stdin);
	int aa,b,k;
	scanf("%d%d%d",&aa,&b,&k);
	bool ff=true;
	for (int i=2; i*i<=k; ++i)
		if ((k%i)==0)
		{
			ff=false;
			break;
		}
	if (!ff)
	{
		printf("0\n");
		return 0;
	}
    FOR(i,0,M)
	{
		a[i]=i;
		f[i]=true;
	}
	for (int i=2; i*i<=M; ++i)
		if (f[i])
		for (int j=i+i; j<M; j+=i)
		{
			f[j]=false;
			a[j]=MIN(a[j],i);
		}
	a[1]=2000000001;
	int res=solve(b,k)-solve(aa-1,k);
	cout<<res<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1<<29;
const int MOD=1000000007;
#define pp pair<ll,ll>
typedef long long int ll;
bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
}
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
////////////////////////////////////////////////////////////////////
char a[7]={'R','O','Y','G','B','I','V'};
int main()
{
  fastio();
  int t=1;
  //cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    for(int i=0;i<n/7;i++)
    {
        REP(j,7)cout<<a[j];
    }
    if(n%7==1)cout<<'G';
    else if(n%7==2)cout<<"GB";
    else if(n%7==3)cout<<"YGB";
    else if(n%7==4)cout<<"YGBI";
    else if(n%7==5)cout<<"OYGBI";
    else if(n%7==6)cout<<"OYGBIV";
  }
  return 0;
  //Read the stuff at the bottom
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* 1LL<<i and not 1<<i
* overflow (int vs ll?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/
/*lcm(gcd(N1, M), gcd(N2, M), ..., gcd(Nk, M)) = gcd(lcm(N1, ..., Nk), M)
gcd(lcm(N1, M), lcm(N2, M), ..., lcm(Nk, M)) = lcm(gcd(N1, ..., Nk), M).

If gcd(N1, N2) = 1, then
gcd(N1·N2, M) = gcd(N1, M)·gcd(N2, M)
lcm(N1·N2, M) === lcm(N1, M)·lcm(N2, M)/M.

lcm(M, N, P) · gcd(M, N) · gcd(N, P) · gcd(P, M) = NMP · gcd(N, M, P).
*/


#include<bits/stdc++.h>
#define db double
#define pb push_back
using namespace std;
const int maxn = 1e3+5;
struct node{
    db x[5];
}a[maxn];

db dot(node A, node B, node C){
    db res = 0;
    for(int i = 0; i < 5; i++){
        res += (B.x[i]-A.x[i])*(C.x[i]-A.x[i]);
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            cin >> a[i].x[j];
        }
    }
    if(n > 11){ puts("0"); }
    else{
        vector<int>ans;
        bool flag = true;
        for(int i = 0; i < n; i++){
            flag = true;
            for(int j = 0; j < n && flag; j++){
                if(j == i) continue;
                for(int k = 0; k < n && flag; k++){
                    if(j == k || k == i) continue;
                    if(dot(a[i],a[j],a[k]) > 0){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag){ ans.pb(i+1); }
        }
        cout << ans.size() << endl;
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i] << endl;
        }
    }
}


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

#define fi first
#define se second
#define pb push_back

typedef pair<int,int> ii;
typedef long long ll;
const int N = 10+5;
ll l, r;

bool check(ll x)
{
	bool data[N];
	memset(data,false,sizeof(data));
	while (x > 0)
	{
		int now = x % 10;
		if (data[now])
			return false;
		data[now] = true;
		x /= 10;
	}
	return true;
}

int main()
{
	cin >> l >> r;
	for (ll i = l; i <= r; i++)
	{
		if (check(i))
		{
			cout << i << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
	return 0;
}


/*input
2
3
1 2 3 5 6 E 7
8 9 10 4 11 12 13
11
34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1
E 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3

*/

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <utility>
#include <tuple>
#include <climits>
#include <fstream>
#include <bitset>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <random>
#include <chrono>
#include <ios>
#include <iomanip>
#include <functional>

using namespace std;

// start of code

int K;
vector<int> A;
vector<vector<int>> table;
string finalSequence;

void rotateForward()
{
	// cout << "rotate forward" << endl;
	if (!finalSequence.empty() && finalSequence.back() == 'B') finalSequence.pop_back();
	else finalSequence += "F";

	for (int i = 4 * K; i > 0; --i) {
		swap(A[i - 1], A[i]);
	}
}

void rotateBackward()
{
	// cout << "rotate backward" << endl;
	if (!finalSequence.empty() && finalSequence.back() == 'F') finalSequence.pop_back();
	else finalSequence += "B";

	for (int i = 1; i <= 4 * K; ++i) {
		swap(A[i - 1], A[i]);
	}
}

void simpleJump() // jump first value pass 2 positions
{
	finalSequence += "JFF";
	for (int i = 1; i <= 2; ++i) {
		swap(A[i - 1], A[i]);
	}
}

void customJump(int idx) // jump (idx)`s value pass 2 positions
{
	for (int i = 0; i < idx; ++i) rotateBackward();
	simpleJump();
	while (A[0] != 1) rotateForward();
}

void readFromInput()
{
	cin >> K;
	finalSequence = "";
	table.assign(2, vector<int>(2 * K + 1));
	for (auto &vec : table) for (auto &i : vec) {
		string str;
		cin >> str;
		if (str == "E") i = 0;
		else i = stoi(str);
	}
}

void backToCorner()
{
	for (int row = 0; row < 2; ++row) {
		for (int col = 0; col < 2 * K; ++col) {
			if (table[row][col] == 0) {
				finalSequence += 'r';
				swap(table[row][col], table[row][col + 1]);
			}
		}
	}

	if (table[0][2 * K] == 0) {
		finalSequence += 'd';
		swap(table[0][2 * K], table[1][2 * K]);
	}
}

void relabel()
{
	for (auto &vec : table) for (int &i : vec) {
		if (i >= 2 * K + 2) i = 4 * K + 2 - i;
		else if (i >= 1) i += 2 * K;
	}
}

void convertToA()
{
	A.resize(4 * K + 1);
	for (int i = 0; i <= 2 * K; ++i) {
		A[2 * K + i] = table[0][i];
	}
	for (int i = 0; i < 2 * K; ++i) {
		A[2 * K - 1 - i] = table[1][i];
	}
	assert(table[1][2 * K] == 0);
}

string forwardDefinition()
{
	return "u" + string(2 * K, 'l') + "d" + string(2 * K, 'r');
}

string backwardDefinition()
{
	return string(2 * K, 'l') + "u" + string(2 * K, 'r') + "d";
}

string jumpKDefinition()
{
	return string(K + 1, 'B') + (string(K, 'l') + "u" + string(K, 'r') + "d") + string(K + 1, 'F');
}

string jumpDefinition()
{
	string def = "";
	def += "B";
	def += jumpKDefinition();
	def += jumpKDefinition();
	def += "F";
	for (int i = 0; i < K * 2; ++i) def += jumpKDefinition();
	def += "B";
	for (int i = 0; i < K * 2; ++i) def += jumpKDefinition();
	def += "F";

	// dirty optimization
	assert(def.back() == 'F'); def.pop_back();
	assert(def.back() == 'F'); def.pop_back();

	// cout << "SZ " << def.size() << endl;
	return def;

	// return "B" + jumpKDefinition() + jumpKDefinition() + "F" + string(K, jumpKDefinition().c_str()) + "B" + string(K, jumpKDefinition().c_str()) + "F";
}

void trim()
{
	string copySequence = finalSequence + "$";
	finalSequence = "";

	char curChar = '?';
	int curCount = 0;
	for (char ch : copySequence) {
		if (curChar == ch) {
			++curCount;
			if (curCount == 10) {
				if (ch == 'F') finalSequence += "X", curCount = 0;
				else if (ch == 'B') finalSequence += "Y", curCount = 0;
				else if (ch == 'J') finalSequence += "Z", curCount = 0;
			}
		} else {
			finalSequence += string(curCount, curChar);
			curChar = ch;
			curCount = 1;
		}
	}
}

void outputSuccess()
{
	trim();
	// cout <<	finalSequence.size() << ' ' << jumpDefinition().size() << endl;
	cout << "SURGERY COMPLETE" << '\n';
	cout << finalSequence << '\n';
	cout << "F " << forwardDefinition() << '\n';
	cout << "B " << backwardDefinition() << '\n';
	cout << "J " << jumpDefinition() << '\n';
	cout << "X FFFFFFFFFF" << '\n';
	cout << "Y BBBBBBBBBB" << '\n';
	cout << "Z JJJJJJJJJJ" << '\n';
	cout << "DONE" << '\n';
}

void outputFailure()
{
	cout << "SURGERY FAILED" << '\n';
}

void log() // for debugging purposes
{
	cout << "--------------------------------" << endl;
	cout << "A = ";
	for (int x : A) cout << x << ' ';
	cout << endl;
	return;
	cout << "table: " << endl;
	for (int i = 2 * K; i <= 4 * K; ++i) {
		cout << A[i] << ' ';
	}
	cout << '\n';

	for (int i = 2 * K - 1; i >= 0; --i) {
		cout << A[i] << ' ';
	}
	cout << 'E';
	cout << '\n';

	cout << "current sequence = " << finalSequence << endl;
	cout << "--------------------------------" << endl;
	cout << endl;
}

void solve()
{
	readFromInput();
	backToCorner();
	relabel();
	convertToA();
	while (A[0] != 1) rotateForward();

	for (int noFixed = 1; noFixed <= 4 * K - 2; ++noFixed) {
		int nextValue = noFixed + 1;

		int curPos = (int) (find(A.begin(), A.end(), nextValue) - A.begin());

		while (curPos < noFixed || curPos > noFixed + 2) {
			// log();
			customJump(curPos);
			curPos = (int) (find(A.begin(), A.end(), nextValue) - A.begin());
		}

		while (A[noFixed] != nextValue) {
			// log();
			customJump(noFixed);
		}
	}

	bool isSorted = is_sorted(A.begin(), A.end());
	if (isSorted) {
		outputSuccess();
	} else {
		outputFailure();
	}
}

signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int tests;
	cin >> tests;
	while (tests--) {
		solve();
	}

	return 0;
}