You are an expert at testing code. You will be given the complete description of a problem statement, along with a buggy code and correct code to solve it. You have to find a test-case where the buggy code fails. To do this, write a randomised test case generator script. I will then repeatedly compare the buggy code against the correct solution on the generator's outputs until a failing test case is found.

Aim for diversity and coverage in the generated tests. Feel free to vary the range of all variables as needed while staying within problem constraints.

Provide the test-case generator to me in the exact XML format I show below. Do not include anything else in your responses. Your code must be written in Python 3 or C++ 23.

```
<action>
<name>generate_tc</name>
<code>
[code to generate random test-cases]
</code>
<lang>[Python 3 | C++ 23]</lang>
</action>
```

# Example 1

## Statement

An array $$b$$ of length $$m$$ is good if for all $$i$$ the $$i$$-th element is greater than or equal to $$i$$. In other words, $$b$$ is good if and only if $$b_i \geq i$$ for all $$i$$ ($$1 \leq i \leq m$$). You are given an array $$a$$ consisting of $$n$$ positive integers. Find the number of pairs of indices $$(l, r)$$, where $$1 \le l \le r \le n$$, such that the array $$[a_l, a_{l+1}, \ldots, a_r]$$ is good .

Time Limit: 1000ms

Memory Limit: 256 megabytes

## Input Format

Each test contains multiple test cases. The first line contains the number of test cases $$t$$ ($$1 \leq t \leq 2 \cdot 10^5$$). Description of the test cases follows.
The first line of each test case contains an integer $$n$$ ($$1 \leq n \leq 2 \cdot 10^5$$), the length of the array $$a$$.
The second line of each test case contains $$n$$ space-separated integers $$a_1,a_2,\ldots,a_n$$ ($$1 \leq a_i \leq n$$), representing the array $$a$$.
It is guaranteed that the sum of $$n$$ over all test cases does not exceed $$2 \cdot 10^5$$.

## Output Format

For each test case, print the number of suitable pairs of indices.

## Example Input

```
3
3
1 2 3
3
1 1 1
4
2 1 4 3

```

## Example Output

```
6
3
7
```

## Note

In the first test case, all subarrays of $$a$$ are good , so all pairs are suitable. In the second test case, the pairs $$(1, 1)$$, $$(2, 2)$$, and $$(3, 3)$$ are suitable. For example, when $$(l, r) = (1, 2)$$, the array $$b=[1,1]$$ is not good because $$b_2 < 2$$.

## Buggy Code

```
#include <iostream>

typedef unsigned int uint;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  uint t;
  cin >> t;

  for (uint test_case = 0; test_case < t; test_case++) {
    uint n;
    cin >> n;

    uint total = 0;
    uint start = 1;

    for (uint i = start; i <= n; i++) {
      uint a;
      cin >> a;

      uint l = i - start;

      if (a < l + 1) {
        // cout << "total += " << (l * (l + 1)) / 2 << endl;
        total += (l * (l + 1)) / 2;

        start = i;
      }
    }

    uint l = n - start + 1;
    // cout << "Final l = " << l << endl;
    total += (l * (l + 1)) / 2;

    cout << total << endl;
  }
}
```

## Correct Code

```
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
    ll n; cin>>n;
    vector<ll> dp(n+5,0);
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll x; cin>>x;
        dp[i]=min(dp[i-1]+1,x);
        ans+=dp[i];
    }
    cout<<ans<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t; cin>>t;
    while(t--){
        solve();
    }
}
```

## You would respond with:

```
<action>
<name>generate_tc</name>
<code>
t = 1
print(t)
for _ in range(t):
    n = random.randint(1, 100)
    print(n)
    print(' '.join(str(random.randint(1, n)) for _ in range(n)))
</code>
<lang>Python 3</lang>
</action>
```

# Example 2

## Statement

You have an array $$a$$ consisting of $$n$$ positive integers and you have to handle $$q$$ queries of the following types:
$$1$$ $$i$$ $$x$$: change $$a_{i}$$ to $$x$$,
$$2$$ $$l$$ $$r$$ $$k$$: check if the number of occurrences of every positive integer in the subarray $$a_{l}, a_{l+1}, \ldots a_{r}$$ is a multiple of $$k$$ (check the example for better understanding).

Time Limit: 3000ms

Memory Limit: 256 megabytes

## Input Format

The first line of the input contains two integers $$n$$ and $$q$$ ($$1 \le n , q \le 3 \cdot 10^5$$), the length of $$a$$ and the number of queries.
Next line contains $$n$$ integers $$a_{1}, a_{2}, \ldots a_{n}$$ ($$1 \le a_{i} \le 10^9$$) — the elements of $$a$$.
Each of the next $$q$$ lines describes a query. It has one of the following forms.
$$1$$ $$i$$ $$x$$, ($$1 \le i \le n$$ , $$1 \le x \le 10^9$$), or
$$2$$ $$l$$ $$r$$ $$k$$, ($$1 \le l \le r \le n$$ , $$1 \le k \le n$$).

