-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution123.cpp
More file actions
199 lines (186 loc) · 3.5 KB
/
solution123.cpp
File metadata and controls
199 lines (186 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//SRI_SUNDARAN_13
#include <bits/stdc++.h>
#include<math.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define nline "\n"
#define MOD 1000000007
#define f(i,n) for(int i=0;i<n;i++)
template<typename T>
istream &operator>>(istream &istream,vector<T> &v){
for(auto &it:v)
cin>>it;
return istream;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
const ll N=1'000'000'000'000L;
//typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
int gcd_sum(long long int n)
{
long long int tmp=n,digitsum=0;
while(tmp)
{
digitsum=digitsum+tmp%10;
tmp/=10;
}
long long int gcd1=gcd(n,digitsum);
return gcd1;
}
struct Test
{
int x, y;
};
char small_alpha(char a[],int n)
{
char min='z';
for(int i=0;i<n;i++)
{
if(a[i]<min)
min=a[i];
}
return min;
}
long long getR(long long a)
{
while(a%2==0)
a/=2;
return a;
}
ll findlcm(int arr[], int n)
{
// Initialize result
ll ans = arr[0];
// ans contains LCM of arr[0], ..arr[i]
// after i'th iteration,
for (int i = 1; i < n; i++)
ans = (((arr[i] * ans)) /
(gcd(arr[i], ans)));
return ans;
}
//min(m-cd+m-cb,n-rd+n-cd)
bool isVowel(char a){
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
return true;
return false;
}
bool isPalindrome(string S)
{
// Stores the reverse of the
// string S
string P = S;
// Reverse the string P
reverse(P.begin(), P.end());
// If S is equal to P
if (S == P) {
// Return "Yes"
return true;
}
// Otherwise
else {
// return "No"
return false;
}
}
int sum_of_arr(vector<int> v){
int sum1=0;
for(int i=0;i<v.size();i++){
sum1+=v[i];
}
return sum1;
}
int sum(vector<int> a,int l,int r){
int sum=0;
for(int i=l-1;i<=r-1;i++){
sum+=a[i];
}
return sum;
}
bool sortbysec(const pair<int,int>&a,const pair<int,int> &b){
return(a.second<b.second);
}
ll getAdd(ll x){
ll m1=10,m2=0;
while(x>0){
ll y=x%10;
x/=10;
m1=min(m1,y);
m2=max(m2,y);
}
return m1*m2;
}
//int x,y;
ll countOdd(ll L, ll R){
ll N = (R - L) / 2;
// if either R or L is odd
if (R % 2 != 0 || L % 2 != 0)
N += 1;
return N;
}
int bitcount(int n){
int k=0;
while(n){
n/=2;
k++;
}
return k;
}
bool flag;
unordered_set<ll> cubes;
int factorial(int n){
int temp=1;
while(n>=1){
temp*=n;
n--;
}
}
unsigned int factorial(unsigned int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
void solve(){
ll n;
cin>>n;
string s;
cin>>s;
ll mid=n/2;
ll i;
ll count=0;
if(n%2==0){
//mid++;
i=mid;
while(s[i]==s[i+1]){
i++;
count++;
}
count++;
cout<<2*count<<nline;
}
else{
//mid++;
i=mid;
while(s[i]==s[i+1]){
i++;
count++;
}
cout<<2*count+1<<nline;
}
}
signed main() {
//precalc();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin>>t;
while(t--){
solve();
}
}