	/* package whatever; // don't place package name! */

	import java.util.*;
	import java.lang.*;
	import java.io.*;

	enum TokenKind
	{
		WordSeparator,
		Word
	}

	class Token
	{
		int _start;
		int _end;
		String _text;
		TokenKind _kind;
	
		public String getText()
		{
			return _text;
		}

		public void setText(String value)
		{
			_text = value;
		}

		public void setStart(int value)
		{
			_start = value;
		}

		public void setEnd(int value)
		{
			_end = value;
		}

		public int getStart()
		{
			return _start;
		}

		public int getEnd()
		{
			return _end;
		}
	
		public TokenKind getKind()
		{
			return _kind;
		}
	
		public void setKind(TokenKind value)
		{
			_kind = value;
		}
	}

	class LinearRepeatSearchLexer
	{
		StringBuffer _text;
		int _position;
		char _peek;

		public LinearRepeatSearchLexer(StringBuffer text)
		{
			_text = text;
			_position = 0;
			_peek = (char)0;
		}

		public Token nextToken()
		{
			Token ret = new Token();
			char peek = PeekChar();

			if(isWordSeparator(peek))
			{
				ret.setStart(_position);
				readWordSeparator(ret);
				ret.setEnd(_position - 1);
				return ret;
			}
			else if(isLetterOrDigit(peek))
			{
				ret.setStart(_position);
				readWord(ret);
				ret.setEnd(_position - 1);
				return ret;
			} 
			else if(peek == (char)0)
			{
				return null;
			}
			else
			{
				// TODO: 
				//	caracteres não identificados
				//	ou você pode simplificar o readWord
				return null;
			}
		}

		void readWordSeparator(Token token)
		{
			char c = (char)0;
			StringBuffer tokenText = new StringBuffer();
			while(isWordSeparator(c = PeekChar()))
			{
				tokenText.append(c);
				MoveNext(1);
			}
			token.setText(tokenText.toString());
			token.setKind(TokenKind.WordSeparator);
		}

		void readWord(Token token)
		{
			char c = (char)0;
			StringBuffer tokenText = new StringBuffer();
			while(isLetterOrDigit(c = PeekChar()))
			{
				tokenText.append(c);
				MoveNext(1);
			}
			token.setText(tokenText.toString());
			token.setKind(TokenKind.Word);
		}

		boolean isWordSeparator(char c)
		{
			// TODO: outros separadores aqui
			return c == ' ' ||
				c == '\t' ||
				c == '\n' ||
				c == '\r' ||
				c == ',' ||
				c == '.' || 
				c == '-' || 
				c == ';' || 
				c == ':' ||
				c == '=' ||
				c == '>';
		}

		boolean isLetterOrDigit(char c)
		{
			// TODO: outras letras aqui
			return (c >= 'a' && c <= 'z') ||
				(c >= 'A' && c <= 'Z') ||
				(c >= '0' && c <= '9') ||
				(c >= 'à' && c <= 'ú') ||
				(c >= 'À' && c <= 'Ú') ||
				c == '_';
		}

		char PeekChar()
		{
			if(_position < _text.length())
				return _text.charAt(_position);
			return (char)0;
		}

		void MoveNext(int plus)
		{
			_position += plus;
		}
	}

	class LinearRepeatSearch
	{
		StringBuffer _text;
		int _radius;
	
		public LinearRepeatSearch(StringBuffer text, int radius)
		{
			_text = text;
			_radius = radius;
		}
	
		public LinearRepeatSearch(String text, int radius)
		{
			this(new StringBuffer(text), radius);	
		}
	
		public List<Token> getRepeatedWords()
		{
			// ler todos os tokens
			ArrayList<Token> ret = new ArrayList<Token>();
			ArrayList<Token> readed = new ArrayList<Token>();
			LinearRepeatSearchLexer lexer = new LinearRepeatSearchLexer(_text);
			Token token = null;
			while((token = lexer.nextToken()) != null)
			{
				if(token.getKind() == TokenKind.Word)
					readed.add(token);
			}

			// localizar repetições a partir do raio
			// PERF:
			//		este laço pode ser melhorado em termos de performance
			//		pois há comparações repetidas aqui
			int size = readed.size();
			for(int x = 0; x < size; x++)
			{
				Token a = readed.get(x);
				for(int y = Math.max(0, x - _radius); y < size && (y - x) < _radius; y++)
				{
					if(x == y) continue;
					Token b = readed.get(y);
					if(a.getText().equals(b.getText()))
					{
						ret.add(a);
						break;
					}
				}
			}

			return ret;
		}
	}

	class Ideone
	{
		public static void main (String[] args) throws java.lang.Exception
		{
			// your code goes here

			StringBuffer input = new StringBuffer("Hoje em dia, é necessário ser esperto. O nosso dia a dia é complicado.");
			StringBuffer output = new StringBuffer();
			LinearRepeatSearch searcher = new LinearRepeatSearch(input, 10);
			List<Token> spans = searcher.getRepeatedWords();
			int listSize = spans.size();
			int position = 0;
			for(int x = 0; x < listSize; x++)
			{
				Token item = spans.get(x);
				output.append(input.substring(position, item.getStart()));
				output.append("<b>");
				output.append(item.getText());
				output.append("</b>");
				position = item.getEnd() + 1;
			}
			if(position < input.length())
			{
				output.append(input.substring(position));
			}
			System.out.println(output.toString());
		}
	}