Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solutions to lc problems: No.3151~3153 #2838

Merged
merged 1 commit into from
May 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions solution/3100-3199/3151.Special Array I/README.md
Original file line number Diff line number Diff line change
@@ -71,32 +71,77 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3151.Sp

<!-- solution:start -->

### 方法一
### 方法一:一次遍历

我们从左到右遍历数组,对于每一对相邻元素,如果它们的奇偶性相同,那么数组就不是特殊数组,返回 `false`;否则,数组是特殊数组,返回 `true`

时间复杂度 $O(n)$,其中 $n$ 是数组的长度。空间复杂度 $O(1)$。

<!-- tabs:start -->

#### Python3

```python

class Solution:
def isArraySpecial(self, nums: List[int]) -> bool:
return all(a % 2 != b % 2 for a, b in pairwise(nums))
```

#### Java

```java

class Solution {
public boolean isArraySpecial(int[] nums) {
for (int i = 1; i < nums.length; ++i) {
if (nums[i] % 2 == nums[i - 1] % 2) {
return false;
}
}
return true;
}
}
```

#### C++

```cpp

class Solution {
public:
bool isArraySpecial(vector<int>& nums) {
for (int i = 1; i < nums.size(); ++i) {
if (nums[i] % 2 == nums[i - 1] % 2) {
return false;
}
}
return true;
}
};
```
#### Go
```go
func isArraySpecial(nums []int) bool {
for i, x := range nums[1:] {
if x%2 == nums[i]%2 {
return false
}
}
return true
}
```

#### TypeScript

```ts
function isArraySpecial(nums: number[]): boolean {
for (let i = 1; i < nums.length; ++i) {
if (nums[i] % 2 === nums[i - 1] % 2) {
return false;
}
}
return true;
}
```

<!-- tabs:end -->
53 changes: 49 additions & 4 deletions solution/3100-3199/3151.Special Array I/README_EN.md
Original file line number Diff line number Diff line change
@@ -69,32 +69,77 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3151.Sp

<!-- solution:start -->

### Solution 1
### Solution 1: Single Pass

We traverse the array from left to right. For each pair of adjacent elements, if their parity is the same, then the array is not a special array, return `false`; otherwise, the array is a special array, return `true`.

The time complexity is $O(n)$, where $n$ is the length of the array. The space complexity is $O(1)`.

<!-- tabs:start -->

#### Python3

```python

class Solution:
def isArraySpecial(self, nums: List[int]) -> bool:
return all(a % 2 != b % 2 for a, b in pairwise(nums))
```

#### Java

```java

class Solution {
public boolean isArraySpecial(int[] nums) {
for (int i = 1; i < nums.length; ++i) {
if (nums[i] % 2 == nums[i - 1] % 2) {
return false;
}
}
return true;
}
}
```

#### C++

```cpp

class Solution {
public:
bool isArraySpecial(vector<int>& nums) {
for (int i = 1; i < nums.size(); ++i) {
if (nums[i] % 2 == nums[i - 1] % 2) {
return false;
}
}
return true;
}
};
```
#### Go
```go
func isArraySpecial(nums []int) bool {
for i, x := range nums[1:] {
if x%2 == nums[i]%2 {
return false
}
}
return true
}
```

#### TypeScript

```ts
function isArraySpecial(nums: number[]): boolean {
for (let i = 1; i < nums.length; ++i) {
if (nums[i] % 2 === nums[i - 1] % 2) {
return false;
}
}
return true;
}
```

<!-- tabs:end -->
11 changes: 11 additions & 0 deletions solution/3100-3199/3151.Special Array I/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public:
bool isArraySpecial(vector<int>& nums) {
for (int i = 1; i < nums.size(); ++i) {
if (nums[i] % 2 == nums[i - 1] % 2) {
return false;
}
}
return true;
}
};
8 changes: 8 additions & 0 deletions solution/3100-3199/3151.Special Array I/Solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
func isArraySpecial(nums []int) bool {
for i, x := range nums[1:] {
if x%2 == nums[i]%2 {
return false
}
}
return true
}
10 changes: 10 additions & 0 deletions solution/3100-3199/3151.Special Array I/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public boolean isArraySpecial(int[] nums) {
for (int i = 1; i < nums.length; ++i) {
if (nums[i] % 2 == nums[i - 1] % 2) {
return false;
}
}
return true;
}
}
3 changes: 3 additions & 0 deletions solution/3100-3199/3151.Special Array I/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution:
def isArraySpecial(self, nums: List[int]) -> bool:
return all(a % 2 != b % 2 for a, b in pairwise(nums))
8 changes: 8 additions & 0 deletions solution/3100-3199/3151.Special Array I/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function isArraySpecial(nums: number[]): boolean {
for (let i = 1; i < nums.length; ++i) {
if (nums[i] % 2 === nums[i - 1] % 2) {
return false;
}
}
return true;
}
86 changes: 82 additions & 4 deletions solution/3100-3199/3152.Special Array II/README.md
Original file line number Diff line number Diff line change
@@ -67,32 +67,110 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3152.Sp

<!-- solution:start -->

### 方法一
### 方法一:记录每个位置的最左特殊数组位置

我们可以定义一个数组 $d$ 来记录每个位置的最左特殊数组位置,初始时 $d[i] = i$。然后我们从左到右遍历数组 $nums$,如果 $nums[i]$ 和 $nums[i - 1]$ 的奇偶性不同,那么 $d[i] = d[i - 1]$。

最后我们遍历每个查询,判断 $d[to] <= from$ 是否成立即可。

时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 是数组的长度。

<!-- tabs:start -->

#### Python3

```python