## Output Format

For each query of the second type, if answer of the query is yes, print " YES ", otherwise print " NO ".

## Example Input

```
10 8
1234 2 3 3 2 1 1 2 3 4
2 1 6 2
1 1 1
2 1 6 2
2 1 9 2
1 10 5
2 1 9 3
1 3 5
2 3 10 2
```

## Example Output

```
NO
YES
NO
YES
YES
```

## Note

In the first query, requested subarray is $$[1234, 2, 3, 3, 2, 1]$$, and it's obvious that the number of occurrence of $$1$$ isn't divisible by $$k = 2$$. So the answer is " NO ". In the third query, requested subarray is $$[1, 2, 3, 3, 2, 1]$$, and it can be seen that the number of occurrence of every integer in this sub array is divisible by $$k = 2$$. So the answer is " YES ". In the sixth query, requested subarray is $$[1, 2, 3, 3, 2, 1, 1, 2, 3]$$, and it can be seen that the number of occurrence of every integer in this sub array is divisible by $$k = 3$$. So the answer is " YES ".

## Buggy Code

```
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,Q,q[300003][5],a[300003],ans[300003],totq,B=70;
set<int>R;
int stk[600003],tots;
struct BIT{
	int TreeAr[300003];
	int lowbit(int X){return (X&(-X));}
	void modify(int wz,int val){
		for(int i=wz;i<=n;i+=lowbit(i))TreeAr[i]+=val;
		return;
	}
	int Query(int l,int r){
		int ret=0;
		for(int i=r;i;i-=lowbit(i))ret+=TreeAr[i];
		for(int i=l-1;i>0;i-=lowbit(i))ret-=TreeAr[i];
		return ret;
	}
};
struct rndseq{
	char val[600003];
	BIT T;
}C[73];
int fff(int X){return (int)(lower_bound(stk+1,stk+tots+1,X)-stk);}
void m0dify(int wz,int v,int val){
	for(int i=1;i<=B;i++)C[i].T.modify(wz,val*C[i].val[v]);
	return;
}
ll seed=257825;
int rnd(){
	seed=(seed*4132ll+1ll*seed*seed+98521)%998244353;
	seed=(seed<<13)^seed^(seed>>5);
	seed%=998244353;
	return seed;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>Q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)R.insert(a[i]);
	for(int i=1;i<=Q;i++){
		cin>>q[i][0]>>q[i][1]>>q[i][2];
		if(q[i][0]==1)R.insert(q[i][2]);
		else{
			cin>>q[i][3];
			ans[++totq]=1;
			q[i][4]=totq;
		}
	}
	for(auto i:R)stk[++tots]=i;
	for(int i=1;i<=n;i++)a[i]=fff(a[i]);
	for(int i=1;i<=n;i++)if(q[i][0]==1)q[i][2]=fff(q[i][2]);
	for(int i=1;i<=B;i++){
		for(int j=1;j<=tots;j++)C[i].val[j]=rnd()%2;
	}
	for(int i=1;i<=n;i++)m0dify(i,a[i],1);
	for(int i=1;i<=Q;i++){
		if(q[i][0]==1){
			m0dify(q[i][1],a[q[i][1]],-1);
			a[q[i][1]]=q[i][2];
			m0dify(q[i][1],a[q[i][1]],1);
		}
		else{
			for(int j=1;j<=B;j++)if(C[j].T.Query(q[i][1],q[i][2])%q[i][3]!=0)ans[q[i][4]]=0;
		}
	}
	for(int i=1;i<=totq;i++){
		if(ans[i])cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}
```

## Correct Code

```
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

mt19937 rnd(time(0));

const int N = 300'000 + 5;
const int Q = 300'000 + 5;
const int T = 50;
bitset<N+Q> RandomSet[T];
unordered_map<int, int> id; int cnt_id = 0;
int n, q, A[N];

struct fenwick
{
	int PartialSum[N];
	fenwick()
	{
		for(int i = 0; i < N; i++)PartialSum[i] = 0;
	}
	inline void add(int index, bool increase)
	{
		while(index < N)
		{
			PartialSum[index] += (increase? 1 : -1);
			index += index&-index;
		}
	}
	inline int get(int index)
	{
		int sum = 0;
		while(index)
		{
			sum += PartialSum[index];
			index -= index&-index;
		}
		return sum;
	}
}Fen[T];

inline int GetId(const int x)
{
	auto id_iterator = id.find(x);
	if(id_iterator == id.end())
	{
		return id[x] = cnt_id++;
	}
	else return (*id_iterator).second;
}

inline void ChooseRandomSets()
{
	for(int i = 0; i < T; i++)
	{
		for(int j = 0; j < N+Q; j++)
		{
			if(rnd()&1)RandomSet[i].set(j);
		}
	}
}

inline void AddArrayToFenwick()
{
	for(int i = 0; i < n; i++)
	{
		int MyId = GetId(A[i]);
		for(int j = 0; j < T; j++)
		{
			if(RandomSet[j][MyId])Fen[j].add(i+1, true);
		}
	}
}

inline void Query()
{
	int index, l, r, k, x, type;
	for(int i = 0; i < q; i++)
	{
		cin >> type;
		if(type == 1)
		{
			cin >> index >> x;
			index --;
			int IdPre = GetId(A[index]);
			int IdNew = GetId(x);
			A[index] = x;
			for(int j = 0; j < T; j++)
			{
				if(RandomSet[j][IdPre])Fen[j].add(index+1, false);
				if(RandomSet[j][IdNew])Fen[j].add(index+1, true);
			}
		}
		if(type == 2)
		{
			cin >> l >> r >> k;
			l--;
			if(k == 1){cout << "YES\n"; continue;}
			else if((r-l)%k != 0){cout << "NO\n"; continue;}
			bool answer = true;
			for(int j = 0; j < T; j++)
			{
				if((Fen[j].get(r)-Fen[j].get(l))%k != 0){answer = false; break;}
			}
			cout << (answer?"YES":"NO") << '\n';
		}
	}
}

int main()
{
    ios::sync_with_stdio(false) , cin.tie(0);
    ChooseRandomSets();
    cin >> n >> q;
    for(int i = 0; i < n; i++) cin >> A[i];
    AddArrayToFenwick();
    Query();
    return 0;
}
```

