Problem:


Score : 1500 points

Problem Statement

Given is a string S consisting of A,B, and C.

Consider the (not necessarily contiguous) subsequences x of S that satisfy all of the following conditions:

A, B, and C all occur the same number of times in x.

No two adjacent characters in x are the same.

Among these subsequences, find one of the longest. Here a subsequence of S is a string obtained by deleting zero or more characters from S.

Constraints

1 \leq |S| \leq 10^6

S consists of A,B, and C.

Input

Input is given from Standard Input in the following format:

S

Output

Print one longest subsequence that satisfies the conditions.
If multiple solutions exist, any of them will be accepted.

Sample Input 1

ABBCBCAB

Sample Output 1

ACBCAB

Consider the subsequence ACBCAB of S. It satisfies the conditions and is one of the longest with these properties, along with ABCBCA.
On the other hand, the subsequences ABCBCAB and ABBCCA do not satisfy the conditions.

Sample Input 2

ABABABABACACACAC

Sample Output 2

BABCAC

Sample Input 3

ABCABACBCBABABACBCBCBCBCBCAB

Sample Output 3

ACABACABABACBCBCBCBCA

Sample Input 4

AAA

Sample Output 4

It is possible that only the empty string satisfies the condition.



Sample input:
ABBCBCAB


Sample output:
ACBCAB

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':
    string = input()
    result = []
    for s in string.split():
        if result[-2:] == 'AA' or 'BB' or 'CC':
            result = []
        else:
            result.append(s)
    print(result)

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':
    string = input()
    result = []
    for s in string.split():
        if result[-2:] == 'AA' or 'BB' or 'CC':
            result = []
        else:
            result.append(s)

Submission status: Wrong Answer

Solution code:
s=input()
a=0
b=0
c=0
for i in range(len(s)):
	if s[i]=='A':
		a=a+1
	if s[i]=='B':
		b=b+1
	if s[i]=='C':
		c=c+1

little=0



if a<=b:
	if a<=c:
		little=a
	if a>=c:
		little=c
else:
	if b<=c:
		little=b
	if b>=c:
		little=c


dl=''

for i in range(little):
	dl=''+dl+'ABC'
print(dl)

Submission status: Wrong Answer

Solution code:
s=input()
ch=s[0]
for i in range(1,len(s)):
    if ch !="":
        if s[i] != ch[len(ch)-1]:
            ch+=s[i]
        else:
            ch=ch[0:len(ch)-1]
    else:
        ch=s[i]
print(ch)

Submission status: Wrong Answer

Solution code:
import collections
s = [s for s in input()]
t = s[0]
i = 1
while len(s) > i:
	tmp = s
	if t == s[i]:
		tmp = s[:i]+s[i+1:]
	t = s[i]
	s = tmp
	i+=1
c = collections.Counter(s)
m = min(c.values())
if m == 0:
	print("")
	exit()
mA = m
mB = m
mC = m
for i in range(len(s)):
	if s[i] == "A":
		if mA > 0:
			print(s[i],end="")
			mA-=1
	elif s[i] == "B":
		if mB > 0:
			print(s[i],end="")
			mB-=1
	elif s[i] == "C":
		if mC > 0:
			print(s[i],end="")
			mC-=1
print("")

Submission status: Wrong Answer

Solution code:
import collections
s = [s for s in input()]
t = s[0]
i = 1
while len(s) > i:
	tmp = s
	if t == s[i]:
		tmp = s[:i]+s[i+1:]
	t = s[i]
	s = tmp
	i+=1
c = collections.Counter(s)
m = min(c.values())
mA = m
mB = m
mC = m
for i in range(len(s)):
	if s[i] == "A":
		if mA > 0:
			print(s[i],end="")
			mA-=1
	elif s[i] == "B":
		if mB > 0:
			print(s[i],end="")
			mB-=1
	elif s[i] == "C":
		if mC > 0:
			print(s[i],end="")
			mC-=1
print("")

Submission status: Wrong Answer

Solution code:
import collections
s = [s for s in input()]
t = s[0]
i = 1
while len(s) > i:
	tmp = s
	if t == s[i]:
		tmp = s[:i]+s[i+1:]
	t = s[i]
	s = tmp
	i+=1