class Solution:
def isArraySpecial(self, nums: List[int], queries: List[List[int]]) -> List[bool]:
n = len(nums)
d = list(range(n))
for i in range(1, n):
if nums[i] % 2 != nums[i - 1] % 2:
d[i] = d[i - 1]
return [d[t] <= f for f, t in queries]
```

#### Java

```java

class Solution {
public boolean[] isArraySpecial(int[] nums, int[][] queries) {
int n = nums.length;
int[] d = new int[n];
for (int i = 1; i < n; ++i) {
if (nums[i] % 2 != nums[i - 1] % 2) {
d[i] = d[i - 1];
} else {
d[i] = i;
}
}
int m = queries.length;
boolean[] ans = new boolean[m];
for (int i = 0; i < m; ++i) {
ans[i] = d[queries[i][1]] <= queries[i][0];
}
return ans;
}
}
```

#### C++

```cpp

class Solution {
public:
vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) {
int n = nums.size();
vector<int> d(n);
iota(d.begin(), d.end(), 0);
for (int i = 1; i < n; ++i) {
if (nums[i] % 2 != nums[i - 1] % 2) {
d[i] = d[i - 1];
}
}
vector<bool> ans;
for (auto& q : queries) {
ans.push_back(d[q[1]] <= q[0]);
}
return ans;
}
};
```
#### Go
```go
func isArraySpecial(nums []int, queries [][]int) (ans []bool) {
n := len(nums)
d := make([]int, n)
for i := range d {
d[i] = i
}
for i := 1; i < len(nums); i++ {
if nums[i]%2 != nums[i-1]%2 {
d[i] = d[i-1]
}
}
for _, q := range queries {
ans = append(ans, d[q[1]] <= q[0])
}
return
}
```

#### TypeScript

```ts
function isArraySpecial(nums: number[], queries: number[][]): boolean[] {
const n = nums.length;
const d: number[] = Array.from({ length: n }, (_, i) => i);
for (let i = 1; i < n; ++i) {
if (nums[i] % 2 !== nums[i - 1] % 2) {
d[i] = d[i - 1];
}
}
return queries.map(([from, to]) => d[to] <= from);
}
```

<!-- tabs:end -->
86 changes: 82 additions & 4 deletions solution/3100-3199/3152.Special Array II/README_EN.md
Original file line number Diff line number Diff line change
@@ -61,7 +61,13 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3152.Sp

<!-- description:end -->

## Solutions
### Solution 1: Record the Leftmost Special Array Position for Each Position

We can define an array $d$ to record the leftmost special array position for each position, initially $d[i] = i$. Then we traverse the array $nums$ from left to right. If $nums[i]$ and $nums[i - 1]$ have different parities, then $d[i] = d[i - 1]$.

Finally, we traverse each query and check whether $d[to] <= from$ holds.

The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is the length of the array.

<!-- solution:start -->

@@ -72,25 +78,97 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3152.Sp
#### Python3

```python

