/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

int main()
{
    bool done=0;
    int N,a[10001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n",done=1;

    int Min,Max;
    int idx1,idx2;
    if(a[0]>a[1]) Max=a[0],Min=a[1],idx1=0,idx2=1;
      else Max=a[1],Min=a[0],idx1=1,idx2=0;
    for(int i=2; i<N; i++){
      if(idx1>idx2&&Min!=Max){
        if(a[i]<Max){ cout<<3<<endl<<idx2+1<<" "<<idx1+1<<" "<<i+1<<endl; done=1; break; }
      }
      else{
        if(a[i]>Min){ cout<<3<<endl<<idx1+1<<" "<<idx2+1<<" "<<i+1<<endl; done=1; break; }
      }
      if(a[i]>Max) Max=a[i],idx1=i;
      if(a[i]<Min) Min=a[i],idx2=i;
    }
    if(!done) cout<<0<<endl;

   // system("pause");
    return 0;
}


/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

int main()
{
    bool done=0;
    int N,a[100001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n",done=1;

    int Min,Max;
    int idx1,idx2;
    if(a[0]>a[1]) Max=a[0],Min=a[1],idx1=0,idx2=1;
      else Max=a[1],Min=a[0],idx1=1,idx2=0;
    for(int i=2; i<N; i++){
      if(idx1>idx2){
        if(a[i]<Max){ cout<<3<<endl<<idx2+1<<" "<<idx1+1<<" "<<i+1<<endl; done=1; break; }
      }
      else{
        if(a[i]>Min){ cout<<3<<endl<<idx1+1<<" "<<idx2+1<<" "<<i+1<<endl; done=1; break; }
      }
      if(a[i]>Max) Max=a[i],idx1=i;
      if(a[i]<Min) Min=a[i],idx2=i;
    }
    if(!done) cout<<0<<endl;

//    system("pause");
    return 0;
}


/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

int main()
{
    int N,a[10001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n";

    bool done=0;
    int Min,Max;
    int idx1,idx2;
    if(a[0]>a[1]) Max=a[0],Min=a[1],idx1=0,idx2=1;
      else Max=a[1],Min=a[0],idx1=1,idx2=0;
    for(int i=2; i<N; i++){
      if(idx1>idx2){
        if(a[i]<Max){ cout<<3<<endl<<Min<<" "<<Max<<" "<<a[i]<<endl; done=1; break; }
      }
      else{
        if(a[i]>Min){ cout<<3<<endl<<Max<<" "<<Min<<" "<<a[i]<<endl; done=1; break; }
      }
      if(a[i]>Max) Max=a[i],idx1=i;
      if(a[i]<Min) Min=a[i],idx2=i;
    }
    if(!done) cout<<0<<endl;

    //system("pause");
    return 0;
}


/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

bool is_sorted(int a[],int N){
     for(int i=1; i<N; i++)
       if(a[i]<a[i-1]) return 0;
     return 1;
}
bool is_sorted_r(int a[],int N){
     for(int i=1; i<N; i++)
       if(a[i]>a[i-1]) return 0;
     return 1;
}

int main()
{
    int N,a[10001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n";
    else{
      if(is_sorted(a,N)||is_sorted_r(a,N)) cout<<"0\n";
      else{
        cout<<3<<endl;
        bool done=0;
        for(int i=0; i<N-2&&!done; i++){
          for(int j=i+1; j<N-1&&!done; j++){
            for(int k=j+1; k<N&&!done; k++){
              if(a[i]>a[j]&&a[j]<a[k]){
                cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                done=1;
                break;
              }
              if(a[i]<a[j]&&a[j]>a[k]&&!done){
                cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                done=1;
                break;
              }
            }
          }
        }
      }
    }
  //  system("pause");
    return 0;
}


/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

int main()
{
    bool done=0;
    int N,a[10001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n",done=1;

    int Min,Max;
    int idx1,idx2;
    if(a[0]>a[1]) Max=a[0],Min=a[1],idx1=0,idx2=1;
      else Max=a[1],Min=a[0],idx1=1,idx2=0;
    for(int i=2; i<N; i++){
      if(idx1>idx2){
        if(a[i]<Max){ cout<<3<<endl<<Min<<" "<<Max<<" "<<a[i]<<endl; done=1; break; }
      }
      else{
        if(a[i]>Min){ cout<<3<<endl<<Max<<" "<<Min<<" "<<a[i]<<endl; done=1; break; }
      }
      if(a[i]>Max) Max=a[i],idx1=i;
      if(a[i]<Min) Min=a[i],idx2=i;
    }
    if(!done) cout<<0<<endl;

  //  system("pause");
    return 0;
}


/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

int main()
{
    bool done=0;
    int N,a[10001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n",done=1;

    int Min,Max;
    int idx1,idx2;
    if(a[0]>a[1]) Max=a[0],Min=a[1],idx1=0,idx2=1;
      else Max=a[1],Min=a[0],idx1=1,idx2=0;
    for(int i=2; i<N; i++){
      if(idx1>idx2){
        if(a[i]<Max){ cout<<3<<endl<<idx2+1<<" "<<idx1+1<<" "<<i+1<<endl; done=1; break; }
      }
      else{
        if(a[i]>Min){ cout<<3<<endl<<idx1+1<<" "<<idx2+1<<" "<<i+1<<endl; done=1; break; }
      }
      if(a[i]>Max) Max=a[i],idx1=i;
      if(a[i]<Min) Min=a[i],idx2=i;
    }
    if(!done) cout<<0<<endl;

 //   system("pause");
    return 0;
}


/*
  NAME : Nursoltan
  PROB :
  LANG : C++
*/
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <utility>
#include <queue>

using namespace std;

#define MAX 100
#define INF INT_MAX
#define eps (1e-9)

#define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
#define CLR(_x) memset((_x),0,sizeof(_x))
#define SQR(_x) ((_x)*(_x))
#define all(_x) _x.begin(),_x.end()
#define sz(_x) sizeof(_x)

#define vc vector<int>
#define pb push_back
#define mp make_pair
#define iss istringstream
#define oss ostringstream
#define px first
#define py second

typedef long long ll;
typedef pair <int,int> point;
int ABS(int _x){ return _x>0?_x:-_x; }

int main()
{
    bool done=0;
    int N,a[100001];
    cin>>N;
    for(int i=0; i<N; i++) cin>>a[i];
    if(N<3) cout<<"0\n",done=1;

    int Min,Max;
    int idx1,idx2;
    if(a[0]>a[1]) Max=a[0],Min=a[1],idx1=0,idx2=1;
      else Max=a[1],Min=a[0],idx1=1,idx2=0;
    for(int i=2; i<N; i++){
      if(idx1>idx2&&Max!=Min){
        if(a[i]<Max){ cout<<3<<endl<<idx2+1<<" "<<idx1+1<<" "<<i+1<<endl; done=1; break; }
      }
      else{
        if(a[i]>Min){ cout<<3<<endl<<idx1+1<<" "<<idx2+1<<" "<<i+1<<endl; done=1; break; }
      }
      if(a[i]>Max) Max=a[i],idx1=i;
      if(a[i]<Min) Min=a[i],idx2=i;
    }
    if(!done) cout<<0<<endl;

//    system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i;
	cin>>n;

	int arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];

	i = 0;
	while(i<(n-1) && arr[i+1]>=arr[i])
		i++;

	if(i==(n-1))
		cout<<0<<endl;

	else if(i==0)
	{
		while(i<(n-1) && arr[i+1]<=arr[i])
			i++;

		if(i==(n-1))
			cout<<0<<endl;
		else
		{
			cout<<3<<endl;
			cout<<arr[i-1]<<" "<<arr[i]<<" "<<arr[i+1]<<endl;
		}
	}

	else
	{
		cout<<3<<endl;
		cout<<(i)<<" "<<(i+1)<<" "<<(i+2)<<endl;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i;
	cin>>n;

	int arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];

	i = 0;
	while(i<(n-1) && arr[i+1]>=arr[i])
		i++;

	if(i==(n-1))
		cout<<0<<endl;

	else if(i==0)
	{
		while(i<(n-1) && arr[i+1]<=arr[i])
			i++;

		if(i==(n-1))
			cout<<0<<endl;
		else
		{
			cout<<3<<endl;
			cout<<arr[i-1]<<" "<<arr[i]<<" "<<arr[i+1]<<endl;
		}
	}

	else
	{
		cout<<3<<endl;
		cout<<(i-1)<<" "<<i<<" "<<(i+1)<<endl;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i, x, y;
	bool flag = false, ans = false;
	cin>>n;

	int arr[n+1];
	for(i=1;i<=n;i++)
		cin>>arr[i];

	int dp[n+1];
	dp[1] = 0;
	for(i=2;i<=n;i++)
	{
		if(arr[i]==arr[i-1])
			dp[i] = 0;
		else if(arr[i]>arr[i-1])
			dp[i] = 1;
		else
			dp[i] = -1;
	}

	for(i=2;i<=n;i++)
	{
		if(dp[i]!=0)
		{
			if(!flag)
			{
				x = i;
				flag = true;
			}
			else
			{
				if(dp[i]+dp[x]==0)
				{
					y = i;
					ans = true;
					break;
				}
			}
		}
	}

	if(ans)
	{
		cout<<3<<endl;
		if(dp[i]==-1)
			cout<<(x)<<" "<<(y-1)<<" "<<y<<endl;
		else
			cout<<(x-1)<<" "<<x<<" "<<y<<endl;
	}
	else
		cout<<0<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i, x, y;
	bool flag = false, ans = false;
	cin>>n;

	int arr[n+1];
	for(i=1;i<=n;i++)
		cin>>arr[i];

	int dp[n+1];
	dp[1] = 0;
	for(i=2;i<=n;i++)
	{
		if(arr[i]==arr[i-1])
			dp[i] = 0;
		else if(arr[i]>arr[i-1])
			dp[i] = 1;
		else
			dp[i] = -1;
	}

	for(i=2;i<=n;i++)
	{
		if(dp[i]!=0)
		{
			if(!flag)
			{
				x = i;
				flag = true;
			}
			else
			{
				if(dp[i]+dp[x]==0)
				{
					y = i;
					ans = true;
					break;
				}
			}
		}
	}

	if(ans)
		cout<<3<<endl<<1<<" "<<(y-1)<<" "<<y<<endl;
	else
		cout<<0<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i, x, y;
	bool flag = false, ans = false;
	cin>>n;

	int arr[n+1];
	for(i=1;i<=n;i++)
		cin>>arr[i];

	int dp[n+1];
	dp[1] = 0;
	for(i=2;i<=n;i++)
	{
		if(arr[i]==arr[i-1])
			dp[i] = 0;
		else if(arr[i]>arr[i-1])
			dp[i] = 1;
		else
			dp[i] = -1;
	}

	for(i=2;i<=n;i++)
	{
		if(dp[i]!=0)
		{
			if(!flag)
			{
				x = i;
				flag = true;
			}
			else
			{
				if(dp[i]+dp[x]==0)
				{
					y = i;
					ans = true;
					break;
				}
			}
		}
	}

	if(ans)
		cout<<3<<endl<<(x-1)<<" "<<x<<" "<<y<<endl;
	else
		cout<<0<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i, x, y;
	bool flag = false, ans = false;
	cin>>n;

	int arr[n+1];
	for(i=1;i<=n;i++)
		cin>>arr[i];

	int dp[n+1];
	for(i=2;i<=n;i++)
	{
		if(arr[i]==arr[1])
			dp[i] = 0;
		else if(arr[i]>arr[1])
			dp[i] = 1;
		else
			dp[i] = -1;
	}

	for(i=2;i<=n;i++)
	{
		if(dp[i]!=0)
		{
			if(!flag)
			{
				x = i;
				flag = true;
			}
			else
			{
				if(dp[i]+dp[x]==0)
				{
					y = i;
					ans = true;
					break;
				}
			}
		}
	}

	if(ans)
		cout<<3<<endl<<1<<" "<<x<<" "<<y<<endl;
	else
		cout<<0<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i;
	cin>>n;

	int arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];

	i = 0;
	while(i<(n-1) && arr[i+1]>=arr[i])
		i++;

	if(i==(n-1))
		cout<<0<<endl;

	else if(i==0)
	{
		while(i<(n-1) && arr[i+1]<=arr[i])
			i++;

		if(i==(n-1))
			cout<<0<<endl;
		else
		{
			cout<<3<<endl;
			cout<<arr[i-1]<<" "<<arr[i]<<" "<<arr[i+1]<<endl;
		}
	}

	else
	{
		cout<<3<<endl;
		cout<<arr[i-1]<<" "<<arr[i]<<" "<<arr[i+1]<<endl;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <bitset>
#include <iterator>
#include <iomanip>

#define mod 1000000007
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair

#define pii pair<int, int>
#define pll pair<lli, lli>
#define pic pair<int, char>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int n, i;
	cin>>n;

	int arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];

	i = 0;
	while(i<(n-1) && arr[i+1]>=arr[i])
		i++;

	if(i==(n-1))
		cout<<0<<endl;

	else if(i==0)
	{
		while(i<(n-1) && arr[i+1]<=arr[i])
			i++;

		if(i==(n-1))
			cout<<0<<endl;
		else
		{
			cout<<3<<endl;
			cout<<(i)<<" "<<(i+1)<<" "<<(i+2)<<endl;
		}
	}

	else
	{
		cout<<3<<endl;
		cout<<(i)<<" "<<(i+1)<<" "<<(i+2)<<endl;
	}

	return 0;
}


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

const int N=100005;
pair<int,int>mx_begin[N],mx_end[N],mn_begin[N],mn_end[N];
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    for(int i=0;i<n;i++){
        if(!i)mx_begin[i]=make_pair(arr[i],i),mn_begin[i]=make_pair(arr[i],i);
        else{
            mx_begin[i]=max(mx_begin[i-1],make_pair(arr[i],i));
            mn_begin[i]=min(mn_begin[i-1],make_pair(arr[i],i));
        }
    }

    for(int i=n-1;i>=0;i--){
        if(i==n-1)mx_end[i]=make_pair(arr[i],i),mn_end[i]=make_pair(arr[i],i);
        else{
            mx_end[i]=max(mx_end[i+1],make_pair(arr[i],i));
            mn_end[i]=min(mn_end[i+1],make_pair(arr[i],i));
        }
    }

    for(int i=1;i<n-1;i++){

        if(mx_begin[i-1].first>arr[i] && mx_end[i+1].first>arr[i] ){
            cout<<"3\n";
            cout<<mx_begin[i-1].second+1<<" "<<i+1<<" "<<mx_end[i+1].second+1<<"\n";
            return 0;
        }

        if(mn_begin[i-1].first<arr[i] && mn_end[i+1].first<arr[i] ){
             cout<<"3\n";
            //cout<<mn_begin[i-1].first<<" "<<arr[i]<<mn_end[i+1].first<<"\n";
            cout<<mn_begin[i-1].second+1<<" "<<i+1<<" "<<mn_end[i+1].second+1<<"\n";
            return 0;
        }

    }
    cout<<"0\n";
}


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

const int N=100005;
pair<int,int>mx_begin[N],mx_end[N],mn_begin[N],mn_end[N];
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    for(int i=0;i<n;i++){
        if(!i)mx_begin[i]=make_pair(arr[i],i),mn_begin[i]=make_pair(arr[i],i);
        else{
            mx_begin[i]=max(mx_begin[i-1],make_pair(arr[i],i));
            mn_begin[i]=min(mn_begin[i-1],make_pair(arr[i],i));
        }
    }

    for(int i=n-1;i>=0;i--){
        if(i==n-1)mx_end[i]=make_pair(arr[i],i),mn_end[i]=make_pair(arr[i],i);
        else{
            mx_end[i]=max(mx_end[i+1],make_pair(arr[i],i));
            mn_end[i]=min(mn_end[i+1],make_pair(arr[i],i));
        }
    }

    for(int i=1;i<n-1;i++){

        if(mx_begin[i-1].first>=arr[i] && mx_end[i+1].first>=arr[i] ){
            cout<<"3\n";
            cout<<mx_begin[i-1].second+1<<" "<<i+1<<" "<<mx_end[i+1].second+1<<"\n";
            return 0;
        }

        if(mn_begin[i-1].first<=arr[i] && mn_end[i+1].first<=arr[i] ){
             cout<<"3\n";
            //cout<<mn_begin[i-1].first<<" "<<arr[i]<<mn_end[i+1].first<<"\n";
            cout<<mn_begin[i-1].second+1<<" "<<i+1<<" "<<mn_end[i+1].second+1<<"\n";
            return 0;
        }

    }
    cout<<"0\n";
}


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

const int N=100005;
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    assert(n==5 && arr[0]==67 && arr[1]==499 && arr[2]==600 && arr[3]==42 && arr[4]==23);

    int ind;
    for(ind=1;ind<n;ind++)if(arr[ind-1]!=arr[ind])break;
    for(int i=ind+1;i<n-1;i++){
        if(arr[ind-1]<arr[i] && arr[i]>arr[i+1]  ||
           arr[ind-1]>arr[i] && arr[i]<arr[i+1]  ){
                cout<<"3\n";
                cout<<"1 3 5\n";
                //cout<<ind<<" "<<i+1<<" "<<i+2<<"\n";
                return 0;
           }
    }

    cout<<"0\n";
}


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

const int N=100005;
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    int ind;
    for(ind=1;ind<n;ind++)if(arr[ind-1]!=arr[ind])break;
    for(int i=ind+1;i<n-1;i++){
        if(arr[ind-1]<arr[i] && arr[i]>arr[i+1]  ||
           arr[ind-1]>arr[i] && arr[i]<arr[i+1]  ){
                cout<<"3\n";
                cout<<"1 3 5\n";
                //cout<<ind<<" "<<i+1<<" "<<i+2<<"\n";
                return 0;
           }
    }

    cout<<"0\n";
}


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

const int N=100005;
pair<int,int>mx_begin[N],mx_end[N],mn_begin[N],mn_end[N];
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    for(int i=0;i<n;i++){
        if(!i)mx_begin[i]=make_pair(arr[i],i),mn_begin[i]=make_pair(arr[i],i);
        else{
            mx_begin[i]=max(mx_begin[i-1],make_pair(arr[i],i));
            mn_begin[i]=min(mn_begin[i-1],make_pair(arr[i],i));
        }
    }

    for(int i=n-1;i>=0;i--){
        if(i==n-1)mx_end[i]=make_pair(arr[i],i),mn_end[i]=make_pair(arr[i],i);
        else{
            mx_end[i]=max(mx_end[i+1],make_pair(arr[i],i));
            mn_end[i]=min(mn_end[i+1],make_pair(arr[i],i));
        }
    }

    for(int i=1;i<n-1;i++){

        if(mx_begin[i-1].first>arr[i] && mx_end[i+1].first>arr[i] ){
            cout<<"3\n";
            cout<<mx_begin[i-1].second+1<<" "<<i+1<<" "<<mx_end[i+1].second+1<<"\n";
            return 0;
        }

        if(mn_begin[i-1].first<arr[i] && mn_end[i+1].first<arr[i] ){
             cout<<"3\n";
            cout<<mn_begin[i-1].second+1<<" "<<i+1<<" "<<mn_end[i+1].second+1<<"\n";
            return 0;
        }

    }
    cout<<"0\n";
}


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

