fork download
  1. //Bismillahir Rahmanir Rahim
  2. /******Harun Or Rashid******/
  3. /***********Template Starts Here***********/
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<cstring>
  7. #include<cmath>
  8. #include<cctype>
  9. #include<cstdlib>
  10. #include<cassert>
  11. #include<string>
  12. #include<vector>
  13. #include<set>
  14. #include<stack>
  15. #include<queue>
  16. #include<map>
  17. #include<algorithm>
  18. using namespace std;
  19.  
  20. #define MEM(a,b) memset(a,b,sizeof(a))
  21. #define CLR(a) memset(a,0,sizeof(a))
  22. #define MAX(a,b) ((a)>(b)?(a):(b))
  23. #define MIN(a,b) ((a)>(b)?(b):(a))
  24. #define ABS(a) ((a)>0? (a):(-(a)))
  25. #define SQ(a) ((a)*(a))
  26. #define SZ(a) (int)a.size()
  27. #define FORN(i,n) for(i=1;i<=n;i++)
  28. #define FORAB(i,a,b) for(i=a;i<=b;i++)
  29. #define ALL(V) V.begin(),V.end()
  30. #define pb(a) push_back(a)
  31. #define pr(a) cout<<a<<endl
  32. #define SQR(a) ((a)*(a))
  33. #define pf printf
  34. #define sf scanf
  35. #define mp make_pair
  36. #define swap(a,b) (a ^= b, b ^= a, a ^= b)
  37. #define PI acos(-1)
  38. #define x first
  39. #define y second
  40. #define eps 1e-7
  41.  
  42. typedef int D;
  43. typedef long long int LLD;
  44. typedef unsigned long long int LLU;
  45. typedef vector<D> VI;
  46. typedef set<D> SI;
  47. typedef vector<D>::iterator Viti;
  48.  
  49. /***********Template Ends Here***********/
  50.  
  51. int gcd(int a,int b)
  52. {
  53. if(b==0) return a;
  54. return gcd(b,a%b);
  55. }
  56.  
  57. int lcm(int a,int b)
  58. {
  59. return a*(b/gcd(a,b));
  60. }
  61.  
  62. int main()
  63. {
  64. char str[21];
  65. int i,cnt,ans;
  66. while(1)
  67. {
  68. cin>>str;
  69. if(str[0]=='*') break;
  70. vector<int>tocheak;
  71. vector<int>tocount;
  72. for(i=0; str[i] ; i++)
  73. {
  74. if(str[i]=='N') tocheak.pb(i+1);
  75. else tocount.pb(i+1);
  76. }
  77. if(tocount.size())
  78. {
  79. cnt=tocount[0];
  80. for(i=1; i<tocount.size(); i++)
  81. cnt=lcm(cnt,tocount[i]);
  82. ans=cnt;
  83. for(i=0; i<tocheak.size(); i++)
  84. {
  85. if(cnt%tocheak[i]==0)
  86. {
  87. ans=-1;
  88. break;
  89. }
  90. }
  91. cout<<ans<<endl;
  92. }
  93. else cout<<-1<<endl;
  94. }
  95. return 0;
  96. }
  97.  
  98.  
Success #stdin #stdout 0s 3480KB
stdin
YYNYY
YYYNNN
*
stdout
20
-1