class Solution:
def isArraySpecial(self, nums: List[int], queries: List[List[int]]) -> List[bool]:
n = len(nums)
d = list(range(n))
for i in range(1, n):
if nums[i] % 2 != nums[i - 1] % 2:
d[i] = d[i - 1]
return [d[t] <= f for f, t in queries]
```

#### Java

```java

class Solution {
public boolean[] isArraySpecial(int[] nums, int[][] queries) {
int n = nums.length;
int[] d = new int[n];
for (int i = 1; i < n; ++i) {
if (nums[i] % 2 != nums[i - 1] % 2) {
d[i] = d[i - 1];
} else {
d[i] = i;
}
}
int m = queries.length;
boolean[] ans = new boolean[m];
for (int i = 0; i < m; ++i) {
ans[i] = d[queries[i][1]] <= queries[i][0];
}
return ans;
}
}
```

#### C++

```cpp

class Solution {
public:
vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) {
int n = nums.size();
vector<int> d(n);
iota(d.begin(), d.end(), 0);
for (int i = 1; i < n; ++i) {
if (nums[i] % 2 != nums[i - 1] % 2) {
d[i] = d[i - 1];
}
}
vector<bool> ans;
for (auto& q : queries) {
ans.push_back(d[q[1]] <= q[0]);
}
return ans;
}
};
```
#### Go
```go
func isArraySpecial(nums []int, queries [][]int) (ans []bool) {
n := len(nums)
d := make([]int, n)
for i := range d {
d[i] = i
}
for i := 1; i < len(nums); i++ {
if nums[i]%2 != nums[i-1]%2 {
d[i] = d[i-1]
}
}
for _, q := range queries {
ans = append(ans, d[q[1]] <= q[0])
}
return
}
```

#### TypeScript

```ts
function isArraySpecial(nums: number[], queries: number[][]): boolean[] {
const n = nums.length;
const d: number[] = Array.from({ length: n }, (_, i) => i);
for (let i = 1; i < n; ++i) {
if (nums[i] % 2 !== nums[i - 1] % 2) {
d[i] = d[i - 1];
}
}
return queries.map(([from, to]) => d[to] <= from);
}
```

<!-- tabs:end -->
18 changes: 18 additions & 0 deletions solution/3100-3199/3152.Special Array II/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) {
int n = nums.size();
vector<int> d(n);
iota(d.begin(), d.end(), 0);
for (int i = 1; i < n; ++i) {
if (nums[i] % 2 != nums[i - 1] % 2) {
d[i] = d[i - 1];
}
}
vector<bool> ans;
for (auto& q : queries) {
ans.push_back(d[q[1]] <= q[0]);
}
return ans;
}
};
16 changes: 16 additions & 0 deletions solution/3100-3199/3152.Special Array II/Solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func isArraySpecial(nums []int, queries [][]int) (ans []bool) {
n := len(nums)
d := make([]int, n)
for i := range d {
d[i] = i
}
for i := 1; i < len(nums); i++ {
if nums[i]%2 != nums[i-1]%2 {
d[i] = d[i-1]
}
}
for _, q := range queries {
ans = append(ans, d[q[1]] <= q[0])
}
return
}
19 changes: 19 additions & 0 deletions solution/3100-3199/3152.Special Array II/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public boolean[] isArraySpecial(int[] nums, int[][] queries) {
int n = nums.length;
int[] d = new int[n];
for (int i = 1; i < n; ++i) {
if (nums[i] % 2 != nums[i - 1] % 2) {
d[i] = d[i - 1];
} else {
d[i] = i;
}
}
int m = queries.length;
boolean[] ans = new boolean[m];
for (int i = 0; i < m; ++i) {
ans[i] = d[queries[i][1]] <= queries[i][0];
}
return ans;
}
}
8 changes: 8 additions & 0 deletions solution/3100-3199/3152.Special Array II/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def isArraySpecial(self, nums: List[int], queries: List[List[int]]) -> List[bool]:
n = len(nums)
d = list(range(n))
for i in range(1, n):
if nums[i] % 2 != nums[i - 1] % 2:
d[i] = d[i - 1]
return [d[t] <= f for f, t in queries]
10 changes: 10 additions & 0 deletions solution/3100-3199/3152.Special Array II/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function isArraySpecial(nums: number[], queries: number[][]): boolean[] {
const n = nums.length;
const d: number[] = Array.from({ length: n }, (_, i) => i);
for (let i = 1; i < n; ++i) {
if (nums[i] % 2 !== nums[i - 1] % 2) {
d[i] = d[i - 1];
}
}
return queries.map(([from, to]) => d[to] <= from);
}
Original file line number Diff line number Diff line change
@@ -64,32 +64,127 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3153.Su

<!-- solution:start -->

### 方法一
### 方法一:计数

我们先获取数组中数字的位数 $m$,然后对于每一位,我们统计数组 $\textit{nums}$ 中每个数字在该位上的出现次数,记为 $\textit{cnt}$。那么在该位上,所有数对的数位不同之和为:

$$
\sum_{v \in \textit{cnt}} v \times (n - v)
$$

其中 $n$ 是数组的长度。我们将所有位的数位不同之和相加,再除以 $2$ 即可得到答案。

时间复杂度 $O(n \times m)$,空间复杂度 $O(C)$,其中 $n$ 和 $m$ 分别是数组的长度和数字的位数;而 $C$ 是常数,本题中 $C = 10$。

<!-- tabs:start -->

#### Python3

```python

