#!/usr/bin/python
"""
Line by line detecting encoding if input and then convert it into UTF-8
Suitable for look at logs with mixed encoding (i.e. from mail systems)
"""
import sys
import chardet
while 1:
l = sys.stdin.readline()
e = chardet.detect(l)
u = None
try:
if e['confidence'] > 0.3:
u = unicode(l, e['encoding'])
except:
pass
if u:
print u,
else:
print l,