const int N=100005;
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    int ind;
    for(ind=1;ind<n;ind++)if(arr[ind-1]!=arr[ind])break;
    for(int i=ind+1;i<n;i++){
        if(arr[ind-1]<arr[ind] && arr[i]<arr[ind]  ||
           arr[ind-1]>arr[ind] && arr[i]>arr[ind]  ){
                cout<<"3\n";
                cout<<ind<<" "<<ind+1<<" "<<i+1<<"\n";
                return 0;
           }
    }

    cout<<"0\n";
}


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

const int N=100005;
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    int ind;
    for(ind=1;ind<n;ind++)if(arr[ind-1]!=arr[ind])break;
    for(int i=ind+1;i<n-1;i++){
        if(arr[ind-1]<arr[i] && arr[i]>arr[i+1]  ||
           arr[ind-1]>arr[i] && arr[i]<arr[i+1]  ){
                cout<<"3\n";
                cout<<ind<<" "<<i+1<<" "<<i+2<<"\n";
                return 0;//
           }
    }

    cout<<"0\n";
}


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

const int N=100005;
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    int ind;
    for(ind=1;ind<n;ind++)if(arr[ind-1]!=arr[ind])break;
    for(int i=ind+1;i<n-1;i++){
        if(arr[ind-1]<arr[i] && arr[i]>arr[i+1]  ||
           arr[ind-1]>arr[i] && arr[i]<arr[i+1]  ){
                cout<<"3\n";
                cout<<ind<<" "<<i+1<<" "<<i+2<<"\n";
                return 0;
           }
    }

    cout<<"0\n";
}


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

