gym100971



Mihahim has a string s. He wants to delete exactly one character from it so that the resulting string would be a palindrome. Determine if he can do it, and if he can, what character should be deleted.

Input

The input contains a string s of length (2 ≤ |s| ≤ 200000), consisting of lowercase Latin letters.

Output

If the solution exists, output «YES» (without quotes) in the first line. Then in the second line output a single integer x — the number of the character that should be removed from s so that the resulting string would be a palindrome. The characters in the string are numbered from 1. If there are several possible solutions, output any of them.

If the solution doesn't exist, output «NO» (without quotes).

Example
Input
evertree
Output
YES
2
Input
emerald
Output
NO
Input
aa
Output
YES
2
给你一个串然后问你删除一个字符能不能形成回文串
ac代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char a[1000005];
int main()
{
    while(gets(a))
    {
       int len=strlen(a);
       int sum=0;
       int p=0,q=len-1;
       int k;
       while(p<=q)
       {
           if(a[p]==a[q])
           {
               p++;q--;
           }
           else
           {
               sum++;
               int sum1=0,sum2=0;
               int r=p,t=q-1;
               while(r<=t)
               {
                   if(a[r]==a[t])
                   {
                       r++;t--;
                   }
                   else
                   {
                       sum1++;break;
                   }
               }
               r=p+1;t=q;
               while(r<=t)
               {
                  if(a[r]==a[t])
                   {
                       r++;t--;
                   }
                   else
                   {
                       sum2++;break;
                   }
               }
               sum+=min(sum1,sum2);
               if(sum1>sum2)
               k=p;
               else
               k=q;
               break;
           }
       }
       if(sum==0)
       {
           printf("YES\n");
           printf("%d\n",len/2+1);
       }
       if(sum==1)
       {
           printf("YES\n");
           printf("%d\n",k+1);
       }
       if(sum==2)
       printf("NO\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值