description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
n = len(s)
l = []
i = 0
while i < n:
j = i + 1
while j < n and s[j] == s[i]:
j += 1
if j - i == 1:
l.append(s[i])
i += 1
continue
l.append(s[i])
l.append(s[i])
k = j + 1
while k < n and s[k] == s[j]:
k += 1
if j < n:
l.append(s[j])
i = k
print("".join(l))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def main():
s = input()
letters = [[s[0], 1]]
curr = s[0]
ans = 0
for i in range(1, len(s)):
if s[i] == curr:
if letters[-1][1] < 2:
letters[-1][1] += 1
else:
ans += 1
else:
if len(letters) > 1:
if letters[-2][1] == 2 and letters[-1][1] == 2:
letters[-1][1] = 1
ans += 1
letters.append([s[i], 1])
curr = s[i]
if len(letters) > 1:
if letters[-2][1] == 2 and letters[-1][1] == 2:
letters[-1][1] = 1
ans += 1
new = ""
for i in letters:
new += i[0] * i[1]
print(new)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
__author__ = "Lipen"
def actions(s):
if len(s) <= 2:
return s
lasttwo = s[0], s[1]
formated = s[0:2]
for c in s[2:]:
if not (c == lasttwo[0] and c == lasttwo[1]):
formated += c
lasttwo = lasttwo[1], c
if len(formated) <= 3:
return formated
lastthree = formated[0], formated[1], formated[2]
answer = formated[0:3]
for i in range(3, len(formated)):
c = formated[i]
if not (lastthree[0] == lastthree[1] and lastthree[2] == c):
answer += c
lastthree = lastthree[1], lastthree[2], c
return answer
def main():
s = input()
print(actions(s))
main()
|
ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
def correctTypo22(typoWord):
wordCorrected = ""
i = len(typoWord) - 1
while i >= 3:
if typoWord[i] == typoWord[i - 1] and typoWord[i - 2] == typoWord[i - 3]:
wordCorrected += typoWord[i] + typoWord[i - 1] + typoWord[i - 2]
i -= 4
else:
wordCorrected += typoWord[i]
i -= 1
while i >= 0:
wordCorrected += typoWord[i]
i -= 1
return wordCorrected[::-1]
def correctTypo3(typoWord):
wordCorrected = ""
i = 0
while i < len(typoWord) - 2:
if typoWord[i] == typoWord[i + 1] and typoWord[i + 1] == typoWord[i + 2]:
wordCorrected += typoWord[i] + typoWord[i + 1]
i += 3
else:
wordCorrected += typoWord[i]
i += 1
while i < len(typoWord):
wordCorrected += typoWord[i]
i += 1
return wordCorrected
def correctTypo(typoWord):
corrected = correctTypo3(typoWord)
while len(corrected) < len(typoWord):
typoWord = corrected
corrected = correctTypo3(typoWord)
return correctTypo22(corrected)
def main():
f = sys.stdin
print(correctTypo(f.readline()))
main()
|
IMPORT FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
s = input()
ans = []
for c in s:
if len(ans) >= 2:
if c == ans[-1] and c == ans[-2]:
continue
if len(ans) >= 3:
if c == ans[-1] and ans[-2] == ans[-3]:
continue
ans.append(c)
print("".join(ans))
|
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def fixing_typos(s):
if len(s) == 1:
print(s)
else:
count = 0
array = []
values = ""
for i in range(1, len(s)):
if s[i - 1] == s[i]:
count += 1
else:
values += s[i - 1]
if count + 1 >= 3:
array.append(2)
else:
array.append(count + 1)
count = 0
if count + 1 >= 3:
array.append(2)
else:
array.append(count + 1)
values += s[i]
for i in range(1, len(array)):
if array[i - 1] == 2 and array[i - 1] == array[i]:
array[i] = 1
new_array = [(values[i] * array[i]) for i in range(len(array))]
print("".join(new_array))
s = input()
fixing_typos(s)
|
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
l = str(input())
s = list(l)
n = len(s)
ans = ""
pre = 0
cur = 1
for i in range(1, n):
if l[i] == l[i - 1]:
cur += 1
if cur == 2:
if pre >= 2:
s[i] = -1
cur -= 1
elif cur >= 3:
s[i] = -1
cur -= 1
else:
pre = cur
cur = 1
for i in range(n):
if s[i] != -1:
print(s[i], end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = ""
i = 0
first = True
while i < len(s):
c = s[i]
d = 1
while i + d < len(s) and s[i + d] == c:
d += 1
if d > 1:
if first:
ans += 2 * c
first = False
else:
ans += c
first = True
else:
ans += c
first = True
i += d
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
word = list(input())
ans = []
for i in word:
if (
len(ans) > 2
and ans[-3] == ans[-2]
and ans[-1] == i
or len(ans) > 1
and ans[-2] == ans[-1] == i
):
continue
ans.append(i)
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input().strip()
if len(s) <= 2:
print(s)
exit(0)
ne = s[0] + s[1]
for i in range(2, len(s)):
if s[i] != s[i - 1] or s[i] != s[i - 2]:
ne += s[i]
ne2 = ne[:3]
for i in range(3, len(ne), 1):
if ne2[-3] == ne2[-2] and ne2[-1] == ne[i]:
pass
else:
ne2 += ne[i]
print(ne2)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
ans = [s[0]]
cnt = 0
f = 0
for i in range(1, len(s)):
if s[i] != s[i - 1]:
ans.append(s[i])
if cnt == 1:
f = 1
else:
f = 0
cnt = 0
elif f == 0:
if cnt < 1:
cnt += 1
ans.append(s[i])
print(*ans, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
res = ""
s = input()
for i in s:
if (
len(res) >= 3
and res[-3] == res[-2]
and res[-1] == i
or len(res) >= 2
and res[-2] == res[-1] == i
):
continue
res += i
print(res)
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
n = len(s)
ans = "***"
for i in s:
if i == ans[-1] and ans[-2] == ans[-3] and ans[-2] != "*":
pass
elif i == ans[-1] and i == ans[-2]:
pass
else:
ans += i
print(ans[3:])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER STRING IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
temp = s[0]
sn = []
val = 0
for i in range(len(s)):
if s[i] == temp:
val += 1
if val < 3:
sn.append(s[i])
else:
temp = s[i]
val = 1
sn.append(s[i])
snd = []
cnt = 0
i = 0
while i < len(sn):
if i + 1 < len(sn):
if sn[i] == sn[i + 1]:
if cnt == 0:
cnt = 1
snd.append(sn[i])
snd.append(sn[i + 1])
i += 2
else:
cnt = 0
snd.append(sn[i])
i += 2
else:
snd.append(sn[i])
cnt = 0
i += 1
else:
snd.append(sn[i])
i += 1
for i in snd:
print(i, end="")
print("")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
a = input()
s = ""
n = len(a)
a += "-.,"
i = 0
while i != n:
if a[i] == a[i + 1] == a[i + 2]:
i += 1
continue
else:
s += a[i]
i += 1
n = len(s)
j = ""
i = 0
s += ";,."
while i != n:
if s[i] == s[i + 1] and s[i + 3] == s[i + 2]:
j += s[i] + s[i + 1] + s[i + 2]
i += 4
else:
j += s[i]
i += 1
print(j)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR STRING WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
to_be_removed = []
cur_char = s[0]
cur_char_cnt = 1
for i, c in enumerate(s):
if i == 0:
continue
if c == cur_char:
cur_char_cnt += 1
if cur_char_cnt >= 3:
to_be_removed.append(i)
else:
cur_char = c
cur_char_cnt = 1
s = [c for c in s]
for i in to_be_removed:
s[i] = ""
s = "".join(s)
islands_of_2 = []
cur_char = s[0]
cur_char_cnt = 1
for i, c in enumerate(s):
if i == 0:
continue
if c == cur_char:
cur_char_cnt += 1
if cur_char_cnt == 2:
islands_of_2.append(i)
else:
cur_char = c
cur_char_cnt = 1
if islands_of_2:
island_to_remove = []
prev_island = None
for island in islands_of_2:
if prev_island and prev_island + 2 == island:
island_to_remove.append(island)
prev_island = None
continue
else:
prev_island = island
s = [c for c in s]
for i in island_to_remove:
s[i] = ""
print("".join(s))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST ASSIGN VAR NONE FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = []
cur = 0
for i in range(len(s)):
if cur >= 2:
if s[i] == ans[cur - 1] and ans[cur - 1] == ans[cur - 2]:
continue
if cur >= 3:
if ans[cur - 1] == s[i] and ans[cur - 3] == ans[cur - 2]:
continue
ans.append(s[i])
cur += 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
newWord = ""
word = str(input())
for c in word:
if (
len(newWord) > 2
and newWord[len(newWord) - 3] == newWord[len(newWord) - 2]
and newWord[len(newWord) - 1] == c
or len(newWord) > 1
and newWord[len(newWord) - 2] == newWord[len(newWord) - 1]
and newWord[len(newWord) - 1] == c
):
continue
newWord += c
print(newWord)
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from itertools import groupby
s = input().rstrip()
s = [i for i in s]
g = []
for key, value in groupby(s):
g.append([len(list(value)), key])
for i in range(len(g) - 1):
if g[i][0] >= 2 and g[i + 1][0] >= 2:
g[i + 1][0] = 1
if g[i][0] >= 3:
g[i][0] = 2
if g[-1][0] >= 3:
g[-1][0] = 2
if g[0][0] >= 3:
g[-1][0] = 2
ans = ""
for i in g:
for j in range(i[0]):
print(i[1], end="")
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
fs = []
f = 0
fs.append(s[0])
e = s[0]
l = 0
for i in range(1, len(s)):
if s[i] == e and f == 0:
if i >= 2 and fs[l - 1] != fs[l - 2]:
f = 1
fs.append(s[i])
l += 1
e = s[i]
elif i < 2:
fs.append(s[i])
l += 1
elif s[i] != e:
f = 0
fs.append(s[i])
l += 1
e = s[i]
for i in range(len(fs)):
print(fs[i], end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
sans = []
for i in s:
if len(sans) == 0:
sans.append((i, 1))
else:
tmp, cnt = sans.pop()
if tmp == i:
sans.append((i, cnt + 1))
else:
sans.append((tmp, cnt))
sans.append((i, 1))
sans = list(map(lambda x: [x[0], 1] if x[1] == 1 else [x[0], 2], sans))
for i in range(len(sans) - 1):
if sans[i][1] == 2 and sans[i + 1][1] == 2:
sans[i + 1][1] = 1
print("".join(map(lambda x: x[0] * x[1], sans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER LIST VAR NUMBER NUMBER LIST VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = ""
for i in input():
if not (
len(s) >= 2
and s[-1] == s[-2] == i
or len(s) >= 3
and s[-2] == s[-3]
and s[-1] == i
):
s += i
print(s)
|
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
ans = ""
n = len(s)
for i in range(n):
if len(ans) >= 2 and ans[-1] == ans[-2] == s[i]:
continue
elif len(ans) >= 3 and (ans[-3] == ans[-2] and ans[-1] == s[i]):
continue
ans += s[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
if len(s) == 1:
print(s)
exit()
c = 1
st = ""
for i in range(1, len(s)):
if s[i] == s[i - 1]:
c += 1
else:
c = min(2, c)
st += s[i - 1] * c
c = 1
if c == 1:
st += s[i]
else:
st += s[i - 1] * 2
c = 1
pre = 0
ans = ""
for i in range(1, len(st)):
if st[i] == st[i - 1]:
c += 1
elif c == 2:
if pre < 2:
ans += st[i - 1] * c
pre = c
c = 1
else:
ans += st[i - 1]
c = 1
pre = 1
else:
ans += st[i - 1] * c
pre = c
c = 1
if c == 2:
if pre < 2:
ans += st[i - 1] * c
pre = c
c = 1
else:
ans += st[i - 1]
c = 1
pre = 1
else:
ans += st[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from itertools import *
mod = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
it = lambda: tuple(map(int, input().split()))
ls = lambda: list(input())
s = si()
l = []
lch = []
for i, j in groupby(s):
l.append(len(list(j)))
lch.append(i)
n = len(l)
if l[0] >= 3:
l[0] = 2
for i in range(1, n):
if l[i] >= 3:
l[i] = 2
if l[i - 1] == 2 and l[i] == 2:
l[i] = 1
for i, j in zip(l, lch):
print(j * i, end="")
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
input = sys.stdin.readline
s = list(input())
ans = ""
for i in s:
if len(ans) > 2 and ans[-3] == ans[-2] and ans[-1] == i:
continue
elif len(ans) > 1 and ans[-1] == ans[-2] == i:
continue
ans += i
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = s[0]
doub = False
ct = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
ct += 1
if not doub:
if ct <= 2:
ans += s[i]
doub = True
rep = True
elif not rep:
doub = False
else:
ans += s[i]
if ct == 1:
doub = False
rep = False
ct = 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
x = []
for c in s:
i = len(x)
if i >= 2 and x[i - 2] == x[i - 1] and x[i - 1] == c:
continue
if i >= 3 and x[i - 3] == x[i - 2] and x[i - 1] == c:
continue
x.append(c)
print("".join(x))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
inf = float("inf")
mod, MOD = 1000000007, 998244353
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def input():
return sys.stdin.readline().strip()
string = input()
ans = string[0]
length = len(string)
curr = 1
for i in range(1, length):
if curr >= 2 and string[i] == ans[-1] and string[i] == ans[-2]:
continue
elif curr >= 3 and string[i] == ans[-1] and ans[-2] == ans[-3]:
continue
else:
ans += string[i]
curr += 1
print(ans)
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
n = len(s)
li = [s[i] for i in range(n)]
g = []
for i in range(2, n):
if li[i] == li[i - 1] and li[i] == li[i - 2]:
g.append(i)
li1 = []
k = 0
for i in range(n):
if k < len(g) and i == g[k]:
k += 1
else:
li1.append(li[i])
n = len(li1)
fl = 0
g = []
i = 1
while i < n:
if li1[i] == li1[i - 1] and fl == 1:
g.append(i)
fl = 0
elif li1[i] == li1[i - 1]:
fl = 1
i += 1
elif li1[i] != li1[i - 1] and fl == 1:
fl = 0
i += 1
li2 = []
k = 0
for i in range(n):
if k < len(g) and i == g[k]:
k += 1
else:
li2.append(li1[i])
print("".join(li2))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def typo(text1):
text = list(text1)
k = len(text)
i = 0
double_flag = 0
while i < k:
j = 0
while i + j + 1 < k and text[i] == text[i + j + 1]:
j += 1
if j >= 1:
if not double_flag:
double_flag = 1
else:
double_flag = 3 - double_flag
else:
double_flag = 0
if double_flag == 1:
del text[i + 2 : i + j + 1]
k -= j - 1
i += 2
elif double_flag == 2:
del text[i + 1 : i + j + 1]
k -= j
i += 1
else:
i += 1
return "".join(text)
print(typo(input()))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from sys import stdin
def f(s):
s = list(s)
if len(s) in (1, 2):
return "".join(s)
r = s[:2]
i = 2
while i < len(s):
if r[-2] == r[-1] == s[i]:
i += 1
continue
else:
r.append(s[i])
i += 1
if len(r) < 4:
return "".join(r)
ans = r[:3]
i = 3
while i < len(r):
if ans[-3] == ans[-2] and ans[-1] == r[i]:
i += 1
continue
else:
ans.append(r[i])
i += 1
return "".join(ans)
s = str(input())
i = 0
print(f(s))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from itertools import groupby
s = input()
x = [(k, len(list(g))) for k, g in groupby(s)]
t = ""
current = 0
for i in range(len(x)):
key, cnt = x[i]
if i > 0 and cnt > 1 and current > 1:
current = 1
else:
current = min(cnt, 2)
t += key * current
print(t)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
string = input()
previous_char = ""
previous_freq = 0
current_char = ""
current_freq = 0
ans = list()
i = 0
while i < len(string):
current_char = string[i]
i += 1
current_freq = 1
while i < len(string) and string[i] == current_char:
current_freq += 1
i += 1
current_freq = min(current_freq, 2)
if previous_freq == 2:
current_freq = 1
for _ in range(current_freq):
ans.append(current_char)
previous_freq = current_freq
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
l = [[s[0], 1]]
for val in s[1:]:
if val == l[-1][0]:
l[-1][1] += 1
else:
l.append([val, 1])
for val in l:
if val[1] > 2:
val[1] = 2
ll = len(l)
for i in range(1, ll):
if l[i][1] == l[i - 1][1] == 2:
l[i][1] = 1
for val in l:
print(val[0] * val[1], end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s1 = input()
s2 = " "
for c in s1:
if s2[-1] == c:
if s2[-2] != c:
s2 += c
else:
s2 += c
s3 = ""
i = 2
s2 += "_+_"
while i < len(s2) - 3:
if s2[i] == s2[i + 1] and s2[i + 2] == s2[i + 3]:
s3 += s2[i : i + 3]
i = i + 3
else:
s3 += s2[i]
i += 1
print(s3)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR STRING WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
l = [0] * len(s)
x = 0
x = 0
for i in range(1, len(s)):
if s[i] == s[i - 1]:
if l[i - 1] == 0:
l[i] = 1
else:
l[i] = -1
t = ""
for i in range(len(s)):
if l[i] != -1:
t += s[i]
l = [0] * len(t)
for i in range(1, len(t)):
if t[i] == t[i - 1]:
if l[i - 1] == 0:
if i - 2 >= 0 and l[i - 2] == 1:
l[i] = -1
else:
l[i] = 1
ans = ""
for i in range(len(t)):
if l[i] != -1:
ans += t[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
given = input()
l = len(given)
typos = 0
yesno = [(1) for _ in range(l)]
i = -1
while i < l - 1:
i += 1
cur = given[i]
while i < l - 2 and cur == given[i + 1] == given[i + 2]:
i += 1
yesno[i] = 0
given = "".join([c for i, c in enumerate(given) if yesno[i] == 1])
l = len(given)
typos = 0
yesno = [(1) for _ in range(l)]
i = 0
while i < l - 3:
if given[i] == given[i + 1] and given[i + 2] == given[i + 3]:
yesno[i + 2] = 0
i += 3
else:
i += 1
print("".join([c for i, c in enumerate(given) if yesno[i] == 1]))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
c = 1
dic = {}
if len(s) == 1:
print(s)
else:
l = -1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
c += 1
if s[i] != s[i - 1]:
if c >= 2 and l >= 2:
l = 1
else:
l = c
c = 1
if l >= 2 and c >= 2:
dic[i] = 1
elif c > 2:
dic[i] = 1
ans = ""
for i in range(len(s)):
if i not in dic:
ans = ans + s[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = ""
for i in s:
if len(ans) >= 2 and i == ans[-1] and i == ans[-2]:
continue
if len(ans) >= 3 and i == ans[-1] and ans[-2] == ans[-3]:
continue
ans += i
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
a = list(input())
x = ""
t = 0
y = 1
while t != len(a):
if t == 0:
x += a[t]
else:
if a[t] == a[t - 1]:
y += 1
else:
x += a[t]
y = 1
t += 1
continue
if y > 2:
t += 1
continue
else:
x += a[t]
t += 1
ans = ""
x = list(x)
i = 0
d = []
while i != len(x):
if i == 0:
d.append(x[i])
i += 1
elif x[i] == x[i - 1]:
d[-1] += x[i]
i += 1
else:
d.append(x[i])
i += 1
i = 0
while i != len(d):
if i == 0:
ans += d[i]
i += 1
else:
if len(d[i - 1]) == 2:
if len(d[i]) == 2:
ans += d[i][0]
d[i] = d[i][0]
else:
ans += d[i]
else:
ans += d[i]
i += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
a = input()
n = len(a)
a += ";[-"
a = list(a)
stack = []
for i in range(n - 1, -1, -1):
if a[i] == a[i + 1] and a[i + 2] == a[i + 3]:
a[i + 1] = a[i + 2]
stack.append(i + 1)
if a[i] == a[i + 1] == a[i + 2]:
stack.append(i + 1)
for i in stack:
a[i] = ""
print("".join(a[:-3]))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
l = list(s)
l.append(1)
l1 = []
c1, c = 1, 1
for i in range(len(s)):
if l[i] == l[i + 1]:
c1 += 1
else:
l1.append([s[i], c1])
c1 = 1
n = len(l1)
i = 0
while n > i:
if i == n - 1:
if l1[i][1] >= 2:
print(l1[i][0] * 2, end="")
else:
print(l1[i][0])
exit()
if l1[i][1] == 1:
print(l1[i][0], end="")
elif l1[i][1] >= 2 and l1[i + 1][1] > 2:
print(l1[i][0] * 2, end="")
print(l1[i + 1][0], end="")
i += 1
elif l1[i][1] >= 2 and l1[i + 1][1] == 2:
print(l1[i][0] * 2, end="")
print(l1[i + 1][0], end="")
i += 1
elif l1[i][1] >= 2 and l1[i + 1][1] == 1:
print(l1[i][0] * 2, end="")
i += 1
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER STRING VAR NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER STRING VAR NUMBER IF VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER STRING VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = []
l = input()
c = 0
for i in l:
if len(s) == 0 or len(s) == 1:
s.append(i)
elif i == s[c - 1] == s[c - 2]:
continue
elif i == s[c - 1] and s[c - 2] == s[c - 3]:
continue
else:
s.append(i)
c = c + 1
print("".join(s))
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
ch = input()
verif = False
i = 0
n = len(ch)
ch = ch + " "
ch1 = ""
while i < n:
if ch[i] == ch[i + 1] and ch[i + 1] == ch[i + 2] and ch[i + 2] == ch[i + 3]:
k = 0
elif ch[i] == ch[i + 1] and ch[i + 1] == ch[i + 2] and verif == True:
ch1 += ch[i]
i = i + 2
verif = False
elif ch[i] == ch[i + 1] and ch[i + 1] == ch[i + 2]:
ch1 = ch1 + ch[i + 1] + ch[i + 2]
i = i + 2
verif = True
elif ch[i] == ch[i + 1] and verif == True:
ch1 = ch1 + ch[i]
i = i + 1
verif = False
elif ch[i] == ch[i + 1]:
ch1 = ch1 + ch[i] + ch[i + 1]
verif = True
i = i + 1
else:
ch1 = ch1 + ch[i]
verif = False
i = i + 1
print(ch1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR STRING WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = ""
last = ""
lcount = 0
for i in range(len(s)):
if last == "":
ans += s[i]
last = s[i]
lcount = 1
elif last == s[i]:
if lcount == 1:
ans += s[i]
lcount += 1
else:
continue
else:
ans += s[i]
last = s[i]
lcount = 1
last = ""
lcount = 0
result = ""
i = 0
flag = False
while i < len(ans) - 1:
if ans[i] != ans[i + 1]:
result += ans[i]
i += 1
flag = False
else:
if flag == False:
result += ans[i] + ans[i]
last = ans[i]
flag = True
else:
result += ans[i]
last = ans[i]
flag = False
i += 2
if i == len(ans) - 1:
result += ans[-1]
print(result)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
s = input()
n = len(s)
if n < 3:
print(s)
sys.exit(0)
s = list(s)
for i in range(2, n):
if s[i] == s[i - 1] and s[i - 1] == s[i - 2]:
s[i - 2] = -1
ans = []
for i in s:
if i != -1:
ans.append(i)
n = len(ans)
if n < 4:
print("".join(ans))
sys.exit(0)
for i in range(3, n):
if ans[i] == ans[i - 1] and ans[i - 2] == ans[i - 3]:
ans[i] = -1
s = ""
for i in ans:
if i != -1:
s += i
print(s)
|
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
temp = s[0]
c = 1
ans = ""
ans += temp
tempC = 0
for i in range(1, len(s)):
if len(ans) < 2:
ans += s[i]
elif ans[len(ans) - 1] == ans[len(ans) - 2] and ans[len(ans) - 1] == s[i]:
continue
elif len(ans) >= 3 and (
ans[len(ans) - 2] == ans[len(ans) - 3] and ans[len(ans) - 1] == s[i]
):
continue
else:
ans += s[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
class Node:
def __init__(self, value, i=0, previous=None, next=None):
self.value = value
self.i = i
self.previous = previous
self.next = next
class LL:
def __init__(self):
self.size = 0
self.start = None
def from_str(self, s):
self.start = Node(s[0])
node = self.start
for i, el in enumerate(s[1:]):
node.next = Node(el, i + 1, previous=node)
node = node.next
def __str__(self):
node = self.start
s = ""
while node:
s += node.value
node = node.next
return s
linkedlist = LL()
linkedlist.from_str(s)
if (
linkedlist.start is not None
and linkedlist.start.next is not None
and linkedlist.start.next.next is not None
):
node = linkedlist.start.next.next
else:
node = None
while node:
if node.previous.value == node.previous.previous.value == node.value:
node.previous.next = node.next
if node.next is not None:
node.next.previous = node.previous
elif (
node.previous.previous.previous is not None
and node.previous.previous.previous.value == node.previous.previous.value
and node.previous.value == node.value
):
node.previous.next = node.next
if node.next is not None:
node.next.previous = node.previous
node = node.next
print(linkedlist)
|
ASSIGN VAR FUNC_CALL VAR CLASS_DEF FUNC_DEF NUMBER NONE NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING WHILE VAR VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE VAR NONE ASSIGN VAR VAR ASSIGN VAR NONE WHILE VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NONE VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from itertools import groupby
s = input()
lst = list("".join(g) for _, g in groupby(s))
if len(lst) == 1:
if len(lst[0]) > 2:
lst[0] = lst[0][0] * 2
print(lst[0])
exit(0)
for i in range(len(lst) - 1):
if len(lst[i]) > 1:
if len(lst[i]) > 2:
lst[i] = lst[i][0] * 2
if len(lst[i + 1]) > 1:
lst[i + 1] = lst[i + 1][0]
if len(lst[len(lst) - 1]) > 2:
lst[len(lst) - 1] = lst[len(lst) - 1][0] * 2
s1 = ""
for i in range(len(lst)):
s1 += lst[i]
print(s1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def fixing(s, i, n, b):
t, k = s[i], i + 1
if not b and k < n and s[k] == s[i]:
t = t * 2
k += 1
while k < n and s[k] == s[i]:
k += 1
return k, t, len(t) > 1
def main():
s = list(input())
i, n, b = 0, len(s), False
w = ""
while i < n:
i, t, b = fixing(s, i, n, b)
w += t
print("".join(w))
main()
|
FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
n = len(s)
arr = []
for i in range(n):
arr.append(s[i])
for i in range(n - 2):
if arr[i] == arr[i + 1] == arr[i + 2]:
arr[i] = ""
arr1 = []
for i in arr:
if i != "":
arr1.append(i)
arr = arr1
n = len(arr)
for i in range(n - 3):
if arr[i] == arr[i + 1] and arr[i + 2] == arr[i + 3]:
arr[i + 2] = ""
for i in arr:
print(i, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
if s.count("a") == len(s):
s = "a" * 2
else:
for i in range(len(s)):
if len(s) < i + 3:
break
if s[i] == s[i + 1] and s[i + 2] == s[i + 1]:
del s[i]
ans = ""
for ch in range(len(s)):
if len(ans) >= 2:
if (
s[ch] == ans[-1]
and ans[-2] == s[ch]
or s[ch] == ans[-1]
and ans[len(ans) - 2] == ans[len(ans) - 3]
):
pass
else:
ans = ans + s[ch]
else:
ans = ans + s[ch]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
res = ""
for ch in s:
ok = True
if len(res) >= 2:
if ch == res[-1] and res[-1] == res[-2]:
ok = False
if len(res) >= 3:
if ch == res[-1] and res[-2] == res[-3]:
ok = False
if ok:
res += ch
print(res)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
x = input()
n = len(x)
s = ""
if n < 3:
print(x)
else:
for i in range(2):
s += x[i]
for i in range(2, n):
if x[i] == s[-1] == s[-2]:
pass
else:
s += x[i]
n = len(s)
inc = [1]
dp = [False]
if n > 1:
if s[1] == s[0]:
dp.append(True)
inc.append(1)
else:
dp.append(False)
inc.append(1)
for i in range(2, n):
if s[i] == s[i - 1]:
dp.append(True)
if dp[i - 1] == True or dp[i - 2] == True:
inc.append(0)
if s[i - 1] != s[i] or s[i - 1] != s[i - 2]:
dp[-1] = False
else:
inc.append(1)
else:
dp.append(False)
inc.append(1)
ans = ""
for i in range(n):
if inc[i] == 1:
ans += s[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def correct(A):
a = A[0]
B = [A[0]]
C = [1]
c = 0
for i in range(1, len(A)):
if A[i] == a:
C[c] = C[c] + 1
else:
B.append(A[i])
C.append(1)
a = A[i]
c = c + 1
correctto(B, C)
def correctto(B, C):
if C[0] > 2:
C[0] = 2
for i in range(1, len(B)):
if C[i] > 2:
C[i] = 2
if C[i - 1] == 2:
C[i] = 1
A = []
for i in range(len(B)):
for c in range(C[i]):
A.append(B[i])
print("".join(A))
n = input()
correct(list(n))
|
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = [".", "@", "%"]
for i in input():
if s[-1] == i and (s[-2] == i or s[-2] == s[-3]):
s.pop()
s.append(i)
print("".join(s[3:]))
|
ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def main():
x = input()
x += "0"
curPlat = 0
lastPlat = 0
lastVal = 0
for c in x:
if c == lastVal:
curPlat += 1
else:
if curPlat >= 3:
curPlat = 2
if lastPlat >= 2:
curPlat = 1
for i in range(curPlat):
print(lastVal, end="")
lastPlat = curPlat
curPlat = 1
lastVal = c
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from sys import stdin, stdout
def main(s):
segs = []
cur = [0, 0, s[0]]
for i, c in enumerate(s[1:]):
if cur[2] != c:
segs.append(cur)
cur = [i, i, c]
prev = c
else:
cur[1] += 1
segs.append(cur)
for seg in segs:
if seg[1] - seg[0] + 1 > 2:
seg[1] = seg[0] + 1
for i in range(len(segs) - 1):
sega = segs[i]
segb = segs[i + 1]
if sega[1] - sega[0] + 1 == 2 and segb[1] - segb[0] + 1 == 2:
segb[1] = segb[0]
for seg in segs:
stdout.write("{}".format(seg[2] * (seg[1] - seg[0] + 1)))
stdout.write("\n")
main(stdin.readline().strip())
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
count = 0
startIndex = 0
hasDuplicates = False
printWord = ""
doubleTest = ""
word = input()
for i in range(len(word)):
if word[i] == doubleTest:
if count < 2 and hasDuplicates == False:
printWord += word[i]
doubleTest = word[i]
count += 1
else:
if count > 1:
hasDuplicates = True
if count == 1:
hasDuplicates = False
count = 1
printWord += word[i]
doubleTest = word[i]
print(printWord)
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
l = []
if len(s) <= 2:
print("".join(s))
elif len(s) == 3:
if s[0] == s[1] == s[2]:
s = s[:2]
print("".join(s))
else:
c = 0
l.append(s[0])
l.append(s[1])
c += 2
if l[0] == l[1] == s[2]:
pass
else:
l.append(s[2])
c += 1
for i in range(3, len(s)):
if s[i] != l[-1]:
l.append(s[i])
c += 1
elif l[-1] == l[-2] == s[i]:
pass
elif c >= 3 and l[-2] == l[-3] and s[i] == l[-1]:
pass
else:
l.append(s[i])
c += 1
print("".join(l))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
string = list(input())
z = len(string)
cnt = 0
flag = False
while cnt < z - 2:
if string[cnt] == string[cnt + 1] == string[cnt + 2]:
string[cnt] = ""
cnt += 1
cnt = 0
string = [x for x in string if x != ""]
try:
while cnt < z - 2:
if string[cnt] == string[cnt + 1] and string[cnt + 2] == string[cnt + 3]:
string[cnt + 2] = ""
cnt += 1
except IndexError:
pass
print(*string, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR STRING WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
str = input()
arr, cur = len(str) * [0], 0
for i in range(len(str)):
if str[i - cur] == str[i]:
cur += 1
else:
cur = 1
arr[i - cur + 1] = cur
flag, it, i = 0, 0, 0
while i < len(str):
it = arr[i]
if arr[i] > 1 and not flag:
flag = 1
else:
if arr[i] > 1:
arr[i] = 1
flag = 0
i += it
for i in range(len(str)):
arr[i] = min(arr[i], 2)
ret = ""
i = 0
while i < len(str):
for j in range(arr[i]):
ret += str[i]
i += max(1, arr[i])
print(ret)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
count = 1
prevCount = 1
stack = [s[0]]
for i in range(1, len(s)):
if s[i] == s[i - 1]:
count += 1
else:
prevCount = count
count = 1
if count == 2 and prevCount >= 2:
count = 1
continue
elif count >= 3:
continue
else:
stack.append(s[i])
print("".join(stack))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def main():
c = input()
c = list(c)
v = c[0]
k = 1
for i in range(1, len(c)):
if v == c[i]:
k += 1
if k > 2:
c[i] = " "
else:
v = c[i]
k = 1
c = [i for i in c if i != " "]
for i in range(len(c) - 1):
if c[i] == c[i + 1]:
if i + 3 < len(c) and c[i + 2] == c[i + 3]:
c[i + 3] = " "
c = [i for i in c if i != " "]
return c
print("".join(main()))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR VAR VAR STRING RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
l = list(input())
n = len(l)
i = 0
while i < n:
if i + 2 < n and l[i] == l[i + 2] and l[i] == l[i + 1] and l[i] != ".":
l[i] = "."
i += 1
l = [i for i in l if i != "."]
i = 0
n = len(l)
while i < n:
if (
i + 3 < n
and l[i] == l[i + 1]
and l[i + 2] == l[i + 3]
and l[i] != l[i + 2]
and l[i] != "."
):
l[i + 2] = "."
i += 2
i += 1
l = [i for i in l if i != "."]
print("".join(l))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
x = 0
l1 = []
c = 0
for i in range(0, len(s)):
if i == 0:
l1.append(s[i])
c = 1
f = s[0]
elif c < 2:
l1.append(s[i])
if s[i] == f:
c += 1
else:
f = s[i]
c = 1
elif s[i] == f:
c += 1
else:
l1.append(s[i])
f = s[i]
c = 1
c = 0
flag = 0
l2 = []
for i in range(0, len(l1)):
if flag == 0:
l2.append(l1[i])
if c == 0:
c = 1
f = l1[i]
elif l1[i] == f:
c = 2
flag = 1
else:
c = 1
f = l1[i]
elif c == 2:
x = l1[i]
c -= 1
l2.append(l1[i])
elif l1[i] == x:
c = 0
flag = 0
else:
l2.append(l1[i])
f = l1[i]
c = 1
flag = 0
print("".join(l2))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = str(input())
i = 0
n = len(s)
p = ""
while i < n:
x = True
k = len(p)
if k > 1 and p[-1] == p[-2] and p[-1] == s[i]:
x = False
elif k > 2 and p[-3] == p[-2] and p[-1] == s[i]:
x = False
if x:
p += s[i]
i += 1
print(p)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = []
for i in range(len(s)):
if i > 1:
if s[i] == ans[-1] and ans[-2] == ans[-1]:
continue
if i > 2:
if s[i] == ans[-1] and ans[-2] == ans[-3]:
continue
ans.append(s[i])
print(*ans, sep="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
strs = input()
arr = []
prev = ""
count = 0
strsarr = []
for i in strs:
if i != prev:
arr.append(count)
strsarr.append(prev)
prev = i
count = 1
else:
count += 1
arr.pop(0)
arr.append(count)
strsarr.append(i)
strsarr.pop(0)
ans = ""
n = len(arr)
flag = 0
ans = []
for i, j in enumerate(arr):
if flag == 1:
flag = 0
elif j == 1:
ans.append(strsarr[i])
elif j >= 3 and i + 1 != n and arr[i + 1] >= 2:
ans.append(strsarr[i])
ans.append(strsarr[i])
ans.append(strsarr[i + 1])
flag = 1
elif j >= 3:
ans.append(strsarr[i])
ans.append(strsarr[i])
elif j == 2 and i + 1 != n and arr[i + 1] >= 2:
ans.append(strsarr[i])
ans.append(strsarr[i])
ans.append(strsarr[i + 1])
flag = 1
else:
for times in range(j):
ans.append(strsarr[i])
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
res = []
n = len(s)
i = 0
prevTwo = False
while i < n:
cnt = 0
curr = s[i]
while i < n and s[i] == curr:
i += 1
cnt += 1
if prevTwo:
prevTwo = False
res.append(curr)
else:
prevTwo = True if cnt > 1 else False
res.append(curr * min(cnt, 2))
print("".join(res))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def go():
o = ""
for c in input():
if len(o) > 2 and o[-1] == c and o[-2] == o[-3]:
continue
if len(o) > 1 and o[-2] == o[-1] == c:
continue
o += c
return o
print(go())
|
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
class GoodString:
def __init__(self):
self.string = []
self.prev = []
self.current = []
def appendChar(self, char):
if len(self.current) == 0:
self.current.append(char)
elif self.current[-1] != char:
for ii in range(len(self.prev)):
self.string.append(self.prev[ii])
self.prev = self.current
self.current = [char]
elif len(self.current) == 2:
pass
elif len(self.prev) == 2:
pass
else:
self.current.append(char)
def getString(self):
return [self.string, self.prev, self.current]
def main():
string = input()
goodString = GoodString()
for i in range(len(string)):
goodString.appendChar(string[i])
sol = goodString.getString()
for i in range(len(sol)):
for j in range(len(sol[i])):
print(sol[i][j], end="")
main()
|
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN LIST VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
a = []
k = 0
for i in range(0, len(s)):
if i == len(s) - 1:
if k >= 1:
a.append(s[i])
a.append(s[i])
k = 0
continue
a.append(s[i])
continue
if s[i] == s[i + 1]:
k = k + 1
continue
if k >= 1:
a.append(s[i])
a.append(s[i])
k = 0
continue
a.append(s[i])
b = []
i = 0
while i < len(a) - 3:
if a[i] == a[i + 1] and a[i + 2] == a[i + 3]:
b.append(a[i])
b.append(a[i + 1])
b.append(a[i + 2])
i = i + 4
continue
b.append(a[i])
i = i + 1
h = i
for j in a[h:]:
b.append(j)
ans = ""
ans = ans.join(b)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
n = len(s)
if n == 1:
t = s
else:
t = s[0] + s[1]
i = 2
j = 1
while i < n:
if s[i] == t[j] and s[i] == t[j - 1]:
i += 1
continue
elif s[i] == t[j] and j > 1 and t[j - 1] == t[j - 2]:
i += 1
continue
else:
t += s[i]
i += 1
j += 1
print(t)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
sys.setrecursionlimit(10**8)
try:
FILE_POINTER = open("input.inpt")
input = FILE_POINTER.readline
except:
FILE_POINTER = None
input = sys.stdin.readline
s = input().strip()
ans = s[0]
cnt = 1
n = len(s)
for i in range(1, n):
if s[i] == s[i - 1]:
if cnt == 1:
ans += s[i]
cnt += 1
else:
ans += s[i]
cnt = 1
final = list(ans)
n = len(final)
c1, c2, n1, n2 = 0, 1, 2, 3
while c1 < n and c2 < n and n1 < n and n2 < n:
if final[c1] == final[c2] and final[n1] == final[n2]:
final[n2] = -1
c1 += 4
c2 += 4
n1 += 4
n2 += 4
else:
c1 += 1
c2 += 1
n1 += 1
n2 += 1
print("".join([i for i in final if i != -1]))
if FILE_POINTER:
FILE_POINTER.close()
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def readln():
return tuple(map(int, input().split()))
cnt = []
for s in list(input() + "#"):
if cnt == [] or cnt[-1][0] != s:
cnt.append([s, 1])
else:
cnt[-1][1] += 1
ans = []
tmp = []
for s, c in cnt:
if c == 1:
for _ in range(len(tmp)):
if _ % 2 == 0:
ans.append(tmp[_] * 2)
else:
ans.append(tmp[_])
ans.append(s)
tmp = []
else:
tmp.append(s)
print("".join(ans[:-1]))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING IF VAR LIST VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def main():
s, l, z = input(), [], False
a, b, f = "", s[0], l.append
u = v = 0
for s in (s, "+-"):
for c in s:
if b == c:
v += 1
else:
if z:
z = False
elif u > 1:
z = True
f(a)
f(a)
u, v, a, b = v, 1, b, c
print("".join(l))
main()
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR VAR STRING VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR STRING FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
__author__ = "Alex"
s = input().strip()
cur = "#"
cnt = 0
pd = False
ans = []
for x in s:
if x != cur:
cnt = 0
cur = x
cnt += 1
if cnt == 3:
cnt -= 1
else:
ans.append(x)
cur = "#"
cnt = 0
s = ans
ans = []
for x in s:
if x != cur:
if cnt != 2:
pd = False
cnt = 0
cur = x
cnt += 1
if not (cnt == 2 and pd):
ans.append(x)
else:
pd = False
cnt -= 1
if cnt == 2 and not pd:
pd = True
print("".join(ans))
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
a = list(input())
b = []
c = 1
for i in range(1, len(a)):
if a[i] == a[i - 1]:
c += 1
else:
b.append(c)
c = 1
b.append(c)
for i in range(len(b)):
if b[i] > 2:
b[i] = 2
for i in range(1, len(b)):
if b[i] == 2 and b[i] == b[i - 1]:
b[i] = 1
s = ""
s += a[0]
for i in range(1, len(a)):
if a[i] != a[i - 1]:
s += a[i]
res = ""
for i in range(len(b)):
for j in range(b[i]):
res += s[i]
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
def check(a1, a2, ans):
s = ""
c1 = c2 = c3 = None
c1 = ans[-1]
c2 = ans[-2]
if len(ans) >= 3:
c3 = ans[-3]
else:
c3 = None
if c1 == c2:
if c1 == a1 and c1 == a2:
return []
elif c1 == a1 and c1 != a2:
return [a2]
elif a1 == a2:
return [a1]
else:
return [a1, a2]
elif c2 == c3:
if c1 == a1 and c1 == a2:
return []
elif c1 == a1 and c1 != a2:
return [a2]
else:
return [a1, a2]
elif c1 == a1 == a2:
return [a1]
else:
return [a1, a2]
if len(s) <= 2:
print(s)
elif len(s) == 3:
if s[0] == s[1] == s[2]:
print(s[:2])
else:
print(s)
else:
i = 2
ans = []
ans.append(s[0])
ans.append(s[1])
while i <= len(s) - 1:
c1 = s[i]
if i + 1 <= len(s) - 1:
c2 = s[i + 1]
else:
c2 = ""
ans += check(c1, c2, ans)
i += 2
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NONE IF VAR VAR IF VAR VAR VAR VAR RETURN LIST IF VAR VAR VAR VAR RETURN LIST VAR IF VAR VAR RETURN LIST VAR RETURN LIST VAR VAR IF VAR VAR IF VAR VAR VAR VAR RETURN LIST IF VAR VAR VAR VAR RETURN LIST VAR RETURN LIST VAR VAR IF VAR VAR VAR RETURN LIST VAR RETURN LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
i = 0
n = len(s)
ans = ""
while i < n:
curr = 0
start = i
while i < n and s[start] == s[i]:
i += 1
curr += 1
if curr > 2:
ans += 2 * s[start]
else:
ans += curr * s[start]
n = len(ans)
res = ""
i = 0
while i < n:
if i + 3 >= n:
res += ans[i:]
break
if ans[i] == ans[i + 1] and ans[i + 2] == ans[i + 3]:
res += ans[i : i + 3]
i += 4
else:
res += ans[i]
i += 1
print(res)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
word = input()
solution = [word[0]]
state = 0
for pos in range(1, len(word)):
if state == 0:
solution.append(word[pos])
if word[pos] == word[pos - 1]:
state = 1
elif state == 1:
if word[pos] != word[pos - 1]:
state = 2
solution.append(word[pos])
elif word[pos] != word[pos - 1]:
state = 0
solution.append(word[pos])
print("".join(solution))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
ans = s[:2]
for i in range(2, len(s)):
if s[i] == ans[len(ans) - 1] and s[i] == ans[len(ans) - 2]:
continue
elif (
len(ans) > 2
and s[i] == ans[len(ans) - 1]
and ans[len(ans) - 2] == ans[len(ans) - 3]
):
continue
else:
ans += s[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
def fun(s):
cnt = 1
ans = []
cas = []
num = []
for i in range(len(s)):
if i == 0:
flag = s[i]
continue
if s[i] != s[i - 1]:
cas.append(s[i - 1])
if cnt > 1:
ans.append(s[i - 1] + s[i - 1])
num.append(2)
cnt = 1
else:
ans.append(s[i - 1])
num.append(1)
else:
cnt += 1
if i == len(s) - 1:
cas.append(s[i])
if cnt > 1:
num.append(2)
ans.append(s[i] + s[i])
else:
num.append(1)
ans.append(s[i])
for i in range(1, len(num)):
if num[i] > 1 and num[i - 1] > 1:
ans[i] = cas[i]
num[i] -= 1
print("".join(ans))
s = list(input())
if len(s) > 1:
fun(s)
else:
print("".join(s))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
s1 = ""
count = 0
prev = 0
for i in range(len(s) - 1):
if s[i] == s[i + 1]:
count += 1
if count == 1:
s1 += s[i]
elif count >= 1 and prev == 0:
s1 += s[i]
prev = 1
count = 0
elif count == 0:
s1 += s[i]
prev = 0
count = 0
else:
count = 0
prev = 0
if len(s) == 1:
s1 += s[0]
elif s[-1] != s[-2]:
s1 += s[-1]
elif count >= 1 and prev == 0:
s1 += s[-1]
print(s1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
t = ""
for i in range(len(s)):
if len(t) >= 2 and s[i] == t[-1]:
if t[-2] != t[-1]:
t += s[i]
else:
t += s[i]
ans = ""
i = 0
t += " "
while i < len(t) - 3:
if t[i] == t[i + 1] and t[i + 2] == t[i + 3]:
ans += t[i]
ans += t[i + 1]
ans += t[i + 2]
i += 3
else:
ans += t[i]
i += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR STRING WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
string = list(input())
ans = []
prev_cnt, cnt = 1, 1
for i, ch in enumerate(string):
if i > 0:
if string[i - 1] == ch:
cnt += 1
else:
if cnt == 1:
ans.append(string[i - 1])
elif cnt == 2 or cnt >= 3:
ans.append(string[i - 1])
ans.append(string[i - 1])
cnt = 2
if cnt > 1 and prev_cnt == 2:
ans.pop()
cnt = 1
prev_cnt = cnt
cnt = 1
ch = string[-1]
if cnt == 1:
ans.append(ch)
elif cnt == 2 or cnt >= 3:
ans.append(ch)
ans.append(ch)
if cnt > 1 and prev_cnt >= 2:
ans.pop()
ans = "".join(ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
n = input()
l = len(n)
if l < 3:
print(n)
else:
s = "-" + n[:2]
i = 2
while i < l:
a = s[-3]
b = s[-2]
c = s[-1]
if c == n[i]:
if b == c or a == b:
i += 1
else:
s += n[i]
i += 1
else:
s += n[i]
i += 1
print(s[1:])
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = [*input()]
c = [0] * len(s)
i = 0
z = 0
while i < len(s):
j = i
t = j
while t < len(s) and s[j] == s[t]:
c[i] += 1
t += 1
y = c[i]
while c[i] > 2 or z == 2 and z == c[i]:
s[j] = " "
c[i] -= 1
j += 1
z = c[i]
i += y
for i in s:
if i != " ":
print(i, end="")
|
ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR STRING VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
n = len(s)
flag = 0
for i in range(1, n):
if s[i] == s[i - 1] and flag == 0:
flag = 1
elif s[i] == s[i - 1] and (flag == 1 or flag == 3):
s[i - 1] = ""
elif s[i] != s[i - 1] and (flag == 1 or flag == 3):
if flag == 3:
flag = 0
else:
flag = 2
elif s[i] != s[i - 1] and flag == 2:
flag = 0
elif s[i] == s[i - 1] and flag == 2:
s[i - 1] = ""
flag = 3
print(*s, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
t, p = input(), []
n, k, x = 0, True, t[0]
for i in t[1:] + " ":
if i == x:
n += 1
else:
if n and k:
p += [x, x]
k = False
else:
p.append(x)
k = True
x, n = i, 0
print("".join(p))
|
ASSIGN VAR VAR FUNC_CALL VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR NUMBER IF VAR VAR VAR LIST VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
a = []
if len(s) < 3:
print(s)
else:
for i in s:
if i not in a:
a.append(i)
elif len(a) >= 3:
if a[-1] == i and a[-2] == i:
continue
elif a[-1] == i and a[-2] == a[-3]:
continue
else:
a.append(i)
elif len(a) >= 2:
if a[-1] == i and a[-2] == i:
continue
else:
a.append(i)
else:
a.append(i)
print("".join(a))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
if len(set(s)) == 1:
print(s[0] * min(len(s), 2))
exit()
n = len(s)
lis = []
c = 1
for i in range(1, n):
if s[i] == s[i - 1]:
c += 1
else:
lis.append([s[i - 1], c])
c = 1
lis.append([s[-1], c])
a = len(lis)
ans = ""
ans += min(lis[0][1], 2) * lis[0][0] + min(lis[1][1], 2) * lis[1][0]
if len(ans) == 4:
ans = ans[:3]
lis[1][1] = 1
else:
lis[1][1] = min(lis[1][1], 2)
for i in range(2, len(lis)):
if lis[i][1] > 1:
if lis[i - 1][1] == 2:
ans += lis[i][0]
lis[i][1] = 1
else:
ans += min(lis[i][1], 2) * lis[i][0]
lis[i][1] = min(lis[i][1], 2)
elif lis[i - 1][1] == 2:
ans += lis[i][0]
lis[i][0] = 1
else:
ans += min(lis[i][1], 2) * lis[i][0]
lis[i][1] = min(lis[i][1], 2)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
import sys
input = sys.stdin.readline
def solve():
r = []
for c in input().strip():
r.append(c)
while True:
if len(r) > 2 and r[-1] == r[-2] and r[-1] == r[-3]:
r.pop()
elif len(r) > 3 and r[-1] == r[-2] and r[-3] == r[-4]:
r.pop()
else:
break
print("".join(r))
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input()
r = []
s += "8"
c = 0
k = []
for i in range(len(s) - 1):
c += 1
if s[i] != s[i + 1]:
k.append(s[i])
if c > 2:
c = 2
r.append(c)
c = 0
for i in range(1, len(r)):
if r[i] == 2 and r[i - 1] == 2:
r[i] = 1
for i in range(len(k)):
print(k[i] * r[i], end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = input().strip()
stack = []
for i in range(len(s)):
if len(stack) == 0:
stack.append([s[i], 1])
elif len(stack) == 1:
if stack[-1][0] == s[i]:
stack.append([s[i], 2])
else:
stack.append([s[i], 1])
elif s[i] == stack[-1][0] and stack[-1][1] == 1 and stack[-2][1] < 2:
stack.append([s[i], 2])
elif s[i] != stack[-1][0]:
stack.append([s[i], 1])
for i in stack:
print(i[0], end="")
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = list(input())
c = 1
last = s[0]
dele = []
for i in range(1, len(s)):
if s[i] == last:
c += 1
if c >= 3:
dele.append(i)
else:
last = s[i]
c = 1
for ind in dele[::-1]:
del s[ind]
dele = []
cc = 0
c = 0
last = ""
bre = 0
for i in range(len(s)):
if s[i] == last:
bre = 0
c += 1
if c == 2:
cc += 1
if cc == 2:
dele.append(i)
cc = 0
else:
if bre:
cc = 0
last = s[i]
c = 1
bre = 1
for ind in dele[::-1]:
del s[ind]
print("".join(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
from sys import stdin, stdout
def solve():
s = stdin.readline().strip()
res = s[0]
rep = 1
previous_rep = 0
for i in range(1, len(s)):
if s[i] == s[i - 1]:
if rep >= (1 if previous_rep else 2):
continue
else:
rep += 1
else:
previous_rep = True if rep > 1 else False
rep = 1
res += s[i]
print(res)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
infile = __file__.split(".")[0] + "-test.in"
stdin = open(infile, "r")
tcs = int(stdin.readline()) if LOCAL_TEST else 1
t = 1
while t <= tcs:
solve()
t += 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
-----Input-----
The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.
-----Output-----
Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.
If there are multiple solutions, print any of them.
-----Examples-----
Input
helloo
Output
hello
Input
woooooow
Output
woow
-----Note-----
The second valid answer to the test from the statement is "heloo".
|
s = [i for i in input()]
moved = True
while moved:
moved = False
for i in range(len(s) - 3, -1, -1):
if s[i] == s[i + 1] and s[i] == s[i + 2] and s[i + 1] == s[i + 2]:
s.pop(i + 1)
moved = True
i = len(s) - 4
while i >= 0:
if s[i] == s[i + 1] and s[i + 2] == s[i + 3]:
s.pop(i + 1)
moved = True
i -= 1
print("".join(s))
|
ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.