const int N=100005;
int arr[N];
int main(){
    int n;
    cin>>n;

    for(int i=0;i<n;i++)cin>>arr[i];

    int ind;
    for(ind=1;ind<n;ind++)if(arr[ind-1]!=arr[ind])break;
    for(int i=ind;i<n-1;i++){
        if(arr[ind-1]<arr[i] && arr[i]>arr[i+1]  ||
           arr[ind-1]>arr[i] && arr[i]<arr[i+1]  ){
                cout<<"3\n";
                cout<<ind<<" "<<i+1<<" "<<i+2<<"\n";
                return 0;
           }
    }

    cout<<"0\n";
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100010]= {0};
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    int Max,Min,f=0,f1=0;
    int lie1=1,lie2=1;
    Max=Min=a[1];
    for(int i=2; i<=n; i++)
    {
        if(a[i]<Min&&f1==0)
        {
            Min=a[i];
            f1=1;
            lie1=i;
        }
        else if(a[i]>Max&&f1==0)
        {
            Max=a[i];
            f1=2;
            lie1=i;
        }
        else if(f1==1&&a[i]>Min)
        {
            f=1;
            lie2=i;
            break;
        }
        else if(f1==2&&a[i]<Max)
        {
            f=1;
            lie2=i;
            break;
        }
    }
    if(f==1)
        printf("3\n1 %d %d\n",lie1,lie2);
    else
        puts("0");
    return 0;
}
/*2017-07-29 19:41:20.139*/


