func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 11;   const long long mod = 1e9 + 7;   const int inf = 1e9;   const int bl = 320;   deque<int> arr[bl];   int cnt[bl][N];   void shift(int l, int r) {     vector<int> a;     int b = l / bl;     while (!arr[b].empty()) {       a.push_back(arr[b].front());       arr[b].pop_front();     }     int last = a[r - b * bl];     for (int i = l - b * bl; i <= r - b * bl; i++) {       swap(a[i], last);     }     while (!a.empty()) {       arr[b].push_front(a.back());       a.pop_back();     }   }   int del(int first) {     int b = first / bl;     int second = first - b * bl;     vector<int> a;     for (int i = 0; i < second; i++) {       a.push_back(arr[b].front());       arr[b].pop_front();     }     int res = arr[b].front();     arr[b].pop_front();     while (!a.empty()) {       arr[b].push_front(a.back());       a.pop_back();     }     return res;   }   void add(int first, int val) {     int b = first / bl;     int second = first - b * bl;     vector<int> a;     for (int i = arr[b].size() - 1; i >= second; i--) {       a.push_back(arr[b].back());       arr[b].pop_back();     }     arr[b].push_back(val);     while (!a.empty()) {       arr[b].push_back(a.back());       a.pop_back();     }   }   void solve() {     int n;     cin >> n;     arr[0].push_back(0);     for (int i = 1; i <= n; i++) {       int first;       cin >> first;       arr[i / bl].push_back(first);       cnt[i / bl][first]++;     }     int q;     cin >> q;     int lastans = 0;     for (int i = 1; i <= q; i++) {       int type, l, r, k;       cin >> type >> l >> r;       if (type == 1) {         l = (l + lastans - 1) % n + 1;         r = (r + lastans - 1) % n + 1;         if (l > r) swap(l, r);         if (l / bl == r / bl) {           shift(l, r);         } else {           int last = del(r);           cnt[r / bl][last]--;           add(l, last);           cnt[l / bl][last]++;           for (int i = l / bl; i <= r / bl; i++) {             if (i > l / bl) {               arr[i].push_front(last);               cnt[i][last]++;             }             if (i < r / bl) {               int first = arr[i].back();               arr[i].pop_back();               cnt[i][first]--;               last = first;             }           }         }       } else {         cin >> k;         l = (l + lastans - 1) % n + 1;         r = (r + lastans - 1) % n + 1;         k = (k + lastans - 1) % n + 1;         if (l > r) swap(l, r);         int ans = 0;         if (l / bl == r / bl) {           int b = l / bl;           for (int i = l - b * bl; i <= r - b * bl; i++) {             if (arr[b][i] == k) ans++;           }         } else {           int b = l / bl;           for (int i = l; i < (b + 1) * bl; i++) {             if (arr[b][i - b * bl] == k) ans++;           }           b = r / bl;           for (int i = b * bl; i <= r; i++) {             if (arr[b][i - b * bl] == k) ans++;           }           for (int i = l / bl + 1; i < r / bl; i++) {             ans += cnt[i][k];           }         }         cout << ans <<   n ;         lastans = ans;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int T = 1;     while (T--) {       solve();       cout <<   n ;     }   }   