output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int cnt[1000001];
int lt[1000001];
int rt[1000001];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
++cnt[a[i]];
rt[a[i]] = i;
}
for (int i = n - 1; i > -1; --i) {
lt[a[i]] = i;
}
int mx = -1;
for (int i = 1; i <= 1e6; ++i) {
mx = max(mx, cnt[i]);
}
int len = 1e9;
int a, b;
for (int i = 1; i <= 1e6; ++i) {
if (cnt[i] == mx) {
if (rt[i] - lt[i] < len) {
len = rt[i] - lt[i];
a = lt[i];
b = rt[i];
}
}
}
printf("%d %d\n", a + 1, b + 1);
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int cnt[1000001];
int lt[1000001];
int rt[1000001];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
++cnt[a[i]];
rt[a[i]] = i;
}
for (int i = n - 1; i > -1; --i) {
lt[a[i]] = i;
}
int mx = -1;
for (int i = 1; i <= 1e6; ++i) {
mx = max(mx, cnt[i]);
}
int len = 1e9;
int a, b;
for (int i = 1; i <= 1e6; ++i) {
if (cnt[i] == mx) {
if (rt[i] - lt[i] < len) {
len = rt[i] - lt[i];
a = lt[i];
b = rt[i];
}
}
}
printf("%d %d\n", a + 1, b + 1);
return 0;
}
```
|
#include <bits/stdc++.h>
int n = 0, m = 0, a[100002], b[1000002], c[1000002];
int main() {
while (scanf("%d", &n) != EOF) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
if (n == 0) continue;
int max = 0;
int p = 0, q = 0, k = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
if (b[a[i]] == 1) c[a[i]] = i;
if (b[a[i]] > max) {
max = b[a[i]];
k = a[i];
q = i;
}
if (b[a[i]] == max) {
if (i - c[a[i]] < q - c[a[q]]) {
q = i;
k = a[i];
}
}
}
for (int j = 0; j <= q; j++) {
if (a[j] == k) {
p = j;
break;
}
}
printf("%d %d\n", p + 1, q + 1);
}
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
int n = 0, m = 0, a[100002], b[1000002], c[1000002];
int main() {
while (scanf("%d", &n) != EOF) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
if (n == 0) continue;
int max = 0;
int p = 0, q = 0, k = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
if (b[a[i]] == 1) c[a[i]] = i;
if (b[a[i]] > max) {
max = b[a[i]];
k = a[i];
q = i;
}
if (b[a[i]] == max) {
if (i - c[a[i]] < q - c[a[q]]) {
q = i;
k = a[i];
}
}
}
for (int j = 0; j <= q; j++) {
if (a[j] == k) {
p = j;
break;
}
}
printf("%d %d\n", p + 1, q + 1);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 100005;
int cnt[maxn * 10];
int l[maxn * 10], r[maxn * 10];
int main() {
int n;
scanf("%d", &n);
int a;
memset(l, -1, sizeof(l));
memset(r, -1, sizeof(r));
for (int i = 0; i < n; i++) {
scanf("%d", &a);
cnt[a]++;
if (l[a] == -1)
l[a] = r[a] = i;
else
r[a] = i;
}
vector<pair<int, int> > v;
int cmp = 0;
int p = 0, q = 0;
for (int i = 1; i <= 1000000; i++) {
if (cnt[i]) {
if (cmp < cnt[i]) {
cmp = cnt[i];
p = l[i], q = r[i];
} else if (cmp == cnt[i] && r[i] - l[i] <= q - p) {
p = l[i], q = r[i];
}
}
}
cout << p + 1 << ' ' << q + 1 << endl;
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 100005;
int cnt[maxn * 10];
int l[maxn * 10], r[maxn * 10];
int main() {
int n;
scanf("%d", &n);
int a;
memset(l, -1, sizeof(l));
memset(r, -1, sizeof(r));
for (int i = 0; i < n; i++) {
scanf("%d", &a);
cnt[a]++;
if (l[a] == -1)
l[a] = r[a] = i;
else
r[a] = i;
}
vector<pair<int, int> > v;
int cmp = 0;
int p = 0, q = 0;
for (int i = 1; i <= 1000000; i++) {
if (cnt[i]) {
if (cmp < cnt[i]) {
cmp = cnt[i];
p = l[i], q = r[i];
} else if (cmp == cnt[i] && r[i] - l[i] <= q - p) {
p = l[i], q = r[i];
}
}
}
cout << p + 1 << ' ' << q + 1 << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
pair<int, int> A[(int)1e6 + 10];
int b[(int)1e6 + 10];
int main() {
int n;
cin >> n;
int t;
for (int i = 0; i < n; i++) {
cin >> t;
b[t]++;
if (A[t].first == 0) A[t].first = i + 1;
A[t].second = i + 1;
}
int mx = -1;
for (int i = 0; i < 1e6 + 10; i++) mx = max(mx, b[i]);
int mn = 1e9;
int ans[2] = {0, 0};
for (int i = 0; i < 1e6 + 10; i++)
if (mx == b[i] && mn > A[i].second - A[i].first) {
mn = A[i].second - A[i].first;
ans[0] = A[i].first;
ans[1] = A[i].second;
}
cout << ans[0] << " " << ans[1] << endl;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
pair<int, int> A[(int)1e6 + 10];
int b[(int)1e6 + 10];
int main() {
int n;
cin >> n;
int t;
for (int i = 0; i < n; i++) {
cin >> t;
b[t]++;
if (A[t].first == 0) A[t].first = i + 1;
A[t].second = i + 1;
}
int mx = -1;
for (int i = 0; i < 1e6 + 10; i++) mx = max(mx, b[i]);
int mn = 1e9;
int ans[2] = {0, 0};
for (int i = 0; i < 1e6 + 10; i++)
if (mx == b[i] && mn > A[i].second - A[i].first) {
mn = A[i].second - A[i].first;
ans[0] = A[i].first;
ans[1] = A[i].second;
}
cout << ans[0] << " " << ans[1] << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct num {
int count;
int start;
int end;
} N[1000001];
bool compare(const struct num &f, const struct num &s) {
if (f.count != s.count)
return f.count > s.count;
else
return (f.end - f.start) < (s.end - s.start);
}
int main() {
int n, i;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
N[a[i]].count++;
if (N[a[i]].count == 1) {
N[a[i]].start = i + 1;
}
N[a[i]].end = i + 1;
}
sort(N, N + 1000001, compare);
cout << N[0].start << " " << N[0].end;
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct num {
int count;
int start;
int end;
} N[1000001];
bool compare(const struct num &f, const struct num &s) {
if (f.count != s.count)
return f.count > s.count;
else
return (f.end - f.start) < (s.end - s.start);
}
int main() {
int n, i;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
N[a[i]].count++;
if (N[a[i]].count == 1) {
N[a[i]].start = i + 1;
}
N[a[i]].end = i + 1;
}
sort(N, N + 1000001, compare);
cout << N[0].start << " " << N[0].end;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> cc, start, endd;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cc[x]++;
start[x] = !start[x] ? i : min(start[x], i);
endd[x] = !endd[x] ? i : max(endd[x], i);
}
int currentMax = 0, resx = 0, resy = n + 1;
for (auto x : cc) {
if (x.second >= currentMax) {
if (x.second > currentMax ||
resy - resx > endd[x.first] - start[x.first]) {
resx = start[x.first];
resy = endd[x.first];
}
currentMax = x.second;
}
}
cout << resx << " " << resy;
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> cc, start, endd;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cc[x]++;
start[x] = !start[x] ? i : min(start[x], i);
endd[x] = !endd[x] ? i : max(endd[x], i);
}
int currentMax = 0, resx = 0, resy = n + 1;
for (auto x : cc) {
if (x.second >= currentMax) {
if (x.second > currentMax ||
resy - resx > endd[x.first] - start[x.first]) {
resx = start[x.first];
resy = endd[x.first];
}
currentMax = x.second;
}
}
cout << resx << " " << resy;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const long long mod = (1e9) + 7;
int n;
int cnt[N], a[N];
vector<int> vec[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
vec[x].push_back(i);
cnt[x]++;
a[i] = x;
}
int mx = 0;
for (int i = 1; i <= n; i++) {
int x = a[i];
mx = max(mx, cnt[x]);
}
int l = 1, r = n;
for (int i = 1; i <= n; i++) {
int x = a[i];
if (vec[x].size() == mx) {
int l1 = vec[x][0], r1 = vec[x].back();
if (r - l > r1 - l1) {
l = l1;
r = r1;
}
}
}
cout << l << " " << r;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const long long mod = (1e9) + 7;
int n;
int cnt[N], a[N];
vector<int> vec[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
vec[x].push_back(i);
cnt[x]++;
a[i] = x;
}
int mx = 0;
for (int i = 1; i <= n; i++) {
int x = a[i];
mx = max(mx, cnt[x]);
}
int l = 1, r = n;
for (int i = 1; i <= n; i++) {
int x = a[i];
if (vec[x].size() == mx) {
int l1 = vec[x][0], r1 = vec[x].back();
if (r - l > r1 - l1) {
l = l1;
r = r1;
}
}
}
cout << l << " " << r;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
int A[100010];
int has[1000100];
int l[1000100];
int r[1000100];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
has[A[i]]++;
if (!l[A[i]]) l[A[i]] = i;
r[A[i]] = i;
}
int mx = 0;
for (int i = 1; i <= 1000000; i++) mx = max(mx, has[i]);
int res = n + 1, se;
for (int i = 1; i <= 1000000; i++) {
if (has[i] == mx) {
if (res > r[i] - l[i] + 1) {
res = min(res, r[i] - l[i] + 1);
se = i;
}
}
}
cout << l[se] << " " << r[se] << endl;
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int A[100010];
int has[1000100];
int l[1000100];
int r[1000100];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
has[A[i]]++;
if (!l[A[i]]) l[A[i]] = i;
r[A[i]] = i;
}
int mx = 0;
for (int i = 1; i <= 1000000; i++) mx = max(mx, has[i]);
int res = n + 1, se;
for (int i = 1; i <= 1000000; i++) {
if (has[i] == mx) {
if (res > r[i] - l[i] + 1) {
res = min(res, r[i] - l[i] + 1);
se = i;
}
}
}
cout << l[se] << " " << r[se] << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int N = 100010;
const int K = 1000010;
int n, x[N], mx;
vector<int> v[K];
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x[i];
v[x[i]].push_back(i);
mx = max(mx, int(v[x[i]].size()));
}
int l = 1, r = n + 1;
for (int i = 1; i <= K - 10; ++i)
if (!v[i].empty())
if (v[i].back() - v[i][0] + 1 < r - l + 1 && int(v[i].size()) == mx) {
l = v[i][0];
r = v[i].back();
}
cout << l << ' ' << r << '\n';
}
|
### Prompt
Please create a solution in CPP to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int N = 100010;
const int K = 1000010;
int n, x[N], mx;
vector<int> v[K];
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x[i];
v[x[i]].push_back(i);
mx = max(mx, int(v[x[i]].size()));
}
int l = 1, r = n + 1;
for (int i = 1; i <= K - 10; ++i)
if (!v[i].empty())
if (v[i].back() - v[i][0] + 1 < r - l + 1 && int(v[i].size()) == mx) {
l = v[i][0];
r = v[i].back();
}
cout << l << ' ' << r << '\n';
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
static int freq[1000001];
static int l[1000001];
static int r[1000001];
int arr;
for (register int i = 0; i < n; i++) {
scanf("%d", &arr);
if (l[arr] == 0) {
l[arr] = i + 1;
r[arr] = i + 1;
freq[arr]++;
} else {
r[arr] = i + 1;
freq[arr]++;
}
}
int a1, a2, a3 = INT_MIN;
for (register int i = 1; i <= 1000000; i++) {
if (freq[i] > a3) {
a3 = freq[i];
a1 = l[i];
a2 = r[i];
} else if (freq[i] == a3) {
if (r[i] - l[i] < a2 - a1) {
a1 = l[i];
a2 = r[i];
}
}
}
printf("%d %d\n", a1, a2);
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
static int freq[1000001];
static int l[1000001];
static int r[1000001];
int arr;
for (register int i = 0; i < n; i++) {
scanf("%d", &arr);
if (l[arr] == 0) {
l[arr] = i + 1;
r[arr] = i + 1;
freq[arr]++;
} else {
r[arr] = i + 1;
freq[arr]++;
}
}
int a1, a2, a3 = INT_MIN;
for (register int i = 1; i <= 1000000; i++) {
if (freq[i] > a3) {
a3 = freq[i];
a1 = l[i];
a2 = r[i];
} else if (freq[i] == a3) {
if (r[i] - l[i] < a2 - a1) {
a1 = l[i];
a2 = r[i];
}
}
}
printf("%d %d\n", a1, a2);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int mxc = 0;
map<int, int> m;
map<int, int>::iterator it;
map<int, pair<int, int> > p;
int n;
cin >> n;
int nn;
int minInd = 1000009;
int mnc = 1000009;
for (int i = 1; i <= n; i++) {
cin >> nn;
it = m.find(nn);
if (it != m.end()) {
it->second = it->second + 1;
p[nn].second = i;
int newd = p[nn].second - p[nn].first;
if (mxc == it->second && mnc > newd) {
mnc = newd;
minInd = nn;
} else if (mxc < it->second) {
mxc = it->second;
mnc = newd;
minInd = nn;
}
} else {
m[nn] = 1;
if (mxc < 1) {
mxc = 1;
mnc = 0;
minInd = nn;
}
p[nn] = pair<int, int>(i, i);
}
}
cout << p[minInd].first << " " << p[minInd].second << "\n";
}
|
### Prompt
In cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int mxc = 0;
map<int, int> m;
map<int, int>::iterator it;
map<int, pair<int, int> > p;
int n;
cin >> n;
int nn;
int minInd = 1000009;
int mnc = 1000009;
for (int i = 1; i <= n; i++) {
cin >> nn;
it = m.find(nn);
if (it != m.end()) {
it->second = it->second + 1;
p[nn].second = i;
int newd = p[nn].second - p[nn].first;
if (mxc == it->second && mnc > newd) {
mnc = newd;
minInd = nn;
} else if (mxc < it->second) {
mxc = it->second;
mnc = newd;
minInd = nn;
}
} else {
m[nn] = 1;
if (mxc < 1) {
mxc = 1;
mnc = 0;
minInd = nn;
}
p[nn] = pair<int, int>(i, i);
}
}
cout << p[minInd].first << " " << p[minInd].second << "\n";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int firstOccur[1000010];
int secondOccur[1000010];
int cnt[1000010];
int main() {
int i, j, k, n, v1;
scanf("%d", &n);
int mx = 0;
for (i = 0; i < n; i++) {
scanf("%d", &v1);
if (firstOccur[v1] == 0) firstOccur[v1] = i + 1;
secondOccur[v1] = i + 1;
cnt[v1]++;
mx = max(mx, cnt[v1]);
}
int minD = 100000000;
int l, r;
for (i = 1; i <= 1000000; i++) {
int v1 = i;
if (mx == cnt[v1]) {
if (minD > (secondOccur[v1] - firstOccur[v1])) {
minD = (secondOccur[v1] - firstOccur[v1]);
l = firstOccur[v1];
r = secondOccur[v1];
}
}
}
cout << l << " " << r << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int firstOccur[1000010];
int secondOccur[1000010];
int cnt[1000010];
int main() {
int i, j, k, n, v1;
scanf("%d", &n);
int mx = 0;
for (i = 0; i < n; i++) {
scanf("%d", &v1);
if (firstOccur[v1] == 0) firstOccur[v1] = i + 1;
secondOccur[v1] = i + 1;
cnt[v1]++;
mx = max(mx, cnt[v1]);
}
int minD = 100000000;
int l, r;
for (i = 1; i <= 1000000; i++) {
int v1 = i;
if (mx == cnt[v1]) {
if (minD > (secondOccur[v1] - firstOccur[v1])) {
minD = (secondOccur[v1] - firstOccur[v1]);
l = firstOccur[v1];
r = secondOccur[v1];
}
}
}
cout << l << " " << r << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long qp(long long a, long long b, long long mod) {
long long t = 1;
while (b) {
if (b & 1) t = t * a % mod;
b >>= 1;
a = a * a % mod;
}
return t;
}
struct DOT {
int x;
int y;
};
inline void read(int &x) {
int k = 0;
char f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
x = k * f;
}
void ex() {
puts("No");
exit(0);
}
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
const int inf = 0x3f3f3f3f;
const long long Linf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
;
const int maxn = 1e5 + 34;
int n, a[maxn];
map<int, int> cnt;
map<int, int> lb, rb;
int main() {
scanf("%d", &n);
int mx = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
mx = max(mx, cnt[a[i]]);
if (cnt[a[i]] == 1) {
lb[a[i]] = i;
}
rb[a[i]] = i;
}
int ans = n;
int ansl = 1;
map<int, int>::iterator it;
for (it = cnt.begin(); it != cnt.end(); it++) {
if (it->second == mx) {
int tmp = rb[it->first] - lb[it->first] + 1;
if (ans > tmp) {
ans = tmp;
ansl = lb[it->first];
}
}
}
printf("%d %d\n", ansl, ansl + ans - 1);
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long qp(long long a, long long b, long long mod) {
long long t = 1;
while (b) {
if (b & 1) t = t * a % mod;
b >>= 1;
a = a * a % mod;
}
return t;
}
struct DOT {
int x;
int y;
};
inline void read(int &x) {
int k = 0;
char f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
x = k * f;
}
void ex() {
puts("No");
exit(0);
}
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
const int inf = 0x3f3f3f3f;
const long long Linf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
;
const int maxn = 1e5 + 34;
int n, a[maxn];
map<int, int> cnt;
map<int, int> lb, rb;
int main() {
scanf("%d", &n);
int mx = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
mx = max(mx, cnt[a[i]]);
if (cnt[a[i]] == 1) {
lb[a[i]] = i;
}
rb[a[i]] = i;
}
int ans = n;
int ansl = 1;
map<int, int>::iterator it;
for (it = cnt.begin(); it != cnt.end(); it++) {
if (it->second == mx) {
int tmp = rb[it->first] - lb[it->first] + 1;
if (ans > tmp) {
ans = tmp;
ansl = lb[it->first];
}
}
}
printf("%d %d\n", ansl, ansl + ans - 1);
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int tot;
int l, r;
};
map<int, node> mm;
inline int getInt() {
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
int num = 0;
while (ch <= '9' && ch >= '0') {
num = num * 10 + (ch - '0');
ch = getchar();
}
return num;
}
int main() {
ios_base::sync_with_stdio(0);
int n = getInt();
for (int i = 1; i <= n; i++) {
int x = getInt();
mm[x].tot++;
if (mm[x].l == 0) {
mm[x].l = i;
mm[x].r = i;
} else {
mm[x].r = i;
}
}
int maxnum = 0;
int maxl = 0, maxr = 0;
for (auto a : mm) {
if (a.second.tot > maxnum) {
maxnum = a.second.tot;
maxl = a.second.l;
maxr = a.second.r;
} else if (a.second.tot == maxnum &&
(maxr - maxl) > (a.second.r - a.second.l)) {
maxnum = a.second.tot;
maxl = a.second.l;
maxr = a.second.r;
}
}
printf("%d %d", maxl, maxr);
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
int tot;
int l, r;
};
map<int, node> mm;
inline int getInt() {
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
int num = 0;
while (ch <= '9' && ch >= '0') {
num = num * 10 + (ch - '0');
ch = getchar();
}
return num;
}
int main() {
ios_base::sync_with_stdio(0);
int n = getInt();
for (int i = 1; i <= n; i++) {
int x = getInt();
mm[x].tot++;
if (mm[x].l == 0) {
mm[x].l = i;
mm[x].r = i;
} else {
mm[x].r = i;
}
}
int maxnum = 0;
int maxl = 0, maxr = 0;
for (auto a : mm) {
if (a.second.tot > maxnum) {
maxnum = a.second.tot;
maxl = a.second.l;
maxr = a.second.r;
} else if (a.second.tot == maxnum &&
(maxr - maxl) > (a.second.r - a.second.l)) {
maxnum = a.second.tot;
maxl = a.second.l;
maxr = a.second.r;
}
}
printf("%d %d", maxl, maxr);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
vector<int> p, rank;
public:
UnionFind(int N) {
rank.assign(N, 0);
p.assign(N, 0);
for (int i = 0; i < N; i++) {
p[i] = i;
}
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
if (!isSameSet(i, j)) {
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y])
p[y] = x;
else {
p[x] = y;
if (rank[x] == rank[y]) rank[y]++;
}
}
}
};
class SegmentTree {
private:
vector<int> st, A;
int n;
int left(int p) { return p << 1; }
int right(int p) { return (p << 1) + 1; }
void build(int p, int L, int R) {
if (L == R)
st[p] = L;
else {
build(left(p), L, (L + R) / 2);
build(right(p), (L + R) / 2 + 1, R);
int p1 = st[left(p)], p2 = st[right(p)];
st[p] = (A[p1] <= A[p2]) ? p1 : p2;
}
}
int rmq(int p, int L, int R, int i, int j) {
if (i > R || j < L) return -1;
if (L >= i && R <= j) return st[p];
int p1 = rmq(left(p), L, (L + R) / 2, i, j);
int p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
if (p1 == -1) return p2;
if (p2 == -1) return p1;
return (A[p1] <= A[p2]) ? p1 : p2;
}
int update_point(int p, int L, int R, int idx, int new_value) {
int i = idx, j = idx;
if (i > R || j < L) return st[p];
if (L == i && R == j) {
A[i] = new_value;
return st[p] = L;
}
int p1, p2;
p1 = update_point(left(p), L, (L + R) / 2, idx, new_value);
p2 = update_point(right(p), (L + R) / 2 + 1, R, idx, new_value);
return st[p] = (A[p1] <= A[p2]) ? p1 : p2;
}
public:
SegmentTree(const vector<int> &_A) {
A = _A;
n = (int)A.size();
st.assign(4 * n, 0);
build(1, 0, n - 1);
}
int rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }
int update_point(int idx, int new_value) {
return update_point(1, 0, n - 1, idx, new_value);
}
};
class FenwickTree {
private:
vector<int> ft;
public:
FenwickTree(int n) { ft.assign(n + 1, 0); }
int rsq(int b) {
int sum = 0;
for (; b; b -= (b & (-b))) sum += ft[b];
return sum;
}
void adjust(int k, int v) {
for (; k < (int)ft.size(); k += (k & (-k))) {
ft[k] += v;
}
}
};
int fi[1000003];
int la[1000003];
int num[1000003];
int o[1000003];
int main() {
int n;
int a[100005];
scanf("%d", &n);
for (int i = int(0); i <= int(n - 1); i++) {
scanf("%d", &a[i]);
}
memset((num), 0, sizeof(num));
memset((fi), 0, sizeof(fi));
memset((la), 0, sizeof(la));
for (int i = int(0); i <= int(n - 1); i++) {
if (fi[a[i]] == 0) {
fi[a[i]] = i + 1;
la[a[i]] = i + 1;
num[a[i]]++;
} else {
la[a[i]] = i + 1;
num[a[i]]++;
}
}
int maxi = a[0], maxn = num[a[0]];
for (int i = int(1); i <= int(n - 1); i++) {
if (num[a[i]] > maxn) {
maxn = num[a[i]];
maxi = a[i];
} else if (num[a[i]] == maxn) {
if ((la[a[i]] - fi[a[i]]) < (la[maxi] - fi[maxi])) {
maxn = num[a[i]];
maxi = a[i];
}
}
}
cout << fi[maxi] << ' ' << la[maxi] << endl;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
vector<int> p, rank;
public:
UnionFind(int N) {
rank.assign(N, 0);
p.assign(N, 0);
for (int i = 0; i < N; i++) {
p[i] = i;
}
}
int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
if (!isSameSet(i, j)) {
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y])
p[y] = x;
else {
p[x] = y;
if (rank[x] == rank[y]) rank[y]++;
}
}
}
};
class SegmentTree {
private:
vector<int> st, A;
int n;
int left(int p) { return p << 1; }
int right(int p) { return (p << 1) + 1; }
void build(int p, int L, int R) {
if (L == R)
st[p] = L;
else {
build(left(p), L, (L + R) / 2);
build(right(p), (L + R) / 2 + 1, R);
int p1 = st[left(p)], p2 = st[right(p)];
st[p] = (A[p1] <= A[p2]) ? p1 : p2;
}
}
int rmq(int p, int L, int R, int i, int j) {
if (i > R || j < L) return -1;
if (L >= i && R <= j) return st[p];
int p1 = rmq(left(p), L, (L + R) / 2, i, j);
int p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
if (p1 == -1) return p2;
if (p2 == -1) return p1;
return (A[p1] <= A[p2]) ? p1 : p2;
}
int update_point(int p, int L, int R, int idx, int new_value) {
int i = idx, j = idx;
if (i > R || j < L) return st[p];
if (L == i && R == j) {
A[i] = new_value;
return st[p] = L;
}
int p1, p2;
p1 = update_point(left(p), L, (L + R) / 2, idx, new_value);
p2 = update_point(right(p), (L + R) / 2 + 1, R, idx, new_value);
return st[p] = (A[p1] <= A[p2]) ? p1 : p2;
}
public:
SegmentTree(const vector<int> &_A) {
A = _A;
n = (int)A.size();
st.assign(4 * n, 0);
build(1, 0, n - 1);
}
int rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }
int update_point(int idx, int new_value) {
return update_point(1, 0, n - 1, idx, new_value);
}
};
class FenwickTree {
private:
vector<int> ft;
public:
FenwickTree(int n) { ft.assign(n + 1, 0); }
int rsq(int b) {
int sum = 0;
for (; b; b -= (b & (-b))) sum += ft[b];
return sum;
}
void adjust(int k, int v) {
for (; k < (int)ft.size(); k += (k & (-k))) {
ft[k] += v;
}
}
};
int fi[1000003];
int la[1000003];
int num[1000003];
int o[1000003];
int main() {
int n;
int a[100005];
scanf("%d", &n);
for (int i = int(0); i <= int(n - 1); i++) {
scanf("%d", &a[i]);
}
memset((num), 0, sizeof(num));
memset((fi), 0, sizeof(fi));
memset((la), 0, sizeof(la));
for (int i = int(0); i <= int(n - 1); i++) {
if (fi[a[i]] == 0) {
fi[a[i]] = i + 1;
la[a[i]] = i + 1;
num[a[i]]++;
} else {
la[a[i]] = i + 1;
num[a[i]]++;
}
}
int maxi = a[0], maxn = num[a[0]];
for (int i = int(1); i <= int(n - 1); i++) {
if (num[a[i]] > maxn) {
maxn = num[a[i]];
maxi = a[i];
} else if (num[a[i]] == maxn) {
if ((la[a[i]] - fi[a[i]]) < (la[maxi] - fi[maxi])) {
maxn = num[a[i]];
maxi = a[i];
}
}
}
cout << fi[maxi] << ' ' << la[maxi] << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void debug(T1 e) {
cout << e << endl;
}
template <class T1, class T2>
void debug(T1 e1, T2 e2) {
cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void debug(T1 e1, T2 e2, T3 e3) {
cout << e1 << "\t" << e2 << "\t" << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void debug(T1 e1, T2 e2, T3 e3, T4 e4) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << "\t"
<< e6 << endl;
}
template <class T>
void debug(vector<vector<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
cout << endl;
}
template <class T>
void debug(vector<basic_string<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j];
cout << endl;
}
cout << endl;
}
template <class T>
void debug(T e[110][110], int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
}
template <class T>
string toString(T n) {
ostringstream oss;
oss << n;
oss.flush();
return oss.str();
}
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
bool isVowel(char ch) {
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
int main() {
vector<int> counta, last_pos, first_pos;
counta.clear();
last_pos.clear();
first_pos.clear();
int n;
int i;
cin >> n;
for (i = 0; i <= 1000008; i++) {
counta.push_back(0);
first_pos.push_back(0);
last_pos.push_back(0);
}
int maximum = 0;
int minNum = 1000000;
int maxNum = 0;
vector<int> V;
V.clear();
for (i = 1; i <= n; i++) {
int temp = 0;
cin >> temp;
V.push_back(temp);
if (counta[temp] == 0) {
counta[temp]++;
first_pos[temp] = i;
last_pos[temp] = i;
} else {
counta[temp]++;
last_pos[temp] = i;
}
if (counta[temp] > maximum) {
maximum = counta[temp];
}
if (temp < minNum) {
minNum = temp;
}
if (temp > maxNum) {
maxNum = temp;
}
}
int start = 0, endd = 0, length = 10000000;
sort(V.begin(), V.end());
for (i = 0; i <= n - 1; i++) {
if (counta[V[i]] == maximum) {
int tstart = first_pos[V[i]];
int tendd = last_pos[V[i]];
int tlength = tendd - tstart;
if (tlength < length) {
length = tlength;
start = tstart;
endd = tendd;
}
}
}
cout << start << " " << endd << endl;
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void debug(T1 e) {
cout << e << endl;
}
template <class T1, class T2>
void debug(T1 e1, T2 e2) {
cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void debug(T1 e1, T2 e2, T3 e3) {
cout << e1 << "\t" << e2 << "\t" << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void debug(T1 e1, T2 e2, T3 e3, T4 e4) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << "\t"
<< e6 << endl;
}
template <class T>
void debug(vector<vector<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
cout << endl;
}
template <class T>
void debug(vector<basic_string<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j];
cout << endl;
}
cout << endl;
}
template <class T>
void debug(T e[110][110], int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
}
template <class T>
string toString(T n) {
ostringstream oss;
oss << n;
oss.flush();
return oss.str();
}
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
bool isVowel(char ch) {
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
int main() {
vector<int> counta, last_pos, first_pos;
counta.clear();
last_pos.clear();
first_pos.clear();
int n;
int i;
cin >> n;
for (i = 0; i <= 1000008; i++) {
counta.push_back(0);
first_pos.push_back(0);
last_pos.push_back(0);
}
int maximum = 0;
int minNum = 1000000;
int maxNum = 0;
vector<int> V;
V.clear();
for (i = 1; i <= n; i++) {
int temp = 0;
cin >> temp;
V.push_back(temp);
if (counta[temp] == 0) {
counta[temp]++;
first_pos[temp] = i;
last_pos[temp] = i;
} else {
counta[temp]++;
last_pos[temp] = i;
}
if (counta[temp] > maximum) {
maximum = counta[temp];
}
if (temp < minNum) {
minNum = temp;
}
if (temp > maxNum) {
maxNum = temp;
}
}
int start = 0, endd = 0, length = 10000000;
sort(V.begin(), V.end());
for (i = 0; i <= n - 1; i++) {
if (counta[V[i]] == maximum) {
int tstart = first_pos[V[i]];
int tendd = last_pos[V[i]];
int tlength = tendd - tstart;
if (tlength < length) {
length = tlength;
start = tstart;
endd = tendd;
}
}
}
cout << start << " " << endd << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int b[maxn];
map<int, vector<int> > a;
int main() {
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
b[i] = x;
if (!a.count(x)) {
a[x] = vector<int>();
}
a[x].push_back(i + 1);
}
sort(b, b + n);
int ms = 1, mi = 0x7fffffff;
for (int i = 0; i < n; i++) {
if (a[b[i]].size() > ms) {
ms = a[b[i]].size();
}
}
int l = 0, r = 0;
if (ms == 1) {
printf("1 1\n");
} else {
for (int i = 0; i < n; i++) {
if (a[b[i]].size() == ms) {
int temp = a[b[i]].size();
int tt = a[b[i]][temp - 1] - a[b[i]][0];
if (mi > tt) {
mi = tt;
l = a[b[i]][0];
r = a[b[i]][temp - 1];
}
}
}
printf("%d %d\n", l, r);
}
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int b[maxn];
map<int, vector<int> > a;
int main() {
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
b[i] = x;
if (!a.count(x)) {
a[x] = vector<int>();
}
a[x].push_back(i + 1);
}
sort(b, b + n);
int ms = 1, mi = 0x7fffffff;
for (int i = 0; i < n; i++) {
if (a[b[i]].size() > ms) {
ms = a[b[i]].size();
}
}
int l = 0, r = 0;
if (ms == 1) {
printf("1 1\n");
} else {
for (int i = 0; i < n; i++) {
if (a[b[i]].size() == ms) {
int temp = a[b[i]].size();
int tt = a[b[i]][temp - 1] - a[b[i]][0];
if (mi > tt) {
mi = tt;
l = a[b[i]][0];
r = a[b[i]][temp - 1];
}
}
}
printf("%d %d\n", l, r);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int s;
int e;
int num;
} b[1000005];
int a[1000005];
int main() {
int n;
int i;
while (scanf("%d", &n) != EOF) {
for (i = 1; i < 1000005; i++) {
b[i].num = 0;
b[i].s = -1;
b[i].e = -1;
}
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= n; i++) {
if (b[a[i]].num == 0) b[a[i]].s = i;
b[a[i]].num++;
b[a[i]].e = i;
}
int k = 0, cnt = 0;
for (i = 1; i < 1000005; i++) {
if (b[i].num > cnt) {
k = i;
cnt = b[i].num;
} else if (b[i].num == cnt) {
if (b[i].e - b[i].s <= b[k].e - b[k].s) k = i;
}
}
printf("%d %d\n", b[k].s, b[k].e);
}
}
|
### Prompt
In Cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
int s;
int e;
int num;
} b[1000005];
int a[1000005];
int main() {
int n;
int i;
while (scanf("%d", &n) != EOF) {
for (i = 1; i < 1000005; i++) {
b[i].num = 0;
b[i].s = -1;
b[i].e = -1;
}
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= n; i++) {
if (b[a[i]].num == 0) b[a[i]].s = i;
b[a[i]].num++;
b[a[i]].e = i;
}
int k = 0, cnt = 0;
for (i = 1; i < 1000005; i++) {
if (b[i].num > cnt) {
k = i;
cnt = b[i].num;
} else if (b[i].num == cnt) {
if (b[i].e - b[i].s <= b[k].e - b[k].s) k = i;
}
}
printf("%d %d\n", b[k].s, b[k].e);
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (!b) return a;
return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
long long modpow(long long a, long long b, long long mod) {
long long x = 1, y = a;
while (b > 0) {
if (b % 2 == 0) {
x = (x * y);
if (x > mod) x %= mod;
}
y = y * y;
if (y > mod) y %= mod;
b /= 2;
}
return x;
}
long long mpow(long long a, long long n) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % 1000000007;
b = (b * b) % 1000000007;
n >>= 1;
}
return (long long)ret;
}
long long modInverse(long long a, long long p) { return modpow(a, p - 2, p); }
long long extGcd(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extGcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
int v[1000003][3];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i += 1) {
int temp;
scanf("%d", &temp);
if (v[temp][0] == 0) {
v[temp][0]++;
v[temp][1] = i + 1;
v[temp][2] = i + 1;
} else {
v[temp][0]++;
v[temp][2] = i + 1;
}
}
int pos = 0, max = -1;
for (int i = 1; i <= 1000000; i += 1) {
if (v[i][0] > max) {
max = v[i][0];
}
}
vector<pair<int, int> > w;
for (int i = 1; i <= 1000000; i += 1) {
if (v[i][0] == max) w.push_back(make_pair(v[i][1], v[i][2]));
}
int l = -1, r = -1;
int diff = 99999999;
for (int i = 0; i < w.size(); i += 1) {
if (w[i].second - w[i].first < diff) {
l = w[i].first;
r = w[i].second;
diff = r - l;
}
}
cout << l << " " << r << endl;
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (!b) return a;
return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
long long modpow(long long a, long long b, long long mod) {
long long x = 1, y = a;
while (b > 0) {
if (b % 2 == 0) {
x = (x * y);
if (x > mod) x %= mod;
}
y = y * y;
if (y > mod) y %= mod;
b /= 2;
}
return x;
}
long long mpow(long long a, long long n) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % 1000000007;
b = (b * b) % 1000000007;
n >>= 1;
}
return (long long)ret;
}
long long modInverse(long long a, long long p) { return modpow(a, p - 2, p); }
long long extGcd(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extGcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
int v[1000003][3];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i += 1) {
int temp;
scanf("%d", &temp);
if (v[temp][0] == 0) {
v[temp][0]++;
v[temp][1] = i + 1;
v[temp][2] = i + 1;
} else {
v[temp][0]++;
v[temp][2] = i + 1;
}
}
int pos = 0, max = -1;
for (int i = 1; i <= 1000000; i += 1) {
if (v[i][0] > max) {
max = v[i][0];
}
}
vector<pair<int, int> > w;
for (int i = 1; i <= 1000000; i += 1) {
if (v[i][0] == max) w.push_back(make_pair(v[i][1], v[i][2]));
}
int l = -1, r = -1;
int diff = 99999999;
for (int i = 0; i < w.size(); i += 1) {
if (w[i].second - w[i].first < diff) {
l = w[i].first;
r = w[i].second;
diff = r - l;
}
}
cout << l << " " << r << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct pi {
int num, l, r;
} c[N];
int n, u;
int main() {
while (scanf("%d", &n) != EOF) {
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (c[u].num == 0) c[u].l = i;
c[u].num++;
c[u].r = i;
}
int ans = 0, l, r, num = 0;
for (int i = 1; i < N; i++) {
if (!c[i].num) continue;
if (c[i].num > num) {
num = c[i].num;
l = c[i].l;
r = c[i].r;
ans = r - l + 1;
} else if (c[i].num == num) {
int k = c[i].r - c[i].l + 1;
if (k < ans) {
ans = k;
l = c[i].l;
r = c[i].r;
}
}
}
printf("%d %d\n", l, r);
}
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct pi {
int num, l, r;
} c[N];
int n, u;
int main() {
while (scanf("%d", &n) != EOF) {
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (c[u].num == 0) c[u].l = i;
c[u].num++;
c[u].r = i;
}
int ans = 0, l, r, num = 0;
for (int i = 1; i < N; i++) {
if (!c[i].num) continue;
if (c[i].num > num) {
num = c[i].num;
l = c[i].l;
r = c[i].r;
ans = r - l + 1;
} else if (c[i].num == num) {
int k = c[i].r - c[i].l + 1;
if (k < ans) {
ans = k;
l = c[i].l;
r = c[i].r;
}
}
}
printf("%d %d\n", l, r);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 2000 * 1000, MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1000 * 1LL * 1000000 * 1000 * 1000000;
vector<int> cnt[1001000], need;
int a[200000], n;
int main() {
srand(time(NULL));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]].push_back(i);
}
int mx = 0;
for (int i = 1; i <= 1000000; i++) {
mx = max(mx, int(cnt[i].size()));
}
for (int i = 1; i <= 1000000; i++) {
if (cnt[i].size() == mx) {
need.push_back(i);
}
}
int Mx = inf, l, r;
for (int i = 0; i < need.size(); i++) {
if (Mx > cnt[need[i]][cnt[need[i]].size() - 1] - cnt[need[i]][0] + 1) {
Mx = cnt[need[i]][cnt[need[i]].size() - 1] - cnt[need[i]][0] + 1;
r = cnt[need[i]][cnt[need[i]].size() - 1];
l = cnt[need[i]][0];
}
}
printf("%d %d", l, r);
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 2000 * 1000, MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1000 * 1LL * 1000000 * 1000 * 1000000;
vector<int> cnt[1001000], need;
int a[200000], n;
int main() {
srand(time(NULL));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
cnt[a[i]].push_back(i);
}
int mx = 0;
for (int i = 1; i <= 1000000; i++) {
mx = max(mx, int(cnt[i].size()));
}
for (int i = 1; i <= 1000000; i++) {
if (cnt[i].size() == mx) {
need.push_back(i);
}
}
int Mx = inf, l, r;
for (int i = 0; i < need.size(); i++) {
if (Mx > cnt[need[i]][cnt[need[i]].size() - 1] - cnt[need[i]][0] + 1) {
Mx = cnt[need[i]][cnt[need[i]].size() - 1] - cnt[need[i]][0] + 1;
r = cnt[need[i]][cnt[need[i]].size() - 1];
l = cnt[need[i]][0];
}
}
printf("%d %d", l, r);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int l[N], r[N], cnt[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < N; ++i) {
l[i] = 1e9;
r[i] = -1e9;
}
int n;
std::cin >> n;
int mx = 0;
for (int i = 0; i < n; ++i) {
int x;
std::cin >> x;
cnt[x]++;
mx = std::max(mx, cnt[x]);
l[x] = std::min(l[x], i);
r[x] = std::max(r[x], i);
}
int answ = 1e9, l1 = 0, r1 = 0;
for (int i = 0; i < N; ++i) {
if (cnt[i] == mx) {
if (r[i] - l[i] + 1 < answ) {
answ = r[i] - l[i] + 1;
l1 = l[i];
r1 = r[i];
}
}
}
std::cout << l1 + 1 << ' ' << r1 + 1 << '\n';
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int l[N], r[N], cnt[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < N; ++i) {
l[i] = 1e9;
r[i] = -1e9;
}
int n;
std::cin >> n;
int mx = 0;
for (int i = 0; i < n; ++i) {
int x;
std::cin >> x;
cnt[x]++;
mx = std::max(mx, cnt[x]);
l[x] = std::min(l[x], i);
r[x] = std::max(r[x], i);
}
int answ = 1e9, l1 = 0, r1 = 0;
for (int i = 0; i < N; ++i) {
if (cnt[i] == mx) {
if (r[i] - l[i] + 1 < answ) {
answ = r[i] - l[i] + 1;
l1 = l[i];
r1 = r[i];
}
}
}
std::cout << l1 + 1 << ' ' << r1 + 1 << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
const int MAX = 1e6 + 5;
int n;
int a[MAX];
int l[MAX], r[MAX], sum[MAX];
int main() {
fill(l, l + MAX, 1e9);
fill(r, r + MAX, -1);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
sum[a[i]]++;
l[a[i]] = min(l[a[i]], i);
r[a[i]] = max(r[a[i]], i);
}
int res = 0, rl = -1, rr = -1;
for (int i = 1; i < MAX; ++i) {
if (sum[i] > res) {
res = sum[i];
rl = l[i];
rr = r[i];
} else if (sum[i] == res && r[i] - l[i] < rr - rl) {
rl = l[i];
rr = r[i];
}
}
cout << rl + 1 << " " << rr + 1;
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
const int MAX = 1e6 + 5;
int n;
int a[MAX];
int l[MAX], r[MAX], sum[MAX];
int main() {
fill(l, l + MAX, 1e9);
fill(r, r + MAX, -1);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
sum[a[i]]++;
l[a[i]] = min(l[a[i]], i);
r[a[i]] = max(r[a[i]], i);
}
int res = 0, rl = -1, rr = -1;
for (int i = 1; i < MAX; ++i) {
if (sum[i] > res) {
res = sum[i];
rl = l[i];
rr = r[i];
} else if (sum[i] == res && r[i] - l[i] < rr - rl) {
rl = l[i];
rr = r[i];
}
}
cout << rl + 1 << " " << rr + 1;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int MAXNUM = 1000010;
int A[MAXNUM];
int B[MAXNUM];
void __main() {
int n;
cin >> n;
fill(A, A + MAXNUM, 0);
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
A[temp]++;
B[i] = temp;
}
int maxoc = *max_element(A, A + MAXNUM);
map<int, pair<int, int> > occ;
for (int i = 0; i < MAXNUM; i++)
if (A[i] == maxoc) occ.insert(make_pair(i, make_pair(-1, -1)));
for (int i = 0; i < n; i++) {
int cure = B[i];
if (occ.find(cure) != occ.end()) {
auto mp = occ[cure];
if (mp.first == -1) {
occ[cure].first = i;
A[cure]--;
}
if (A[cure] > 0)
A[cure]--;
else {
occ[cure].second = i;
}
}
}
pair<int, int> ans;
int blen = 1e8;
for (auto it = occ.begin(); it != occ.end(); it++) {
int curlen = it->second.second - it->second.first + 1;
if (blen > curlen) {
blen = curlen;
ans = it->second;
}
}
cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
int main() {
__main();
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXNUM = 1000010;
int A[MAXNUM];
int B[MAXNUM];
void __main() {
int n;
cin >> n;
fill(A, A + MAXNUM, 0);
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
A[temp]++;
B[i] = temp;
}
int maxoc = *max_element(A, A + MAXNUM);
map<int, pair<int, int> > occ;
for (int i = 0; i < MAXNUM; i++)
if (A[i] == maxoc) occ.insert(make_pair(i, make_pair(-1, -1)));
for (int i = 0; i < n; i++) {
int cure = B[i];
if (occ.find(cure) != occ.end()) {
auto mp = occ[cure];
if (mp.first == -1) {
occ[cure].first = i;
A[cure]--;
}
if (A[cure] > 0)
A[cure]--;
else {
occ[cure].second = i;
}
}
}
pair<int, int> ans;
int blen = 1e8;
for (auto it = occ.begin(); it != occ.end(); it++) {
int curlen = it->second.second - it->second.first + 1;
if (blen > curlen) {
blen = curlen;
ans = it->second;
}
}
cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
int main() {
__main();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct pi {
int num, l, r;
} c[N];
int n, u;
int main() {
while (scanf("%d", &n) != EOF) {
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (c[u].num == 0) c[u].l = i;
c[u].num++;
c[u].r = i;
}
int ans = 0;
for (int i = 1; i < N; i++) {
if (!c[i].num) continue;
if (c[i].num > c[ans].num)
ans = i;
else if (c[i].num == c[ans].num && c[i].r - c[i].l < c[ans].r - c[ans].l)
ans = i;
}
printf("%d %d\n", c[ans].l, c[ans].r);
}
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct pi {
int num, l, r;
} c[N];
int n, u;
int main() {
while (scanf("%d", &n) != EOF) {
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (c[u].num == 0) c[u].l = i;
c[u].num++;
c[u].r = i;
}
int ans = 0;
for (int i = 1; i < N; i++) {
if (!c[i].num) continue;
if (c[i].num > c[ans].num)
ans = i;
else if (c[i].num == c[ans].num && c[i].r - c[i].l < c[ans].r - c[ans].l)
ans = i;
}
printf("%d %d\n", c[ans].l, c[ans].r);
}
return 0;
}
```
|
#include <bits/stdc++.h>
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& v) {
for (T& a : v) input >> a;
return input;
}
void answer(size_t x, size_t y) { std::cout << 1 + x << ' ' << 1 + y << '\n'; }
void solve(const std::vector<unsigned>& a) {
const size_t n = a.size();
struct Element {
unsigned f;
size_t l, r;
};
std::map<unsigned, Element> x;
for (size_t i = 0; i < n; ++i) {
const auto it = x.find(a[i]);
if (it == x.end()) {
x.emplace(a[i], Element{1, i, i});
} else {
++it->second.f;
it->second.r = i;
}
}
const Element* p = &x.begin()->second;
for (const auto& q : x) {
if (q.second.f < p->f) continue;
if (q.second.f > p->f || q.second.r - q.second.l < p->r - p->l)
p = &q.second;
}
answer(p->l, p->r);
}
int main() {
size_t n;
std::cin >> n;
std::vector<unsigned> a(n);
std::cin >> a;
solve(a);
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& v) {
for (T& a : v) input >> a;
return input;
}
void answer(size_t x, size_t y) { std::cout << 1 + x << ' ' << 1 + y << '\n'; }
void solve(const std::vector<unsigned>& a) {
const size_t n = a.size();
struct Element {
unsigned f;
size_t l, r;
};
std::map<unsigned, Element> x;
for (size_t i = 0; i < n; ++i) {
const auto it = x.find(a[i]);
if (it == x.end()) {
x.emplace(a[i], Element{1, i, i});
} else {
++it->second.f;
it->second.r = i;
}
}
const Element* p = &x.begin()->second;
for (const auto& q : x) {
if (q.second.f < p->f) continue;
if (q.second.f > p->f || q.second.r - q.second.l < p->r - p->l)
p = &q.second;
}
answer(p->l, p->r);
}
int main() {
size_t n;
std::cin >> n;
std::vector<unsigned> a(n);
std::cin >> a;
solve(a);
return 0;
}
```
|
#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
long long pows(long long a, long long n, long long m) {
long long res = 1;
while (n) {
if (n % 2 != 0) {
res = (res * a) % m;
n--;
} else {
a = (a * a) % m;
n = n / 2;
}
}
return res % m;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isprime(long long n) {
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
bool istrue(string s) {
int i = 0;
int j = s.size() - 1;
while (i < j) {
if (s[i] == s[j]) {
i++;
j--;
} else {
return false;
}
}
return true;
}
int a[1000001];
vector<int> ar[1000001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
map<int, int> mp;
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
if (mp[a[i]] > mx) {
mx = mp[a[i]];
}
ar[a[i]].push_back(i);
}
if (mx == 1) {
cout << 1 << " " << 1 << endl;
return 0;
}
int mn = 1000000007;
int x = -1, y = -1;
for (auto z : mp) {
int p = z.first;
if (z.second == mx) {
int g = -1, h = -1;
for (int res : ar[p]) {
if (g == -1) {
g = res;
} else {
h = res;
}
}
if (abs(h - g) < mn) {
x = g;
y = h;
mn = abs(h - g);
}
}
}
cout << x + 1 << " " << y + 1 << endl;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
long long pows(long long a, long long n, long long m) {
long long res = 1;
while (n) {
if (n % 2 != 0) {
res = (res * a) % m;
n--;
} else {
a = (a * a) % m;
n = n / 2;
}
}
return res % m;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isprime(long long n) {
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
bool istrue(string s) {
int i = 0;
int j = s.size() - 1;
while (i < j) {
if (s[i] == s[j]) {
i++;
j--;
} else {
return false;
}
}
return true;
}
int a[1000001];
vector<int> ar[1000001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
map<int, int> mp;
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
if (mp[a[i]] > mx) {
mx = mp[a[i]];
}
ar[a[i]].push_back(i);
}
if (mx == 1) {
cout << 1 << " " << 1 << endl;
return 0;
}
int mn = 1000000007;
int x = -1, y = -1;
for (auto z : mp) {
int p = z.first;
if (z.second == mx) {
int g = -1, h = -1;
for (int res : ar[p]) {
if (g == -1) {
g = res;
} else {
h = res;
}
}
if (abs(h - g) < mn) {
x = g;
y = h;
mn = abs(h - g);
}
}
}
cout << x + 1 << " " << y + 1 << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<int, int> a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i].first), a[i].second = i;
sort(a, a + n);
int l = 0, mx = 0, L = 0, R = 0;
for (int i = 1; i < n; i++) {
if (a[i].first != a[i - 1].first) {
if (i - l > mx) {
mx = i - l;
L = a[l].second, R = a[i - 1].second;
} else if (i - l == mx) {
if (R - L + 1 > a[i - 1].second - a[l].second + 1) {
L = a[l].second, R = a[i - 1].second;
}
}
l = i;
}
}
if (l != n - 1) {
if (n - l > mx) {
mx = n - l;
L = a[l].second, R = a[n - 1].second;
} else if (n - l == mx) {
if (R - L + 1 > a[n - 1].second - a[l].second + 1) {
L = a[l].second, R = a[n - 1].second;
}
}
l = n;
}
printf("%d %d\n", L + 1, R + 1);
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<int, int> a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i].first), a[i].second = i;
sort(a, a + n);
int l = 0, mx = 0, L = 0, R = 0;
for (int i = 1; i < n; i++) {
if (a[i].first != a[i - 1].first) {
if (i - l > mx) {
mx = i - l;
L = a[l].second, R = a[i - 1].second;
} else if (i - l == mx) {
if (R - L + 1 > a[i - 1].second - a[l].second + 1) {
L = a[l].second, R = a[i - 1].second;
}
}
l = i;
}
}
if (l != n - 1) {
if (n - l > mx) {
mx = n - l;
L = a[l].second, R = a[n - 1].second;
} else if (n - l == mx) {
if (R - L + 1 > a[n - 1].second - a[l].second + 1) {
L = a[l].second, R = a[n - 1].second;
}
}
l = n;
}
printf("%d %d\n", L + 1, R + 1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int cnt[1000005];
int beg[1000005];
int een[1000005];
int main() {
int n, maxx = 1;
memset(cnt, 0, sizeof(cnt));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (cnt[a[i]] == 0) beg[a[i]] = i;
cnt[a[i]]++;
een[a[i]] = i;
if (cnt[a[i]] > cnt[maxx])
maxx = a[i];
else if (cnt[a[i]] == cnt[maxx] &&
een[a[i]] - beg[a[i]] < een[maxx] - beg[maxx])
maxx = a[i];
}
printf("%d %d\n", beg[maxx], een[maxx]);
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int cnt[1000005];
int beg[1000005];
int een[1000005];
int main() {
int n, maxx = 1;
memset(cnt, 0, sizeof(cnt));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (cnt[a[i]] == 0) beg[a[i]] = i;
cnt[a[i]]++;
een[a[i]] = i;
if (cnt[a[i]] > cnt[maxx])
maxx = a[i];
else if (cnt[a[i]] == cnt[maxx] &&
een[a[i]] - beg[a[i]] < een[maxx] - beg[maxx])
maxx = a[i];
}
printf("%d %d\n", beg[maxx], een[maxx]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
int st[1001000], en[1001000], num[1001000];
int l, r;
int tim;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
++num[x];
if (!st[x]) st[x] = i;
en[x] = i;
}
for (int x = 1; x < 1001000; ++x) {
if (num[x] > tim) {
tim = num[x];
l = st[x];
r = en[x];
} else if (num[x] == tim) {
if (en[x] - st[x] < r - l) {
l = st[x];
r = en[x];
}
}
}
printf("%d %d\n", l, r);
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int st[1001000], en[1001000], num[1001000];
int l, r;
int tim;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
++num[x];
if (!st[x]) st[x] = i;
en[x] = i;
}
for (int x = 1; x < 1001000; ++x) {
if (num[x] > tim) {
tim = num[x];
l = st[x];
r = en[x];
} else if (num[x] == tim) {
if (en[x] - st[x] < r - l) {
l = st[x];
r = en[x];
}
}
}
printf("%d %d\n", l, r);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int numbers[100000];
map<int, int> r;
map<int, int> l;
map<int, int> cnt;
for (int i = 0; i < n; i++) {
cin >> numbers[i];
if (l[numbers[i]] == 0) {
l[numbers[i]] = i + 1;
r[numbers[i]] = i + 1;
cnt[numbers[i]] = 1;
} else {
r[numbers[i]] = i + 1;
cnt[numbers[i]]++;
}
}
int maxRange = -2147483647;
int minRange = 2147483647;
int right = 0;
int left = 0;
map<int, int>::iterator iterRight;
map<int, int>::iterator iterLeft;
map<int, int>::iterator iterCnt;
iterRight = r.begin();
iterCnt = cnt.begin();
for (iterLeft = l.begin(); iterLeft != l.end(); iterLeft++) {
if (iterCnt->second > maxRange) {
maxRange = iterCnt->second;
minRange = iterRight->second - iterLeft->second + 1;
right = iterRight->second;
left = iterLeft->second;
}
if (iterCnt->second == maxRange) {
int curRange = iterRight->second - iterLeft->second + 1;
if (curRange < minRange) {
minRange = curRange;
right = iterRight->second;
left = iterLeft->second;
}
}
iterRight++;
iterCnt++;
}
cout << left << " " << right;
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int numbers[100000];
map<int, int> r;
map<int, int> l;
map<int, int> cnt;
for (int i = 0; i < n; i++) {
cin >> numbers[i];
if (l[numbers[i]] == 0) {
l[numbers[i]] = i + 1;
r[numbers[i]] = i + 1;
cnt[numbers[i]] = 1;
} else {
r[numbers[i]] = i + 1;
cnt[numbers[i]]++;
}
}
int maxRange = -2147483647;
int minRange = 2147483647;
int right = 0;
int left = 0;
map<int, int>::iterator iterRight;
map<int, int>::iterator iterLeft;
map<int, int>::iterator iterCnt;
iterRight = r.begin();
iterCnt = cnt.begin();
for (iterLeft = l.begin(); iterLeft != l.end(); iterLeft++) {
if (iterCnt->second > maxRange) {
maxRange = iterCnt->second;
minRange = iterRight->second - iterLeft->second + 1;
right = iterRight->second;
left = iterLeft->second;
}
if (iterCnt->second == maxRange) {
int curRange = iterRight->second - iterLeft->second + 1;
if (curRange < minRange) {
minRange = curRange;
right = iterRight->second;
left = iterLeft->second;
}
}
iterRight++;
iterCnt++;
}
cout << left << " " << right;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m, lo, hi;
int main() {
long long total, val;
cin >> total;
long long save;
long long max1 = -1;
for (long long i = 1; i <= total; i++) {
cin >> val;
m[val]++;
if (!lo[val]) lo[val] = i;
hi[val] = i;
if (m[val] > max1) {
max1 = m[val];
save = val;
} else if (m[val] == max1) {
if (hi[val] - lo[val] < hi[save] - lo[save]) {
save = val;
}
}
}
cout << lo[save] << " " << hi[save] << endl;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m, lo, hi;
int main() {
long long total, val;
cin >> total;
long long save;
long long max1 = -1;
for (long long i = 1; i <= total; i++) {
cin >> val;
m[val]++;
if (!lo[val]) lo[val] = i;
hi[val] = i;
if (m[val] > max1) {
max1 = m[val];
save = val;
} else if (m[val] == max1) {
if (hi[val] - lo[val] < hi[save] - lo[save]) {
save = val;
}
}
}
cout << lo[save] << " " << hi[save] << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct count_a {
int v, min, max;
count_a() {
v = 0;
min = 0;
max = 0;
}
};
count_a cnt[1000005];
int num[100005];
int main() {
int n;
int max_num = 0, last_value = 0, last_dis = 100005;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &num[i]);
cnt[num[i]].v++;
if (cnt[num[i]].min != 0) {
cnt[num[i]].max = i;
} else {
cnt[num[i]].min = i;
cnt[num[i]].max = i;
}
if (cnt[num[i]].v > last_value) {
last_value = cnt[num[i]].v;
max_num = num[i];
last_dis = cnt[num[i]].max - cnt[num[i]].min;
} else if (cnt[num[i]].v == last_value) {
if (cnt[num[i]].max - cnt[num[i]].min < last_dis) {
last_value = cnt[num[i]].v;
max_num = num[i];
last_dis = cnt[num[i]].max - cnt[num[i]].min;
}
}
}
printf("%d %d\n", cnt[max_num].min, cnt[max_num].max);
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct count_a {
int v, min, max;
count_a() {
v = 0;
min = 0;
max = 0;
}
};
count_a cnt[1000005];
int num[100005];
int main() {
int n;
int max_num = 0, last_value = 0, last_dis = 100005;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &num[i]);
cnt[num[i]].v++;
if (cnt[num[i]].min != 0) {
cnt[num[i]].max = i;
} else {
cnt[num[i]].min = i;
cnt[num[i]].max = i;
}
if (cnt[num[i]].v > last_value) {
last_value = cnt[num[i]].v;
max_num = num[i];
last_dis = cnt[num[i]].max - cnt[num[i]].min;
} else if (cnt[num[i]].v == last_value) {
if (cnt[num[i]].max - cnt[num[i]].min < last_dis) {
last_value = cnt[num[i]].v;
max_num = num[i];
last_dis = cnt[num[i]].max - cnt[num[i]].min;
}
}
}
printf("%d %d\n", cnt[max_num].min, cnt[max_num].max);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int32_t MOD = 1000000007;
long long int prime[1000001] = {0}, ans = 0;
long long int pwe(long long int a, long long int b) {
if (b == 0) return 1;
long long int res = pwe(a, b / 2);
res *= res;
res %= MOD;
if (b % 2)
return (res * a) % MOD;
else
return (res);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return a * b / gcd(a, b);
}
void file() {}
long long int sumofdigits(long long int n) {
long long int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
void sieve() {
prime[0] = 0;
prime[1] = 0;
prime[2] = 1;
long long int i, j, k;
for (i = 3; i <= 1000001; i += 2) {
prime[i] = 1;
}
for (i = 3; i <= 1000001; i++) {
if (prime[i]) {
for (j = i * i; j <= 1000001; j += 2 * i) prime[j] = 0;
}
}
}
bool cmp(pair<long long int, long long int> &a,
pair<long long int, long long int> &b) {
if (a.first != b.first) {
return b.first > a.first;
} else {
return b.second > a.second;
}
}
void solve() {
long long int n, x;
map<long long int, pair<long long int, long long int> > m;
cin >> n;
long long int ma = INT_MIN, in = INT_MIN;
std::vector<long long int> v(n), h(1000001);
for (long long int i = 0; i < n; ++i) {
cin >> v[i], h[v[i]]++;
m[v[i]].first = -1;
m[v[i]].second = -1;
ma = max(ma, h[v[i]]);
}
set<long long int> e;
for (long long int i = 0; i <= 1000001 - 1; i++) {
if (ma == h[i]) {
ma = h[i];
e.insert(i);
}
}
long long int s = -1, en = -1;
ma = INT_MAX;
for (long long int i = 0; i < n; ++i) {
if (e.count(v[i])) {
if (m[v[i]].first == -1) {
m[v[i]].first = i + 1;
} else {
m[v[i]].second = i + 1;
}
}
}
for (auto it : m) {
if (it.second.first != -1 and it.second.second != -1) {
if (it.second.second - it.second.first < ma) {
ma = it.second.second - it.second.first;
s = it.second.first;
en = it.second.second;
}
}
}
if (s == -1 or en == -1) s = 1, en = 1;
cout << s << " ";
cout << en << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
{ solve(); }
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int32_t MOD = 1000000007;
long long int prime[1000001] = {0}, ans = 0;
long long int pwe(long long int a, long long int b) {
if (b == 0) return 1;
long long int res = pwe(a, b / 2);
res *= res;
res %= MOD;
if (b % 2)
return (res * a) % MOD;
else
return (res);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return a * b / gcd(a, b);
}
void file() {}
long long int sumofdigits(long long int n) {
long long int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
void sieve() {
prime[0] = 0;
prime[1] = 0;
prime[2] = 1;
long long int i, j, k;
for (i = 3; i <= 1000001; i += 2) {
prime[i] = 1;
}
for (i = 3; i <= 1000001; i++) {
if (prime[i]) {
for (j = i * i; j <= 1000001; j += 2 * i) prime[j] = 0;
}
}
}
bool cmp(pair<long long int, long long int> &a,
pair<long long int, long long int> &b) {
if (a.first != b.first) {
return b.first > a.first;
} else {
return b.second > a.second;
}
}
void solve() {
long long int n, x;
map<long long int, pair<long long int, long long int> > m;
cin >> n;
long long int ma = INT_MIN, in = INT_MIN;
std::vector<long long int> v(n), h(1000001);
for (long long int i = 0; i < n; ++i) {
cin >> v[i], h[v[i]]++;
m[v[i]].first = -1;
m[v[i]].second = -1;
ma = max(ma, h[v[i]]);
}
set<long long int> e;
for (long long int i = 0; i <= 1000001 - 1; i++) {
if (ma == h[i]) {
ma = h[i];
e.insert(i);
}
}
long long int s = -1, en = -1;
ma = INT_MAX;
for (long long int i = 0; i < n; ++i) {
if (e.count(v[i])) {
if (m[v[i]].first == -1) {
m[v[i]].first = i + 1;
} else {
m[v[i]].second = i + 1;
}
}
}
for (auto it : m) {
if (it.second.first != -1 and it.second.second != -1) {
if (it.second.second - it.second.first < ma) {
ma = it.second.second - it.second.first;
s = it.second.first;
en = it.second.second;
}
}
}
if (s == -1 or en == -1) s = 1, en = 1;
cout << s << " ";
cout << en << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
{ solve(); }
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[100005], c[1000005], L[1000005], R[1000005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (c[a[i]] == 0) L[a[i]] = i;
R[a[i]] = i;
c[a[i]]++;
}
int ma = -1, ans = 1;
for (int i = 1; i <= 1000000; i++)
if (c[i] > ma) {
ans = i;
ma = c[i];
} else if (c[i] == ma) {
if (R[i] - L[i] < R[ans] - L[ans]) ans = i;
}
printf("%d %d\n", L[ans], R[ans]);
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100005], c[1000005], L[1000005], R[1000005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (c[a[i]] == 0) L[a[i]] = i;
R[a[i]] = i;
c[a[i]]++;
}
int ma = -1, ans = 1;
for (int i = 1; i <= 1000000; i++)
if (c[i] > ma) {
ans = i;
ma = c[i];
} else if (c[i] == ma) {
if (R[i] - L[i] < R[ans] - L[ans]) ans = i;
}
printf("%d %d\n", L[ans], R[ans]);
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int arr[100002];
bool vis[1000002];
int b[1000002], e[1000002];
vector<int> v1;
vector<pair<int, int> > v2;
bool compare(pair<int, int> p1, pair<int, int> p2) {
if ((p2.second - p2.first) > (p1.second - p1.first)) return true;
return false;
}
int main() {
int n, i, j, mx;
pair<int, int> pi;
memset(vis, false, sizeof(vis));
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
mp[arr[i]]++;
if (!vis[arr[i]]) {
vis[arr[i]] = true;
b[arr[i]] = i + 1;
e[arr[i]] = i + 1;
} else
e[arr[i]] = i + 1;
}
mx = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second > mx) mx = it->second;
}
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second == mx) v1.push_back(it->first);
}
for (j = 0; j < v1.size(); j++) {
v2.push_back({b[v1[j]], e[v1[j]]});
}
sort(v2.begin(), v2.end(), compare);
cout << v2[0].first << " " << v2[0].second << endl;
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int arr[100002];
bool vis[1000002];
int b[1000002], e[1000002];
vector<int> v1;
vector<pair<int, int> > v2;
bool compare(pair<int, int> p1, pair<int, int> p2) {
if ((p2.second - p2.first) > (p1.second - p1.first)) return true;
return false;
}
int main() {
int n, i, j, mx;
pair<int, int> pi;
memset(vis, false, sizeof(vis));
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
mp[arr[i]]++;
if (!vis[arr[i]]) {
vis[arr[i]] = true;
b[arr[i]] = i + 1;
e[arr[i]] = i + 1;
} else
e[arr[i]] = i + 1;
}
mx = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second > mx) mx = it->second;
}
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second == mx) v1.push_back(it->first);
}
for (j = 0; j < v1.size(); j++) {
v2.push_back({b[v1[j]], e[v1[j]]});
}
sort(v2.begin(), v2.end(), compare);
cout << v2[0].first << " " << v2[0].second << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> a(n), cnt(maxn, 0), left(maxn, 0), right(maxn);
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
if (left[a[i]] == 0) left[a[i]] = i + 1;
right[a[i]] = i + 1;
}
int mx = 0;
vector<int> val;
for (int i = 1; i <= maxn; i++) mx = max(mx, cnt[i]);
for (int i = 1; i <= maxn; i++) {
if (mx == cnt[i]) val.push_back(i);
}
int mn = INT_MAX, l = -1, r = -1;
for (auto x : val) {
int tmp = (right[x] - left[x] + 1);
if (tmp < mn) {
mn = tmp;
l = left[x];
r = right[x];
}
}
cout << l << ' ' << r << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) solve();
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> a(n), cnt(maxn, 0), left(maxn, 0), right(maxn);
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
if (left[a[i]] == 0) left[a[i]] = i + 1;
right[a[i]] = i + 1;
}
int mx = 0;
vector<int> val;
for (int i = 1; i <= maxn; i++) mx = max(mx, cnt[i]);
for (int i = 1; i <= maxn; i++) {
if (mx == cnt[i]) val.push_back(i);
}
int mn = INT_MAX, l = -1, r = -1;
for (auto x : val) {
int tmp = (right[x] - left[x] + 1);
if (tmp < mn) {
mn = tmp;
l = left[x];
r = right[x];
}
}
cout << l << ' ' << r << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, i, x;
map<long long, int> mp;
long long a[100005];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
mp[a[i]]++;
}
map<long long, int>::iterator it;
int maxi = -1;
for (it = mp.begin(); it != mp.end(); it++) {
maxi = max(maxi, it->second);
}
mp.clear();
map<long long, int> first;
for (i = 0; i < n; i++) {
if (first.find(a[i]) == first.end()) first[a[i]] = i;
}
int ans = INT_MAX;
int num, left, l, r, right;
for (i = 0; i < n; i++) {
mp[a[i]]++;
if (maxi == mp[a[i]]) {
num = a[i];
r = i;
l = first[a[i]];
if (ans > r - l) {
ans = r - l;
left = l;
right = r;
}
}
}
printf("%d %d\n", left + 1, right + 1);
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, i, x;
map<long long, int> mp;
long long a[100005];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
mp[a[i]]++;
}
map<long long, int>::iterator it;
int maxi = -1;
for (it = mp.begin(); it != mp.end(); it++) {
maxi = max(maxi, it->second);
}
mp.clear();
map<long long, int> first;
for (i = 0; i < n; i++) {
if (first.find(a[i]) == first.end()) first[a[i]] = i;
}
int ans = INT_MAX;
int num, left, l, r, right;
for (i = 0; i < n; i++) {
mp[a[i]]++;
if (maxi == mp[a[i]]) {
num = a[i];
r = i;
l = first[a[i]];
if (ans > r - l) {
ans = r - l;
left = l;
right = r;
}
}
}
printf("%d %d\n", left + 1, right + 1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const int INF = (int)(INT_MAX - 100);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(1e6);
int main() {
int n;
cin >> n;
vector<int> v(n), k(N + 1), d(N + 1);
vector<pair<int, int> > e(N + 1, {n, 1});
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
for (int i = 0; i < n; i++) {
k[v[i]]++;
e[v[i]].first = min(e[v[i]].first, i + 1);
e[v[i]].second = max(e[v[i]].first, i + 1);
}
int M = *max_element(k.begin(), k.end()), m = INF;
pair<int, int> ans;
for (int num = (1); num <= (N); num++) d[num] = e[num].second - e[num].first;
for (int num = (1); num <= (N); num++) {
if (k[num] != M) continue;
if (m <= d[num]) continue;
m = d[num];
ans = e[num];
}
cout << ans.first << " " << ans.second;
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const int INF = (int)(INT_MAX - 100);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(1e6);
int main() {
int n;
cin >> n;
vector<int> v(n), k(N + 1), d(N + 1);
vector<pair<int, int> > e(N + 1, {n, 1});
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
for (int i = 0; i < n; i++) {
k[v[i]]++;
e[v[i]].first = min(e[v[i]].first, i + 1);
e[v[i]].second = max(e[v[i]].first, i + 1);
}
int M = *max_element(k.begin(), k.end()), m = INF;
pair<int, int> ans;
for (int num = (1); num <= (N); num++) d[num] = e[num].second - e[num].first;
for (int num = (1); num <= (N); num++) {
if (k[num] != M) continue;
if (m <= d[num]) continue;
m = d[num];
ans = e[num];
}
cout << ans.first << " " << ans.second;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, z = 0, d = 1e7, p, k;
map<long long int, long long int> m;
cin >> n;
long long int a[n + 1];
vector<pair<long long int, long long int> > v;
v.push_back(make_pair(0, 0));
for (i = 1; i <= 1000000; i++) v.push_back(make_pair(0, 0));
for (i = 1; i <= n; i++) {
cin >> a[i];
m[a[i]]++;
}
for (i = 1; i <= n; i++) {
if (v[a[i]].first == 0) {
v[a[i]].first = i;
}
}
for (i = n; i >= 1; i--) {
if (v[a[i]].second == 0) {
v[a[i]].second = i;
}
}
map<long long int, long long int>::iterator it;
for (it = m.begin(); it != m.end(); it++) {
z = max(z, it->second);
}
for (it = m.begin(); it != m.end(); it++) {
if (z == it->second) {
if (d > v[it->first].second - v[it->first].first) {
d = v[it->first].second - v[it->first].first;
p = v[it->first].first;
k = v[it->first].second;
}
}
}
cout << p << " " << k << '\n';
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, z = 0, d = 1e7, p, k;
map<long long int, long long int> m;
cin >> n;
long long int a[n + 1];
vector<pair<long long int, long long int> > v;
v.push_back(make_pair(0, 0));
for (i = 1; i <= 1000000; i++) v.push_back(make_pair(0, 0));
for (i = 1; i <= n; i++) {
cin >> a[i];
m[a[i]]++;
}
for (i = 1; i <= n; i++) {
if (v[a[i]].first == 0) {
v[a[i]].first = i;
}
}
for (i = n; i >= 1; i--) {
if (v[a[i]].second == 0) {
v[a[i]].second = i;
}
}
map<long long int, long long int>::iterator it;
for (it = m.begin(); it != m.end(); it++) {
z = max(z, it->second);
}
for (it = m.begin(); it != m.end(); it++) {
if (z == it->second) {
if (d > v[it->first].second - v[it->first].first) {
d = v[it->first].second - v[it->first].first;
p = v[it->first].first;
k = v[it->first].second;
}
}
}
cout << p << " " << k << '\n';
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 10;
int n, a[maxN], ans_l, ans_r, len;
map<int, int> mp, lb, rb;
void solve() {
cin >> n;
for (int i = 1; i <= (int)(n); ++i) {
cin >> a[i];
}
for (int i = 1; i <= (int)(n); ++i) {
mp[a[i]]++;
}
int mx = 0;
for (auto &p : mp) {
uax(mx, p.second);
}
for (int i = 1; i <= (int)(n); ++i) {
rb[a[i]] = i;
}
for (int i = n; i; i--) {
lb[a[i]] = i;
}
len = n + 1;
for (auto &p : mp) {
if (p.second == mx) {
if (uin(len, rb[p.first] - lb[p.first] + 1)) {
ans_l = lb[p.first];
ans_r = rb[p.first];
}
}
}
cout << ans_l << " " << ans_r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while (T--) {
solve();
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 10;
int n, a[maxN], ans_l, ans_r, len;
map<int, int> mp, lb, rb;
void solve() {
cin >> n;
for (int i = 1; i <= (int)(n); ++i) {
cin >> a[i];
}
for (int i = 1; i <= (int)(n); ++i) {
mp[a[i]]++;
}
int mx = 0;
for (auto &p : mp) {
uax(mx, p.second);
}
for (int i = 1; i <= (int)(n); ++i) {
rb[a[i]] = i;
}
for (int i = n; i; i--) {
lb[a[i]] = i;
}
len = n + 1;
for (auto &p : mp) {
if (p.second == mx) {
if (uin(len, rb[p.first] - lb[p.first] + 1)) {
ans_l = lb[p.first];
ans_r = rb[p.first];
}
}
}
cout << ans_l << " " << ans_r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
while (T--) {
solve();
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int l[2000000 + 10], r[2000000 + 10], t[2000000 + 10], n;
int main() {
int ma = 0, ans = 2139062143, j = 0, i;
for (i = 1; i <= 1000000; i++)
l[i] = 2139062143, r[i] = -2139062143, t[i] = 0;
cin >> n;
for (i = 1; i <= n; i++) {
int p;
scanf("%d", &p);
l[p] = min(l[p], i);
r[p] = max(r[p], i);
t[p]++;
ma = max(ma, t[p]);
}
for (i = 1; i <= 1000000; i++)
if (ma == t[i] && ans > r[i] - l[i] + 1) {
ans = r[i] - l[i] + 1;
j = i;
}
cout << l[j] << ' ' << r[j] << endl;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int l[2000000 + 10], r[2000000 + 10], t[2000000 + 10], n;
int main() {
int ma = 0, ans = 2139062143, j = 0, i;
for (i = 1; i <= 1000000; i++)
l[i] = 2139062143, r[i] = -2139062143, t[i] = 0;
cin >> n;
for (i = 1; i <= n; i++) {
int p;
scanf("%d", &p);
l[p] = min(l[p], i);
r[p] = max(r[p], i);
t[p]++;
ma = max(ma, t[p]);
}
for (i = 1; i <= 1000000; i++)
if (ma == t[i] && ans > r[i] - l[i] + 1) {
ans = r[i] - l[i] + 1;
j = i;
}
cout << l[j] << ' ' << r[j] << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int freq[maxn], start[maxn];
int main() {
int n, d, bestFreq = 0, bestSeg = maxn, l, r;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &d);
if (freq[d] == 0) start[d] = i;
++freq[d];
if (freq[d] > bestFreq) {
l = start[d];
r = i;
bestFreq = freq[d];
bestSeg = r - l;
} else if (freq[d] == bestFreq && bestSeg > i - start[d]) {
l = start[d];
r = i;
bestSeg = r - l;
}
}
printf("%d %d", l, r);
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int freq[maxn], start[maxn];
int main() {
int n, d, bestFreq = 0, bestSeg = maxn, l, r;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &d);
if (freq[d] == 0) start[d] = i;
++freq[d];
if (freq[d] > bestFreq) {
l = start[d];
r = i;
bestFreq = freq[d];
bestSeg = r - l;
} else if (freq[d] == bestFreq && bestSeg > i - start[d]) {
l = start[d];
r = i;
bestSeg = r - l;
}
}
printf("%d %d", l, r);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct pi {
int a, x;
} c[N];
bool cmp(pi a, pi b) {
if (a.a != b.a) return a.a < b.a;
return a.x < b.x;
}
int n, pre, num, ans;
int nl, nr, l, r;
void fun() {
if (num < pre) {
num = pre;
l = nl;
r = nr;
ans = r - l + 1;
} else if (num == pre) {
int k = nr - nl + 1;
if (k < ans) {
ans = k;
l = nl;
r = nr;
}
}
}
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%d", &c[i].a);
c[i].x = i + 1;
}
sort(c, c + n, cmp);
pre = ans = num = 1;
l = r = nl = nr = c[0].x;
for (int i = 1; i < n; i++) {
if (c[i].a == c[i - 1].a) {
pre++;
nr = c[i].x;
continue;
}
fun();
pre = 1;
nl = nr = c[i].x;
}
fun();
printf("%d %d\n", l, r);
}
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct pi {
int a, x;
} c[N];
bool cmp(pi a, pi b) {
if (a.a != b.a) return a.a < b.a;
return a.x < b.x;
}
int n, pre, num, ans;
int nl, nr, l, r;
void fun() {
if (num < pre) {
num = pre;
l = nl;
r = nr;
ans = r - l + 1;
} else if (num == pre) {
int k = nr - nl + 1;
if (k < ans) {
ans = k;
l = nl;
r = nr;
}
}
}
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%d", &c[i].a);
c[i].x = i + 1;
}
sort(c, c + n, cmp);
pre = ans = num = 1;
l = r = nl = nr = c[0].x;
for (int i = 1; i < n; i++) {
if (c[i].a == c[i - 1].a) {
pre++;
nr = c[i].x;
continue;
}
fun();
pre = 1;
nl = nr = c[i].x;
}
fun();
printf("%d %d\n", l, r);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int x;
cin >> n;
int maxocc = 0;
int dis = numeric_limits<int>::max();
unordered_map<int, int> occ;
unordered_map<int, int> start;
int candl = 1;
int candr = 1;
for (int i = 0; i < n; i++) {
cin >> x;
if (occ.count(x) == 0) {
occ[x] = 1;
start[x] = i;
} else {
occ[x]++;
}
if (occ[x] > maxocc) {
candl = start[x] + 1;
candr = i + 1;
maxocc = occ[x];
dis = i - start[x] + 1;
} else if (occ[x] == maxocc && (i - start[x] + 1) < dis) {
candl = start[x] + 1;
candr = i + 1;
maxocc = occ[x];
dis = i - start[x] + 1;
}
}
cout << candl << " " << candr << endl;
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int x;
cin >> n;
int maxocc = 0;
int dis = numeric_limits<int>::max();
unordered_map<int, int> occ;
unordered_map<int, int> start;
int candl = 1;
int candr = 1;
for (int i = 0; i < n; i++) {
cin >> x;
if (occ.count(x) == 0) {
occ[x] = 1;
start[x] = i;
} else {
occ[x]++;
}
if (occ[x] > maxocc) {
candl = start[x] + 1;
candr = i + 1;
maxocc = occ[x];
dis = i - start[x] + 1;
} else if (occ[x] == maxocc && (i - start[x] + 1) < dis) {
candl = start[x] + 1;
candr = i + 1;
maxocc = occ[x];
dis = i - start[x] + 1;
}
}
cout << candl << " " << candr << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, max = 0, len, s;
cin >> n;
map<int, int> m;
map<int, int> l;
for (int i = 0; i < n; ++i) {
int temp;
cin >> temp;
if (m[temp])
m[temp]++;
else {
m[temp]++;
l[temp] = i;
}
if (m[temp] > max) {
max = m[temp];
len = i - l[temp] + 1;
s = l[temp] + 1;
} else if (m[temp] == max && i - l[temp] + 1 < len) {
len = i - l[temp] + 1;
s = l[temp] + 1;
}
}
cout << s << ' ' << s + len - 1 << endl;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, max = 0, len, s;
cin >> n;
map<int, int> m;
map<int, int> l;
for (int i = 0; i < n; ++i) {
int temp;
cin >> temp;
if (m[temp])
m[temp]++;
else {
m[temp]++;
l[temp] = i;
}
if (m[temp] > max) {
max = m[temp];
len = i - l[temp] + 1;
s = l[temp] + 1;
} else if (m[temp] == max && i - l[temp] + 1 < len) {
len = i - l[temp] + 1;
s = l[temp] + 1;
}
}
cout << s << ' ' << s + len - 1 << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int _left[1000009];
int cnt[1000009];
int main() {
int l, r;
int n, x;
cin >> n;
int _min = 0;
int _max = 0;
for (int i = 0; i < n; i++) {
cin >> x;
if (!cnt[x]) {
_left[x] = i;
}
cnt[x]++;
if (_max < cnt[x]) {
_max = cnt[x];
l = _left[x];
r = i;
_min = i - _left[x];
}
if (_max == cnt[x] && _min > i - _left[x]) {
_min = i - _left[x];
l = _left[x];
r = i;
}
}
cout << l + 1 << " " << r + 1 << endl;
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int _left[1000009];
int cnt[1000009];
int main() {
int l, r;
int n, x;
cin >> n;
int _min = 0;
int _max = 0;
for (int i = 0; i < n; i++) {
cin >> x;
if (!cnt[x]) {
_left[x] = i;
}
cnt[x]++;
if (_max < cnt[x]) {
_max = cnt[x];
l = _left[x];
r = i;
_min = i - _left[x];
}
if (_max == cnt[x] && _min > i - _left[x]) {
_min = i - _left[x];
l = _left[x];
r = i;
}
}
cout << l + 1 << " " << r + 1 << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long F[1000007], L[1000007];
long long C[1000007];
int main() {
for (long long i = (0); i < (1000007); i++) {
F[i] = -1;
L[i] = -1;
}
memset(C, 0, sizeof(C));
long long n;
scanf("%lld", &n);
for (long long i = (0); i < (n); i++) {
long long v;
scanf("%lld", &v);
if (F[v] == -1) {
F[v] = i;
}
L[v] = i;
C[v]++;
}
long long mx = 0;
long long aL, aR;
for (long long i = (0); i < (1000007); i++) {
if (C[i] > mx) {
aL = F[i];
aR = L[i];
mx = C[i];
} else if (C[i] == mx) {
if (L[i] - F[i] < aR - aL) {
aL = F[i];
aR = L[i];
}
}
}
printf("%lld ", aL + 1);
printf("%lld\n", aR + 1);
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long F[1000007], L[1000007];
long long C[1000007];
int main() {
for (long long i = (0); i < (1000007); i++) {
F[i] = -1;
L[i] = -1;
}
memset(C, 0, sizeof(C));
long long n;
scanf("%lld", &n);
for (long long i = (0); i < (n); i++) {
long long v;
scanf("%lld", &v);
if (F[v] == -1) {
F[v] = i;
}
L[v] = i;
C[v]++;
}
long long mx = 0;
long long aL, aR;
for (long long i = (0); i < (1000007); i++) {
if (C[i] > mx) {
aL = F[i];
aR = L[i];
mx = C[i];
} else if (C[i] == mx) {
if (L[i] - F[i] < aR - aL) {
aL = F[i];
aR = L[i];
}
}
}
printf("%lld ", aL + 1);
printf("%lld\n", aR + 1);
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
set<int> st;
set<int>::iterator it;
int main() {
int x, mx = 0;
cin >> x;
int y[x];
vector<vector<int> > buff(999999);
for (int i = 0; i < x; i++) {
cin >> y[i];
mp[y[i]]++;
if (mp[y[i]] > mx) {
mx = mp[y[i]];
}
}
for (int i = 0; i < x; i++) {
if (mp[y[i]] == mx) {
buff[y[i]].push_back(i);
st.insert(y[i]);
}
}
int a = 0, b = 0, mn = 9999999999, c = 0, d = 0;
for (it = st.begin(); it != st.end(); it++) {
a = buff[*it][0] + 1;
b = buff[*it][buff[*it].size() - 1] + 1;
if (b - a < mn) {
mn = b - a;
c = a;
d = b;
}
}
cout << c << " " << d;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
set<int> st;
set<int>::iterator it;
int main() {
int x, mx = 0;
cin >> x;
int y[x];
vector<vector<int> > buff(999999);
for (int i = 0; i < x; i++) {
cin >> y[i];
mp[y[i]]++;
if (mp[y[i]] > mx) {
mx = mp[y[i]];
}
}
for (int i = 0; i < x; i++) {
if (mp[y[i]] == mx) {
buff[y[i]].push_back(i);
st.insert(y[i]);
}
}
int a = 0, b = 0, mn = 9999999999, c = 0, d = 0;
for (it = st.begin(); it != st.end(); it++) {
a = buff[*it][0] + 1;
b = buff[*it][buff[*it].size() - 1] + 1;
if (b - a < mn) {
mn = b - a;
c = a;
d = b;
}
}
cout << c << " " << d;
}
```
|
#include <bits/stdc++.h>
int main() {
int numbers;
while (scanf("%d", &numbers) == 1) {
int data[numbers + 1];
int *first_occur = (int *)calloc(1000001, sizeof(int));
int *last_occur = (int *)calloc(1000001, sizeof(int));
int *count = (int *)calloc(1000001, sizeof(int));
int max = 0;
for (int i = 1; i <= numbers; i++) {
scanf("%d", &data[i]);
count[data[i]]++;
if (first_occur[data[i]] == 0) {
first_occur[data[i]] = i;
}
last_occur[data[i]] = i;
if (max < count[data[i]]) {
max = count[data[i]];
}
}
int min_dist = 10000000, min_num = 0;
for (int i = 1; i <= 1000000; i++) {
if (count[i] == max) {
if (min_dist > (last_occur[i] - first_occur[i])) {
min_dist = (last_occur[i] - first_occur[i] + 1);
min_num = i;
}
}
}
printf("%d %d\n", first_occur[min_num], last_occur[min_num]);
}
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int numbers;
while (scanf("%d", &numbers) == 1) {
int data[numbers + 1];
int *first_occur = (int *)calloc(1000001, sizeof(int));
int *last_occur = (int *)calloc(1000001, sizeof(int));
int *count = (int *)calloc(1000001, sizeof(int));
int max = 0;
for (int i = 1; i <= numbers; i++) {
scanf("%d", &data[i]);
count[data[i]]++;
if (first_occur[data[i]] == 0) {
first_occur[data[i]] = i;
}
last_occur[data[i]] = i;
if (max < count[data[i]]) {
max = count[data[i]];
}
}
int min_dist = 10000000, min_num = 0;
for (int i = 1; i <= 1000000; i++) {
if (count[i] == max) {
if (min_dist > (last_occur[i] - first_occur[i])) {
min_dist = (last_occur[i] - first_occur[i] + 1);
min_num = i;
}
}
}
printf("%d %d\n", first_occur[min_num], last_occur[min_num]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct arr {
int s, e;
long long int ti = 0;
} ar;
map<int, arr> v;
queue<int> q;
int main() {
int n;
while (cin >> n) {
int mt = -1;
for (int i = 1; i <= n; i++) {
int r;
cin >> r;
if (v[r].ti == 0) v[r].s = i;
v[r].ti++;
v[r].e = i;
if (v[r].ti > mt) {
mt = v[r].ti;
while (!q.empty()) q.pop();
q.push(r);
} else if (v[r].ti == mt) {
q.push(r);
}
}
int w = 1000000;
int a = 1, b = 1;
while (!q.empty()) {
int t = q.front();
q.pop();
if (v[t].e - v[t].s < w) {
w = v[t].e - v[t].s;
a = v[t].s;
b = v[t].e;
}
}
cout << a << ' ' << b << endl;
v.clear();
}
return 0;
}
|
### Prompt
Please create a solution in CPP to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct arr {
int s, e;
long long int ti = 0;
} ar;
map<int, arr> v;
queue<int> q;
int main() {
int n;
while (cin >> n) {
int mt = -1;
for (int i = 1; i <= n; i++) {
int r;
cin >> r;
if (v[r].ti == 0) v[r].s = i;
v[r].ti++;
v[r].e = i;
if (v[r].ti > mt) {
mt = v[r].ti;
while (!q.empty()) q.pop();
q.push(r);
} else if (v[r].ti == mt) {
q.push(r);
}
}
int w = 1000000;
int a = 1, b = 1;
while (!q.empty()) {
int t = q.front();
q.pop();
if (v[t].e - v[t].s < w) {
w = v[t].e - v[t].s;
a = v[t].s;
b = v[t].e;
}
}
cout << a << ' ' << b << endl;
v.clear();
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int arr[1000005], s[1000005], e[10000005];
int main() {
int i, j, n;
memset(arr, 0, sizeof(arr));
memset(s, -1, sizeof(s));
memset(e, -1, sizeof(e));
cin >> n;
int max = -1, maxi, l = INT_MAX;
for (i = 1; i < n + 1; i++) {
cin >> j;
arr[j]++;
if (s[j] == -1) {
s[j] = i;
e[j] = i;
} else
e[j] = i;
if (arr[j] > max) {
max = arr[j];
maxi = j;
l = e[j] - s[j];
} else if (arr[j] == max) {
if ((e[j] - s[j]) < l) {
l = e[j] - s[j];
maxi = j;
}
}
}
cout << s[maxi] << " " << e[maxi];
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[1000005], s[1000005], e[10000005];
int main() {
int i, j, n;
memset(arr, 0, sizeof(arr));
memset(s, -1, sizeof(s));
memset(e, -1, sizeof(e));
cin >> n;
int max = -1, maxi, l = INT_MAX;
for (i = 1; i < n + 1; i++) {
cin >> j;
arr[j]++;
if (s[j] == -1) {
s[j] = i;
e[j] = i;
} else
e[j] = i;
if (arr[j] > max) {
max = arr[j];
maxi = j;
l = e[j] - s[j];
} else if (arr[j] == max) {
if ((e[j] - s[j]) < l) {
l = e[j] - s[j];
maxi = j;
}
}
}
cout << s[maxi] << " " << e[maxi];
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> v(n, 0);
unordered_map<int, int> m;
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
if (m.find(v[i]) != m.end()) {
m[v[i]]++;
} else
m[v[i]] = 1;
}
int mx = -1;
unordered_set<int> nos;
map<int, int> beg;
unordered_map<int, int> c;
map<int, int> e;
for (unordered_map<int, int>::iterator i = m.begin(); i != m.end(); i++) {
if (i->second > mx) {
nos.clear();
c.clear();
mx = i->second;
nos.insert(i->first);
c[i->first] = 0;
} else if (i->second == mx) {
nos.insert(i->first);
c[i->first] = 0;
}
}
for (int i = 0; i < n; i++) {
if (nos.find(v[i]) != nos.end()) {
if (c[v[i]] == 0) beg[v[i]] = i + 1;
c[v[i]]++;
if (c[v[i]] == mx) e[v[i]] = i + 1;
}
}
int mn = 10000000;
int mnval;
for (map<int, int>::iterator i = beg.begin(); i != beg.end(); i++) {
if ((e[i->first] - i->second) < mn) {
mn = (e[i->first] - i->second);
mnval = i->first;
}
}
printf("%d %d", beg[mnval], e[mnval]);
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> v(n, 0);
unordered_map<int, int> m;
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
if (m.find(v[i]) != m.end()) {
m[v[i]]++;
} else
m[v[i]] = 1;
}
int mx = -1;
unordered_set<int> nos;
map<int, int> beg;
unordered_map<int, int> c;
map<int, int> e;
for (unordered_map<int, int>::iterator i = m.begin(); i != m.end(); i++) {
if (i->second > mx) {
nos.clear();
c.clear();
mx = i->second;
nos.insert(i->first);
c[i->first] = 0;
} else if (i->second == mx) {
nos.insert(i->first);
c[i->first] = 0;
}
}
for (int i = 0; i < n; i++) {
if (nos.find(v[i]) != nos.end()) {
if (c[v[i]] == 0) beg[v[i]] = i + 1;
c[v[i]]++;
if (c[v[i]] == mx) e[v[i]] = i + 1;
}
}
int mn = 10000000;
int mnval;
for (map<int, int>::iterator i = beg.begin(); i != beg.end(); i++) {
if ((e[i->first] - i->second) < mn) {
mn = (e[i->first] - i->second);
mnval = i->first;
}
}
printf("%d %d", beg[mnval], e[mnval]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int v[4005];
long long int d[4005];
long long int p[4005];
long long int arr[100005];
pair<pair<int, int>, int> hasher[1000006];
int main() {
int n, maxi = -1, num, ansl, ansr;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
hasher[arr[i]].second++;
if (hasher[arr[i]].second == 1) {
hasher[arr[i]].first.first = i + 1;
}
hasher[arr[i]].first.second = i + 1;
if (hasher[arr[i]].second > maxi ||
(hasher[arr[i]].second == maxi &&
(ansr - ansl + 1 >
hasher[arr[i]].first.second - hasher[arr[i]].first.first + 1))) {
maxi = hasher[arr[i]].second;
ansl = hasher[arr[i]].first.first;
ansr = hasher[arr[i]].first.second;
}
}
cout << ansl << " " << ansr << endl;
}
|
### Prompt
Generate a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int v[4005];
long long int d[4005];
long long int p[4005];
long long int arr[100005];
pair<pair<int, int>, int> hasher[1000006];
int main() {
int n, maxi = -1, num, ansl, ansr;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
hasher[arr[i]].second++;
if (hasher[arr[i]].second == 1) {
hasher[arr[i]].first.first = i + 1;
}
hasher[arr[i]].first.second = i + 1;
if (hasher[arr[i]].second > maxi ||
(hasher[arr[i]].second == maxi &&
(ansr - ansl + 1 >
hasher[arr[i]].first.second - hasher[arr[i]].first.first + 1))) {
maxi = hasher[arr[i]].second;
ansl = hasher[arr[i]].first.first;
ansr = hasher[arr[i]].first.second;
}
}
cout << ansl << " " << ansr << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int mark[1000005];
int a[1000005];
int c[1000005][2];
int main() {
scanf("%d", &n);
memset(c, 0, sizeof(c));
memset(mark, 0, sizeof(mark));
int maxx = 0, z = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (z < a[i]) z = a[i];
mark[a[i]]++;
if (mark[a[i]] > maxx) {
maxx = mark[a[i]];
}
}
for (int i = 1; i <= n; i++) {
if (mark[a[i]] == maxx) {
if (c[a[i]][0] == 0)
c[a[i]][0] = i;
else
c[a[i]][1] = i;
}
}
int minn = 0x3f3f3f3f;
int ans;
for (int i = 1; i <= n; i++) {
if (c[a[i]][0]) {
if (minn > c[a[i]][1] - c[a[i]][0]) {
minn = c[a[i]][1] - c[a[i]][0];
ans = a[i];
}
}
}
if (c[ans][0] == 0) c[ans][0] = c[ans][1];
if (c[ans][1] == 0) c[ans][1] = c[ans][0];
printf("%d %d\n", c[ans][0], c[ans][1]);
}
|
### Prompt
Develop a solution in cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
int mark[1000005];
int a[1000005];
int c[1000005][2];
int main() {
scanf("%d", &n);
memset(c, 0, sizeof(c));
memset(mark, 0, sizeof(mark));
int maxx = 0, z = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (z < a[i]) z = a[i];
mark[a[i]]++;
if (mark[a[i]] > maxx) {
maxx = mark[a[i]];
}
}
for (int i = 1; i <= n; i++) {
if (mark[a[i]] == maxx) {
if (c[a[i]][0] == 0)
c[a[i]][0] = i;
else
c[a[i]][1] = i;
}
}
int minn = 0x3f3f3f3f;
int ans;
for (int i = 1; i <= n; i++) {
if (c[a[i]][0]) {
if (minn > c[a[i]][1] - c[a[i]][0]) {
minn = c[a[i]][1] - c[a[i]][0];
ans = a[i];
}
}
}
if (c[ans][0] == 0) c[ans][0] = c[ans][1];
if (c[ans][1] == 0) c[ans][1] = c[ans][0];
printf("%d %d\n", c[ans][0], c[ans][1]);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int MaxOcc;
const int inf = 1 << 30;
int AnswerProblem = inf;
int AnswerLeft, AnswerRight;
int cnt[1048576];
int helloworld1[1048576], helloworld2[1048576];
int main() {
int n, i;
cin >> n;
for (i = 0; i < n; i++) {
int a;
cin >> a;
if (!cnt[a]) helloworld1[a] = i;
cnt[a]++;
MaxOcc = max(MaxOcc, cnt[a]);
helloworld2[a] = i;
}
for (i = 0; i <= 1000000; i++)
if (cnt[i] == MaxOcc) {
if (helloworld2[i] - helloworld1[i] + 1 < AnswerProblem) {
AnswerProblem = helloworld2[i] - helloworld1[i] + 1;
AnswerLeft = helloworld1[i];
AnswerRight = helloworld2[i];
}
}
AnswerLeft++;
AnswerRight++;
cout << AnswerLeft << " " << AnswerRight << endl;
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int MaxOcc;
const int inf = 1 << 30;
int AnswerProblem = inf;
int AnswerLeft, AnswerRight;
int cnt[1048576];
int helloworld1[1048576], helloworld2[1048576];
int main() {
int n, i;
cin >> n;
for (i = 0; i < n; i++) {
int a;
cin >> a;
if (!cnt[a]) helloworld1[a] = i;
cnt[a]++;
MaxOcc = max(MaxOcc, cnt[a]);
helloworld2[a] = i;
}
for (i = 0; i <= 1000000; i++)
if (cnt[i] == MaxOcc) {
if (helloworld2[i] - helloworld1[i] + 1 < AnswerProblem) {
AnswerProblem = helloworld2[i] - helloworld1[i] + 1;
AnswerLeft = helloworld1[i];
AnswerRight = helloworld2[i];
}
}
AnswerLeft++;
AnswerRight++;
cout << AnswerLeft << " " << AnswerRight << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int v[4005];
long long int d[4005];
long long int p[4005];
long long int arr[100005];
pair<pair<int, int>, int> hasher[1000006];
int main() {
int n, maxi = -1, num, ansl, ansr;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
hasher[arr[i]].second++;
if (hasher[arr[i]].second == 1) {
hasher[arr[i]].first.first = i + 1;
}
hasher[arr[i]].first.second = i + 1;
if (hasher[arr[i]].second >= maxi) {
if (hasher[arr[i]].second > maxi) {
maxi = hasher[arr[i]].second;
ansl = hasher[arr[i]].first.first;
ansr = hasher[arr[i]].first.second;
} else if (hasher[arr[i]].second == maxi) {
if (ansr - ansl + 1 >
hasher[arr[i]].first.second - hasher[arr[i]].first.first + 1) {
ansl = hasher[arr[i]].first.first;
ansr = hasher[arr[i]].first.second;
}
}
}
}
cout << ansl << " " << ansr << endl;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int v[4005];
long long int d[4005];
long long int p[4005];
long long int arr[100005];
pair<pair<int, int>, int> hasher[1000006];
int main() {
int n, maxi = -1, num, ansl, ansr;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
hasher[arr[i]].second++;
if (hasher[arr[i]].second == 1) {
hasher[arr[i]].first.first = i + 1;
}
hasher[arr[i]].first.second = i + 1;
if (hasher[arr[i]].second >= maxi) {
if (hasher[arr[i]].second > maxi) {
maxi = hasher[arr[i]].second;
ansl = hasher[arr[i]].first.first;
ansr = hasher[arr[i]].first.second;
} else if (hasher[arr[i]].second == maxi) {
if (ansr - ansl + 1 >
hasher[arr[i]].first.second - hasher[arr[i]].first.first + 1) {
ansl = hasher[arr[i]].first.first;
ansr = hasher[arr[i]].first.second;
}
}
}
}
cout << ansl << " " << ansr << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
const int MOD = (int)1e9 + 7;
long long pow(long long base, long long exp, long long mod) {
long long result = 1;
while (exp > 0) {
if (exp & 1) result *= base;
base *= base;
if (base > mod) base %= mod;
if (result > mod) result %= mod;
exp /= 2;
}
return result;
}
long long mult(long long A, long long B) {
if (B == 0) return 0;
long long u = mult(A, B / 2);
long long res;
if (B % 2 == 0)
res = u + u;
else
res = u + u + A;
while (res >= MOD) res -= MOD;
return res;
}
long long n, num;
vector<long long> nums;
void inp() {
for (long long i = 0; i < n; i++) {
cin >> num;
nums.push_back(num);
}
}
long long _sieve_size;
bitset<10000010> bs;
vector<int> primes;
void sieve(long long upperbound) {
_sieve_size = upperbound + 1;
bs.set();
bs[0] = bs[1] = 0;
for (long long i = 2; i <= _sieve_size; i++)
if (bs[i]) {
for (long long j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i);
}
}
bool isprime(int a) {
for (int i = 2; i * i <= a; i++)
if (a % i == 0) return false;
return true;
}
int lcs(string a, string b) {
int arr[150][150];
for (long long i = 0; i < a.size() + 1; i++) arr[i][0] = 0;
for (long long j = 0; j < b.size() + 1; j++) arr[0][j] = 0;
for (long long i = 1; i < a.size() + 1; i++)
for (long long j = 1; j < b.size() + 1; j++) {
if (a[i - 1] == b[j - 1])
arr[i][j] = 1 + arr[i - 1][j - 1];
else
arr[i][j] = ((arr[i - 1][j]) > (arr[i][j - 1]) ? (arr[i - 1][j])
: (arr[i][j - 1]));
}
return arr[a.size()][b.size()];
}
bool sorted(int s, int e) {
for (long long i = s; i < e; i++)
if (nums[i] > nums[i + 1]) return false;
return true;
}
bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.first != b.first) return a.first > b.first;
return (a.second.first - a.second.second + 1) <
(b.second.first - b.second.second + 1);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
inp();
map<int, int> c, s, e;
for (long long i = 0; i < n; i++) {
c[nums[i]]++;
e[nums[i]] = i;
s[nums[i]] = -1;
}
for (long long i = 0; i < n; i++)
if (s[nums[i]] == -1) s[nums[i]] = i;
vector<pair<int, pair<int, int> > > ps;
map<int, int>::iterator it;
for (it = c.begin(); it != c.end(); ++it)
ps.push_back(make_pair(it->second, make_pair(e[it->first], s[it->first])));
sort((ps).begin(), (ps).end(), comp);
cout << ps[0].second.second + 1 << " " << ps[0].second.first + 1;
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
const int MOD = (int)1e9 + 7;
long long pow(long long base, long long exp, long long mod) {
long long result = 1;
while (exp > 0) {
if (exp & 1) result *= base;
base *= base;
if (base > mod) base %= mod;
if (result > mod) result %= mod;
exp /= 2;
}
return result;
}
long long mult(long long A, long long B) {
if (B == 0) return 0;
long long u = mult(A, B / 2);
long long res;
if (B % 2 == 0)
res = u + u;
else
res = u + u + A;
while (res >= MOD) res -= MOD;
return res;
}
long long n, num;
vector<long long> nums;
void inp() {
for (long long i = 0; i < n; i++) {
cin >> num;
nums.push_back(num);
}
}
long long _sieve_size;
bitset<10000010> bs;
vector<int> primes;
void sieve(long long upperbound) {
_sieve_size = upperbound + 1;
bs.set();
bs[0] = bs[1] = 0;
for (long long i = 2; i <= _sieve_size; i++)
if (bs[i]) {
for (long long j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i);
}
}
bool isprime(int a) {
for (int i = 2; i * i <= a; i++)
if (a % i == 0) return false;
return true;
}
int lcs(string a, string b) {
int arr[150][150];
for (long long i = 0; i < a.size() + 1; i++) arr[i][0] = 0;
for (long long j = 0; j < b.size() + 1; j++) arr[0][j] = 0;
for (long long i = 1; i < a.size() + 1; i++)
for (long long j = 1; j < b.size() + 1; j++) {
if (a[i - 1] == b[j - 1])
arr[i][j] = 1 + arr[i - 1][j - 1];
else
arr[i][j] = ((arr[i - 1][j]) > (arr[i][j - 1]) ? (arr[i - 1][j])
: (arr[i][j - 1]));
}
return arr[a.size()][b.size()];
}
bool sorted(int s, int e) {
for (long long i = s; i < e; i++)
if (nums[i] > nums[i + 1]) return false;
return true;
}
bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.first != b.first) return a.first > b.first;
return (a.second.first - a.second.second + 1) <
(b.second.first - b.second.second + 1);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
inp();
map<int, int> c, s, e;
for (long long i = 0; i < n; i++) {
c[nums[i]]++;
e[nums[i]] = i;
s[nums[i]] = -1;
}
for (long long i = 0; i < n; i++)
if (s[nums[i]] == -1) s[nums[i]] = i;
vector<pair<int, pair<int, int> > > ps;
map<int, int>::iterator it;
for (it = c.begin(); it != c.end(); ++it)
ps.push_back(make_pair(it->second, make_pair(e[it->first], s[it->first])));
sort((ps).begin(), (ps).end(), comp);
cout << ps[0].second.second + 1 << " " << ps[0].second.first + 1;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > mx[1000001];
int main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
mx[x].first++;
if (!mx[x].second.first)
mx[x].second.first = i + 1, mx[x].second.second = i + 1;
else
mx[x].second.second = i + 1;
}
sort(mx, mx + 1000001);
int i;
int min1 = mx[1000000].second.first, min2 = mx[1000000].second.second,
maxval = mx[1000000].first, dif = min2 - min1;
for (i = 1000000; i >= 0; i--) {
if (mx[i].first == 0) break;
if (mx[i].second.second - mx[i].second.first <= dif &&
mx[i].first == maxval)
min1 = mx[i].second.first, min2 = mx[i].second.second, dif = min2 - min1;
}
cout << min1 << " " << min2 << endl;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > mx[1000001];
int main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
mx[x].first++;
if (!mx[x].second.first)
mx[x].second.first = i + 1, mx[x].second.second = i + 1;
else
mx[x].second.second = i + 1;
}
sort(mx, mx + 1000001);
int i;
int min1 = mx[1000000].second.first, min2 = mx[1000000].second.second,
maxval = mx[1000000].first, dif = min2 - min1;
for (i = 1000000; i >= 0; i--) {
if (mx[i].first == 0) break;
if (mx[i].second.second - mx[i].second.first <= dif &&
mx[i].first == maxval)
min1 = mx[i].second.first, min2 = mx[i].second.second, dif = min2 - min1;
}
cout << min1 << " " << min2 << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct beauty {
int t;
int l, r;
beauty() : t(0) {}
};
const int maxn = 1e6 + 7;
const int N = 1e5 + 7;
int arr[N];
beauty cnt[maxn];
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, v;
while (cin >> n) {
int maxt = 0;
memset(arr, 0, sizeof(arr));
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
cin >> arr[i];
v = arr[i];
cnt[v].t++;
if (cnt[v].t == 1) cnt[v].l = i;
cnt[v].r = i;
maxt = max(maxt, cnt[v].t);
}
int mint = INT_MAX, val;
for (int i = 0; i < n; i++) {
v = arr[i];
if (cnt[v].t == maxt) {
int dis = cnt[v].r - cnt[v].l;
if (dis < mint) {
mint = dis;
val = v;
}
}
}
beauty ans = cnt[val];
printf("%d %d\n", ans.l + 1, ans.r + 1);
}
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct beauty {
int t;
int l, r;
beauty() : t(0) {}
};
const int maxn = 1e6 + 7;
const int N = 1e5 + 7;
int arr[N];
beauty cnt[maxn];
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, v;
while (cin >> n) {
int maxt = 0;
memset(arr, 0, sizeof(arr));
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; i++) {
cin >> arr[i];
v = arr[i];
cnt[v].t++;
if (cnt[v].t == 1) cnt[v].l = i;
cnt[v].r = i;
maxt = max(maxt, cnt[v].t);
}
int mint = INT_MAX, val;
for (int i = 0; i < n; i++) {
v = arr[i];
if (cnt[v].t == maxt) {
int dis = cnt[v].r - cnt[v].l;
if (dis < mint) {
mint = dis;
val = v;
}
}
}
beauty ans = cnt[val];
printf("%d %d\n", ans.l + 1, ans.r + 1);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, a[100011], d[1000111], l[1000111], r[1000111];
int main() {
cin >> n;
int m = 0, k = -1;
memset(l, -1, sizeof l);
memset(r, -1, sizeof r);
for (int i = 0; i < n; ++i) {
cin >> a[i];
d[a[i]]++;
if (d[a[i]] > m) {
m = d[a[i]];
}
}
for (int i = 0; i < n; ++i) {
if (l[a[i]] == -1) l[a[i]] = i;
}
for (int i = n - 1; i >= 0; --i) {
if (r[a[i]] == -1) r[a[i]] = i;
}
int ansl = 1, ansr = n, ans = n;
for (int i = 0; i < n; ++i) {
if (d[a[i]] == m) {
if (r[a[i]] - l[a[i]] + 1 < ans) {
ans = r[a[i]] - l[a[i]] + 1;
ansl = l[a[i]] + 1;
ansr = r[a[i]] + 1;
}
}
}
printf("%d %d", ansl, ansr);
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, a[100011], d[1000111], l[1000111], r[1000111];
int main() {
cin >> n;
int m = 0, k = -1;
memset(l, -1, sizeof l);
memset(r, -1, sizeof r);
for (int i = 0; i < n; ++i) {
cin >> a[i];
d[a[i]]++;
if (d[a[i]] > m) {
m = d[a[i]];
}
}
for (int i = 0; i < n; ++i) {
if (l[a[i]] == -1) l[a[i]] = i;
}
for (int i = n - 1; i >= 0; --i) {
if (r[a[i]] == -1) r[a[i]] = i;
}
int ansl = 1, ansr = n, ans = n;
for (int i = 0; i < n; ++i) {
if (d[a[i]] == m) {
if (r[a[i]] - l[a[i]] + 1 < ans) {
ans = r[a[i]] - l[a[i]] + 1;
ansl = l[a[i]] + 1;
ansr = r[a[i]] + 1;
}
}
}
printf("%d %d", ansl, ansr);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int n, a;
cin >> n;
map<int, pair<int, pair<int, int>>> x;
int c[100001];
for (int i = 0; i < n; i++) {
cin >> a;
c[i] = a;
x[a].second.first = 10000000;
}
for (int i = 0; i < n; i++) {
x[c[i]].first++;
x[c[i]].second.first = min(x[c[i]].second.first, i);
x[c[i]].second.second = max(x[c[i]].second.second, i);
}
std::map<int, pair<int, pair<int, int>>>::iterator it;
pair<int, pair<int, int>> ans;
for (it = x.begin(); it != x.end(); ++it) {
pair<int, pair<int, int>> t = it->second;
if (t.first > ans.first) {
ans = t;
} else if (t.first == ans.first) {
if (abs(ans.second.first - ans.second.second) >
abs(t.second.first - t.second.second))
ans = t;
}
}
cout << ans.second.first + 1 << " " << ans.second.second + 1 << endl;
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int n, a;
cin >> n;
map<int, pair<int, pair<int, int>>> x;
int c[100001];
for (int i = 0; i < n; i++) {
cin >> a;
c[i] = a;
x[a].second.first = 10000000;
}
for (int i = 0; i < n; i++) {
x[c[i]].first++;
x[c[i]].second.first = min(x[c[i]].second.first, i);
x[c[i]].second.second = max(x[c[i]].second.second, i);
}
std::map<int, pair<int, pair<int, int>>>::iterator it;
pair<int, pair<int, int>> ans;
for (it = x.begin(); it != x.end(); ++it) {
pair<int, pair<int, int>> t = it->second;
if (t.first > ans.first) {
ans = t;
} else if (t.first == ans.first) {
if (abs(ans.second.first - ans.second.second) >
abs(t.second.first - t.second.second))
ans = t;
}
}
cout << ans.second.first + 1 << " " << ans.second.second + 1 << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
int st[1001000], en[1001000], num[1001000];
int l, r;
int tim;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
++num[x];
if (!st[x]) st[x] = i;
en[x] = i;
}
for (int x = 1; x < 1001000; ++x) {
if (num[x] > tim) {
tim = num[x];
l = st[x];
r = en[x];
} else if (num[x] == tim) {
if (en[x] - st[x] < r - l + 1) {
l = st[x];
r = en[x];
}
}
}
printf("%d %d\n", l, r);
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int st[1001000], en[1001000], num[1001000];
int l, r;
int tim;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
++num[x];
if (!st[x]) st[x] = i;
en[x] = i;
}
for (int x = 1; x < 1001000; ++x) {
if (num[x] > tim) {
tim = num[x];
l = st[x];
r = en[x];
} else if (num[x] == tim) {
if (en[x] - st[x] < r - l + 1) {
l = st[x];
r = en[x];
}
}
}
printf("%d %d\n", l, r);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, z1, c, n, t, a[1000005], q, p1, l, r, x, y, pi[1000005], nu,
ex, re, ii, ans, ma = -1000, t1;
map<long long, long long> mp, mp1;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
if (mp1[a[i]] == 0) mp1[a[i]] = i;
if (mp[a[i]] >= ma) {
if (mp[a[i]] == ma) {
if (i - mp1[a[i]] + 1 < t1) {
t1 = i - mp1[a[i]] + 1;
t = i;
}
} else {
ma = mp[a[i]];
t = i;
t1 = i - mp1[a[i]] + 1;
}
}
}
cout << mp1[a[t]] << " " << t;
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, z1, c, n, t, a[1000005], q, p1, l, r, x, y, pi[1000005], nu,
ex, re, ii, ans, ma = -1000, t1;
map<long long, long long> mp, mp1;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
if (mp1[a[i]] == 0) mp1[a[i]] = i;
if (mp[a[i]] >= ma) {
if (mp[a[i]] == ma) {
if (i - mp1[a[i]] + 1 < t1) {
t1 = i - mp1[a[i]] + 1;
t = i;
}
} else {
ma = mp[a[i]];
t = i;
t1 = i - mp1[a[i]] + 1;
}
}
}
cout << mp1[a[t]] << " " << t;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int v, pos;
} a[100010];
bool cmp(node x, node y) {
if (x.v == y.v) return x.pos < y.pos;
return x.v < y.v;
}
int main() {
int n, x;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].v);
a[i].pos = i;
}
sort(a + 1, a + n + 1, cmp);
int st = 1, len = 0, cnt = 1;
int ansl, ansr;
for (int i = 2; i <= n; i++) {
if (a[i].v == a[i - 1].v)
cnt++;
else {
if (cnt > len) {
ansl = a[st].pos;
ansr = a[i - 1].pos;
len = cnt;
} else if (cnt == len) {
if (a[i - 1].pos - a[st].pos + 1 < ansr - ansl + 1) {
ansl = a[st].pos;
ansr = a[i - 1].pos;
}
}
st = i;
cnt = 1;
}
}
if (cnt > len) {
ansl = a[st].pos;
ansr = a[n].pos;
cnt = len;
} else if (cnt == len) {
if (a[n].pos - a[st].pos + 1 < ansr - ansl + 1) {
ansl = a[st].pos;
ansr = a[n].pos;
}
}
printf("%d %d\n", ansl, ansr);
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
int v, pos;
} a[100010];
bool cmp(node x, node y) {
if (x.v == y.v) return x.pos < y.pos;
return x.v < y.v;
}
int main() {
int n, x;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i].v);
a[i].pos = i;
}
sort(a + 1, a + n + 1, cmp);
int st = 1, len = 0, cnt = 1;
int ansl, ansr;
for (int i = 2; i <= n; i++) {
if (a[i].v == a[i - 1].v)
cnt++;
else {
if (cnt > len) {
ansl = a[st].pos;
ansr = a[i - 1].pos;
len = cnt;
} else if (cnt == len) {
if (a[i - 1].pos - a[st].pos + 1 < ansr - ansl + 1) {
ansl = a[st].pos;
ansr = a[i - 1].pos;
}
}
st = i;
cnt = 1;
}
}
if (cnt > len) {
ansl = a[st].pos;
ansr = a[n].pos;
cnt = len;
} else if (cnt == len) {
if (a[n].pos - a[st].pos + 1 < ansr - ansl + 1) {
ansl = a[st].pos;
ansr = a[n].pos;
}
}
printf("%d %d\n", ansl, ansr);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[100005], c[1000005], poz[1000005];
int main() {
int n, i, j, k, p, q, x, y, mn, mx, l, r;
while (scanf("%d", &n) == 1) {
memset(c, 0, sizeof c);
memset(poz, 0, sizeof poz);
x = -1;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
c[a[i]]++;
x = max(c[a[i]], x);
}
memset(c, 0, sizeof c);
mx = -1;
mn = 12345678;
for (i = 1; i <= n; i++) {
c[a[i]]++;
if (c[a[i]] == 1) {
poz[a[i]] = i;
}
if (c[a[i]] > 0 && c[a[i]] == x) {
y = i - poz[a[i]];
if (y < mn) {
mn = y;
l = poz[a[i]];
r = i;
}
}
}
printf("%d %d\n", l, r);
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100005], c[1000005], poz[1000005];
int main() {
int n, i, j, k, p, q, x, y, mn, mx, l, r;
while (scanf("%d", &n) == 1) {
memset(c, 0, sizeof c);
memset(poz, 0, sizeof poz);
x = -1;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
c[a[i]]++;
x = max(c[a[i]], x);
}
memset(c, 0, sizeof c);
mx = -1;
mn = 12345678;
for (i = 1; i <= n; i++) {
c[a[i]]++;
if (c[a[i]] == 1) {
poz[a[i]] = i;
}
if (c[a[i]] > 0 && c[a[i]] == x) {
y = i - poz[a[i]];
if (y < mn) {
mn = y;
l = poz[a[i]];
r = i;
}
}
}
printf("%d %d\n", l, r);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int mx = -1;
map<int, vector<int>> pos;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
pos[x].push_back(i);
mx = max(mx, (int)pos[x].size());
}
int mn = n + 1;
int wr = -1;
for (auto [x, p] : pos) {
assert(!p.empty());
if ((int)p.size() == mx && p.back() - p.front() < mn) {
mn = p.back() - p.front();
wr = x;
}
}
cout << pos[wr].front() + 1 << ' ' << pos[wr].back() + 1 << endl;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int mx = -1;
map<int, vector<int>> pos;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
pos[x].push_back(i);
mx = max(mx, (int)pos[x].size());
}
int mn = n + 1;
int wr = -1;
for (auto [x, p] : pos) {
assert(!p.empty());
if ((int)p.size() == mx && p.back() - p.front() < mn) {
mn = p.back() - p.front();
wr = x;
}
}
cout << pos[wr].front() + 1 << ' ' << pos[wr].back() + 1 << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long tt = 1;
while (tt--) {
int n;
int i, j;
cin >> n;
vector<pair<int, pair<int, int> > > a(1000001);
for (i = 0; i < 1000001; i++) {
a[i].first = 0;
a[i].second.first = -1;
a[i].second.second = -1;
}
for (i = 0; i < n; i++) {
long long temp;
cin >> temp;
a[temp].first++;
if (a[temp].second.first == -1) {
a[temp].second.first = i + 1;
}
a[temp].second.second = i + 1;
}
sort(a.begin(), a.end());
long long left, right;
left = a[1000000].second.first;
right = a[1000000].second.second;
long long N = 1000000;
for (; N >= 1; N--) {
if (a[N].first != a[1000000].first) {
break;
}
long long temp = right - left + 1;
long long comp = a[N].second.second - a[N].second.first + 1;
if (comp < temp) {
left = a[N].second.first;
right = a[N].second.second;
}
}
cout << left << " " << right << "\n";
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long tt = 1;
while (tt--) {
int n;
int i, j;
cin >> n;
vector<pair<int, pair<int, int> > > a(1000001);
for (i = 0; i < 1000001; i++) {
a[i].first = 0;
a[i].second.first = -1;
a[i].second.second = -1;
}
for (i = 0; i < n; i++) {
long long temp;
cin >> temp;
a[temp].first++;
if (a[temp].second.first == -1) {
a[temp].second.first = i + 1;
}
a[temp].second.second = i + 1;
}
sort(a.begin(), a.end());
long long left, right;
left = a[1000000].second.first;
right = a[1000000].second.second;
long long N = 1000000;
for (; N >= 1; N--) {
if (a[N].first != a[1000000].first) {
break;
}
long long temp = right - left + 1;
long long comp = a[N].second.second - a[N].second.first + 1;
if (comp < temp) {
left = a[N].second.first;
right = a[N].second.second;
}
}
cout << left << " " << right << "\n";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int cnt[1000005];
int minloc[1000005];
int maxloc[1000005];
int main() {
int i, n;
cin >> n;
int mcnt = 0;
memset(minloc, 7, sizeof(minloc));
for (i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
mcnt = max(cnt[a[i]], mcnt);
minloc[a[i]] = min(minloc[a[i]], i);
maxloc[a[i]] = i;
}
int bst = 1000000000, bloc = -1;
for (i = 0; i <= 1000000; i++) {
if (mcnt == cnt[i]) {
int clen = maxloc[i] - minloc[i] + 1;
if (clen < bst) {
bst = clen;
bloc = i;
}
}
}
cout << minloc[bloc] + 1 << " " << maxloc[bloc] + 1 << endl;
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int cnt[1000005];
int minloc[1000005];
int maxloc[1000005];
int main() {
int i, n;
cin >> n;
int mcnt = 0;
memset(minloc, 7, sizeof(minloc));
for (i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
mcnt = max(cnt[a[i]], mcnt);
minloc[a[i]] = min(minloc[a[i]], i);
maxloc[a[i]] = i;
}
int bst = 1000000000, bloc = -1;
for (i = 0; i <= 1000000; i++) {
if (mcnt == cnt[i]) {
int clen = maxloc[i] - minloc[i] + 1;
if (clen < bst) {
bst = clen;
bloc = i;
}
}
}
cout << minloc[bloc] + 1 << " " << maxloc[bloc] + 1 << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<int, pair<int, pair<int, int> > > m;
int main() {
int n;
scanf("%d", &n);
int maxx = -1;
for (int i = 0; i < n; i++) {
int x = 0;
scanf("%d", &x);
if (m[x].first == 0) {
m[x].first = 1;
m[x].second.first = i + 1;
m[x].second.second = i + 1;
} else {
m[x].first++;
m[x].second.second = i + 1;
}
maxx = max(maxx, m[x].first);
}
int res = 1 << 30;
int i = 0;
int j = 0;
for (auto it : m) {
if (it.second.first == maxx) {
int ii = it.second.second.first;
int jj = it.second.second.second;
if (jj - ii < res) {
res = jj - ii;
i = ii;
j = jj;
}
}
}
cout << i << " " << j << endl;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, pair<int, pair<int, int> > > m;
int main() {
int n;
scanf("%d", &n);
int maxx = -1;
for (int i = 0; i < n; i++) {
int x = 0;
scanf("%d", &x);
if (m[x].first == 0) {
m[x].first = 1;
m[x].second.first = i + 1;
m[x].second.second = i + 1;
} else {
m[x].first++;
m[x].second.second = i + 1;
}
maxx = max(maxx, m[x].first);
}
int res = 1 << 30;
int i = 0;
int j = 0;
for (auto it : m) {
if (it.second.first == maxx) {
int ii = it.second.second.first;
int jj = it.second.second.second;
if (jj - ii < res) {
res = jj - ii;
i = ii;
j = jj;
}
}
}
cout << i << " " << j << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long n, i, t[1000005], a[1000005][2], x, mi, ma, le;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
t[x]++;
if (t[x] == 1) {
a[x][0] = i;
}
a[x][1] = i;
}
x = 0;
mi = 0;
ma = 1000005;
for (i = 1; i < 1000005; i++) {
if (t[i] > 0 && (t[i] > x || (t[i] == x && a[i][1] - a[i][0] < ma - mi))) {
x = t[i];
mi = a[i][0];
ma = a[i][1];
}
}
cout << mi << " " << ma << endl;
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, i, t[1000005], a[1000005][2], x, mi, ma, le;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
t[x]++;
if (t[x] == 1) {
a[x][0] = i;
}
a[x][1] = i;
}
x = 0;
mi = 0;
ma = 1000005;
for (i = 1; i < 1000005; i++) {
if (t[i] > 0 && (t[i] > x || (t[i] == x && a[i][1] - a[i][0] < ma - mi))) {
x = t[i];
mi = a[i][0];
ma = a[i][1];
}
}
cout << mi << " " << ma << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100000;
int msq[maxn];
int Msq[maxn];
int MSq[maxn];
int MSQ[maxn];
int MSQQ[maxn];
int n;
int main() {
while (scanf("%d", &n) != EOF) {
memset(Msq, 0, sizeof(Msq));
memset(MSQ, 0, sizeof(MSQ));
for (int i = 0; i < n; i++) {
scanf("%d", &msq[i]);
if (MSQ[msq[i]] == 0)
MSQ[msq[i]] = i + 1;
else
MSQQ[msq[i]] = i + 1;
MSq[i] = msq[i];
}
sort(msq, msq + n);
int tmd = msq[0];
int len = 0;
for (int i = 0; i < n; i++) {
if (msq[i] == tmd)
Msq[len]++;
else {
tmd = msq[i];
Msq[++len]++;
}
}
int md = 0, mlb = 0;
for (int i = 0; i <= len; i++) {
if (Msq[i] > md) {
md = Msq[i];
mlb = i;
}
}
if (md == 1) {
printf("1 1\n");
continue;
}
int CNM = 0;
for (int i = 0; i <= len; i++) {
if (Msq[i] == md) CNM++;
}
int mmmmm;
int sum = 0;
int a = 0;
int b = 99999999;
for (int i = 0; i <= len; i++) {
sum += Msq[i];
if (Msq[i] == md) {
mmmmm = msq[sum - 1];
if (MSQQ[mmmmm] - MSQ[mmmmm] < b - a) {
a = MSQ[mmmmm];
b = MSQQ[mmmmm];
}
}
}
printf("%d %d\n", a, b);
}
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100000;
int msq[maxn];
int Msq[maxn];
int MSq[maxn];
int MSQ[maxn];
int MSQQ[maxn];
int n;
int main() {
while (scanf("%d", &n) != EOF) {
memset(Msq, 0, sizeof(Msq));
memset(MSQ, 0, sizeof(MSQ));
for (int i = 0; i < n; i++) {
scanf("%d", &msq[i]);
if (MSQ[msq[i]] == 0)
MSQ[msq[i]] = i + 1;
else
MSQQ[msq[i]] = i + 1;
MSq[i] = msq[i];
}
sort(msq, msq + n);
int tmd = msq[0];
int len = 0;
for (int i = 0; i < n; i++) {
if (msq[i] == tmd)
Msq[len]++;
else {
tmd = msq[i];
Msq[++len]++;
}
}
int md = 0, mlb = 0;
for (int i = 0; i <= len; i++) {
if (Msq[i] > md) {
md = Msq[i];
mlb = i;
}
}
if (md == 1) {
printf("1 1\n");
continue;
}
int CNM = 0;
for (int i = 0; i <= len; i++) {
if (Msq[i] == md) CNM++;
}
int mmmmm;
int sum = 0;
int a = 0;
int b = 99999999;
for (int i = 0; i <= len; i++) {
sum += Msq[i];
if (Msq[i] == md) {
mmmmm = msq[sum - 1];
if (MSQQ[mmmmm] - MSQ[mmmmm] < b - a) {
a = MSQ[mmmmm];
b = MSQQ[mmmmm];
}
}
}
printf("%d %d\n", a, b);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[100000], b[100000];
int main() {
int n;
cin >> n;
map<int, int> map1;
map<int, int> map2;
map<int, bool> mapbool;
int res[200000] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
if (!mapbool[a[i]]) {
mapbool[a[i]] = true;
map1[a[i]] = i;
}
map2[a[i]] = i;
if (a[map1[a[i]]] == a[i]) res[map1[a[i]]]++;
}
int ans1, ans2;
int a1 = 0, b1 = 0, d = 0, d1 = 0, res2 = 0;
for (int i = 0; i < n; i++) {
a1 = map1[a[i]];
b1 = map2[a[i]];
if (res2 < res[i]) {
ans1 = a1;
ans2 = b1;
res2 = res[i];
}
if (res2 == res[i]) {
if (b1 - a1 < ans2 - ans1) {
ans1 = a1;
ans2 = b1;
}
}
}
cout << ans1 + 1 << " " << ans2 + 1;
}
|
### Prompt
Create a solution in Cpp for the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100000], b[100000];
int main() {
int n;
cin >> n;
map<int, int> map1;
map<int, int> map2;
map<int, bool> mapbool;
int res[200000] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
if (!mapbool[a[i]]) {
mapbool[a[i]] = true;
map1[a[i]] = i;
}
map2[a[i]] = i;
if (a[map1[a[i]]] == a[i]) res[map1[a[i]]]++;
}
int ans1, ans2;
int a1 = 0, b1 = 0, d = 0, d1 = 0, res2 = 0;
for (int i = 0; i < n; i++) {
a1 = map1[a[i]];
b1 = map2[a[i]];
if (res2 < res[i]) {
ans1 = a1;
ans2 = b1;
res2 = res[i];
}
if (res2 == res[i]) {
if (b1 - a1 < ans2 - ans1) {
ans1 = a1;
ans2 = b1;
}
}
}
cout << ans1 + 1 << " " << ans2 + 1;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[1000100][3];
int main() {
int n;
cin >> n;
for (int i = 0; i < 1000010; i++) a[i][0] = 0;
int r;
int max_length = 0;
int nomer = 0;
int length = 1000000;
for (int i = 0; i < n; i++) {
cin >> r;
if (a[r][0] == 0) {
a[r][0] = 1;
a[r][1] = i + 1;
a[r][2] = i + 1;
} else if (a[r][0] == 1) {
a[r][0] = 2;
a[r][2] = i + 1;
} else {
a[r][0]++;
a[r][2] = i + 1;
}
if (max_length < a[r][0]) {
nomer = r;
max_length = a[r][0];
length = a[r][2] - a[r][1];
}
if (max_length == a[r][0] && length > a[r][2] - a[r][1]) {
nomer = r;
length = a[r][2] - a[r][1];
}
}
cout << a[nomer][1] << " " << a[nomer][2] << "\n";
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000100][3];
int main() {
int n;
cin >> n;
for (int i = 0; i < 1000010; i++) a[i][0] = 0;
int r;
int max_length = 0;
int nomer = 0;
int length = 1000000;
for (int i = 0; i < n; i++) {
cin >> r;
if (a[r][0] == 0) {
a[r][0] = 1;
a[r][1] = i + 1;
a[r][2] = i + 1;
} else if (a[r][0] == 1) {
a[r][0] = 2;
a[r][2] = i + 1;
} else {
a[r][0]++;
a[r][2] = i + 1;
}
if (max_length < a[r][0]) {
nomer = r;
max_length = a[r][0];
length = a[r][2] - a[r][1];
}
if (max_length == a[r][0] && length > a[r][2] - a[r][1]) {
nomer = r;
length = a[r][2] - a[r][1];
}
}
cout << a[nomer][1] << " " << a[nomer][2] << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n;
int tra;
int maxl;
int l;
int r;
int ans = (int)1e9;
struct NUM {
int sta;
int end;
int timel;
} num[1000001];
bool comp(const NUM &a, const NUM &b) { return a.timel > b.timel; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &tra);
if (num[tra].sta == 0) {
num[tra].sta = i;
num[tra].end = i;
num[tra].timel++;
} else {
num[tra].end = i;
num[tra].timel++;
}
}
sort(num + 1, num + 1 + 1000000, comp);
maxl = num[1].timel;
for (int i = 1; i <= 1000000; i++) {
if (num[i].timel != maxl) break;
if (ans > num[i].end - num[i].sta + 1) {
ans = num[i].end - num[i].sta + 1;
l = num[i].sta;
r = num[i].end;
}
}
cout << l << " " << r << endl;
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int tra;
int maxl;
int l;
int r;
int ans = (int)1e9;
struct NUM {
int sta;
int end;
int timel;
} num[1000001];
bool comp(const NUM &a, const NUM &b) { return a.timel > b.timel; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &tra);
if (num[tra].sta == 0) {
num[tra].sta = i;
num[tra].end = i;
num[tra].timel++;
} else {
num[tra].end = i;
num[tra].timel++;
}
}
sort(num + 1, num + 1 + 1000000, comp);
maxl = num[1].timel;
for (int i = 1; i <= 1000000; i++) {
if (num[i].timel != maxl) break;
if (ans > num[i].end - num[i].sta + 1) {
ans = num[i].end - num[i].sta + 1;
l = num[i].sta;
r = num[i].end;
}
}
cout << l << " " << r << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
vector<int> a, f(1e6 + 100);
vector<int> v[N];
int main() {
int n;
cin >> n;
a.resize(n);
int mx = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
f[a[i]]++;
v[a[i]].push_back(i);
mx = max(mx, f[a[i]]);
}
for (int i = 0; i < 1e6 + 100; i++) {
sort(v[i].begin(), v[i].end());
}
int diff = INT_MAX;
int ans[2];
for (int i = 0; i < 1e6 + 100; i++) {
if (f[i] == mx) {
int temp = v[i][v[i].size() - 1] - v[i][0];
if (diff > temp) {
diff = temp;
ans[0] = v[i][0];
ans[1] = v[i][v[i].size() - 1];
}
}
}
cout << ans[0] + 1 << " " << ans[1] + 1;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
vector<int> a, f(1e6 + 100);
vector<int> v[N];
int main() {
int n;
cin >> n;
a.resize(n);
int mx = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
f[a[i]]++;
v[a[i]].push_back(i);
mx = max(mx, f[a[i]]);
}
for (int i = 0; i < 1e6 + 100; i++) {
sort(v[i].begin(), v[i].end());
}
int diff = INT_MAX;
int ans[2];
for (int i = 0; i < 1e6 + 100; i++) {
if (f[i] == mx) {
int temp = v[i][v[i].size() - 1] - v[i][0];
if (diff > temp) {
diff = temp;
ans[0] = v[i][0];
ans[1] = v[i][v[i].size() - 1];
}
}
}
cout << ans[0] + 1 << " " << ans[1] + 1;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[1000010], l[1000010], r[1000010], ans;
void work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]), b[a[i]]++;
if (!l[a[i]]) l[a[i]] = i;
r[a[i]] = max(r[a[i]], i);
}
for (int i = 1; i <= 1e6; i++)
if ((b[ans] < b[i]) ||
((b[ans] == b[i]) && (r[ans] - l[ans] > r[i] - l[i])))
ans = i;
printf("%d %d\n", l[ans], r[ans]);
}
int main() {
work();
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[1000010], l[1000010], r[1000010], ans;
void work() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]), b[a[i]]++;
if (!l[a[i]]) l[a[i]] = i;
r[a[i]] = max(r[a[i]], i);
}
for (int i = 1; i <= 1e6; i++)
if ((b[ans] < b[i]) ||
((b[ans] == b[i]) && (r[ans] - l[ans] > r[i] - l[i])))
ans = i;
printf("%d %d\n", l[ans], r[ans]);
}
int main() {
work();
return 0;
}
```
|
#include <bits/stdc++.h>
int freq[1000005], l[1000005], r[1000005];
int main() {
int n, x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (freq[x]++ == 0) {
l[x] = i;
}
r[x] = i;
}
int a = -1, b, c;
for (int i = 0; i < 1000005; i++) {
if (freq[i] > a) {
a = freq[i];
b = l[i];
c = r[i];
} else if (freq[i] == a && r[i] - l[i] < c - b) {
b = l[i];
c = r[i];
}
}
printf("%d %d\n", b, c);
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
int freq[1000005], l[1000005], r[1000005];
int main() {
int n, x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (freq[x]++ == 0) {
l[x] = i;
}
r[x] = i;
}
int a = -1, b, c;
for (int i = 0; i < 1000005; i++) {
if (freq[i] > a) {
a = freq[i];
b = l[i];
c = r[i];
} else if (freq[i] == a && r[i] - l[i] < c - b) {
b = l[i];
c = r[i];
}
}
printf("%d %d\n", b, c);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct amr {
int s;
int l;
int c;
};
amr s[1000005];
int main() {
ios_base::sync_with_stdio(false);
int n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (s[x].c == 0) s[x].s = i;
s[x].c++;
s[x].l = i;
}
int maxx = 0, loc = -1;
for (int i = 0; i < 1000005; i++) {
if (s[i].c > maxx) {
maxx = s[i].c;
loc = i;
} else if (s[i].c == maxx) {
if ((s[i].l - s[i].s) < (s[loc].l - s[loc].s)) {
maxx = s[i].c;
loc = i;
}
}
}
cout << s[loc].s + 1 << " " << s[loc].l + 1;
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct amr {
int s;
int l;
int c;
};
amr s[1000005];
int main() {
ios_base::sync_with_stdio(false);
int n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (s[x].c == 0) s[x].s = i;
s[x].c++;
s[x].l = i;
}
int maxx = 0, loc = -1;
for (int i = 0; i < 1000005; i++) {
if (s[i].c > maxx) {
maxx = s[i].c;
loc = i;
} else if (s[i].c == maxx) {
if ((s[i].l - s[i].s) < (s[loc].l - s[loc].s)) {
maxx = s[i].c;
loc = i;
}
}
}
cout << s[loc].s + 1 << " " << s[loc].l + 1;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int be[1000001], en[1000001], nu[1000001];
int main() {
int n, i, a, l = 0, r = 0, o = 0;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
if (be[a] == 0) {
be[a] = i;
en[a] = i;
nu[a] = 1;
} else {
en[a] = i;
nu[a]++;
}
}
for (i = 0; i < 1000001; i++)
if (o < nu[i] || (o == nu[i] && r - l > en[i] - be[i])) {
l = be[i];
r = en[i];
o = nu[i];
}
cout << l << " " << r << endl;
}
|
### Prompt
In CPP, your task is to solve the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int be[1000001], en[1000001], nu[1000001];
int main() {
int n, i, a, l = 0, r = 0, o = 0;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
if (be[a] == 0) {
be[a] = i;
en[a] = i;
nu[a] = 1;
} else {
en[a] = i;
nu[a]++;
}
}
for (i = 0; i < 1000001; i++)
if (o < nu[i] || (o == nu[i] && r - l > en[i] - be[i])) {
l = be[i];
r = en[i];
o = nu[i];
}
cout << l << " " << r << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct Cut {
int val;
int kol;
int l, r;
Cut(int val = 0, int kol = 0, int l = 0, int r = 0) {
this->val = val;
this->kol = kol;
this->l = l;
this->r = r;
}
bool operator<(const Cut &c) const {
return kol > c.kol || kol == c.kol && (r - l) < (c.r - c.l) ||
(r - l) == (c.r - c.l) && val < c.val;
}
};
int main() {
int n;
cin >> n;
map<int, Cut> M;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
Cut c = M[a];
if (c.kol == 0) {
c.kol = 1;
c.val = a;
c.l = i + 1;
c.r = i + 1;
} else {
c.kol = c.kol + 1;
c.l = min(c.l, i + 1);
c.r = max(c.r, i + 1);
}
M[a] = c;
}
set<Cut> q;
for (auto it = M.begin(); it != M.end(); it++) {
q.insert(it->second);
}
Cut c = *q.begin();
cout << c.l << " " << c.r;
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct Cut {
int val;
int kol;
int l, r;
Cut(int val = 0, int kol = 0, int l = 0, int r = 0) {
this->val = val;
this->kol = kol;
this->l = l;
this->r = r;
}
bool operator<(const Cut &c) const {
return kol > c.kol || kol == c.kol && (r - l) < (c.r - c.l) ||
(r - l) == (c.r - c.l) && val < c.val;
}
};
int main() {
int n;
cin >> n;
map<int, Cut> M;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
Cut c = M[a];
if (c.kol == 0) {
c.kol = 1;
c.val = a;
c.l = i + 1;
c.r = i + 1;
} else {
c.kol = c.kol + 1;
c.l = min(c.l, i + 1);
c.r = max(c.r, i + 1);
}
M[a] = c;
}
set<Cut> q;
for (auto it = M.begin(); it != M.end(); it++) {
q.insert(it->second);
}
Cut c = *q.begin();
cout << c.l << " " << c.r;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
struct point_int {
int x, y;
point_int() {}
point_int(int a, int b) { x = a, y = b; }
};
struct point_double {
double x, y;
point_double() {}
point_double(double a, double b) { x = a, y = b; }
};
struct Node {
int v, w;
Node() {}
bool operator<(const Node &a) const { return w > a.w; }
Node(int _v, int _w) { v = _v, w = _w; }
};
namespace my {
template <class T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
T big_mod(T n, T p, T m) {
if (p == 0) return (T)1;
T x = big_mod(n, p / 2, m);
x = (x * x) % m;
if (p & 1) x = (x * n) % m;
return x;
}
template <class T>
T multiplication(T n, T p, T m) {
if (p == 0) return (T)0;
T x = multiplication(n, p / 2, m);
x = (x + x) % m;
if (p & 1) x = (x + n) % m;
return x;
}
template <class T>
T my_pow(T n, T p) {
if (p == 0) return 1;
T x = my_pow(n, p / 2);
x = (x * x);
if (p & 1) x = (x * n);
return x;
}
template <class T>
double getdist(T a, T b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
stringstream ss(s);
ss >> ret;
return ret;
}
template <class T>
string tostring(T n) {
stringstream ss;
ss << n;
return ss.str();
}
template <class T>
inline T Mod(T n, T m) {
return (n % m + m) % m;
}
template <class T>
T MIN3(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T MAX3(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void print_vector(T &v) {
int sz = v.size();
if (sz) cout << v[0];
for (int i = 1; i < sz; i++) cout << ' ' << v[i];
cout << endl;
}
bool isVowel(char ch) {
ch = toupper(ch);
if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
return true;
return false;
}
bool isConsonant(char ch) {
if (isalpha(ch) && !isVowel(ch)) return true;
return false;
}
} // namespace my
int read_int() {
int n;
scanf("%d", &n);
return n;
}
int read_LLD() {
long long int n;
scanf("%lld", &n);
return n;
}
inline int buffer_input() {
char inp[1000];
scanf("%s", inp);
return atoi(inp);
}
int posS[1000005];
int posE[1000005];
map<int, int> M;
int main() {
int N;
cin >> N;
fill(posS, posS + 1000005, inf);
fill(posE, posE + 1000005, -inf);
for (int i = 1; i <= N; i++) {
int x;
cin >> x;
posS[x] = min(posS[x], i);
posE[x] = max(posE[x], i);
M[x]++;
}
int Max = -1;
int val;
int beauty;
for (auto x : M) {
if (x.second > Max) {
val = x.first;
Max = x.second;
beauty = posE[val] - posS[val] + 1;
} else if (x.second == Max) {
if (beauty > (posE[x.first] - posS[x.first] + 1)) {
beauty = posE[x.first] - posS[x.first] + 1;
val = x.first;
}
}
}
cout << posS[val] << " " << posE[val] << endl;
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
struct point_int {
int x, y;
point_int() {}
point_int(int a, int b) { x = a, y = b; }
};
struct point_double {
double x, y;
point_double() {}
point_double(double a, double b) { x = a, y = b; }
};
struct Node {
int v, w;
Node() {}
bool operator<(const Node &a) const { return w > a.w; }
Node(int _v, int _w) { v = _v, w = _w; }
};
namespace my {
template <class T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
T big_mod(T n, T p, T m) {
if (p == 0) return (T)1;
T x = big_mod(n, p / 2, m);
x = (x * x) % m;
if (p & 1) x = (x * n) % m;
return x;
}
template <class T>
T multiplication(T n, T p, T m) {
if (p == 0) return (T)0;
T x = multiplication(n, p / 2, m);
x = (x + x) % m;
if (p & 1) x = (x + n) % m;
return x;
}
template <class T>
T my_pow(T n, T p) {
if (p == 0) return 1;
T x = my_pow(n, p / 2);
x = (x * x);
if (p & 1) x = (x * n);
return x;
}
template <class T>
double getdist(T a, T b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
stringstream ss(s);
ss >> ret;
return ret;
}
template <class T>
string tostring(T n) {
stringstream ss;
ss << n;
return ss.str();
}
template <class T>
inline T Mod(T n, T m) {
return (n % m + m) % m;
}
template <class T>
T MIN3(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T MAX3(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void print_vector(T &v) {
int sz = v.size();
if (sz) cout << v[0];
for (int i = 1; i < sz; i++) cout << ' ' << v[i];
cout << endl;
}
bool isVowel(char ch) {
ch = toupper(ch);
if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
return true;
return false;
}
bool isConsonant(char ch) {
if (isalpha(ch) && !isVowel(ch)) return true;
return false;
}
} // namespace my
int read_int() {
int n;
scanf("%d", &n);
return n;
}
int read_LLD() {
long long int n;
scanf("%lld", &n);
return n;
}
inline int buffer_input() {
char inp[1000];
scanf("%s", inp);
return atoi(inp);
}
int posS[1000005];
int posE[1000005];
map<int, int> M;
int main() {
int N;
cin >> N;
fill(posS, posS + 1000005, inf);
fill(posE, posE + 1000005, -inf);
for (int i = 1; i <= N; i++) {
int x;
cin >> x;
posS[x] = min(posS[x], i);
posE[x] = max(posE[x], i);
M[x]++;
}
int Max = -1;
int val;
int beauty;
for (auto x : M) {
if (x.second > Max) {
val = x.first;
Max = x.second;
beauty = posE[val] - posS[val] + 1;
} else if (x.second == Max) {
if (beauty > (posE[x.first] - posS[x.first] + 1)) {
beauty = posE[x.first] - posS[x.first] + 1;
val = x.first;
}
}
}
cout << posS[val] << " " << posE[val] << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int ll[1000010];
int rr[1000010];
int main() {
int n;
cin >> n;
int max = 0;
for (int i = 0; i < n; ++i) {
int q;
cin >> q;
if (a[q] == 0) ll[q] = i;
rr[q] = i;
++a[q];
if (a[q] > a[max]) {
max = q;
}
}
int l = 0, r = n - 1;
for (int i = 0; i <= 1000000; ++i) {
if (a[i] == a[max]) {
if (rr[i] - ll[i] < r - l) {
l = ll[i];
r = rr[i];
}
}
}
cout << l + 1 << " " << r + 1 << "\n";
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int ll[1000010];
int rr[1000010];
int main() {
int n;
cin >> n;
int max = 0;
for (int i = 0; i < n; ++i) {
int q;
cin >> q;
if (a[q] == 0) ll[q] = i;
rr[q] = i;
++a[q];
if (a[q] > a[max]) {
max = q;
}
}
int l = 0, r = n - 1;
for (int i = 0; i <= 1000000; ++i) {
if (a[i] == a[max]) {
if (rr[i] - ll[i] < r - l) {
l = ll[i];
r = rr[i];
}
}
}
cout << l + 1 << " " << r + 1 << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mx = -100000, mn = 1000000000, x, i, lu;
cin >> n;
vector<int> cnt(1e6 + 5), l(1e6 + 5);
for (i = 0; cin >> x; i++) {
if (cnt[x] == 0) l[x] = i;
cnt[x]++;
if (mx < cnt[x])
mx = cnt[x], lu = l[x], mn = i - lu;
else if (mx == cnt[x] && mn > i - l[x])
lu = l[x], mn = i - lu;
}
cout << lu + 1 << " " << lu + mn + 1;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mx = -100000, mn = 1000000000, x, i, lu;
cin >> n;
vector<int> cnt(1e6 + 5), l(1e6 + 5);
for (i = 0; cin >> x; i++) {
if (cnt[x] == 0) l[x] = i;
cnt[x]++;
if (mx < cnt[x])
mx = cnt[x], lu = l[x], mn = i - lu;
else if (mx == cnt[x] && mn > i - l[x])
lu = l[x], mn = i - lu;
}
cout << lu + 1 << " " << lu + mn + 1;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
struct mang {
int sl = 0, dau = 0, cuoi = 0;
} a[maxn], ans;
int n, x, y, z;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
++a[x].sl;
if (a[x].sl == 1) a[x].dau = i;
a[x].cuoi = i;
if (a[x].sl > ans.sl) {
ans = a[x];
} else if (a[x].sl == ans.sl and
(a[x].cuoi - a[x].dau + 1 <= ans.cuoi - ans.dau + 1)) {
ans = a[x];
}
}
cout << ans.dau << " " << ans.cuoi;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
struct mang {
int sl = 0, dau = 0, cuoi = 0;
} a[maxn], ans;
int n, x, y, z;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
++a[x].sl;
if (a[x].sl == 1) a[x].dau = i;
a[x].cuoi = i;
if (a[x].sl > ans.sl) {
ans = a[x];
} else if (a[x].sl == ans.sl and
(a[x].cuoi - a[x].dau + 1 <= ans.cuoi - ans.dau + 1)) {
ans = a[x];
}
}
cout << ans.dau << " " << ans.cuoi;
}
```
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> v(n);
unordered_map<int, int> count;
set<int> s;
int maxc = 0;
for (long long i = 0; i < (n); i++) {
cin >> v[i];
count[v[i]]++;
maxc = max(maxc, count[v[i]]);
}
for (auto i : v) {
if (maxc == count[i]) {
s.insert(i);
}
}
unordered_map<int, int> last;
for (int i = n - 1; i >= 0; i--) {
if (!last[v[i]]) {
last[v[i]] = i + 1;
}
}
int l = 0, r = 0;
int diff = 1e5;
unordered_map<int, int> vis;
for (auto i = 0; i < n; i++) {
if (s.find(v[i]) != s.end() && vis[v[i]] == 0) {
if (diff > last[v[i]] - i - 1) {
l = i + 1;
r = last[v[i]];
diff = last[v[i]] - i - 1;
}
vis[v[i]] = 1;
}
}
cout << l << " " << r;
}
int main() { solve(); }
|
### Prompt
Construct a CPP code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> v(n);
unordered_map<int, int> count;
set<int> s;
int maxc = 0;
for (long long i = 0; i < (n); i++) {
cin >> v[i];
count[v[i]]++;
maxc = max(maxc, count[v[i]]);
}
for (auto i : v) {
if (maxc == count[i]) {
s.insert(i);
}
}
unordered_map<int, int> last;
for (int i = n - 1; i >= 0; i--) {
if (!last[v[i]]) {
last[v[i]] = i + 1;
}
}
int l = 0, r = 0;
int diff = 1e5;
unordered_map<int, int> vis;
for (auto i = 0; i < n; i++) {
if (s.find(v[i]) != s.end() && vis[v[i]] == 0) {
if (diff > last[v[i]] - i - 1) {
l = i + 1;
r = last[v[i]];
diff = last[v[i]] - i - 1;
}
vis[v[i]] = 1;
}
}
cout << l << " " << r;
}
int main() { solve(); }
```
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
ios_base::sync_with_stdio(false);
int count;
cin >> count;
map<int, pair<int, pair<int, int> > > data;
int t;
for (int i = 0; i < count; i++) {
cin >> t;
if (data.count(t) == 0) {
data.insert(make_pair(t, make_pair(1, make_pair(i, i))));
} else {
pair<int, pair<int, int> > value = data[t];
data[t] = make_pair(value.first + 1, make_pair(value.second.first, i));
}
}
int sol_count = 0, sol_from = 0, sol_to = 0;
for (map<int, pair<int, pair<int, int> > >::iterator it = data.begin();
it != data.end(); it++) {
pair<int, pair<int, pair<int, int> > > value = *it;
int numb_count = value.second.first;
int from = value.second.second.first;
int to = value.second.second.second;
if (numb_count > sol_count) {
sol_count = numb_count;
sol_from = from;
sol_to = to;
} else if (numb_count == sol_count && ((sol_to - sol_from) > (to - from))) {
sol_count = numb_count;
sol_from = from;
sol_to = to;
}
}
cout << (sol_from + 1) << " " << (sol_to + 1) << endl;
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
ios_base::sync_with_stdio(false);
int count;
cin >> count;
map<int, pair<int, pair<int, int> > > data;
int t;
for (int i = 0; i < count; i++) {
cin >> t;
if (data.count(t) == 0) {
data.insert(make_pair(t, make_pair(1, make_pair(i, i))));
} else {
pair<int, pair<int, int> > value = data[t];
data[t] = make_pair(value.first + 1, make_pair(value.second.first, i));
}
}
int sol_count = 0, sol_from = 0, sol_to = 0;
for (map<int, pair<int, pair<int, int> > >::iterator it = data.begin();
it != data.end(); it++) {
pair<int, pair<int, pair<int, int> > > value = *it;
int numb_count = value.second.first;
int from = value.second.second.first;
int to = value.second.second.second;
if (numb_count > sol_count) {
sol_count = numb_count;
sol_from = from;
sol_to = to;
} else if (numb_count == sol_count && ((sol_to - sol_from) > (to - from))) {
sol_count = numb_count;
sol_from = from;
sol_to = to;
}
}
cout << (sol_from + 1) << " " << (sol_to + 1) << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long p[3][1000009];
long long maxx;
long long ans1, ans2, ans3 = 100009;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (long long i = (0); i < (n); i++) {
cin >> x;
p[0][x]++;
if (p[0][x] == 1) p[1][x] = i + 1;
p[2][x] = i + 1;
}
for (long long i = (1); i < (1000001); i++)
maxx = maxx < p[0][i] ? p[0][i] : maxx;
for (long long i = (1); i < (1000001); i++) {
if (p[0][i] == maxx) {
if (p[2][i] - p[1][i] < ans3) {
ans1 = p[1][i];
ans2 = p[2][i];
ans3 = ans2 - ans1;
}
}
}
cout << ans1 << " " << ans2;
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long p[3][1000009];
long long maxx;
long long ans1, ans2, ans3 = 100009;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (long long i = (0); i < (n); i++) {
cin >> x;
p[0][x]++;
if (p[0][x] == 1) p[1][x] = i + 1;
p[2][x] = i + 1;
}
for (long long i = (1); i < (1000001); i++)
maxx = maxx < p[0][i] ? p[0][i] : maxx;
for (long long i = (1); i < (1000001); i++) {
if (p[0][i] == maxx) {
if (p[2][i] - p[1][i] < ans3) {
ans1 = p[1][i];
ans2 = p[2][i];
ans3 = ans2 - ans1;
}
}
}
cout << ans1 << " " << ans2;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int freq[1000010];
int A[1000010];
bool marked[1000010];
vector<pair<int, int> > v(1000010);
int main() {
int n;
cin >> n;
int maxa = 0;
for (int i = 0; i < n; i++) {
cin >> A[i];
freq[A[i]]++;
maxa = max(maxa, freq[A[i]]);
}
for (int i = 0; i < 1000010; i++) {
v[i].first = v[i].second = INT_MAX;
}
for (int i = 0; i < n; i++) {
if (freq[A[i]] == maxa && marked[A[i]] == 0) {
v[A[i]].second = i + 1;
marked[A[i]] = 1;
} else if (freq[A[i]] == maxa && marked[A[i]] == 1) {
v[A[i]].first = i + 1 - v[A[i]].second;
}
}
if (maxa == 1) {
cout << "1 1" << endl;
return 0;
}
sort(v.begin(), v.end());
cout << v[0].second << " " << v[0].first + v[0].second << endl;
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int freq[1000010];
int A[1000010];
bool marked[1000010];
vector<pair<int, int> > v(1000010);
int main() {
int n;
cin >> n;
int maxa = 0;
for (int i = 0; i < n; i++) {
cin >> A[i];
freq[A[i]]++;
maxa = max(maxa, freq[A[i]]);
}
for (int i = 0; i < 1000010; i++) {
v[i].first = v[i].second = INT_MAX;
}
for (int i = 0; i < n; i++) {
if (freq[A[i]] == maxa && marked[A[i]] == 0) {
v[A[i]].second = i + 1;
marked[A[i]] = 1;
} else if (freq[A[i]] == maxa && marked[A[i]] == 1) {
v[A[i]].first = i + 1 - v[A[i]].second;
}
}
if (maxa == 1) {
cout << "1 1" << endl;
return 0;
}
sort(v.begin(), v.end());
cout << v[0].second << " " << v[0].first + v[0].second << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int arr[1000005], li[1000005], ri[1000005];
int main() {
int i, j, k, n, m, x, y, arr1[100005], maxi, max1, l, r;
cin >> n;
memset(arr, 0, sizeof arr);
memset(li, 0, sizeof li);
memset(ri, 0, sizeof ri);
for (i = 0; i < n; i++) {
cin >> x;
arr1[i] = x;
if (arr[x] == 0) {
li[x] = i;
ri[x] = i;
arr[x]++;
} else {
arr[x]++;
ri[x] = i;
}
}
maxi = 0;
for (i = 0; i < n; i++) {
maxi = max(arr[arr1[i]], maxi);
}
max1 = 999999999;
for (i = 0; i < n; i++) {
if (arr[arr1[i]] == maxi) {
x = arr1[i];
if (abs(li[x] - ri[x]) < max1) {
max1 = abs(li[x] - ri[x]);
l = li[x], r = ri[x];
}
}
}
cout << l + 1 << " " << r + 1 << endl;
}
|
### Prompt
Create a solution in Cpp for the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int arr[1000005], li[1000005], ri[1000005];
int main() {
int i, j, k, n, m, x, y, arr1[100005], maxi, max1, l, r;
cin >> n;
memset(arr, 0, sizeof arr);
memset(li, 0, sizeof li);
memset(ri, 0, sizeof ri);
for (i = 0; i < n; i++) {
cin >> x;
arr1[i] = x;
if (arr[x] == 0) {
li[x] = i;
ri[x] = i;
arr[x]++;
} else {
arr[x]++;
ri[x] = i;
}
}
maxi = 0;
for (i = 0; i < n; i++) {
maxi = max(arr[arr1[i]], maxi);
}
max1 = 999999999;
for (i = 0; i < n; i++) {
if (arr[arr1[i]] == maxi) {
x = arr1[i];
if (abs(li[x] - ri[x]) < max1) {
max1 = abs(li[x] - ri[x]);
l = li[x], r = ri[x];
}
}
}
cout << l + 1 << " " << r + 1 << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
long double PI = 3.14159265358979323846264338327950;
const int N = 1e6 + 10;
int st[N], End[N], mp[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
End[a[i]] = i;
if (!st[a[i]]) st[a[i]] = i;
}
int l, r, mx = 0;
for (int i = 0; i < N; i++) {
if (mp[i]) {
if (mp[i] > mx) {
mx = mp[i];
l = st[i];
r = End[i];
} else if (mp[i] == mx) {
if (End[i] - st[i] < r - l) {
l = st[i];
r = End[i];
}
}
}
}
cout << l << " " << r;
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
long double PI = 3.14159265358979323846264338327950;
const int N = 1e6 + 10;
int st[N], End[N], mp[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
End[a[i]] = i;
if (!st[a[i]]) st[a[i]] = i;
}
int l, r, mx = 0;
for (int i = 0; i < N; i++) {
if (mp[i]) {
if (mp[i] > mx) {
mx = mp[i];
l = st[i];
r = End[i];
} else if (mp[i] == mx) {
if (End[i] - st[i] < r - l) {
l = st[i];
r = End[i];
}
}
}
}
cout << l << " " << r;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int a[M];
int has[M * 10 * 2];
int l[M * 10];
int main() {
int n;
int maxx = -1;
int minx = 100 * M;
int tmp, tmp2;
scanf("%d", &n);
int ch = -1;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (has[x] == 0) {
has[x] = 1;
l[x] = i;
} else
has[x]++;
if (has[x] > maxx) {
maxx = has[x];
minx = i - l[x] + 1;
ch = l[x] + 1;
}
if (has[x] == maxx && (i - l[x] + 1 < minx)) {
minx = i - l[x] + 1;
ch = l[x] + 1;
}
}
printf("%d %d\n", ch, ch + minx - 1);
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int a[M];
int has[M * 10 * 2];
int l[M * 10];
int main() {
int n;
int maxx = -1;
int minx = 100 * M;
int tmp, tmp2;
scanf("%d", &n);
int ch = -1;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (has[x] == 0) {
has[x] = 1;
l[x] = i;
} else
has[x]++;
if (has[x] > maxx) {
maxx = has[x];
minx = i - l[x] + 1;
ch = l[x] + 1;
}
if (has[x] == maxx && (i - l[x] + 1 < minx)) {
minx = i - l[x] + 1;
ch = l[x] + 1;
}
}
printf("%d %d\n", ch, ch + minx - 1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int maxi = 0;
long mini = n;
vector<int> beaty_elem(1000005, 0);
vector<int> distance(1000005, 0);
int x;
int ch = 1;
for (int i = 1; i <= n; i++) {
cin >> x;
if (beaty_elem[x] == 0) {
beaty_elem[x] = 1;
distance[x] = i;
} else {
beaty_elem[x]++;
}
if (beaty_elem[x] > maxi) {
maxi = beaty_elem[x];
mini = i - distance[x] + 1;
ch = i;
}
if ((beaty_elem[x] == maxi) && (abs(i + 1 - distance[x]) < mini)) {
mini = i - distance[x] + 1;
ch = i;
}
}
cout << ch - mini + 1 << "\t" << ch;
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int maxi = 0;
long mini = n;
vector<int> beaty_elem(1000005, 0);
vector<int> distance(1000005, 0);
int x;
int ch = 1;
for (int i = 1; i <= n; i++) {
cin >> x;
if (beaty_elem[x] == 0) {
beaty_elem[x] = 1;
distance[x] = i;
} else {
beaty_elem[x]++;
}
if (beaty_elem[x] > maxi) {
maxi = beaty_elem[x];
mini = i - distance[x] + 1;
ch = i;
}
if ((beaty_elem[x] == maxi) && (abs(i + 1 - distance[x]) < mini)) {
mini = i - distance[x] + 1;
ch = i;
}
}
cout << ch - mini + 1 << "\t" << ch;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int e[1000000 + 10], s[1000000 + 10], t[1000000 + 10], a[1000000 + 10];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
t[a[i]]++;
if (s[a[i]] == 0) s[a[i]] = i;
e[a[i]] = i;
}
int mx = 0, l = 0, r = 0;
for (int i = 1; i <= 1000000; i++) {
if ((t[i] > mx) || (t[i] == mx && e[i] - s[i] < r - l))
mx = t[i], l = s[i], r = e[i];
}
cout << l << ' ' << r;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int e[1000000 + 10], s[1000000 + 10], t[1000000 + 10], a[1000000 + 10];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
t[a[i]]++;
if (s[a[i]] == 0) s[a[i]] = i;
e[a[i]] = i;
}
int mx = 0, l = 0, r = 0;
for (int i = 1; i <= 1000000; i++) {
if ((t[i] > mx) || (t[i] == mx && e[i] - s[i] < r - l))
mx = t[i], l = s[i], r = e[i];
}
cout << l << ' ' << r;
}
```
|
#include <bits/stdc++.h>
int b[1000001], d[1000001], c[1000001], a[100000];
int main() {
int i, n, ans, num, max;
for (i = 0; i <= 1000000; i++) {
b[i] = 0;
}
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
if (b[a[i]] == 1) {
c[a[i]] = i + 1;
}
d[a[i]] = i + 1;
}
max = 0;
for (i = 0; i <= 1000000; i++) {
if (b[i] > max) {
max = b[i];
num = i;
}
}
for (i = 0; i <= 1000000; i++) {
if (b[i] == max && d[i] - c[i] < d[num] - c[num]) {
max = b[i];
num = i;
}
}
printf("%d %d\n", c[num], d[num]);
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
int b[1000001], d[1000001], c[1000001], a[100000];
int main() {
int i, n, ans, num, max;
for (i = 0; i <= 1000000; i++) {
b[i] = 0;
}
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
if (b[a[i]] == 1) {
c[a[i]] = i + 1;
}
d[a[i]] = i + 1;
}
max = 0;
for (i = 0; i <= 1000000; i++) {
if (b[i] > max) {
max = b[i];
num = i;
}
}
for (i = 0; i <= 1000000; i++) {
if (b[i] == max && d[i] - c[i] < d[num] - c[num]) {
max = b[i];
num = i;
}
}
printf("%d %d\n", c[num], d[num]);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int mark[1000005], beauty;
vector<int> last[1000005];
int n;
int a[1000005], l, r;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
last[a[i]].push_back(i);
mark[a[i]]++;
beauty = max(beauty, mark[a[i]]);
}
int ans = INT_MAX;
for (int i = 0; i <= 1000000; i++) {
if (last[i].size() == beauty) {
if (last[i][last[i].size() - 1] - last[i][0] < ans) {
ans = last[i][last[i].size() - 1] - last[i][0];
l = last[i][0];
r = last[i][last[i].size() - 1];
}
}
}
cout << 1 + l << " " << 1 + r << endl;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int mark[1000005], beauty;
vector<int> last[1000005];
int n;
int a[1000005], l, r;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
last[a[i]].push_back(i);
mark[a[i]]++;
beauty = max(beauty, mark[a[i]]);
}
int ans = INT_MAX;
for (int i = 0; i <= 1000000; i++) {
if (last[i].size() == beauty) {
if (last[i][last[i].size() - 1] - last[i][0] < ans) {
ans = last[i][last[i].size() - 1] - last[i][0];
l = last[i][0];
r = last[i][last[i].size() - 1];
}
}
}
cout << 1 + l << " " << 1 + r << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int l[1000005], r[1000005], cnt[1000005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x]++;
if (l[x] == 0) l[x] = i;
r[x] = i;
}
int ll, rr, mx = -1, dff = 9999999;
for (int i = 1; i <= 1000000; i++) {
if (mx == cnt[i]) {
if (r[i] - l[i] < dff) {
ll = l[i];
rr = r[i];
dff = r[i] - l[i];
}
} else if (cnt[i] > mx) {
mx = cnt[i];
ll = l[i];
rr = r[i];
dff = r[i] - l[i];
}
}
cout << ll << " " << rr << endl;
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int l[1000005], r[1000005], cnt[1000005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x]++;
if (l[x] == 0) l[x] = i;
r[x] = i;
}
int ll, rr, mx = -1, dff = 9999999;
for (int i = 1; i <= 1000000; i++) {
if (mx == cnt[i]) {
if (r[i] - l[i] < dff) {
ll = l[i];
rr = r[i];
dff = r[i] - l[i];
}
} else if (cnt[i] > mx) {
mx = cnt[i];
ll = l[i];
rr = r[i];
dff = r[i] - l[i];
}
}
cout << ll << " " << rr << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<pair<int, pair<int, int> > > has(1000005, {0, {n, -1}});
vector<int> arr(n);
int a;
int maxc = 0;
for (int i = 0; i < n; i++) {
cin >> a;
arr[i] = a;
has[a].first++;
maxc = max(maxc, has[a].first);
has[a].second.first = min(has[a].second.first, i);
has[a].second.second = max(has[a].second.second, i);
}
int len = INT_MAX;
int l = 1, r = n;
for (int i = 1; i <= 1000000; i++) {
if (has[i].first == maxc) {
if (len > (has[i].second.second - has[i].second.first + 1)) {
len = has[i].second.second - has[i].second.first + 1;
l = has[i].second.first + 1;
r = has[i].second.second + 1;
}
}
}
cout << l << " " << r;
}
|
### Prompt
Generate a CPP solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<pair<int, pair<int, int> > > has(1000005, {0, {n, -1}});
vector<int> arr(n);
int a;
int maxc = 0;
for (int i = 0; i < n; i++) {
cin >> a;
arr[i] = a;
has[a].first++;
maxc = max(maxc, has[a].first);
has[a].second.first = min(has[a].second.first, i);
has[a].second.second = max(has[a].second.second, i);
}
int len = INT_MAX;
int l = 1, r = n;
for (int i = 1; i <= 1000000; i++) {
if (has[i].first == maxc) {
if (len > (has[i].second.second - has[i].second.first + 1)) {
len = has[i].second.second - has[i].second.first + 1;
l = has[i].second.first + 1;
r = has[i].second.second + 1;
}
}
}
cout << l << " " << r;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int cnt[1000005];
int sp[1000005];
void init(int a[]) {
for (int i = 0; i < 1000005; i++) a[i] = 0;
}
int main() {
int n;
int max = 0;
int dis = 0;
while (scanf("%d", &n) != EOF) {
int a, r = 0, l = 0;
init(cnt);
init(sp);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
if (!cnt[a]) sp[a] = i;
cnt[a]++;
if (max < cnt[a]) {
max = cnt[a];
l = sp[a], r = i;
dis = i - l;
} else if (max == cnt[a] && i - sp[a] < dis) {
dis = i - sp[a];
l = sp[a];
r = i;
}
}
printf("%d %d\n", l + 1, r + 1);
}
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int cnt[1000005];
int sp[1000005];
void init(int a[]) {
for (int i = 0; i < 1000005; i++) a[i] = 0;
}
int main() {
int n;
int max = 0;
int dis = 0;
while (scanf("%d", &n) != EOF) {
int a, r = 0, l = 0;
init(cnt);
init(sp);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
if (!cnt[a]) sp[a] = i;
cnt[a]++;
if (max < cnt[a]) {
max = cnt[a];
l = sp[a], r = i;
dis = i - l;
} else if (max == cnt[a] && i - sp[a] < dis) {
dis = i - sp[a];
l = sp[a];
r = i;
}
}
printf("%d %d\n", l + 1, r + 1);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int fst[1000001], last[1000001];
int was[1000001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (fst[a] == 0) fst[a] = i + 1;
last[a] = i + 1;
was[a]++;
}
int ans = 1e9, ansl = 0, ansr = 0;
int maxx = *max_element(was, was + 1000001);
for (int i = 1; i <= 1000000; i++) {
if (last[i] - fst[i] + 1 < ans and was[i] == maxx) {
ans = last[i] - fst[i] + 1;
ansl = fst[i];
ansr = last[i];
}
}
cout << ansl << ' ' << ansr << endl;
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.
Help Amr by choosing the smallest subsegment possible.
Input
The first line contains one number n (1 ≤ n ≤ 105), the size of the array.
The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.
Output
Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them.
Examples
Input
5
1 1 2 2 1
Output
1 5
Input
5
1 2 2 3 1
Output
2 3
Input
6
1 2 2 1 1 2
Output
1 5
Note
A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int fst[1000001], last[1000001];
int was[1000001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (fst[a] == 0) fst[a] = i + 1;
last[a] = i + 1;
was[a]++;
}
int ans = 1e9, ansl = 0, ansr = 0;
int maxx = *max_element(was, was + 1000001);
for (int i = 1; i <= 1000000; i++) {
if (last[i] - fst[i] + 1 < ans and was[i] == maxx) {
ans = last[i] - fst[i] + 1;
ansl = fst[i];
ansr = last[i];
}
}
cout << ansl << ' ' << ansr << endl;
return 0;
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.