gym100971

来源:互联网 发布:java怎么反序列化 编辑:程序博客网 时间:2024/05/18 17:01


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 integerx — the number of the character that should be removed froms 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
YES2
Input
emerald
Output
NO
Input
aa
Output
YES2
给你一个串然后问你删除一个字符能不能形成回文串
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;}