﻿namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class TwoWaysSorting
	{
		public string sortingMethod(string[] stringList)
		{
			bool l = isLexi(stringList);
			bool ll = isLen(stringList);
			if (l && ll)
				return "both";
			else if (!l && !ll)
				return "none";
			else if (l)
				return "lexicographically";
			else
				return "lengths";
		}

		private bool isLen(string[] stringList)
		{
			int prev = 0;
			int n = stringList.Length;
			int i;
			for (i = 0; i < n; i++)
			{
				if (prev > stringList[i].Length)
					break;
				else
				{
					prev = stringList[i].Length;
				}
			}
			if (i < n)
			{
				return false;
			}
			return true;
		}

		private bool isLexi(string[] stringList)
		{
			int n = stringList.Length;
			string[] c = new string[n];
			for (int i = 0; i < n; i++)
			{
				c[i] = (string)stringList[i].Clone();
			}

			Array.Sort<string>(c);

			int k;
			for (k = 0; k < n; k++)
			{
				if (c[k] != stringList[k])
				{
					break;
				}
			}
			if (k < n)
			{
				return false;
			}
			return true;
		}
	}
}