## You would respond with:

```
<action>
<name>generate_tc</name>
<code>
import random
MXN, MXQ = 100, 100

n, q = random.randint(1, MXN), random.randint(MXQ, MXQ)
print(n, q)
print(' '.join(str(random.randint(1, n)) for _ in range(n)))
for _ in range(q):
    if random.randint(0, 1):
        i, x = random.randint(1, n), random.randint(1, n)
        print(1, i, x)
    else:
        l, r, k = random.randint(1, n), random.randint(1, n), random.randint(1, 5)
        print(2, min(l, r), max(l, r), k)
</code>
<lang>Python 3</lang>
</action>
```

# Example 3

## Statement

You are given an integer $$x$$ and an array of integers $$a_1, a_2, \ldots, a_n$$. You have to determine if the number $$a_1! + a_2! + \ldots + a_n!$$ is divisible by $$x!$$.
Here $$k!$$ is a factorial of $$k$$ — the product of all positive integers less than or equal to $$k$$. For example, $$3! = 1 \cdot 2 \cdot 3 = 6$$, and $$5! = 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 = 120$$.

Time Limit: 2000ms

Memory Limit: 256 megabytes

## Input Format

The first line contains two integers $$n$$ and $$x$$ ($$1 \le n \le 500\,000$$, $$1 \le x \le 500\,000$$).
The second line contains $$n$$ integers $$a_1, a_2, \ldots, a_n$$ ($$1 \le a_i \le x$$) — elements of given array.

## Output Format

In the only line print " Yes " (without quotes) if $$a_1! + a_2! + \ldots + a_n!$$ is divisible by $$x!$$, and " No " (without quotes) otherwise.

## Example Input

```
6 4
3 2 2 2 3 3
```

## Example Output

```
Yes
```

## Note

In the first example $$3! + 2! + 2! + 2! + 3! + 3! = 6 + 2 + 2 + 2 + 6 + 6 = 24$$. Number $$24$$ is divisible by $$4! = 24$$.
In the second example $$3! + 2! + 2! + 2! + 2! + 2! + 1! + 1! = 18$$, is divisible by $$3! = 6$$.
In the third example $$7! + 7! + 7! + 7! + 7! + 7! + 7! = 7 \cdot 7!$$. It is easy to prove that this number is not divisible by $$8!$$.

## Buggy Code

```
def ntor(n, r):
    m = n
    i = 1
    while n - i > r:
        m *= n - i
        i += 1
    return m

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 1
ans = True

for i in range(1, n):
    if a[i] == a[i - 1]:
        count += 1
    else:
        m = ntor(a[i], a[i - 1])
        # print(i,m,count)
        if count % m == 0:
            count = (count // m) + 1
        else:
            ans = False
            break
if ans:
    if count % ntor(x,a[-1]) != 0 : ans = False

if ans == True:
    print('Yes')
else:
    print('No')
```

## Correct Code

```
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, x;
    std::cin >> n >> x;

    std::vector<int> cnt(x + 1);
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        cnt[std::min(a, x)]++;
    }

    for (int i = 1; i < x; i++) {
        if (cnt[i] % (i + 1)) {
            std::cout << "No\n";
            return 0;
        }
        cnt[i + 1] += cnt[i] / (i + 1);
    }
    std::cout << "Yes\n";

    return 0;
}
```

## You would respond with:

```
<action>
<name>generate_tc</name>
<code>
import random
MXN, MXV = 200, 200

n, x = random.randint(1, MXN), random.randint(1, MXV)
print(n, x)
print(' '.join(str(random.randint(1, MXV)) for _ in range(n)))
</code>
<lang>Python 3</lang>
</action>
```