output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <iostream>
using namespace std;
string a;
int n;
int main() {
cin>>a;
n = a.size();
a = '.' + a + '.';
for(int i=1; i<n; i++) {
if(a[i]==a[i+1]) {cout<<i<<' '<<i+1; return 0;}
if(a[i]==a[i+2]) {cout<<i<<' '<<i+2; return 0;}
}
cout<<"-1 -1";
return 0;
} | ### Prompt
Please formulate a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
using namespace std;
string a;
int n;
int main() {
cin>>a;
n = a.size();
a = '.' + a + '.';
for(int i=1; i<n; i++) {
if(a[i]==a[i+1]) {cout<<i<<' '<<i+1; return 0;}
if(a[i]==a[i+2]) {cout<<i<<' '<<i+2; return 0;}
}
cout<<"-1 -1";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char s[100010];
int main()
{
scanf("%s", s);
int x = strlen(s);
int p = -1, q = -1;
if (x == 2) {
if (s[0] == s[1]) {
p = 1, q = 2;
}
} else
for (int i = 0; i + 2 < x; i++) {
if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
p = i + 1, q = i + 3;
break;
}
}
printf("%d %d\n", p, q);
} | ### Prompt
Generate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100010];
int main()
{
scanf("%s", s);
int x = strlen(s);
int p = -1, q = -1;
if (x == 2) {
if (s[0] == s[1]) {
p = 1, q = 2;
}
} else
for (int i = 0; i + 2 < x; i++) {
if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
p = i + 1, q = i + 3;
break;
}
}
printf("%d %d\n", p, q);
}
``` |
#include<cstdio>
#include<cstring>
using namespace std;
char a[100004];
int main()
{
scanf("%s",a+1);
int n=strlen(a+1);
for(int i=1;i!=n;++i) if(a[i]==a[i+1]) {printf("%d %d\n",i,i+1);return 0;}
for(int i=1;i<n-1;++i) if(a[i]==a[i+2]) {printf("%d %d\n",i,i+2);return 0;}
printf("-1 -1\n");
return 0;
} | ### Prompt
Please create a solution in Cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
char a[100004];
int main()
{
scanf("%s",a+1);
int n=strlen(a+1);
for(int i=1;i!=n;++i) if(a[i]==a[i+1]) {printf("%d %d\n",i,i+1);return 0;}
for(int i=1;i<n-1;++i) if(a[i]==a[i+2]) {printf("%d %d\n",i,i+2);return 0;}
printf("-1 -1\n");
return 0;
}
``` |
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
char str[100005];
cin>>str;
int N=strlen(str);
for(int i=0;i<N;i++){
if(str[i]==str[i+2]&&i<N-2){cout<<i+1<<' '<<i+3; break;}
else if(str[i]==str[i+1]&&i<N-1){cout<<i+1<<' '<<i+2; break;}
if(i==N-1){cout<<-1<<' '<<-1;}
}
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
char str[100005];
cin>>str;
int N=strlen(str);
for(int i=0;i<N;i++){
if(str[i]==str[i+2]&&i<N-2){cout<<i+1<<' '<<i+3; break;}
else if(str[i]==str[i+1]&&i<N-1){cout<<i+1<<' '<<i+2; break;}
if(i==N-1){cout<<-1<<' '<<-1;}
}
return 0;
}
``` |
#include<cstdio>
char s[111111];
int main() {
scanf("%s", s);
for(int i=1;s[i];i++) {
if(s[i]==s[i-1]) {
printf("%d %d\n", i, i+1);
return 0;
}
if(i>1 && s[i]==s[i-2]) {
printf("%d %d\n", i-1, i+1);
return 0;
}
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Generate a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
char s[111111];
int main() {
scanf("%s", s);
for(int i=1;s[i];i++) {
if(s[i]==s[i-1]) {
printf("%d %d\n", i, i+1);
return 0;
}
if(i>1 && s[i]==s[i-2]) {
printf("%d %d\n", i-1, i+1);
return 0;
}
}
printf("-1 -1\n");
return 0;
}
``` |
#include <iostream>
int main() {
std::string s;
std::cin >> s;
for (unsigned i = 0; i < s.size() - 1; ++i) {
if (s[i] == s[i + 1]) {
std::cout << i + 1 << " " << i + 2;
return 0;
}
}
for (unsigned i = 0; i < s.size() - 2; ++i) {
if (s[i] == s[i + 2]) {
std::cout << i + 1 << " " << i + 3;
return 0;
}
}
std::cout << -1 << " " << -1;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
int main() {
std::string s;
std::cin >> s;
for (unsigned i = 0; i < s.size() - 1; ++i) {
if (s[i] == s[i + 1]) {
std::cout << i + 1 << " " << i + 2;
return 0;
}
}
for (unsigned i = 0; i < s.size() - 2; ++i) {
if (s[i] == s[i + 2]) {
std::cout << i + 1 << " " << i + 3;
return 0;
}
}
std::cout << -1 << " " << -1;
return 0;
}
``` |
#include <cstdio>
#include <cstring>
const int N=100005;
char a[N];
int main (){
scanf ("%s",a+1);
int n=strlen(a+1);
if (n==2) {
if (a[1]==a[2]) puts("1 2");
else puts("-1 -1");
return 0;
}
for (int i=1;i<=n-2;i++)
if ((a[i]==a[i+1])||(a[i]==a[i+2])||(a[i+1]==a[i+2])){
printf ("%d %d",i,i+2);return 0;
}
puts("-1 -1");
return 0;
} | ### Prompt
In Cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <cstdio>
#include <cstring>
const int N=100005;
char a[N];
int main (){
scanf ("%s",a+1);
int n=strlen(a+1);
if (n==2) {
if (a[1]==a[2]) puts("1 2");
else puts("-1 -1");
return 0;
}
for (int i=1;i<=n-2;i++)
if ((a[i]==a[i+1])||(a[i]==a[i+2])||(a[i+1]==a[i+2])){
printf ("%d %d",i,i+2);return 0;
}
puts("-1 -1");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int n=0,l=-1,r=-1;
int main()
{
scanf("%s",s+1);
for(int i=1;s[i];i++)
{
++n;
}
for(int i=1;i<n;i++)
{
if(s[i]==s[i+1])
{
l=i;
r=i+1;
}
}
for(int i=1;i<n-1;i++)
{
if(s[i]==s[i+2])
{
l=i;
r=i+2;
}
}
printf("%d %d\n",l,r);
} | ### Prompt
Your task is to create a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int n=0,l=-1,r=-1;
int main()
{
scanf("%s",s+1);
for(int i=1;s[i];i++)
{
++n;
}
for(int i=1;i<n;i++)
{
if(s[i]==s[i+1])
{
l=i;
r=i+1;
}
}
for(int i=1;i<n-1;i++)
{
if(s[i]==s[i+2])
{
l=i;
r=i+2;
}
}
printf("%d %d\n",l,r);
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
char a[MAX];
int main() {
scanf("%s", a + 1);
int n = strlen(a + 1);
int x = -1, y = -1;
for(int i = 1; i <= n; i++) {
if(i + 1 <= n && a[i] == a[i + 1])
x = i, y = i + 1;
if(i + 2 <= n && a[i] == a[i + 2])
x = i, y = i + 2;
}
printf("%d %d\n", x, y);
return 0;
} | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
char a[MAX];
int main() {
scanf("%s", a + 1);
int n = strlen(a + 1);
int x = -1, y = -1;
for(int i = 1; i <= n; i++) {
if(i + 1 <= n && a[i] == a[i + 1])
x = i, y = i + 1;
if(i + 2 <= n && a[i] == a[i + 2])
x = i, y = i + 2;
}
printf("%d %d\n", x, y);
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1])
{
printf("%d %d\n",i+1,i+2); return 0;
}
if(i<s.size()-2&&s[i]==s[i+2])
{
printf("%d %d\n",i+1,i+3); return 0;
}
}
printf("-1 -1\n");
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1])
{
printf("%d %d\n",i+1,i+2); return 0;
}
if(i<s.size()-2&&s[i]==s[i+2])
{
printf("%d %d\n",i+1,i+3); return 0;
}
}
printf("-1 -1\n");
return 0;
}
``` |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int la[101];
int main()
{
int l;
for(int i=0;i<26;i++)
la[i]=-100;
scanf("%s",s+1);
l=strlen(s+1);
for(int i=1;i<=l;i++)
{
if(i-la[s[i]-'a']<=2)
{
printf("%d %d",la[s[i]-'a'],i);
return 0;
}
la[s[i]-'a']=i;
}
printf("-1 -1");
return 0;
} | ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int la[101];
int main()
{
int l;
for(int i=0;i<26;i++)
la[i]=-100;
scanf("%s",s+1);
l=strlen(s+1);
for(int i=1;i<=l;i++)
{
if(i-la[s[i]-'a']<=2)
{
printf("%d %d",la[s[i]-'a'],i);
return 0;
}
la[s[i]-'a']=i;
}
printf("-1 -1");
return 0;
}
``` |
#include<cstdio>
char c1,c2,c;
int l=0;
int main()
{
while((c=getchar())!=-1)
{
l++;
if(c1==c)
{
printf("%d %d",l-1,l);
return 0;
}
if(c2==c)
{
printf("%d %d",l-2,l);
return 0;
}
c2=c1; c1=c;
}
puts("-1 -1");
return 0;
} | ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
char c1,c2,c;
int l=0;
int main()
{
while((c=getchar())!=-1)
{
l++;
if(c1==c)
{
printf("%d %d",l-1,l);
return 0;
}
if(c2==c)
{
printf("%d %d",l-2,l);
return 0;
}
c2=c1; c1=c;
}
puts("-1 -1");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
void solve()
{
pair<int,int> ans ={-1,-1};
const int n = s.length();
for(int i=0;i+1<n;++i)if(s[i]==s[i+1]){
ans={i+1,i+2};
break;
}
if(ans.first==-1)for(int i=0;i+2<n;++i){
if(s[i]==s[i+2]){
ans={i+1,i+3};
break;
}
}
cout << ans.first << " " << ans.second << endl;
}
int main()
{
cin >> s;
solve();
return 0;
} | ### Prompt
Your task is to create a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
void solve()
{
pair<int,int> ans ={-1,-1};
const int n = s.length();
for(int i=0;i+1<n;++i)if(s[i]==s[i+1]){
ans={i+1,i+2};
break;
}
if(ans.first==-1)for(int i=0;i+2<n;++i){
if(s[i]==s[i+2]){
ans={i+1,i+3};
break;
}
}
cout << ans.first << " " << ans.second << endl;
}
int main()
{
cin >> s;
solve();
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
char word[100100];
int main()
{
scanf("%s",word);
for(int i=1;word[i];i++)
{
if(word[i]==word[i-1])
{
printf("%d %d\n",i,i+1);
return 0;
}
if(i>=2&&word[i]==word[i-2])
{
printf("%d %d\n",i-1,i+1);
return 0;
}
}
printf("-1 -1\n");
} | ### Prompt
Please provide a cpp coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
char word[100100];
int main()
{
scanf("%s",word);
for(int i=1;word[i];i++)
{
if(word[i]==word[i-1])
{
printf("%d %d\n",i,i+1);
return 0;
}
if(i>=2&&word[i]==word[i-2])
{
printf("%d %d\n",i-1,i+1);
return 0;
}
}
printf("-1 -1\n");
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
for(int i=0;i<s.size()-1;i++)
if (s[i]==s[i+1])
{
cout<<i+1<<" "<<i+2;
return 0;
}
for(int i=0;i<s.size()-2;i++)
if (s[i]==s[i+2])
{
cout<<i+1<<" "<<i+3;
return 0;
}
cout<<-1<<" "<<-1;
return 0;
} | ### Prompt
Generate a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
for(int i=0;i<s.size()-1;i++)
if (s[i]==s[i+1])
{
cout<<i+1<<" "<<i+2;
return 0;
}
for(int i=0;i<s.size()-2;i++)
if (s[i]==s[i+2])
{
cout<<i+1<<" "<<i+3;
return 0;
}
cout<<-1<<" "<<-1;
return 0;
}
``` |
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int const N = 41 * 41;
string s;
void ok(int a, int b){
cout << a << " " << b << endl;
exit(0);
}
int main(){
cin >> s;
int n = s.size();
for(int i=1;i<n;++i){
if(s[i] == s[i-1]){
ok(i, i+1);
}
if(i > 2 && s[i] == s[i-2]){
ok(i-1, i+1);
}
}
ok(-1, -1);
return 0;
} | ### Prompt
Please formulate a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int const N = 41 * 41;
string s;
void ok(int a, int b){
cout << a << " " << b << endl;
exit(0);
}
int main(){
cin >> s;
int n = s.size();
for(int i=1;i<n;++i){
if(s[i] == s[i-1]){
ok(i, i+1);
}
if(i > 2 && s[i] == s[i-2]){
ok(i-1, i+1);
}
}
ok(-1, -1);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char s[100001];
int c[26];
int main() {
scanf("%s", s);
memset(c, -1, sizeof c);
int i;
for (i = 0; s[i]; i++) {
int j = s[i] - 'a';
if (c[j] != -1 && i - c[j] <= 2)
break;
c[j] = i;
}
if (s[i])
printf("%d %d\n", c[s[i]-'a']+1, i+1);
else
printf("-1 -1\n");
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100001];
int c[26];
int main() {
scanf("%s", s);
memset(c, -1, sizeof c);
int i;
for (i = 0; s[i]; i++) {
int j = s[i] - 'a';
if (c[j] != -1 && i - c[j] <= 2)
break;
c[j] = i;
}
if (s[i])
printf("%d %d\n", c[s[i]-'a']+1, i+1);
else
printf("-1 -1\n");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
for(int i=1;i<s.size();i++)if(s[i]==s[i-1]){printf("%d %d\n",i,i+1);return 0;}
for(int i=1;i<s.size();i++)if(s[i]==s[i-2]){printf("%d %d\n",i-1,i+1);return 0;}
printf("-1 -1\n");
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
for(int i=1;i<s.size();i++)if(s[i]==s[i-1]){printf("%d %d\n",i,i+1);return 0;}
for(int i=1;i<s.size();i++)if(s[i]==s[i-2]){printf("%d %d\n",i-1,i+1);return 0;}
printf("-1 -1\n");
return 0;
}
``` |
#include <iostream>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-2;i++)
{ if(s[i]==s[i+1])
{cout<<i+1<<" "<<i+2;return 0;}
if(s[i]==s[i+2])
{ cout<<i+1<<" "<<i+3;
return 0;}}
if(s[s.size()-1]==s[s.size()-2])
cout<<s.size()-1<<" "<<s.size();
else
cout<<-1<<" "<<-1;
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-2;i++)
{ if(s[i]==s[i+1])
{cout<<i+1<<" "<<i+2;return 0;}
if(s[i]==s[i+2])
{ cout<<i+1<<" "<<i+3;
return 0;}}
if(s[s.size()-1]==s[s.size()-2])
cout<<s.size()-1<<" "<<s.size();
else
cout<<-1<<" "<<-1;
return 0;
}
``` |
#include <iostream>
#include <vector>
using namespace std;
int main(){
string str;
cin >> str;
for(int i=1; i<(int)str.length(); i++){
if(str[i-1]==str[i]){
cout << i << " " << i+1 << endl;
return 0;
}
}
for(int i=2; i<(int)str.length(); i++){
if(str[i-2]==str[i]){
cout << i-1 << " " << i+1 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
} | ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <vector>
using namespace std;
int main(){
string str;
cin >> str;
for(int i=1; i<(int)str.length(); i++){
if(str[i-1]==str[i]){
cout << i << " " << i+1 << endl;
return 0;
}
}
for(int i=2; i<(int)str.length(); i++){
if(str[i-2]==str[i]){
cout << i-1 << " " << i+1 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int n=s.size();
array<int,2> res={-1,-1};
for(int i=0;i<n;i++)
{
if(i+1<n&&s[i]==s[i+1]) res={i+1,i+2};
if(i+2<n&&s[i]==s[i+2]) res={i+1,i+3};
}
cout << res[0] << " " << res[1] << "\n";
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int n=s.size();
array<int,2> res={-1,-1};
for(int i=0;i<n;i++)
{
if(i+1<n&&s[i]==s[i+1]) res={i+1,i+2};
if(i+2<n&&s[i]==s[i+2]) res={i+1,i+3};
}
cout << res[0] << " " << res[1] << "\n";
return 0;
}
``` |
#include <iostream>
#include <string>
using namespace std;
int main(){
int l = -2,r = -2;
string s;
cin >> s;
for(int i = 0;i < s.length() - 1;i++){
if(s[i] == s[i + 1]){
l = i;
r = i + 1;
}
}
for(int i = 0;i < s.length() - 2;i++){
if(s[i] == s[i + 2]){
l = i;
r = i + 2;
}
}
cout << l + 1 << " " << r + 1 << endl;
return 0;
} | ### Prompt
Construct a CPP code solution to the problem outlined:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <string>
using namespace std;
int main(){
int l = -2,r = -2;
string s;
cin >> s;
for(int i = 0;i < s.length() - 1;i++){
if(s[i] == s[i + 1]){
l = i;
r = i + 1;
}
}
for(int i = 0;i < s.length() - 2;i++){
if(s[i] == s[i + 2]){
l = i;
r = i + 2;
}
}
cout << l + 1 << " " << r + 1 << endl;
return 0;
}
``` |
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n ;
string s ;
int main()
{
IO;
cin>>s;
n=s.size();
for (int i=1; i<n; i++)
{
if (s[i]==s[i-1])
return cout<< i<<" "<<i+1, 0;
if (i>1&&s[i]==s[i-2])
return cout<< i-1<<" "<<i+1, 0;
}
cout<<-1<<" "<<-1;
}
| ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n ;
string s ;
int main()
{
IO;
cin>>s;
n=s.size();
for (int i=1; i<n; i++)
{
if (s[i]==s[i-1])
return cout<< i<<" "<<i+1, 0;
if (i>1&&s[i]==s[i-2])
return cout<< i-1<<" "<<i+1, 0;
}
cout<<-1<<" "<<-1;
}
``` |
#include <iostream>
#include <cstdio>
using namespace std;
string a;
int main()
{
int i;
cin >> a;
for (i = 0; i < a.size() - 2; i++) {
if (a[i] == a[i + 1] || a[i] == a[i + 2]) {
cout << i + 1 << ' ' << i + 3;
return 0;
}
}
if (a[i] == a[i + 1]) {
cout << i + 1 << ' ' << i + 2;
return 0;
}
cout << "-1 -1" << endl;
return 0;
} | ### Prompt
Create a solution in CPP for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <cstdio>
using namespace std;
string a;
int main()
{
int i;
cin >> a;
for (i = 0; i < a.size() - 2; i++) {
if (a[i] == a[i + 1] || a[i] == a[i + 2]) {
cout << i + 1 << ' ' << i + 3;
return 0;
}
}
if (a[i] == a[i + 1]) {
cout << i + 1 << ' ' << i + 2;
return 0;
}
cout << "-1 -1" << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std ;
char s[ 100010 ] ;
int main() {
scanf( "%s" , s + 1 ) ;
int n = strlen( s + 1 ) ;
for( int i = 1 ; i <= n ; i ++ ) {
if( s[ i ] == s[ i + 2 ] ) {
printf( "%d %d\n" , i , i + 2 ) ;
return 0 ;
}
if( s[ i ] == s[ i + 1 ] ) {
printf( "%d %d\n" , i , i + 1 ) ;
return 0 ;
}
}
puts( "-1 -1" ) ;
return 0 ;
} | ### Prompt
Please formulate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std ;
char s[ 100010 ] ;
int main() {
scanf( "%s" , s + 1 ) ;
int n = strlen( s + 1 ) ;
for( int i = 1 ; i <= n ; i ++ ) {
if( s[ i ] == s[ i + 2 ] ) {
printf( "%d %d\n" , i , i + 2 ) ;
return 0 ;
}
if( s[ i ] == s[ i + 1 ] ) {
printf( "%d %d\n" , i , i + 1 ) ;
return 0 ;
}
}
puts( "-1 -1" ) ;
return 0 ;
}
``` |
#include <iostream>
using namespace std;
string a;
int main() {
cin>>a;
for(int i=1; i<a.size(); i++) {
if(a[i]==a[i-1]) {cout<<i<<' '<<i+1; return 0;}
if(a[i]==a[i-2]) {cout<<i-1<<' '<<i+1; return 0;}
}
cout<<"-1 -1";
return 0;
} | ### Prompt
In CPP, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
using namespace std;
string a;
int main() {
cin>>a;
for(int i=1; i<a.size(); i++) {
if(a[i]==a[i-1]) {cout<<i<<' '<<i+1; return 0;}
if(a[i]==a[i-2]) {cout<<i-1<<' '<<i+1; return 0;}
}
cout<<"-1 -1";
return 0;
}
``` |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void die(int x, int y) {
cout << x << " " << y;
exit(0);
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
string s;
cin >> s;
int n = s.size();
for (int i = 1; i < n; ++i)
if (s[i] == s[i - 1])
die(i, i + 1);
else if (i - 2 >= 0 && s[i - 2] == s[i])
die(i - 1, i + 1);
cout << "-1 -1";
} | ### Prompt
Please formulate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void die(int x, int y) {
cout << x << " " << y;
exit(0);
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
string s;
cin >> s;
int n = s.size();
for (int i = 1; i < n; ++i)
if (s[i] == s[i - 1])
die(i, i + 1);
else if (i - 2 >= 0 && s[i - 2] == s[i])
die(i - 1, i + 1);
cout << "-1 -1";
}
``` |
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200006
using namespace std;
char s[MAXN];
int n;
int main()
{
scanf("%s",s);
n=strlen(s);
for(int i=n;i>=1;i--)
{
s[i]=s[i-1];
if(s[i+1]==s[i])
{
printf("%d %d",i,i+1);
return 0;
}
}
for(int i=1;i<=n-2;i++)
if(s[i]==s[i+2])
{
printf("%d %d",i,i+2);
return 0;
}
printf("-1 -1");
} | ### Prompt
Create a solution in cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 200006
using namespace std;
char s[MAXN];
int n;
int main()
{
scanf("%s",s);
n=strlen(s);
for(int i=n;i>=1;i--)
{
s[i]=s[i-1];
if(s[i+1]==s[i])
{
printf("%d %d",i,i+1);
return 0;
}
}
for(int i=1;i<=n-2;i++)
if(s[i]==s[i+2])
{
printf("%d %d",i,i+2);
return 0;
}
printf("-1 -1");
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for(int i=0;i<s.length();i++){
if(s[i]==s[i-1]){
cout << i << ' ' << i+1;
break;
}
else if(s[i]==s[i-2]){
cout << i-1 << ' ' << i+1;
break;
}
else if(i==s.length()-1)
cout << -1 << ' ' << -1;
}
}
| ### Prompt
In CPP, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for(int i=0;i<s.length();i++){
if(s[i]==s[i-1]){
cout << i << ' ' << i+1;
break;
}
else if(s[i]==s[i-2]){
cout << i-1 << ' ' << i+1;
break;
}
else if(i==s.length()-1)
cout << -1 << ' ' << -1;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int N=S.size();
bool a=false;
int A=-1,B=-1;
for(int i=0;i<N-1;i++){
if(S.at(i)==S.at(i+1)){
A=i+1,B=i+2;
}
}
for(int i=0;i<N-2;i++){
if(S.at(i)==S.at(i+2)){
A=i+1,B=i+3;
}
}
cout << A << " " << B << endl;
} | ### Prompt
Develop a solution in CPP to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int N=S.size();
bool a=false;
int A=-1,B=-1;
for(int i=0;i<N-1;i++){
if(S.at(i)==S.at(i+1)){
A=i+1,B=i+2;
}
}
for(int i=0;i<N-2;i++){
if(S.at(i)==S.at(i+2)){
A=i+1,B=i+3;
}
}
cout << A << " " << B << endl;
}
``` |
#include<cstring>
#include<string>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int n=s.length();
for(int i=1;i<n;i++)
{
if(s[i]==s[i-1])
{
cout<<i<<" "<<i+1<<endl;
return 0;
}
else if(i>1 && s[i]==s[i-2])
{
cout<<i-1<<" "<<i+1<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstring>
#include<string>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int n=s.length();
for(int i=1;i<n;i++)
{
if(s[i]==s[i-1])
{
cout<<i<<" "<<i+1<<endl;
return 0;
}
else if(i>1 && s[i]==s[i-2])
{
cout<<i-1<<" "<<i+1<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
}
``` |
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXS 100000
int len;
char s[MAXS+5];
int main() {
scanf("%s",s);
len=strlen(s);
if(s[0]==s[1]) {
printf("1 2\n");
return 0;
}
for(int i=2;i<len;i++) {
if(s[i]==s[i-1]) {
printf("%d %d\n",i,i+1);
return 0;
}
if(s[i]==s[i-2]) {
printf("%d %d\n",i-1,i+1);
return 0;
}
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Develop a solution in Cpp to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXS 100000
int len;
char s[MAXS+5];
int main() {
scanf("%s",s);
len=strlen(s);
if(s[0]==s[1]) {
printf("1 2\n");
return 0;
}
for(int i=2;i<len;i++) {
if(s[i]==s[i-1]) {
printf("%d %d\n",i,i+1);
return 0;
}
if(s[i]==s[i-2]) {
printf("%d %d\n",i-1,i+1);
return 0;
}
}
printf("-1 -1\n");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
string s;
int len;
int main()
{
cin>>s;
len=s.size();
for(int i=0;i<len-1;i++)
{
if(s[i]==s[i+1]){printf("%d %d\n",i+1,i+2);return 0;}
}
for(int i=0;i<len-2;i++)
{
if(s[i]==s[i+2]){printf("%d %d\n",i+1,i+3);return 0;}
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
string s;
int len;
int main()
{
cin>>s;
len=s.size();
for(int i=0;i<len-1;i++)
{
if(s[i]==s[i+1]){printf("%d %d\n",i+1,i+2);return 0;}
}
for(int i=0;i<len-2;i++)
{
if(s[i]==s[i+2]){printf("%d %d\n",i+1,i+3);return 0;}
}
printf("-1 -1\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s.size() == 2){
if(s[0] == s[1])puts("1 2");
else puts("-1 -1");
}
else {
for(int i = 0 ; i+2 < s.size() ; i ++){
if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
puts("-1 -1");
}
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s.size() == 2){
if(s[0] == s[1])puts("1 2");
else puts("-1 -1");
}
else {
for(int i = 0 ; i+2 < s.size() ; i ++){
if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
puts("-1 -1");
}
}
``` |
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100005
char s[MAXN];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<=len-2;i++)
{
if(s[i]==s[i+1])
{
printf("%d %d\n",i+1,i+2);
return 0;
}
if(s[i]==s[i+2])
{
printf("%d %d\n",i+1,i+3);
return 0;
}
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Please create a solution in Cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100005
char s[MAXN];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<=len-2;i++)
{
if(s[i]==s[i+1])
{
printf("%d %d\n",i+1,i+2);
return 0;
}
if(s[i]==s[i+2])
{
printf("%d %d\n",i+1,i+3);
return 0;
}
}
printf("-1 -1\n");
return 0;
}
``` |
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string s;
cin >> s;
s.push_back('A');
for(i=0;i<s.size()-2;i++)
if(s.substr(i,1)==s.substr(i+1,1)){
cout << (i+1) << " " << (i+2) << endl;
return 0;
} else if(s.substr(i,1)==s.substr(i+2,1)){
cout << (i+1) << " " << (i+3) << endl;
return 0;
}
cout << "-1 -1" << endl;
return 0;
} | ### Prompt
Develop a solution in CPP to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string s;
cin >> s;
s.push_back('A');
for(i=0;i<s.size()-2;i++)
if(s.substr(i,1)==s.substr(i+1,1)){
cout << (i+1) << " " << (i+2) << endl;
return 0;
} else if(s.substr(i,1)==s.substr(i+2,1)){
cout << (i+1) << " " << (i+3) << endl;
return 0;
}
cout << "-1 -1" << endl;
return 0;
}
``` |
#include<cstdio>
#include<cstring>
char s[100005];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i+2<len;i++)
if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i])
{
printf("%d %d",i+1,i+3);
return 0;
}
printf("%s",len==2&&s[0]==s[1]?"1 2":"-1 -1");
} | ### Prompt
Please create a solution in cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
char s[100005];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i+2<len;i++)
if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i])
{
printf("%d %d",i+1,i+3);
return 0;
}
printf("%s",len==2&&s[0]==s[1]?"1 2":"-1 -1");
}
``` |
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mn = 100005;
char s[mn];
int a[mn][30], b[mn][30];
int main()
{
int n, i;
scanf("%s", s + 1);
n = strlen(s + 1);
for(i = 1; i <= n; i++)
if(s[i] == s[i - 1])
{
printf("%d %d\n", i - 1, i);
return 0;
}
else if(s[i] == s[i - 2])
{
printf("%d %d\n", i - 2, i);
return 0;
}
printf("-1 -1\n");
}
| ### Prompt
Generate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mn = 100005;
char s[mn];
int a[mn][30], b[mn][30];
int main()
{
int n, i;
scanf("%s", s + 1);
n = strlen(s + 1);
for(i = 1; i <= n; i++)
if(s[i] == s[i - 1])
{
printf("%d %d\n", i - 1, i);
return 0;
}
else if(s[i] == s[i - 2])
{
printf("%d %d\n", i - 2, i);
return 0;
}
printf("-1 -1\n");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int n;
char s[100005];
int X,Y;
void solve(){
X=Y=-1;
if(n==1)return;
for(int i=0;i<n;i++){
if(i+1<n&&s[i]==s[i+1]){
X=i+1;
Y=X+1;
return;
}
if(i+2<n&&s[i]==s[i+2]){
X=i+1;
Y=X+2;
return;
}
}
}
int main(){
scanf("%s",s);
n=strlen(s);
solve();
printf("%d %d\n",X,Y);
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
char s[100005];
int X,Y;
void solve(){
X=Y=-1;
if(n==1)return;
for(int i=0;i<n;i++){
if(i+1<n&&s[i]==s[i+1]){
X=i+1;
Y=X+1;
return;
}
if(i+2<n&&s[i]==s[i+2]){
X=i+1;
Y=X+2;
return;
}
}
}
int main(){
scanf("%s",s);
n=strlen(s);
solve();
printf("%d %d\n",X,Y);
return 0;
}
``` |
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
string s;
int main(){
cin>>s;
for(int i=0;i<s.length()-1;i++)
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2;
return 0;
}
for(int i=0;i<s.length()-2;i++)
if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3;
return 0;
}
cout<<-1<<" "<<-1;
return 0;
} | ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
string s;
int main(){
cin>>s;
for(int i=0;i<s.length()-1;i++)
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2;
return 0;
}
for(int i=0;i<s.length()-2;i++)
if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3;
return 0;
}
cout<<-1<<" "<<-1;
return 0;
}
``` |
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
char c;
cin>>str;
n = str.length();
for (int i = 0; i < n-1; i++) {
c = str[i];
if (c == str[i + 1]) {
cout<<i + 1<<" "<<i + 2;
return 0;
}
else if (c == str[i + 2]) {
cout<<i + 1<<" "<<i + 3;
return 0;
}
}
cout<<-1<<" "<<-1<<endl;
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
char c;
cin>>str;
n = str.length();
for (int i = 0; i < n-1; i++) {
c = str[i];
if (c == str[i + 1]) {
cout<<i + 1<<" "<<i + 2;
return 0;
}
else if (c == str[i + 2]) {
cout<<i + 1<<" "<<i + 3;
return 0;
}
}
cout<<-1<<" "<<-1<<endl;
return 0;
}
``` |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
string s;
cin>>s;
int l=s.length();
for(int i=0;i<l-2;i++){
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2;
return 0;
}
else if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3;
return 0;
}
}
if(s[l-2]==s[l-1]){
cout<<l-1<<" "<<l;
return 0;
}
cout<<-1<<" "<<-1;
return 0;
} | ### Prompt
Please create a solution in Cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
string s;
cin>>s;
int l=s.length();
for(int i=0;i<l-2;i++){
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2;
return 0;
}
else if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3;
return 0;
}
}
if(s[l-2]==s[l-1]){
cout<<l-1<<" "<<l;
return 0;
}
cout<<-1<<" "<<-1;
return 0;
}
``` |
#include<cstdio>
char s[1000005];
int main(){
scanf("%s",s+1);
for(int i=1;s[i+1];i++){
if(s[i]==s[i+1])return !printf("%d %d\n",i,i+1);
if(s[i]==s[i+2])return !printf("%d %d\n",i,i+2);
}
printf("-1 -1\n");
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
char s[1000005];
int main(){
scanf("%s",s+1);
for(int i=1;s[i+1];i++){
if(s[i]==s[i+1])return !printf("%d %d\n",i,i+1);
if(s[i]==s[i+2])return !printf("%d %d\n",i,i+2);
}
printf("-1 -1\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
int main() {
string S; cin >> S;
rep(i, 1, S.size()) if(S[i-1] == S[i]) {
cout << i << " " << i + 1 << endl;
return 0;
}
rep(i, 2, S.size()) if(S[i-2] == S[i]) {
cout << i - 1 << " " << i + 1 << endl;
return 0;
}
cout << -1 << " " << -1 << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
int main() {
string S; cin >> S;
rep(i, 1, S.size()) if(S[i-1] == S[i]) {
cout << i << " " << i + 1 << endl;
return 0;
}
rep(i, 2, S.size()) if(S[i-2] == S[i]) {
cout << i - 1 << " " << i + 1 << endl;
return 0;
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2<<endl;return 0;}
}
for(int i=0;i<s.size()-2;i++)
{
if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3<<endl;return 0;}
}
cout<<"-1 -1"<<endl;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1]){
cout<<i+1<<" "<<i+2<<endl;return 0;}
}
for(int i=0;i<s.size()-2;i++)
{
if(s[i]==s[i+2]){
cout<<i+1<<" "<<i+3<<endl;return 0;}
}
cout<<"-1 -1"<<endl;
}
``` |
#include <string>
#include <iostream>
#include <cstdio>
using namespace std;
string a,b,c,d,e,f,g,h;
int main() {
cin >> f;
for(int i=0;i<f.length();i++){
if (f[i]==f[i+1]) return printf("%d %d\n",i+1,i+2), 0;
}
for (int i = 0; i + 2 < f.length(); i++) {
if(f[i]==f[i+2]) return printf("%d %d\n",i+1,i+3), 0;
}
printf("-1 -1\n");
} | ### Prompt
Develop a solution in Cpp to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <string>
#include <iostream>
#include <cstdio>
using namespace std;
string a,b,c,d,e,f,g,h;
int main() {
cin >> f;
for(int i=0;i<f.length();i++){
if (f[i]==f[i+1]) return printf("%d %d\n",i+1,i+2), 0;
}
for (int i = 0; i + 2 < f.length(); i++) {
if(f[i]==f[i+2]) return printf("%d %d\n",i+1,i+3), 0;
}
printf("-1 -1\n");
}
``` |
#include<cstdio>
#include<cstring>
#define maxn 100005
#define N 26
int n,cnt[maxn][N+5],l=-1,r=-1;
char s[maxn];
int main()
{
scanf("%s",s+1);
n=strlen(s+1);
for(int i=2;i<=n;i++)
{
if(s[i]==s[i-1])
{
printf("%d %d\n",i-1,i);
return 0;
}
else if(i>2&&s[i]==s[i-2])
{
printf("%d %d\n",i-2,i);
return 0;
}
}
printf("-1 -1\n");
} | ### Prompt
Please provide a CPP coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
#define maxn 100005
#define N 26
int n,cnt[maxn][N+5],l=-1,r=-1;
char s[maxn];
int main()
{
scanf("%s",s+1);
n=strlen(s+1);
for(int i=2;i<=n;i++)
{
if(s[i]==s[i-1])
{
printf("%d %d\n",i-1,i);
return 0;
}
else if(i>2&&s[i]==s[i-2])
{
printf("%d %d\n",i-2,i);
return 0;
}
}
printf("-1 -1\n");
}
``` |
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
cin >> s;
int l = s.size();
if(l == 2 && s[0] == s[1]){
cout << 1 << " " << 2 << endl;
return 0;
}
for(int i = 0; i < l-2; ++i){
if(s[i] == s[i+1] || s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
cin >> s;
int l = s.size();
if(l == 2 && s[0] == s[1]){
cout << 1 << " " << 2 << endl;
return 0;
}
for(int i = 0; i < l-2; ++i){
if(s[i] == s[i+1] || s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main () {
string s;
cin >> s;
for(int i=0;i<(int)s.size()-1;i++) {
if(s[i] == s[i+1] ) {cout << i+1 << " " << i+2 << endl; return 0;}
if(s[i] == s[i+2] and i+2 < (int)s.size()) {cout << i+1 << " " << i+3 << endl; return 0;}
}
cout << -1 << " " << -1 << endl;
} | ### Prompt
Develop a solution in CPP to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main () {
string s;
cin >> s;
for(int i=0;i<(int)s.size()-1;i++) {
if(s[i] == s[i+1] ) {cout << i+1 << " " << i+2 << endl; return 0;}
if(s[i] == s[i+2] and i+2 < (int)s.size()) {cout << i+1 << " " << i+3 << endl; return 0;}
}
cout << -1 << " " << -1 << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100100];
int l;
int main() {
scanf("%s", s);
l = strlen(s);
if(s[0] == s[1])return cout << 1 << " " << 2, 0;
for(int i = 2; i < l; ++i) {
if(s[i] == s[i - 1])return cout << i << " " << i + 1, 0;
if(s[i - 2] == s[i])return cout << i - 1 << " " << i + 1, 0;
}
cout << -1 << " "<< -1;
}
| ### Prompt
Create a solution in cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100100];
int l;
int main() {
scanf("%s", s);
l = strlen(s);
if(s[0] == s[1])return cout << 1 << " " << 2, 0;
for(int i = 2; i < l; ++i) {
if(s[i] == s[i - 1])return cout << i << " " << i + 1, 0;
if(s[i - 2] == s[i])return cout << i - 1 << " " << i + 1, 0;
}
cout << -1 << " "<< -1;
}
``` |
#include<bits/stdc++.h>
using namespace std;
string st;
int main()
{
getline(cin,st);
for(int i=0;i<st.size()-1;i++)
if(st[i]==st[i+1]) {cout<<i+1<<" "<<i+2<<"\n";return 0;}
for(int i=0;i<st.size()-2;i++)
if(st[i]==st[i+2]) {cout<<i+1<<" "<<i+3<<"\n";return 0;}
cout<<"-1 -1\n";
return 0;
} | ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
string st;
int main()
{
getline(cin,st);
for(int i=0;i<st.size()-1;i++)
if(st[i]==st[i+1]) {cout<<i+1<<" "<<i+2<<"\n";return 0;}
for(int i=0;i<st.size()-2;i++)
if(st[i]==st[i+2]) {cout<<i+1<<" "<<i+3<<"\n";return 0;}
cout<<"-1 -1\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
string s;
cin>>s;
for(ll i=1;i<s.size();i++){
if(s[i-1]==s[i]){
cout << i<<" "<< i+1<<endl;
return 0;
}
if(i>=2&&s[i-2]==s[i]){
cout << i-1<<" "<<i+1<<endl;
return 0;
}
}
cout << -1 <<" "<<-1<<endl;
// your code goes here
return 0;
} | ### Prompt
Please provide a cpp coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
string s;
cin>>s;
for(ll i=1;i<s.size();i++){
if(s[i-1]==s[i]){
cout << i<<" "<< i+1<<endl;
return 0;
}
if(i>=2&&s[i-2]==s[i]){
cout << i-1<<" "<<i+1<<endl;
return 0;
}
}
cout << -1 <<" "<<-1<<endl;
// your code goes here
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
string str;
cin >> str;
for(int i=0;i<str.size()-1;i++){
if(str[i] == str[i+1]){
cout << i+1 << " " << i+2 << endl;
return 0;
}
}
for(int i=0;i<str.size()-2;i++){
if(str[i] == str[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
string str;
cin >> str;
for(int i=0;i<str.size()-1;i++){
if(str[i] == str[i+1]){
cout << i+1 << " " << i+2 << endl;
return 0;
}
}
for(int i=0;i<str.size()-2;i++){
if(str[i] == str[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXL=100005;
char c[MAXL];
int l,d[30],e[30][MAXL],f[30][MAXL];
int main(){
scanf("%s",c+1);
l=strlen(c+1);
for(int i=1;i<=l;i++){
int v=c[i]-'a';
e[v][d[v]+1]=i-f[v][d[v]];
f[v][++d[v]]=i;
if(e[v][d[v]]<=2&&d[v]>=2){
printf("%d %d\n",f[v][d[v]-1],f[v][d[v]]);
return 0;
}
}
printf("-1 -1\n");
} | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXL=100005;
char c[MAXL];
int l,d[30],e[30][MAXL],f[30][MAXL];
int main(){
scanf("%s",c+1);
l=strlen(c+1);
for(int i=1;i<=l;i++){
int v=c[i]-'a';
e[v][d[v]+1]=i-f[v][d[v]];
f[v][++d[v]]=i;
if(e[v][d[v]]<=2&&d[v]>=2){
printf("%d %d\n",f[v][d[v]-1],f[v][d[v]]);
return 0;
}
}
printf("-1 -1\n");
}
``` |
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
string s;
cin >> s;
for(int i=0; i<s.size()-1; i++) {
if(s[i]==s[i+1]) {
cout << i+1 << " " << i+2 << endl;
return 0;
}
else if(s[i]==s[i+2]) {
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
string s;
cin >> s;
for(int i=0; i<s.size()-1; i++) {
if(s[i]==s[i+1]) {
cout << i+1 << " " << i+2 << endl;
return 0;
}
else if(s[i]==s[i+2]) {
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
bool res = false;
for (int k = 0; k <S.length()-1;k++){
if (S[k]==S[k+1]){
res = true;
cout << k+1 <<" "<< k+1+1 << endl;
break;
}
if (k < S.length()-2){
if(S[k]==S[k+2]){
res = true;
cout<<k+1<<" "<< k+3<<endl;
break;
}
}
}
if(!res){
cout<<"-1 -1"<<endl;
}
return 0;
} | ### Prompt
Your task is to create a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
bool res = false;
for (int k = 0; k <S.length()-1;k++){
if (S[k]==S[k+1]){
res = true;
cout << k+1 <<" "<< k+1+1 << endl;
break;
}
if (k < S.length()-2){
if(S[k]==S[k+2]){
res = true;
cout<<k+1<<" "<< k+3<<endl;
break;
}
}
}
if(!res){
cout<<"-1 -1"<<endl;
}
return 0;
}
``` |
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s;
cin >> s;
int sz = s.size(), a = -1, b = 1;
while (++b < sz) {
char c = s[a = b];
if (s[--a] == c || s[--a] == c) break;
}
if (b >= sz)
if (sz >= 2 && s[0] == s[1]) cout << "1 2";
else cout << "-1 -1";
else cout << (a + 1) << " " << (b + 1);
cout << endl;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s;
cin >> s;
int sz = s.size(), a = -1, b = 1;
while (++b < sz) {
char c = s[a = b];
if (s[--a] == c || s[--a] == c) break;
}
if (b >= sz)
if (sz >= 2 && s[0] == s[1]) cout << "1 2";
else cout << "-1 -1";
else cout << (a + 1) << " " << (b + 1);
cout << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int n = s.length();
if(s[0]==s[1]){ cout << 1 << " " << 2 << endl; return 0;}
for(int i=0;i<n-2;i++) {
if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i]==s[i+2]){ cout << i+1 << " " << i+3 << endl; return 0;}
}
cout << -1 << " " << -1 << endl;
return 0;
} | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int n = s.length();
if(s[0]==s[1]){ cout << 1 << " " << 2 << endl; return 0;}
for(int i=0;i<n-2;i++) {
if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i]==s[i+2]){ cout << i+1 << " " << i+3 << endl; return 0;}
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include<iostream>
#include<string>
using namespace std;
int main(){
string buf;
cin>>buf;
bool flag=false;
for(int i=0;i<buf.length();++i){
if(buf[i]==buf[i+1]){
cout<<i+1<<" "<<i+2<<endl;
flag=true;
break;
}
else if(buf[i]==buf[i+2] && i<buf.length()-2){
cout<<i+1<<" "<<i+3<<endl;
flag=true;
break;
}
}
if(!flag)
cout<<-1<<" "<<-1<<endl;
return 0;
} | ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<string>
using namespace std;
int main(){
string buf;
cin>>buf;
bool flag=false;
for(int i=0;i<buf.length();++i){
if(buf[i]==buf[i+1]){
cout<<i+1<<" "<<i+2<<endl;
flag=true;
break;
}
else if(buf[i]==buf[i+2] && i<buf.length()-2){
cout<<i+1<<" "<<i+3<<endl;
flag=true;
break;
}
}
if(!flag)
cout<<-1<<" "<<-1<<endl;
return 0;
}
``` |
#include<cstdio>
#include<cstring>
char s[100005];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<len-2;i++)
if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i])
{
printf("%d %d",i+1,i+3);
return 0;
}
printf("%s",len==2&&s[0]==s[1]?"1 2":"-1 -1");
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
char s[100005];
int main()
{
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<len-2;i++)
if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i])
{
printf("%d %d",i+1,i+3);
return 0;
}
printf("%s",len==2&&s[0]==s[1]?"1 2":"-1 -1");
}
``` |
#include <iostream>
#include <string>
std::string s;
int ans[2] = { -1,-1 };
int main()
{
std::cin >> s;
for (int i = 0; i <= s.length() - 2; ++i)
{
if (s[i] == s[i + 1])
{
ans[0] = i + 1, ans[1] = i + 2;
break;
}
if (s[i] == s[i + 2])
{
ans[0] = i + 1, ans[1] = i + 3;
break;
}
}
printf("%d %d\n", ans[0], ans[1]);
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <string>
std::string s;
int ans[2] = { -1,-1 };
int main()
{
std::cin >> s;
for (int i = 0; i <= s.length() - 2; ++i)
{
if (s[i] == s[i + 1])
{
ans[0] = i + 1, ans[1] = i + 2;
break;
}
if (s[i] == s[i + 2])
{
ans[0] = i + 1, ans[1] = i + 3;
break;
}
}
printf("%d %d\n", ans[0], ans[1]);
return 0;
}
``` |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int l,r;
char s[1000005];
int main()
{
int i;
cin>>(s+1);
l=r=-1;
for(i=2;i<=strlen(s+1)&&l==-1;i++)
if(s[i]==s[i-1]) l=i-1,r=i;
else if(i!=1&&s[i]==s[i-2]) l=i-2,r=i;
cout<<l<<" "<<r;
return 0;
} | ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int l,r;
char s[1000005];
int main()
{
int i;
cin>>(s+1);
l=r=-1;
for(i=2;i<=strlen(s+1)&&l==-1;i++)
if(s[i]==s[i-1]) l=i-1,r=i;
else if(i!=1&&s[i]==s[i-2]) l=i-2,r=i;
cout<<l<<" "<<r;
return 0;
}
``` |
#include <iostream>
using namespace std;
int main() {
int n;
string s;
cin >> s;
n = s.length();
for(int i=1;i<n;i++){
if(s[i] == s[i-1]){
cout << i << " " << i+1 << endl;
return 0;
}
if(i>2&&s[i] == s[i-2]){
cout << i-1 << " " << i+1 << endl;
return 0;
}
}
cout << "-1 -1" << endl;
return 0;
} | ### Prompt
Create a solution in cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
using namespace std;
int main() {
int n;
string s;
cin >> s;
n = s.length();
for(int i=1;i<n;i++){
if(s[i] == s[i-1]){
cout << i << " " << i+1 << endl;
return 0;
}
if(i>2&&s[i] == s[i-2]){
cout << i-1 << " " << i+1 << endl;
return 0;
}
}
cout << "-1 -1" << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main()
{
scanf("%s",s);
int n = strlen(s);
for(int i = 1; i < n; i++)
{
if(s[i] == s[i-1])
{
printf("%d %d\n",i,i+1);
return 0;
}
}
for(int i = 2; i < n; i++)
{
if(s[i] == s[i-2])
{
printf("%d %d\n",i-1,i+1);
return 0;
}
}
puts("-1 -1");
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main()
{
scanf("%s",s);
int n = strlen(s);
for(int i = 1; i < n; i++)
{
if(s[i] == s[i-1])
{
printf("%d %d\n",i,i+1);
return 0;
}
}
for(int i = 2; i < n; i++)
{
if(s[i] == s[i-2])
{
printf("%d %d\n",i-1,i+1);
return 0;
}
}
puts("-1 -1");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin>>S;
int Z=0;
for(int i=1;i<S.size();i++){
if(S.at(i-1)==S.at(i)){
cout<<i<<" "<<i+1<<endl;
Z++;
break;
}
if(i!=1){
if(S.at(i-2)==S.at(i)){
cout<<i-1<<" "<<i+1<<endl;
Z++;
break;
}
}
}
if(Z==0){
cout<<"-1"<<" "<<"-1"<<endl;
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin>>S;
int Z=0;
for(int i=1;i<S.size();i++){
if(S.at(i-1)==S.at(i)){
cout<<i<<" "<<i+1<<endl;
Z++;
break;
}
if(i!=1){
if(S.at(i-2)==S.at(i)){
cout<<i-1<<" "<<i+1<<endl;
Z++;
break;
}
}
}
if(Z==0){
cout<<"-1"<<" "<<"-1"<<endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.size();
int r = -1, l = -1;
if (N == 2 && S[0] == S[1]) r = 1, l = 2;
for (int i = 2;i < N;i++) {
if (S[i] == S[i - 1] || S[i] == S[i - 2] || S[i - 1] == S[i - 2])
r = i - 1, l = i + 1;
}
cout << r << " " << l << endl;
} | ### Prompt
Please create a solution in Cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.size();
int r = -1, l = -1;
if (N == 2 && S[0] == S[1]) r = 1, l = 2;
for (int i = 2;i < N;i++) {
if (S[i] == S[i - 1] || S[i] == S[i - 2] || S[i - 1] == S[i - 2])
r = i - 1, l = i + 1;
}
cout << r << " " << l << endl;
}
``` |
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char t[100002];
int main()
{
scanf("%s",t);
int len=strlen(t);
for(int i=0;i<len;i++)
{
if(t[i]==t[i+1])
{
printf("%d %d",i+1,i+2);
return 0;
}
if(t[i]==t[i+2])
{
printf("%d %d",i+1,i+3);
return 0;
}
}
printf("-1 -1");
return 0;
} | ### Prompt
Your task is to create a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char t[100002];
int main()
{
scanf("%s",t);
int len=strlen(t);
for(int i=0;i<len;i++)
{
if(t[i]==t[i+1])
{
printf("%d %d",i+1,i+2);
return 0;
}
if(t[i]==t[i+2])
{
printf("%d %d",i+1,i+3);
return 0;
}
}
printf("-1 -1");
return 0;
}
``` |
#include<cstdio>
#include<cstring>
char s[200000];
int main(void) {
scanf("%s",s+2);
int n = strlen(s+2);
for(int i=2; i<n+2; i++) {
if(s[i-2] == s[i]) {
printf("%d %d\n", i-3, i-1);
return 0;
}
if(s[i-1] == s[i]) {
printf("%d %d\n", i-2, i-1);
return 0;
}
}
puts("-1 -1");
return 0;
} | ### Prompt
Construct a CPP code solution to the problem outlined:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
char s[200000];
int main(void) {
scanf("%s",s+2);
int n = strlen(s+2);
for(int i=2; i<n+2; i++) {
if(s[i-2] == s[i]) {
printf("%d %d\n", i-3, i-1);
return 0;
}
if(s[i-1] == s[i]) {
printf("%d %d\n", i-2, i-1);
return 0;
}
}
puts("-1 -1");
return 0;
}
``` |
#include <stdio.h>
char S[100100];
int main()
{
scanf("%s", S);
for (int i=1;S[i];i++) if (S[i-1] == S[i]){
printf("%d %d\n", i, i+1);
return 0;
}
for (int i=2;S[i];i++) if (S[i-2] == S[i]){
printf("%d %d\n", i-1, i+1);
return 0;
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <stdio.h>
char S[100100];
int main()
{
scanf("%s", S);
for (int i=1;S[i];i++) if (S[i-1] == S[i]){
printf("%d %d\n", i, i+1);
return 0;
}
for (int i=2;S[i];i++) if (S[i-2] == S[i]){
printf("%d %d\n", i-1, i+1);
return 0;
}
printf("-1 -1\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
cin>>a;
for(int i=1;i<a.size();i++)
if(a[i]==a[i-1])
{
cout<<i<<" "<<i+1<<"\n";
return 0;
}
for(int i=2;i<a.size();i++)
if(a[i]==a[i-2])
{
cout<<i-1<<" "<<i+1<<"\n";
return 0;
}
cout<<-1<<" "<<-1<<"\n";
} | ### Prompt
Create a solution in CPP for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
cin>>a;
for(int i=1;i<a.size();i++)
if(a[i]==a[i-1])
{
cout<<i<<" "<<i+1<<"\n";
return 0;
}
for(int i=2;i<a.size();i++)
if(a[i]==a[i-2])
{
cout<<i-1<<" "<<i+1<<"\n";
return 0;
}
cout<<-1<<" "<<-1<<"\n";
}
``` |
#include<bits/stdc++.h>
#define N (100009)
using namespace std;
char s[N];
int main()
{
cin>>s+1;
for (int i=1,l=strlen(s+1); i<=l; ++i)
{
if (i-1>=1 && s[i-1]==s[i]) {cout<<i-1<<' '<<i<<endl; return 0;}
if (i-2>=1 && s[i-2]==s[i]) {cout<<i-2<<' '<<i<<endl; return 0;}
}
cout<<-1<<' '<<-1<<endl;
} | ### Prompt
Please formulate a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
#define N (100009)
using namespace std;
char s[N];
int main()
{
cin>>s+1;
for (int i=1,l=strlen(s+1); i<=l; ++i)
{
if (i-1>=1 && s[i-1]==s[i]) {cout<<i-1<<' '<<i<<endl; return 0;}
if (i-2>=1 && s[i-2]==s[i]) {cout<<i-2<<' '<<i<<endl; return 0;}
}
cout<<-1<<' '<<-1<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
cin>>s;
int len=s.size();
for(int i=1;i<len;i++){
if(s[i]==s[i-1]){
printf("%d %d\n",i,i+1);
exit(0);
}
if(i!=1){
if(s[i]==s[i-2]){
printf("%d %d\n",i-1,i+1);
exit(0);
}
}
}
printf("-1 -1\n");
} | ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
cin>>s;
int len=s.size();
for(int i=1;i<len;i++){
if(s[i]==s[i-1]){
printf("%d %d\n",i,i+1);
exit(0);
}
if(i!=1){
if(s[i]==s[i-2]){
printf("%d %d\n",i-1,i+1);
exit(0);
}
}
}
printf("-1 -1\n");
}
``` |
#include<cstdio>
#include<cstring>
#include<climits>
using namespace std;
#define N 100000
char s[N];
int main()
{
scanf("%s",s+1);
int lens=strlen(s+1);
for(int i=1;i<=lens;i++)
{
if(s[i]==s[i+1])
{
printf("%d %d",i,i+1);
return 0;
}
else if(s[i]==s[i+2])
{
printf("%d %d",i,i+2);
return 0;
}
}
printf("-1 -1");
} | ### Prompt
Develop a solution in CPP to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
#include<climits>
using namespace std;
#define N 100000
char s[N];
int main()
{
scanf("%s",s+1);
int lens=strlen(s+1);
for(int i=1;i<=lens;i++)
{
if(s[i]==s[i+1])
{
printf("%d %d",i,i+1);
return 0;
}
else if(s[i]==s[i+2])
{
printf("%d %d",i,i+2);
return 0;
}
}
printf("-1 -1");
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(void){
string s;cin >> s;
for(int i=0;i<s.size()-1;i++){
if(s[i] == s[i+1]){
cout << i+1 << " " << i+2 << endl;return 0;
}
if(i < s.size()-2 && s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
} | ### Prompt
Create a solution in CPP for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void){
string s;cin >> s;
for(int i=0;i<s.size()-1;i++){
if(s[i] == s[i+1]){
cout << i+1 << " " << i+2 << endl;return 0;
}
if(i < s.size()-2 && s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include <iostream>
#include <set>
using namespace std;
int main()
{
string s;
cin >> s;
for (int i=0;i<s.size()-1;i++)
{
set<char> st;
st.insert(s[i]);
st.insert(s[i+1]);
if (st.size()==1)
{
cout << i+1 << ' ' << i+2;
return 0;
}
if (i+2<s.size())
{
st.insert(s[i+2]);
if (st.size()==2)
{
cout << i+1 << ' ' << i+3;
return 0;
}
}
}
cout << "-1 -1";
} | ### Prompt
Generate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <set>
using namespace std;
int main()
{
string s;
cin >> s;
for (int i=0;i<s.size()-1;i++)
{
set<char> st;
st.insert(s[i]);
st.insert(s[i+1]);
if (st.size()==1)
{
cout << i+1 << ' ' << i+2;
return 0;
}
if (i+2<s.size())
{
st.insert(s[i+2]);
if (st.size()==2)
{
cout << i+1 << ' ' << i+3;
return 0;
}
}
}
cout << "-1 -1";
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s[0] == s[1]){
printf("1 2\n");
return 0;
}
for(int i = 2; i < s.size(); i++){
if(s[i-2] == s[i]){
printf("%d %d\n", i-1, i+1);
return 0;
}else if(s[i-1] == s[i]){
printf("%d %d\n", i, i+1);
return 0;
}
}
printf("-1 -1\n");
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s[0] == s[1]){
printf("1 2\n");
return 0;
}
for(int i = 2; i < s.size(); i++){
if(s[i-2] == s[i]){
printf("%d %d\n", i-1, i+1);
return 0;
}else if(s[i-1] == s[i]){
printf("%d %d\n", i, i+1);
return 0;
}
}
printf("-1 -1\n");
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int l=s.size();
if(l==2){
if(s[0]==s[1]){
puts("1 2");
}else puts("-1 -1");
return 0;
}
for(int i=1;i<l-1;i++){
if(s[i-1]==s[i]||s[i]==s[i+1]||s[i-1]==s[i+1]){
printf("%d %d\n",i,i+2);
return 0;
}
}
puts("-1 -1");
return 0;
} | ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int l=s.size();
if(l==2){
if(s[0]==s[1]){
puts("1 2");
}else puts("-1 -1");
return 0;
}
for(int i=1;i<l-1;i++){
if(s[i-1]==s[i]||s[i]==s[i+1]||s[i-1]==s[i+1]){
printf("%d %d\n",i,i+2);
return 0;
}
}
puts("-1 -1");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)
char s[100001];
int main() {
int n;
scanf("%s", s);
n = strlen(s);
f(i, 1, n)if (s[i] == s[i - 1]) {
printf("%d %d", i, i + 1);
return 0;
}
f(i, 2, n)if (s[i] == s[i - 2]) {
printf("%d %d", i - 1, i + 1);
return 0;
}
printf("-1 -1");
} | ### Prompt
In Cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)
char s[100001];
int main() {
int n;
scanf("%s", s);
n = strlen(s);
f(i, 1, n)if (s[i] == s[i - 1]) {
printf("%d %d", i, i + 1);
return 0;
}
f(i, 2, n)if (s[i] == s[i - 2]) {
printf("%d %d", i - 1, i + 1);
return 0;
}
printf("-1 -1");
}
``` |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main() {
string s;
cin >> s;
for (ll i=0;i<s.size()-1;i++) {
if(s[i]==s[i+1]) {
cout << i+1 << " " << i+2 << endl;
return 0;
}
}
for (ll i=0;i<s.size()-2;i++) {
if(s[i]==s[i+2]) {
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << "-1 -1" << endl;
} | ### Prompt
Develop a solution in CPP to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main() {
string s;
cin >> s;
for (ll i=0;i<s.size()-1;i++) {
if(s[i]==s[i+1]) {
cout << i+1 << " " << i+2 << endl;
return 0;
}
}
for (ll i=0;i<s.size()-2;i++) {
if(s[i]==s[i+2]) {
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << "-1 -1" << endl;
}
``` |
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100005
char s[MAXN];
int main()
{
scanf("%s",s+1);
int len=strlen(s+1);
for(int i=1;i<=len-1;i++)
{
if(s[i]==s[i+2])
{
printf("%d %d\n",i,i+2);
return 0;
}
if(s[i]==s[i+1])
{
printf("%d %d\n",i,i+1);
return 0;
}
}
printf("-1 -1\n");
return 0;
} | ### Prompt
In CPP, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100005
char s[MAXN];
int main()
{
scanf("%s",s+1);
int len=strlen(s+1);
for(int i=1;i<=len-1;i++)
{
if(s[i]==s[i+2])
{
printf("%d %d\n",i,i+2);
return 0;
}
if(s[i]==s[i+1])
{
printf("%d %d\n",i,i+1);
return 0;
}
}
printf("-1 -1\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
if(s.size()==2) {
if(s[0]==s[1]) {
cout << 1 << " " << 2 << endl;
return 0;
}
}
for(int i=0;i<s.size()-2;++i) {
if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]) {
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
} | ### Prompt
Construct a Cpp code solution to the problem outlined:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
if(s.size()==2) {
if(s[0]==s[1]) {
cout << 1 << " " << 2 << endl;
return 0;
}
}
for(int i=0;i<s.size()-2;++i) {
if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]) {
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include<stdio.h>
#include<string.h>
char s[111111];
bool chk(){
int l=strlen(s);
for(int i=0; i+1<l; i++)
if(s[i]==s[i+1]){
printf("%d %d\n",i+1,i+2);
return true;
}
for(int i=0; i+2<l; i++)
if(s[i]==s[i+2]){
printf("%d %d\n",i+1,i+3);
return true;
}
return false;
}
int main(){
scanf("%s",s);
if(!chk())
puts("-1 -1");
return 0;
} | ### Prompt
Your task is to create a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<stdio.h>
#include<string.h>
char s[111111];
bool chk(){
int l=strlen(s);
for(int i=0; i+1<l; i++)
if(s[i]==s[i+1]){
printf("%d %d\n",i+1,i+2);
return true;
}
for(int i=0; i+2<l; i++)
if(s[i]==s[i+2]){
printf("%d %d\n",i+1,i+3);
return true;
}
return false;
}
int main(){
scanf("%s",s);
if(!chk())
puts("-1 -1");
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1])
{
cout<<i+1<<" "<<i+2;
return 0;
}
}
for(int i=0;i<s.size()-2;i++)
{
if(s[i]==s[i+2])
{
cout<<i+1<<" "<<i+3;
return 0;
}
}
cout<<-1<<" "<<-1;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1])
{
cout<<i+1<<" "<<i+2;
return 0;
}
}
for(int i=0;i<s.size()-2;i++)
{
if(s[i]==s[i+2])
{
cout<<i+1<<" "<<i+3;
return 0;
}
}
cout<<-1<<" "<<-1;
}
``` |
#include <stdio.h>
char s[100001];
int main() {
scanf("%s", s);
int len = 0;
while(s[len] != '\0') { len++; }
int b = -2, e = -2;
for(int i = 1; i < len; i++) {
if( s[i - 1] == s[i]) { b = i - 1; e = i; break; }
if(i >= 2 && s[i - 2] == s[i]) { b = i - 2; e = i; break; }
}
printf("%d %d\n", b + 1, e + 1);
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <stdio.h>
char s[100001];
int main() {
scanf("%s", s);
int len = 0;
while(s[len] != '\0') { len++; }
int b = -2, e = -2;
for(int i = 1; i < len; i++) {
if( s[i - 1] == s[i]) { b = i - 1; e = i; break; }
if(i >= 2 && s[i - 2] == s[i]) { b = i - 2; e = i; break; }
}
printf("%d %d\n", b + 1, e + 1);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int l[109];
int main(){
cin>>s;
for(int i=0;i<s.size();i++){
if(i>0&&s[i-1]==s[i]){
cout<<i<<" "<<i+1<<endl;
exit(0);
}
if(i>1&&s[i-2]==s[i]){
cout<<i-1<<" "<<i+1<<endl;
exit(0);
}
}
cout<<"-1 -1"<<endl;
}
| ### Prompt
Create a solution in cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int l[109];
int main(){
cin>>s;
for(int i=0;i<s.size();i++){
if(i>0&&s[i-1]==s[i]){
cout<<i<<" "<<i+1<<endl;
exit(0);
}
if(i>1&&s[i-2]==s[i]){
cout<<i-1<<" "<<i+1<<endl;
exit(0);
}
}
cout<<"-1 -1"<<endl;
}
``` |
#include<iostream>
#include<string>
using namespace std;
int main() {
string s; cin >> s;
s += "##";
for (int i = 0; i < s.size() - 2; i++) {
if (s[i] == s[i + 1]) {
i++;
cout << i << ' ' << i + 1 << endl;
return 0;
}
else if (s[i] == s[i + 2]) {
i++;
cout << i << ' ' << i + 2 << endl;
return 0;
}
}
cout << "-1 -1\n";
return 0;
} | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<string>
using namespace std;
int main() {
string s; cin >> s;
s += "##";
for (int i = 0; i < s.size() - 2; i++) {
if (s[i] == s[i + 1]) {
i++;
cout << i << ' ' << i + 1 << endl;
return 0;
}
else if (s[i] == s[i + 2]) {
i++;
cout << i << ' ' << i + 2 << endl;
return 0;
}
}
cout << "-1 -1\n";
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<s.size()-1;++i) if(s[i]==s[i+1]){
printf("%d %d\n",i+1,i+2);
return 0;
}
for(int i=0;i<s.size()-2;++i) if(s[i]==s[i+2]){
printf("%d %d\n",i+1,i+3);
return 0;
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Generate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<s.size()-1;++i) if(s[i]==s[i+1]){
printf("%d %d\n",i+1,i+2);
return 0;
}
for(int i=0;i<s.size()-2;++i) if(s[i]==s[i+2]){
printf("%d %d\n",i+1,i+3);
return 0;
}
printf("-1 -1\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//aa
//aba
int main(){
string S; cin>>S;
ll ssz=S.size();
for(int i=0; i<ssz-1; i++){
if(S[i]==S[i+1]){
cout<<i+1<<" "<<i+2<<endl;
return 0;
}
else if(i<ssz-2 && S[i]==S[i+2]){
cout<<i+1<<" "<<i+3<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
} | ### Prompt
Please formulate a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//aa
//aba
int main(){
string S; cin>>S;
ll ssz=S.size();
for(int i=0; i<ssz-1; i++){
if(S[i]==S[i+1]){
cout<<i+1<<" "<<i+2<<endl;
return 0;
}
else if(i<ssz-2 && S[i]==S[i+2]){
cout<<i+1<<" "<<i+3<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
int n = s.length();
int b = 0;
for (int i=0; i<n-1; i++) {
if (s[i] == s[i+1]) {
cout<<i+1<<" "<<i+2<<endl;
return 0;
}
if (i == n-2) {
break;
}
if (s[i] == s[i+2]) {
cout<<i+1<<" "<<i+3<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
} | ### Prompt
Develop a solution in cpp to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
int n = s.length();
int b = 0;
for (int i=0; i<n-1; i++) {
if (s[i] == s[i+1]) {
cout<<i+1<<" "<<i+2<<endl;
return 0;
}
if (i == n-2) {
break;
}
if (s[i] == s[i+2]) {
cout<<i+1<<" "<<i+3<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
}
``` |
#include<bits/stdc++.h>
using namespace std;
char s[110000] = {0};
int main(){
cin >> s;
bool flag = 0;
int len = strlen(s);
for(int i = 0;i<len;i++){
if(s[i]==s[i+1]){
cout << i+1 << " " << i+2 << endl;
flag = 1;
break;
}else if(s[i]==s[i+2]){
cout << i+1 << " " << i+3 << endl;
flag = 1;
break;
}
}
if(!flag)cout << -1 << " " << -1 << endl;
return 0;
} | ### Prompt
In Cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
char s[110000] = {0};
int main(){
cin >> s;
bool flag = 0;
int len = strlen(s);
for(int i = 0;i<len;i++){
if(s[i]==s[i+1]){
cout << i+1 << " " << i+2 << endl;
flag = 1;
break;
}else if(s[i]==s[i+2]){
cout << i+1 << " " << i+3 << endl;
flag = 1;
break;
}
}
if(!flag)cout << -1 << " " << -1 << endl;
return 0;
}
``` |
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
int N = S.size();
for (int i=0;i<N-1;++i){
if (S[i] == S[i+1]){
cout<<i+1<<' '<<i+2;
return 0;
}
}
for (int i=0;i<N-2;++i){
if (S[i] == S[i+2]){
cout<<i+1<<' '<<i+3;
return 0;
}
}
cout<<"-1 -1";
}
| ### Prompt
Develop a solution in CPP to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
int N = S.size();
for (int i=0;i<N-1;++i){
if (S[i] == S[i+1]){
cout<<i+1<<' '<<i+2;
return 0;
}
}
for (int i=0;i<N-2;++i){
if (S[i] == S[i+2]){
cout<<i+1<<' '<<i+3;
return 0;
}
}
cout<<"-1 -1";
}
``` |
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char t[100002];
int main()
{
scanf("%s",t);
int len=strlen(t);
for(int i=0;i<len;i++)
{
if(t[i]==t[i+1])
{
printf("%d %d",i+1,i+2);
return 0;
}
if(t[i]==t[i+2])
{
printf("%d %d",i+1,i+3);
return 0;
}
}
printf("-1 -1");
} | ### Prompt
Construct a cpp code solution to the problem outlined:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char t[100002];
int main()
{
scanf("%s",t);
int len=strlen(t);
for(int i=0;i<len;i++)
{
if(t[i]==t[i+1])
{
printf("%d %d",i+1,i+2);
return 0;
}
if(t[i]==t[i+2])
{
printf("%d %d",i+1,i+3);
return 0;
}
}
printf("-1 -1");
}
``` |
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
string str;
cin>>str;
for(int i=1;i<str.size();i++)
{
if(str[i]==str[i-1])
{
cout<<i<<" "<<i+1<<endl;
return 0;
}
}
for(int i=2;i<str.size();i++)
{
if(str[i]==str[i-2])
{
cout<<i-1<<" "<<i+1<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
return 0;
} | ### Prompt
In cpp, your task is to solve the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
string str;
cin>>str;
for(int i=1;i<str.size();i++)
{
if(str[i]==str[i-1])
{
cout<<i<<" "<<i+1<<endl;
return 0;
}
}
for(int i=2;i<str.size();i++)
{
if(str[i]==str[i-2])
{
cout<<i-1<<" "<<i+1<<endl;
return 0;
}
}
cout<<"-1 -1"<<endl;
return 0;
}
``` |
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define N 100010
using namespace std;
int n,w[30][N]; char s[N];
int main(){
scanf("%s",s+1); n=strlen(s+1);
rep (i,1,n-1) if (s[i]==s[i+1]){
printf("%d %d\n",i,i+1);
exit(0);
}
rep (i,1,n-2) if (s[i]==s[i+2]){
printf("%d %d\n",i,i+2);
exit(0);
}
puts("-1 -1");
return 0;
} | ### Prompt
Please provide a CPP coded solution to the problem described below:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define N 100010
using namespace std;
int n,w[30][N]; char s[N];
int main(){
scanf("%s",s+1); n=strlen(s+1);
rep (i,1,n-1) if (s[i]==s[i+1]){
printf("%d %d\n",i,i+1);
exit(0);
}
rep (i,1,n-2) if (s[i]==s[i+2]){
printf("%d %d\n",i,i+2);
exit(0);
}
puts("-1 -1");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int n = s.size();
for(int i=0; i<n-1; ++i){
if(s[i] == s[i+1]){
cout << i+1 << " " << i+2 << endl;
return 0;
}
if(i<n-2 && s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
} | ### Prompt
Create a solution in Cpp for the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int n = s.size();
for(int i=0; i<n-1; ++i){
if(s[i] == s[i+1]){
cout << i+1 << " " << i+2 << endl;
return 0;
}
if(i<n-2 && s[i] == s[i+2]){
cout << i+1 << " " << i+3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
}
``` |
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int n;
string str;
int main(void){
cin >> str;
n=str.size();
for(int i=0;i<n-1;i++){
if(str[i]==str[i+1]){
printf("%d %d\n",i+1,i+2);
return 0;
}
}
for(int i=0;i<n-2;i++){
if(str[i]==str[i+2]){
printf("%d %d\n",i+1,i+3);
return 0;
}
}
printf("-1 -1\n");
return 0;
} | ### Prompt
Your task is to create a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int n;
string str;
int main(void){
cin >> str;
n=str.size();
for(int i=0;i<n-1;i++){
if(str[i]==str[i+1]){
printf("%d %d\n",i+1,i+2);
return 0;
}
}
for(int i=0;i<n-2;i++){
if(str[i]==str[i+2]){
printf("%d %d\n",i+1,i+3);
return 0;
}
}
printf("-1 -1\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int x = -1, y = -1;
for (int i = 0; i < str.size(); i++) {
if (i > 0 && str[i] == str[i-1]) x = i, y = i+1;
if (i > 1 && str[i] == str[i-2]) x = i-1, y = i+1;
}
cout << x << " " << y << endl;
return 0;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int x = -1, y = -1;
for (int i = 0; i < str.size(); i++) {
if (i > 0 && str[i] == str[i-1]) x = i, y = i+1;
if (i > 1 && str[i] == str[i-2]) x = i-1, y = i+1;
}
cout << x << " " << y << endl;
return 0;
}
``` |
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
int len;
int main()
{
cin >> s;
len = s.size();
for (int i = 0; i < len - 1; i++) if (s[i] == s[i + 1]) { printf("%d %d\n", i + 1, i + 2); return 0; }
for (int i = 0; i < len - 2; i++) if (s[i] == s[i + 2]) { printf("%d %d\n", i + 1, i + 3); return 0; }
printf("-1 -1\n");
return 0;
} | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
int len;
int main()
{
cin >> s;
len = s.size();
for (int i = 0; i < len - 1; i++) if (s[i] == s[i + 1]) { printf("%d %d\n", i + 1, i + 2); return 0; }
for (int i = 0; i < len - 2; i++) if (s[i] == s[i + 2]) { printf("%d %d\n", i + 1, i + 3); return 0; }
printf("-1 -1\n");
return 0;
}
``` |
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s;
int main(){
cin>>s;
int a=-1,b=-1;
for(int i=0;i<s.size()-2;i++){
if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){
if(a==-1){
a=i+1,b=i+3;
}
}
}
if(s.size()==2){
if(s[0]==s[1])a=1,b=2;
}
cout<<a<<" "<<b<<endl;
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string s;
int main(){
cin>>s;
int a=-1,b=-1;
for(int i=0;i<s.size()-2;i++){
if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){
if(a==-1){
a=i+1,b=i+3;
}
}
}
if(s.size()==2){
if(s[0]==s[1])a=1,b=2;
}
cout<<a<<" "<<b<<endl;
return 0;
}
``` |
#include <iostream>
#include <string>
int main()
{
std::string s;
std::cin >> s;
int N = s.size();
for(int i=0; i<N-1; i++){
if(s[i] == s[i+1]){
printf("%d %d\n", i+1, i+2); return 0;
}
else if(i != N-2 && s[i] == s[i+2]){
printf("%d %d\n", i+1, i+3); return 0;
}
}
printf("%d %d\n", -1, -1);
} | ### Prompt
Generate a CPP solution to the following problem:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.
Constraints
* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.
Input
The input is given from Standard Input in the following format:
s
Output
If there exists no unbalanced substring of s, print `-1 -1`.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.
Examples
Input
needed
Output
2 5
Input
atcoder
Output
-1 -1
### Response
```cpp
#include <iostream>
#include <string>
int main()
{
std::string s;
std::cin >> s;
int N = s.size();
for(int i=0; i<N-1; i++){
if(s[i] == s[i+1]){
printf("%d %d\n", i+1, i+2); return 0;
}
else if(i != N-2 && s[i] == s[i+2]){
printf("%d %d\n", i+1, i+3); return 0;
}
}
printf("%d %d\n", -1, -1);
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.