n=int(input())
str=list(input())
result=0
k=0
t=0
while(k<int(n/2)):
if t==2: #出现了2个匹配不到的情况
print("Impossible")
exit()
temp = 0
for i in range(n-k-1-t,k,-1):
if str[i]==str[k]:
result+=(n-i-k-1)
str.pop(i)
k+=1
temp=1 #标记已经找到了相同的
break
if temp==0 and n%2==0:
print("Impossible")
exit()
if temp==0 :
str.pop(k)
t+=1
print(result)
蓝桥杯BASIC-19完美的代价——python
最新推荐文章于 2023-03-02 11:36:18 发布