fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define fi first
  6. #define se second
  7. #define endl "\n"
  8. #define ii pair<int,int>
  9. #define all(a) (a).begin(), (a).end()
  10.  
  11. using namespace std;
  12.  
  13. const int N = 5e4 + 5;
  14. const int mod = 1e9 + 7;
  15. const int base = 1301;
  16.  
  17. int binpow(int a, int b){
  18. int res = 1;
  19. while (b){
  20. if (b & 1) res = a * res % mod;
  21. a = a * a % mod;
  22. b = b >> 1;
  23. }
  24. return res;
  25. }
  26.  
  27. signed main(){
  28. cin.tie(0) -> sync_with_stdio(false);
  29.  
  30. if (fopen( "input.inp" , "r" )){
  31. freopen( "input.inp" , "r" , stdin );
  32. freopen( "output.out" , "w" , stdout );
  33. }
  34.  
  35. int hsh1 = 0, hsh2 = 0, cnt_base = 0;
  36.  
  37. char c;
  38.  
  39. while (cin >> c){
  40. hsh1 = (hsh1 * base + c - 'a' + 1) % mod;
  41. hsh2 = (hsh2 + (c - 'a' + 1) * binpow(base, cnt_base++)) % mod;
  42. }
  43.  
  44. if (hsh1 == hsh2) cout << "YES\n";
  45. else cout << "NO\n";
  46.  
  47. // cout << hsh1 << endl << hsh2 << endl;
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
YES