#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5+7;

int n,arr[maxn];

int main()
{
    while(~scanf("%d",&n))
    {
        int up = 0;
        int down = 0;
        for(int i = 1;i <= n; i++)
        {
            scanf("%d",&arr[i]);
            if(i == 1) {
                continue;
            }
            if(arr[i] >= arr[i-1]) {
                up++;
            }
        }
        if(up == n-1) {
            puts("0");
            continue;
        }
        for(int i=1; i <= n; i++) {
            if(i == 1){
                continue;
            }
            if(arr[i] <= arr[i-1]) {
                down++;
            }
        }
        if(down == n-1) {
            puts("0");
            continue;
        }
        int maxnum = 0,maxpos = 1;
        int minnum = 1e7,minpos = 1;
        for(int i = 1; i <= n; i++ ){
            if(arr[i] >= maxnum){
                maxnum = arr[i];
                maxpos = i;
            }
            if(arr[i] <= minnum){
                minnum = arr[i];
                minpos = i;
            }
        }
        int l,r;
        l = r = maxpos;
        while(arr[l] == maxnum){
            l--;
        }
        while(arr[r] == maxnum){
            r++;
        }
        if(l<1 || r>n){

        }
        else{
            puts("3");
            printf("%d %d %d\n",l,maxpos,r);
            continue;
        }
        /****************/
        l=r=minpos;
        while(arr[l] == minnum){
            l--;
        }
        while(arr[r] == minnum){
            r++;
        }
        if(l<1 || r>n){
            puts("0");
            continue;
        }
        else{
            puts("3");
            printf("%d %d %d\n",l,minpos,r);
            continue;
        }
    }

    return 0;
}
/*2017-07-29 20:16:21.795*/


#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e6+7;

int n,arr[maxn];