class Solution:
def sumDigitDifferences(self, nums: List[int]) -> int:
n = len(nums)
m = int(log10(nums[0])) + 1
ans = 0
for _ in range(m):
cnt = Counter()
for i, x in enumerate(nums):
nums[i], y = divmod(x, 10)
cnt[y] += 1
ans += sum(v * (n - v) for v in cnt.values()) // 2
return ans
```

#### Java

```java

class Solution {
public long sumDigitDifferences(int[] nums) {
int n = nums.length;
int m = (int) Math.floor(Math.log10(nums[0])) + 1;
int[] cnt = new int[10];
long ans = 0;
for (int k = 0; k < m; ++k) {
Arrays.fill(cnt, 0);
for (int i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] /= 10;
}
for (int i = 0; i < 10; ++i) {
ans += 1L * cnt[i] * (n - cnt[i]);
}
}
return ans / 2;
}
}
```

#### C++

```cpp

class Solution {
public:
long long sumDigitDifferences(vector<int>& nums) {
int n = nums.size();
int m = floor(log10(nums[0])) + 1;
int cnt[10];
long long ans = 0;
for (int k = 0; k < m; ++k) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] /= 10;
}
for (int i = 0; i < 10; ++i) {
ans += 1LL * (cnt[i] * (n - cnt[i]));
}
}
return ans / 2;
}
};
```
#### Go
```go
func sumDigitDifferences(nums []int) (ans int64) {
n := len(nums)
m := int(math.Floor(math.Log10(float64(nums[0])))) + 1
for k := 0; k < m; k++ {
cnt := [10]int{}
for i, x := range nums {
cnt[x%10]++
nums[i] /= 10
}
for _, v := range cnt {
ans += int64(v) * int64(n-v)
}
}
ans /= 2
return
}
```

#### TypeScript

```ts
function sumDigitDifferences(nums: number[]): number {
const n = nums.length;
const m = Math.floor(Math.log10(nums[0])) + 1;
let ans: bigint = BigInt(0);
for (let k = 0; k < m; ++k) {
const cnt: number[] = Array(10).fill(0);
for (let i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] = Math.floor(nums[i] / 10);
}
for (let i = 0; i < 10; ++i) {
ans += BigInt(cnt[i]) * BigInt(n - cnt[i]);
}
}
ans /= BigInt(2);
return Number(ans);
}
```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -62,32 +62,127 @@ All the integers in the array are the same. So the total sum of digit difference

<!-- solution:start -->

### Solution 1
### Solution 1: Counting

First, we get the number of digits $m$ in the array. Then for each digit, we count the occurrence of each number at this digit in the array `nums`, denoted as `cnt`. Therefore, the sum of the digit differences of all number pairs at this digit is:

$$
\sum_{v \in \textit{cnt}} v \times (n - v)
$$

where $n$ is the length of the array. We add up the digit differences of all digits and divide by $2$ to get the answer.

The time complexity is $O(n \times m)$, and the space complexity is $O(C)$, where $n$ and $m$ are the length of the array and the number of digits in the numbers, respectively; and $C$ is a constant, in this problem $C = 10$.

<!-- tabs:start -->

#### Python3

```python

class Solution:
def sumDigitDifferences(self, nums: List[int]) -> int:
n = len(nums)
m = int(log10(nums[0])) + 1
ans = 0
for _ in range(m):
cnt = Counter()
for i, x in enumerate(nums):
nums[i], y = divmod(x, 10)
cnt[y] += 1
ans += sum(v * (n - v) for v in cnt.values()) // 2
return ans
```

#### Java

```java

