#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } struct S { int dp[4][4]; int len; S(): len(0) { rep(i,0,4) rep(j,0,4) dp[i][j] = 0; } S(int x): len(1) { rep(i,0,4) rep(j,0,4) dp[i][j] = 0; dp[x][x] = 1; } S(int x, int l): len(l) { rep(i,0,4) rep(j,0,4) dp[i][j] = 0; dp[x][x] = l; } }; int score(S a){ int ret = -1e9; rep(i,0,4){ rep(j,i,4){ chmax(ret, a.dp[i][j]); } } return ret; } S e(){ return S(); } S op(S a, S b){ S ret = S(); ret.len = a.len + b.len; rep(i,0,4){ rep(j,i,4){ chmax(ret.dp[i][j], a.dp[i][j]); chmax(ret.dp[i][j], b.dp[i][j]); } } rep(i,0,4){ rep(j,i,4){ rep(k,j,4){ rep(l,k,4){ chmax(ret.dp[i][l], a.dp[i][j] + b.dp[k][l]); } } } } return ret; } S mapping(int f, S x){ if (f == 4) return x; return S(f, x.len); } int composition(int g, int f){ if (g == 4) return f; return g; } int id(){return 4;} int main(){ int n; cin >> n; vector a(n); vector init(n); rep(i,0,n){ cin >> a[i]; a[i]--; init[i] = S(a[i]); } lazy_segtree seg(init); int q; cin >> q; while(q--){ int t; cin >> t; if (t == 1){ int l, r; cin >> l >> r; l--; cout << score(seg.prod(l, r)) << '\n'; }else{ int l, r; cin >> l >> r; l--; int x; cin >> x; x--; seg.apply(l,r,x); } } }