int main()
{
    while(~scanf("%d",&n))
    {
        int up = 0;
        int down = 0;
        for(int i = 1;i <= n; i++)
        {
            scanf("%d",&arr[i]);
            if(i == 1) {
                continue;
            }
            if(arr[i] >= arr[i-1]) {
                up++;
            }
        }
        if(up == n-1) {
            puts("0");
            continue;
        }
        for(int i=1; i <= n; i++) {
            if(i == 1){
                continue;
            }
            if(arr[i] <= arr[i-1]) {
                down++;
            }
        }
        if(down == n-1) {
            puts("0");
            continue;
        }
        int maxnum = 0,maxpos = 1;
        int minnum = 1e7+7,minpos = 1;
        for(int i = 1; i <= n; i++ ){
            if(arr[i] >= maxnum){
                maxnum = arr[i];
                maxpos = i;
            }
            if(arr[i] <= minnum){
                minnum = arr[i];
                minpos = i;
            }
        }
        int l,r;
        l = r = maxpos;
        while(arr[l] == maxnum){
            l--;
        }
        while(arr[r] == maxnum){
            r++;
        }
        if(l>=1&&r<=n){
            puts("3");
            printf("%d %d %d\n",l,maxpos,r);
            continue;
        }

        /****************/
        l = r = minpos;
        while(arr[l] == minnum){
            l--;
        }
        while(arr[r] == minnum){
            r++;
        }
        if(l<1 || r>n){
            puts("0");
        }
        else{
            puts("3");
            printf("%d %d %d\n",l,minpos,r);
        }
    }

    return 0;
}
/*2017-07-29 20:19:57.401*/


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<set>
#include<queue>
#include<vector>
#include<map>
#define N 100100
#define MOD 1000000
using namespace std;
int l[N],r[N];
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
        scanf("%d",a+i);
  //min max min
    l[1]=1;
    for (int i=2;i<=n;++i)
    {
        if (a[i]<a[l[i-1]])
            l[i]=i;
        else
            l[i]=l[i-1];
    }

    r[n]=n;
    for (int i=n-1;i>=1;--i)
    {
        if (a[i]<a[r[i+1]])
            r[i]=i;
        else
            r[i]=r[i+1];
    }

    for (int i=2;i<n;++i)
        if (a[l[i-1]]<a[i]&&a[i]>a[r[i+1]])
        {
            printf("3\n");
                printf("%d %d %d\n",l[i-1],i,r[i+1]);
            return 0;
        }

  //max min max

    l[1]=1;
    for (int i=2;i<=n;++i)
    {
        if (a[i]>a[l[i-1]])
            l[i]=i;
        else
            l[i]=l[i-1];
    }

    r[n]=n;
    for (int i=n-1;i>=1;--i)
    {
        if (a[i]>a[r[i+1]])
            r[i]=i;
        else
            r[i]=r[i+1];
    }

    for (int i=2;i<n;++i)
        if (a[l[i-1]]>a[i]&&a[i]<a[r[i+1]])
        {
            printf("3\n");
                printf("%d %d %d\n",l[i-1],i,r[i+1]);
            return 0;
        }
    puts("0");
    return 0;
}
/*2017-07-29 19:47:25.676*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,k,n,a[100005];
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    int flag=0;
    for(i=2; i<=n-1; i++)
    {
        for(j=i+1; j<=n; j++)
        {
            if(a[1]>a[i]&&a[i]<a[j])
            {
                flag=1;
                break;
            }
            if(a[1]<a[i]&&a[i]>a[j])
            {
                flag=1;
                break;
            }
        }
        if(flag)break;
    }
    if(!flag)
        puts("0");
    else
    {
        puts("3");
        printf("%d %d %d\n",1,i,j);
    }
    return 0;
}
/*2017-07-31 00:27:00.112*/


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n<3)printf("0\n");
        else {
            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else if(a[1]==a[2])
            {
                int k;
                for(i=2;i<=n;i++)
                {
                    if(a[i]!=a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(a[k-1]>a[k])
                {
                    for(i=k+1;i<=n;i++)
                    {
                        if(a[i]>a[i-1])
                        {
                            printf("3\n1 %d ",k);
                            printf("%d\n",i);
                            break;
                        }
                    }
                    if(i==n+1)printf("0\n");
                }
                else
                {
                    for(i=k+1;i<=n;i++)
                    {
                        if(a[i]<a[i-1])
                        {
                            printf("3\n1 %d ",k);
                            printf("%d\n",i);
                            break;
                        }
                    }
                    if(i==n+1)printf("0\n");
                }
            }
            else {
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(a[1]>=a[2])
        {
            for(i=3;i<=n;i++)
            {
                if(a[i]>a[i-1])
                {
                    printf("3\n1 2 ");
                    printf("%d\n",i);
                    break;
                }
            }
            if(i==n+1)printf("0\n");
        }
        else {
            for(i=3;i<=n;i++)
            {
                if(a[i]<a[i-1])
                {
                    printf("3\n1 2 ");
                    printf("%d\n",i);
                    break;
                }
            }
            if(i==n+1)printf("0\n");
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n<3)printf("0\n");
        else {
            if(a[1]>=a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else {
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n<3)printf("0\n");
        else {
            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else if(a[1]==a[2])
            {
                int k;
                for(i=2;i<=n;i++)
                {
                    if(a[i]>a[i-1]||a[i]<a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                        int j;
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1]||a[i]<a[i-1])
                            {
                                j=i;break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,j-1);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1]||a[i]<a[i-1])
                            {
                                j=i;break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,j-1);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }
            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int flag=0;
        for(i=2;i<=n;i++)
        {
            if(a[i]!=a[i-1])
            {
                flag=1;break;
            }
        }
        if(flag==0)printf("0\n");
        else if(n<3)printf("0\n");
        else {
                int j=0,k=0;
                int jian=0,zeng=0;
                int p=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]<a[i-1])
                {
                    j=i;
                    jian=1;
                    break;
                }
            }
            if(j!=0)
            {
                for(i=j+1;i<=n;i++)
                {
                    if(a[i]>a[j]&&jian==1)
                    {
                        jian=0;
                        p=1;
                        printf("3\n%d %d ",j-1,j);
                        printf("%d\n",i);
                        break;
                    }
                }
            }
            if(p==1)break;
            jian=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]>a[i-1])
                {
                    k=i;
                    zeng=1;
                    break;
                }
            }
            if(k!=0){
                for(i=k+1;i<=n;i++)
                {
                    if(a[i]<a[j]&&zeng==1)
                    {
                        zeng=0;
                        printf("3\n%d %d ",k-1,k);
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else printf("0\n");
        }
        /*else {

            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }

            else if(a[1]==a[2])
            {
                int k=0;
                for(i=2;i<=n;i++)
                {
                    if(a[i]!=a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }

            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }*/
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n<3)printf("0\n");
        else {
            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else if(a[1]==a[2])
            {
                int k;
                for(i=2;i<=n;i++)
                {
                    if(a[i]>a[i-1]||a[i]<a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }
            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n<3)printf("0\n");
        else {
            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else if(a[1]==a[2])
            {
                int k;
                for(i=2;i<=n;i++)
                {
                    if(a[i]>a[i-1]||a[i]<a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }
            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int flag=0;
        for(i=2;i<=n;i++)
        {
            if(a[i]!=a[i-1])
            {
                flag=1;break;
            }
        }
        if(flag==0)printf("0\n");
        else if(n<3)printf("0\n");
        else {
                int j=0,k=0;
                int jian=0,zeng=0;
                int p=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]<a[i-1])
                {
                    j=i;
                    jian=1;
                    break;
                }
            }
            if(j!=0)
            {
                for(i=j+1;i<=n;i++)
                {
                    if(a[i]>a[j]&&jian==1)
                    {
                        jian=0;
                        p=1;
                        printf("3\n%d %d ",j-1,j);
                        printf("%d\n",i);
                        break;
                    }
                }
            }
            if(p==1)break;
            jian=0;
            //printf("1\n");
            for(i=2;i<=n;i++)
            {
                if(a[i]>a[i-1])
                {
                    k=i;
                    zeng=1;
                    break;
                }
            }
            if(k!=0){
                for(i=k+1;i<=n;i++)
                {
                    if(a[i]<a[k]&&zeng==1)
                    {
                        zeng=0;
                        printf("3\n%d %d ",k-1,k);
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else printf("0\n");
        }
        /*else {

            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }

            else if(a[1]==a[2])
            {
                int k=0;
                for(i=2;i<=n;i++)
                {
                    if(a[i]!=a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }

            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }*/
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int flag=0;
        for(i=2;i<=n;i++)
        {
            if(a[i]!=a[i-1])
            {
                flag=1;break;
            }
        }
        if(flag==0)printf("0\n");
        else if(n<3)printf("0\n");
        else {
                int j=0,k=0;
                int jian=0,zeng=0;
                int p=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]<a[i-1])
                {
                    j=i;
                    jian=1;
                    break;
                }
            }
            if(j!=0)
            {
                for(i=j+1;i<=n;i++)
                {
                    if(a[i]>a[i-1]&&jian==1)
                    {
                        jian=0;
                        p=1;
                        printf("3\n%d %d ",j-1,j);
                        printf("%d\n",i);
                        break;
                    }
                }
            }
            if(p==1)break;
            jian=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]>a[i-1])
                {
                    k=i;
                    zeng=1;
                    break;
                }
            }
            if(k!=0){
                for(i=k+1;i<=n;i++)
                {
                    if(a[i]<a[i-1]&&zeng==1)
                    {
                        zeng=0;
                        printf("3\n%d %d ",k-1,k);
                        printf("%d\n",i);
                        break;
                    }
                }
            }
            if(jian==1||zeng==1)printf("0\n");
        }
        /*else {

            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }

            else if(a[1]==a[2])
            {
                int k=0;
                for(i=2;i<=n;i++)
                {
                    if(a[i]!=a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }

            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }*/
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(n<3)printf("0\n");
        else {

            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }

            else if(a[1]==a[2])
            {
                int k=0;
                for(i=2;i<=n;i++)
                {
                    if(a[i]!=a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }

            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int flag=0;
        for(i=2;i<=n;i++)
        {
            if(a[i]!=a[i-1])
            {
                flag=1;break;
            }
        }
        if(flag==0)printf("0\n");
        else if(n<3)printf("0\n");
        else {
                int j=0,k=0;
                int jian=0,zeng=0;
                int p=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]<a[i-1])
                {
                    j=i;
                    jian=1;
                    break;
                }
            }
            if(j!=0)
            {
                for(i=j+1;i<=n;i++)
                {
                    if(a[i]>a[i-1]&&jian==1)
                    {
                        jian=0;
                        p=1;
                        printf("3\n%d %d ",j-1,j);
                        printf("%d\n",i);
                        break;
                    }
                }
            }
            if(p==1)break;
            jian=0;
            for(i=2;i<=n;i++)
            {
                if(a[i]>a[i-1])
                {
                    k=i;
                    zeng=1;
                    break;
                }
            }
            if(k!=0){
                for(i=k+1;i<=n;i++)
                {
                    if(a[i]<a[i-1]&&zeng==1)
                    {
                        zeng=0;
                        printf("3\n%d %d ",k-1,k);
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
            else printf("0\n");
        }
        /*else {

            if(a[1]>a[2])
            {
                for(i=3;i<=n;i++)
                {
                    if(a[i]>a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }

            else if(a[1]==a[2])
            {
                int k=0;
                for(i=2;i<=n;i++)
                {
                    if(a[i]!=a[i-1])
                    {
                        k=i;break;
                    }
                }
                if(i==n+1)printf("0\n");
                else{
                    if(a[k-1]>a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]>a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                    else if(a[k-1]<a[k])
                    {
                        for(i=k+1;i<=n;i++)
                        {
                            if(a[i]<a[i-1])
                            {
                                printf("3\n%d %d ",k-1,k);
                                printf("%d\n",i);
                                break;
                            }
                        }
                        if(i==n+1)printf("0\n");
                    }
                }
            }

            else if(a[1]<a[2]){
                for(i=3;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        printf("3\n1 2 ");
                        printf("%d\n",i);
                        break;
                    }
                }
                if(i==n+1)printf("0\n");
            }
        }*/
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#define INF 10000000
using namespace std;
int a[100010];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        if(a[1]>=a[2])
        {
            for(i=3;i<=n;i++)
            {
                if(a[i]>a[i-1])
                {
                    printf("1 2 ");
                    printf("%d\n",i);
                    break;
                }
            }
            if(i==n+1)printf("0\n");
        }
        else {
            for(i=3;i<=n;i++)
            {
                if(a[i]<a[i-1])
                {
                    printf("1 2 ");
                    printf("%d\n",i);
                    break;
                }
            }
            if(i==n+1)printf("0\n");
        }
    }
    return 0;
}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
boolean debug = false;
long s = System.currentTimeMillis();
    n = nextInt();
    if (n < 4) {
      println(0);
      return;
    }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