class Solution {
public long sumDigitDifferences(int[] nums) {
int n = nums.length;
int m = (int) Math.floor(Math.log10(nums[0])) + 1;
int[] cnt = new int[10];
long ans = 0;
for (int k = 0; k < m; ++k) {
Arrays.fill(cnt, 0);
for (int i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] /= 10;
}
for (int i = 0; i < 10; ++i) {
ans += 1L * cnt[i] * (n - cnt[i]);
}
}
return ans / 2;
}
}
```

#### C++

```cpp

class Solution {
public:
long long sumDigitDifferences(vector<int>& nums) {
int n = nums.size();
int m = floor(log10(nums[0])) + 1;
int cnt[10];
long long ans = 0;
for (int k = 0; k < m; ++k) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] /= 10;
}
for (int i = 0; i < 10; ++i) {
ans += 1LL * (cnt[i] * (n - cnt[i]));
}
}
return ans / 2;
}
};
```
#### Go
```go
func sumDigitDifferences(nums []int) (ans int64) {
n := len(nums)
m := int(math.Floor(math.Log10(float64(nums[0])))) + 1
for k := 0; k < m; k++ {
cnt := [10]int{}
for i, x := range nums {
cnt[x%10]++
nums[i] /= 10
}
for _, v := range cnt {
ans += int64(v) * int64(n-v)
}
}
ans /= 2
return
}
```

#### TypeScript

```ts
function sumDigitDifferences(nums: number[]): number {
const n = nums.length;
const m = Math.floor(Math.log10(nums[0])) + 1;
let ans: bigint = BigInt(0);
for (let k = 0; k < m; ++k) {
const cnt: number[] = Array(10).fill(0);
for (let i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] = Math.floor(nums[i] / 10);
}
for (let i = 0; i < 10; ++i) {
ans += BigInt(cnt[i]) * BigInt(n - cnt[i]);
}
}
ans /= BigInt(2);
return Number(ans);
}
```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public:
long long sumDigitDifferences(vector<int>& nums) {
int n = nums.size();
int m = floor(log10(nums[0])) + 1;
int cnt[10];
long long ans = 0;
for (int k = 0; k < m; ++k) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] /= 10;
}
for (int i = 0; i < 10; ++i) {
ans += 1LL * (cnt[i] * (n - cnt[i]));
}
}
return ans / 2;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
func sumDigitDifferences(nums []int) (ans int64) {
n := len(nums)
m := int(math.Floor(math.Log10(float64(nums[0])))) + 1
for k := 0; k < m; k++ {
cnt := [10]int{}
for i, x := range nums {
cnt[x%10]++
nums[i] /= 10
}
for _, v := range cnt {
ans += int64(v) * int64(n-v)
}
}
ans /= 2
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public long sumDigitDifferences(int[] nums) {
int n = nums.length;
int m = (int) Math.floor(Math.log10(nums[0])) + 1;
int[] cnt = new int[10];
long ans = 0;
for (int k = 0; k < m; ++k) {
Arrays.fill(cnt, 0);
for (int i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] /= 10;
}
for (int i = 0; i < 10; ++i) {
ans += 1L * cnt[i] * (n - cnt[i]);
}
}
return ans / 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def sumDigitDifferences(self, nums: List[int]) -> int:
n = len(nums)
m = int(log10(nums[0])) + 1
ans = 0
for _ in range(m):
cnt = Counter()
for i, x in enumerate(nums):
nums[i], y = divmod(x, 10)
cnt[y] += 1
ans += sum(v * (n - v) for v in cnt.values()) // 2
return ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function sumDigitDifferences(nums: number[]): number {
const n = nums.length;
const m = Math.floor(Math.log10(nums[0])) + 1;
let ans: bigint = BigInt(0);
for (let k = 0; k < m; ++k) {
const cnt: number[] = Array(10).fill(0);
for (let i = 0; i < n; ++i) {
++cnt[nums[i] % 10];
nums[i] = Math.floor(nums[i] / 10);
}
for (let i = 0; i < 10; ++i) {
ans += BigInt(cnt[i]) * BigInt(n - cnt[i]);
}
}
ans /= BigInt(2);
return Number(ans);
}