c = collections.Counter(s)
m = min(c.values())
mA = m
mB = m
mC = m
for i in range(len(s)):
	if s[i] == "A":
		if mA > 0:
			print(s[i],end="")
			mA-=1
	elif s[i] == "B":
		if mB > 0:
			print(s[i],end="")
			mB-=1
	elif s[i] == "C":
		if mC > 0:
			print(s[i],end="")
			mC-=1

Submission status: Wrong Answer

Solution code:
import re
s=input()
rgxa=re.compile(r'A{2,}')
rgxb=re.compile(r'B{2,}')
rgxc=re.compile(r'C{2,}')
s = re.sub(rgxa,'A',s)
s = re.sub(rgxb,'B',s)
s = re.sub(rgxc,'C',s)
na = s.count('A')
nb = s.count('B')
nc = s.count('C')
while not na==nb==nc:
  if max(na,nb,nc) == na:
    if 'BAC' in s:
      s = s.replace('BAC','BC',1)
      na -= 1
    elif 'CAB' in s:
      s = s.replace('CAB','CB',1)
      na -=1
  if max(na,nb,nc) == nb:
    if 'ABC' in s:
      s = s.replace('ABC','AC',1)
      nb -= 1
    elif 'CBA' in s:
      s = s.replace('CBA','CA',1)
      nb -=1
  if max(na,nb,nc) == nc:
    if 'ACB' in s:
      s = s.replace('ACB','AB',1)
      nc -= 1
    elif 'BCA' in s:
      s = s.replace('BCA','BA',1)
      nc -=1
print(s)

Submission status: Wrong Answer

Solution code:
import collections
s = [s for s in input()]
t = s[0]
i = 1
while len(s) > i:
	tmp = s
	if t == s[i]:
		tmp = s[:i]+s[i+1:]
	t = s[i]
	s = tmp
	i+=1
c = collections.Counter(s)
m = 10*6
ANS = ""
for k in "ABC":
	if m < c[k]:
		m = c[k]
		ANS=k

mA = m
mB = m
mC = m
for i in range(len(s)):
	if s[i] == "A":
		if mA != 0:
			print(s[i],end="")
			mA-=1
	elif s[i] == "B":
		if mB != 0:
			print(s[i],end="")
			mB-=1
	elif s[i] == "C":
		if mC != 0:
			print(s[i],end="")
			mC-=1

Submission status: Wrong Answer

Solution code:
s=[]
print(s)

Submission status: Wrong Answer

Solution code:
s=input()
a=[0,0,0,0,0,0,0,0,0]
b=['A','B','C','A','B','C','A','B','C']
c=0
s.replace('AA', 'A')
s.replace('BB', 'B')
s.replace('CC', 'C')
a[0]=s.count('A')
a[1]=s.count('B')
a[2]=s.count('C')
while a[0]!=a[1] or a[1]!=a[2]:
  m=a.index(max(a[0],a[1],a[2]))+3
  for i in range(m):
    if c%2==1:
      s.replace(b[m-1]+b[m]+b[m+1],b[m-1]+b[m+1])
      c=c+1
    else:
      s.replace(b[m+1]+b[m]+b[m-1],b[m+1]+b[m-1])
      c=c+1
  s.replace('AA', 'A')
  s.replace('BB', 'B')
  s.replace('CC', 'C')
  a[0]=s.count('A')
  a[1]=s.count('B')
  a[2]=s.count('C')
  if a[0]==0 or a[1]==0 or a[2] ==0:
    s=[]
    break
print(s)

Submission status: Wrong Answer

Solution code:
abc = "ABC"
acb = "ACB"
bac = "BAC"
bca = "BCA"
cab = "CAB"
cba = "CBA"
aabbcc = [abc, acb, bac, bca, cab, cba]
inds = []
notinds = []
S = str(input())
char = []
for i in aabbcc:
    ind = S.find(i)
    if ind > 0:
        if ind not in inds:
            inds.append(ind)
            inds.append(ind+1)
            inds.append(ind+2)
for i in range(len(S)):
    if i not in inds:
        notinds.append(i)
for i in S:
    char.append(i)
notinds.sort()
notinds.reverse()
for i in notinds:
    del char[i]
answer = "".join(char)
print(answer)