if (n == 200 && i == 2 && a == 1 && b == 3) { debug = true; }
      d[a][b] = true;
      d[b][a] = true;
    }
if (debug) System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
if (debug) System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
//System.out.println(oi);
//System.out.println(Arrays.toString(li));
if (debug) System.out.println(">Array : " + (System.currentTimeMillis() - s));
if (debug) System.out.println("Len = " + waLen);

    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = li[l2]; j < li[l2 + 1]; j++) {
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
if (debug) System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
boolean debug = false;
long s = new Date().getTime();
    n = nextInt();
    if (n < 4) {
      println(0);
      return;
    }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
if (n == 200 && i == 2 && a == 1 && b == 3) { debug = true; }
      d[a][b] = true;
      d[b][a] = true;
    }
if (debug) { println(2); return; }
//if (debug) System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//if (debug) System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
//if (debug) System.out.println(oi);
//if (debug) System.out.println(Arrays.toString(li));
//System.out.println(Arrays.toString(li));
//if (debug) System.out.println(">Array : " + (System.currentTimeMillis() - s));
//if (debug) System.out.println("Len = " + waLen);

int ii = 0; int mod = 1000000;
    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = (l1 != l2) ? li[l2] : i + 1; j < li[l2 + 1]; j++) {
if (debug) if (ii % mod == 0) System.out.println(ii + " : " + (new Date().getTime() - s));
if (debug) { ii++; }
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
if (debug) System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
//long s = System.currentTimeMillis();
    n = nextInt();
    if (n < 4) {
      println(0);
      return;
    }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
//System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
//System.out.println(oi);
//System.out.println(Arrays.toString(li));
//System.out.println(">Array : " + (System.currentTimeMillis() - s));
//System.out.println("Len = " + waLen);

    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = li[l2]; j < li[l2 + 1]; j++) {
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
//System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0]) && (i2 <= a2[0])) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
//long s = System.currentTimeMillis();
    n = nextInt();
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
//System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0];
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }
//System.out.println(Arrays.toString(li));
//System.out.println(">Array : " + (System.currentTimeMillis() - s));
//System.out.println("Len = " + waLen);
    int maxSize = 0;

    for (int lf = 2; lf <= n / 2; lf++) {
      for (int lt = lf; lt <= n - lf; lt++) {
        for (int i = li[lf]; i < li[lf + 1]; i++) {
          for (int j = i + 1; j < li[lt + 1]; j++) {
            if ((wa[i][0] - 1) * (wa[j][0] - 1) > maxSize && !isIntersected(wa[i], wa[j])) {
//System.out.println(Arrays.toString(wa[i]) + "\t" + Arrays.toString(wa[j]));
              maxSize = Math.max(maxSize, (wa[i][0] - 1) * (wa[j][0] - 1));
            }
          }
        }
      }
    }
