import re
def solution(new_id):
# 아이디 제한 - 3~15길이, 소문자 숫자 - _ . 문자 사용 가능, 마침표(.)는 처음과 끝, 연속 사용 불가능
answer = ''
# 1번 : 대문자 -> 소문자
one = new_id.lower()
# 2번 : 소문자, 숫자, -, _, . 제외 문자 제거
condition = '[^a-z0-9-_.]'
two = re.sub(condition, '', one)
# 3번 : .. -> .
three = two
while True:
if '..' in three:
three = three.replace('..', '.')
else:
break
# 4번 : 첫 번째 or 마지막에 . 제거
four = three
if three[0] == '.':
four = four[1:]
if three[-1] =='.':
four = four[:-1]
# 5번 : 빈 문자열은 a 입력
five = four
if len(four)==0:
five = 'a'
# 6번 : 문자열 길이가 16이상이면, 앞의 15개 제외 뒤에 제거
six = five
if len(five)>=16:
six = five[:15]
# 맨 뒤에 . 있으면 제거
if six[-1] == '.':
six = six[:-1]
# 7번 : 문자열 길이가 2 이하면, 문자열의 마지막 문자를 길이가 3이 될 때까지 붙이기
seven = six
if len(six)<=2:
while True:
word = six[-1]
seven += word
if len(seven)==3:
break
answer = seven
return answer