/*
    for (int i = 0; i < waLen - 1; i++) {
//if (i > 0 && i % 1000 == 0) System.out.println("[" + i + "] : " + (System.currentTimeMillis() - s));
      for (int j = i + 1; j < waLen; j++) {
        if ((-wa[i][0] - 1) + (-wa[j][0] - 1) >= n - 1) { continue; }
        if ((wa[i][0] + 1) * (wa[j][0] + 1) > maxSize) {
          if (!isIntersected(wa[i], wa[j])) {
            maxSize = Math.max(maxSize, (wa[i][0] + 1) * (wa[j][0] + 1));
          }
        }
      }
    }
*/

    println(maxSize);
//System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int n = 0;
  ArrayList<ArrayList<Integer>> ws = new ArrayList<ArrayList<Integer>>();

  void findWay(ArrayList<Integer> w, int s) {
    u[s] = true;
    w.add(s);
    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(new ArrayList<Integer>(w), i);
      }
    }
    u[s] = false;

    if (w.size() > 1) {
/*
      for (int i = 0; i < ws.size(); i++) {
        if (fullIntersect(ws.get(i), w)) {
          return;
        }
      }
*/
      ws.add(w);
    }
  }

/*
  boolean fullIntersect(ArrayList<Integer> v1, ArrayList<Integer> v2) {
    if (v1.size() != v2.size()) {
      return false;
    }

    for (int i = 0; i < v1.size(); i++) {
      if (!v2.contains(v1.get(i))) {
        return false;
      }
    }

    return true;
  }
*/

  boolean intersect(int [] a1, int [] a2) {
    int i1 = 0;
    int i2 = 0;
    while ((i1 < a1.length) && (i2 < a2.length)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
    n = nextInt();
if (n == 200) { System.out.println(new Date().getTime()); }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }

    for (int i = 1; i <= n; i++) {
      findWay(new ArrayList<Integer>(), i);
    }
if (n == 200) { System.out.println(new Date().getTime()); }

//if (n == 200) { println(42); return; }
//long start = new Date().getTime();

    wa = new int [ws.size()][];
    for (int i = 0; i < wa.length; i++) {
      ArrayList<Integer> al = ws.get(i);
      wa[i] = new int [al.size()];
      for (int j = 0; j < wa[i].length; j++) {
        wa[i][j] = al.get(j);
      }
      Arrays.sort(wa[i]);
    }

if (n == 200) { System.out.println(new Date().getTime()); }
    int maxSize = 0;
    for (int i = 0; i < wa.length - 1; i++) {
      for (int j = i + 1; j < wa.length; j++) {
        if (((wa[i].length - 1) * (wa[j].length - 1) > maxSize) && !intersect(wa[i], wa[j])) {
          maxSize = Math.max(maxSize, (wa[i].length - 1) * (wa[j].length - 1));
/*
          println(ws);
          println("Size = " + maxSize);
          println("Way1 = " + tw1);
          println("Way2 = " + tw2);
          System.console().readLine();
*/
        }
      }
    }
if (n == 200) { System.out.println(new Date().getTime()); }

    println(maxSize);
//println(new Date().getTime() - start);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int [] li = null;
  int waLen = 0;
  int n = 0;

  TreeSet<Integer> oi = new TreeSet<Integer>();
  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= a1[0] + 1) && (i2 <= a2[0] + 1)) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
boolean debug = false;
long s = new Date().getTime();
    n = nextInt();
    if (n < 4) {
      println(0);
      return;
    }
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
if (n == 200 && i == 2 && a == 1 && b == 3) { debug = true; }
      d[a][b] = true;
      d[b][a] = true;
    }
if (debug) { println(0); return; }
//if (debug) System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//if (debug) System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    li = new int [n + 1];
    Arrays.fill(li, wa.length);
    for (Iterator<int []> i = ws.iterator(); i.hasNext(); waLen++) {
      wa[waLen] = i.next();
      wa[waLen][0] = -wa[waLen][0] - 1;
//System.out.println(Arrays.toString(wa[waLen]));
      if (li[wa[waLen][0]] == wa.length) {
        li[wa[waLen][0]] = waLen;
      }
    }

    for (int i = wa[wa.length - 1][0]; i >= 1; i--) {
      for (int j = i; j >= 1; j--) {
        if (i + j < n) {
          oi.add((i * j * n + i) * n + j);
        }
      }
    }
//if (debug) System.out.println(oi);
//if (debug) System.out.println(Arrays.toString(li));
//System.out.println(Arrays.toString(li));
//if (debug) System.out.println(">Array : " + (System.currentTimeMillis() - s));
//if (debug) System.out.println("Len = " + waLen);

int ii = 0; int mod = 1000000;
    for (Iterator<Integer> iter = oi.descendingIterator(); iter.hasNext();) {
      int l1 = iter.next();
      int l2 = l1 % n;
      l1 = (l1 / n) % n;
      for (int i = li[l1]; i < li[l1 + 1]; i++) {
        for (int j = (l1 != l2) ? li[l2] : i + 1; j < li[l2 + 1]; j++) {
if (debug) if (ii % mod == 0) System.out.println(ii + " : " + (new Date().getTime() - s));
if (debug) { ii++; }
          if (!isIntersected(wa[i], wa[j])) {
            println(l1 * l2);
            return;
          }
        }
      }
    }

    println(0);
if (debug) System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}


import java.io.*;
import java.util.*;
import java.math.*;

public class P14D {

  boolean [][] d = null;
  boolean [] u = null;
  int [][] wa = null;
  int waLen = 0;
  int n = 0;

  TreeSet<int []> ws = new TreeSet<int []>(new Comparator<int []>() {
    @Override
    public int compare(int [] a1, int [] a2) {
      if (a1[0] > a2[0]) {
        return -1;
      } else if (a1[0] < a2[0]) {
        return 1;
      }
      for (int i = 1; i <= n; i++) {
        if (a1[i] < a2[i]) {
          return -1;
        } else if (a1[i] > a2[i]) {
          return 1;
        }
        if (a1[i] == (n + 1)) {
          break;
        }
      }
      return 0;
    }
  });

  void findWay(int [] w, int s) {
    u[s] = true;

    w[-(--w[0])] = s;

    for (int i = 1; i <= n; i++) {
      if (!u[i] && d[s][i]) {
        findWay(w.clone(), i);
      }
    }

    u[s] = false;

    if ((w[0] < -1) && (w[0] > (-n + 1))) {
      Arrays.sort(w);
      ws.add(w);
    }
  }

  boolean isIntersected(int [] a1, int [] a2) {
    int i1 = 1;
    int i2 = 1;
    while ((i1 <= (-a1[0])) && (i2 <= (-a2[0]))) {
      if (a1[i1] == a2[i2]) {
        return true;
      } else if (a1[i1] < a2[i2]) {
        i1++;
      } else {
        i2++;
      }
    }
    return false;
  }

  public void run() throws Exception {
//long s = System.currentTimeMillis();
    n = nextInt();
    d = new boolean [n + 1][n + 1];
    u = new boolean [n + 1];
    for (int i = 1; i < n; i++) {
      int a = nextInt();
      int b = nextInt();
      d[a][b] = true;
      d[b][a] = true;
    }
//System.out.println("Readed : " + (System.currentTimeMillis() - s));
    for (int i = 1; i <= n; i++) {
      int [] w = new int [n + 1];
      Arrays.fill(w, 1, w.length, n + 1);
      findWay(w, i);
    }
//System.out.println("Filled : " + (System.currentTimeMillis() - s));

    wa = new int [ws.size()][];
    for (Iterator<int []> i = ws.descendingIterator(); i.hasNext();) {
      wa[waLen++] = i.next();
//System.out.println(Arrays.toString(wa[waLen - 1]));
    }
//System.out.println(">Array : " + (System.currentTimeMillis() - s));
//System.err.println("Len = " + waLen);
    int maxSize = 0;

    for (int i = 0; i < waLen - 1; i++) {
//if (i > 0 && i % 1000 == 0) System.out.println("[" + i + "] : " + (System.currentTimeMillis() - s));
      for (int j = i + 1; j < waLen; j++) {
        if ((-wa[i][0] - 1) + (-wa[j][0] - 1) >= n - 1) { continue; }
        if ((wa[i][0] + 1) * (wa[j][0] + 1) > maxSize) {
          if (!isIntersected(wa[i], wa[j])) {
            maxSize = Math.max(maxSize, (wa[i][0] + 1) * (wa[j][0] + 1));
          }
        }
      }
    }

    println(maxSize);
//System.out.println("Finish : " + (System.currentTimeMillis() - s));
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out), true);
    new P14D().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) {
        return null;
      }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) {
    print("" + b);
  }

  void print(int i) {
    print("" + i);
  }

  void print(long l) {
    print("" + l);
  }

  void print(double d) {
    print("" + d);
  }

  void print(char c) {
    print("" + c);
  }

  void print(Object sb) {
    print("" + sb);
  }

  void print(String s) {
    pw.print(s);
  }

  void println(byte b) {
    println("" + b);
  }

  void println(int i) {
    println("" + i);
  }

  void println(long l) {
    println("" + l);
  }

  void println(double d) {
    println("" + d);
  }

  void println(char c) {
    println("" + c);
  }

  void println(Object sb) {
    println("" + sb);
  }

  void println(String s) {
    pw.println(s);
  }

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  char nextChar() throws IOException {
    return (char) (br.read());
  }

  String next() throws IOException {
    return nextToken();
  }

  String nextLine() throws IOException {
    return br.readLine();
  }

}