message
stringlengths
2
23.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
97
109k
cluster
float64
0
0
__index_level_0__
int64
194
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1
instruction
0
7,949
0
15,898
Tags: constructive algorithms, greedy, strings Correct Solution: ``` n, t = map(int, input().split()) a, b = input(), input() ans = [] s = d = 0 for i, j in zip(a, b): if i == j: s += 1 else: d += 1 if t < (d + 1) // 2: print(-1) exit() x = min(n - t, s) y = z = max(n - t - s, 0) def f(a, b): for i in range(97, 123): if chr(i) not in [a, b]: return chr(i) for i in range(n): if a[i] == b[i]: if x: ans.append(a[i]) x -= 1 else: ans.append(f(a[i], b[i])) else: if y: ans.append(a[i]) y -= 1 elif z: ans.append(b[i]) z -= 1 else: ans.append(f(a[i], b[i])) print(''.join(ans)) ```
output
1
7,949
0
15,899
Provide tags and a correct Python 3 solution for this coding contest problem. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1
instruction
0
7,950
0
15,900
Tags: constructive algorithms, greedy, strings Correct Solution: ``` n, t = map(int, input().split()) s1 = str(input()) s2 = str(input()) s1cnt, s2cnt = n - t, n - t ans = [None] * n # print(s1cnt, s2cnt) for i in range(n): ch1, ch2 = s1[i], s2[i] if ch1 == ch2 and s1cnt and s2cnt: ans[i] = ch1 s1cnt -= 1 s2cnt -= 1 # print(ans) for i in range(n): ch1, ch2 = s1[i], s2[i] if s1cnt and ans[i] == None: ans[i] = ch1 s1cnt -= 1 elif s2cnt and ans[i] == None: ans[i] = ch2 s2cnt -= 1 elif ans[i] == None: for j in range(ord('a'), ord('e')): if chr(j) != ch1 and chr(j) != ch2: ans[i] = chr(j) break if s1cnt or s2cnt: print(-1) else: print(''.join(ans)) # print(n,t, s1, s2) ```
output
1
7,950
0
15,901
Provide tags and a correct Python 3 solution for this coding contest problem. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1
instruction
0
7,951
0
15,902
Tags: constructive algorithms, greedy, strings Correct Solution: ``` def get_diff(a,b): res='a' while res==a or res==b: res=chr(ord(res)+1) return res n,t=map(int, input().split()) s1=input() s2=input() diff=0 res="-1" for i in range(n): if s1[i]!=s2[i]: diff+=1 if t<diff: if t*2>=diff: res=[None]*n singole=t*2-diff curr=1 for i in range(n): if s1[i]==s2[i]: res[i]=s1[i] else: #diff if singole>0: res[i]=get_diff(s1[i],s2[i]) singole-=1 else: if curr==1: res[i]=s1[i] else: res[i]=s2[i] curr=-curr elif t==diff: res=[None]*n for i in range(n): if s1[i]==s2[i]: res[i]=s1[i] else: res[i]=get_diff(s1[i],s2[i]) else: #t>diff res=[None]*n for i in range(n): if s1[i]==s2[i]: if t>diff: res[i]=get_diff(s1[i],s2[i]) t-=1 else: res[i]=s1[i] else: res[i]=get_diff(s1[i],s2[i]) res="".join(res) print(res) ```
output
1
7,951
0
15,903
Provide tags and a correct Python 3 solution for this coding contest problem. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1
instruction
0
7,952
0
15,904
Tags: constructive algorithms, greedy, strings Correct Solution: ``` import sys letras="abcdefghijklmnopqrstuvwxyz" def distinto(a,b): for lc in range(26): c=letras[lc] if (a!=c and b!= c): return c s3="" l=0 for line in sys.stdin: if l==0: n,t=map(int,line.split()) if l==1: s1=line else: s2=line l+=1 dist=0 for i in range(n): if (s1[i]!=s2[i]): dist+=1 if (t<int((dist+1)/2)): s3+= str(-1) elif (t>=dist) : igdist=t-dist for i in range(n): if (s1[i]!=s2[i]): s3+= distinto(s1[i],s2[i]) else: if (igdist==0): s3+= s1[i]; else: s3+= distinto(s1[i],s2[i]) igdist-=1 else : distdist=dist-t alter=1 for i in range(n): if (s1[i]==s2[i]): s3+= s1[i] else: if (distdist==0): s3+= distinto(s1[i],s2[i]); else: if (alter==1): s3+= s1[i] alter=2 else: s3+= s2[i] alter=1 distdist-=1 print (s3) ```
output
1
7,952
0
15,905
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up down """ n, k = I() s = input() t = input() ans = list(s) cnt = 0 idx = [] for i in range(n): if s[i] != t[i]: idx.append(i) else: ans[i] = s[i] a = 'abcde' ok = len(idx) req = 0 for i in range(ok + 1): if (ok - i) % 2: continue count = i + (ok - i) // 2 if count + n - ok >= k and count <= k: req = max(0, k - count) # print(k - count, count, i) for j in range(i): for ass in a: if ass != s[idx[j]] and ass != t[idx[j]]: ans[idx[j]] = ass break for j in range(i, ok): # print(j) if j % 2: ans[idx[j]] = s[idx[j]] else: ans[idx[j]] = t[idx[j]] break else: print(-1) exit() for i in range(n): if not req: break if s[i] == t[i]: if s[i] == 'a': ans[i] = 'z' else: ans[i] = 'a' req -= 1 print(''.join(ans)) ```
instruction
0
7,953
0
15,906
Yes
output
1
7,953
0
15,907
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` n, t = [int(i) for i in input().split()] s1 = input() s2 = input() same = 0 for i in range(n): if s1[i] is s2[i]: same += 1 diff = n - same if t * 2 < diff: print(-1) exit() if t * 2 == diff: f1 = t f2 = t s3 = "" for i in range(n): if s1[i] == s2[i]: s3 = s3 + s1[i] else: if f1 > 0: s3 = s3 + s1[i] f1 -= 1 else: s3 = s3 + s2[i] print(s3) exit() oth = max(0, t - diff) f1 = max(0, diff - t) f2 = max(0, diff - t) s3 = "" for i in range(n): if s1[i] == s2[i]: if oth > 0: if s1[i] == 'a': s3 = s3 + 'b' else: s3 = s3 + 'a' oth -= 1 else: s3 += s1[i] else: if f1 > 0: s3 += s2[i] f1 -= 1 elif f2 > 0: s3 += s1[i] f2 -= 1 else: if 'a' not in [s1[i], s2[i]]: s3 = s3 + 'a' elif 'b' not in [s1[i], s2[i]]: s3 = s3 + 'b' else: s3 = s3 + 'c' # oth = t - f1 # f = 0 # # if diff % 2 is 1: # f = 1 # oth -= 1 # # for i in range(n): # # if s1[i] == s2[i]: # # if oth > 0: # # if s1[i] == 'a': # # s3 = s3 + 'b' # # else: # # s3 = s3 + 'a' # # oth -= 1 # # else: # # print(s1) # s3 = s3 + s1[i] # # else: # # if f is 1: # # if 'a' not in [s1[i], s2[i]]: # # s3 = s3 + 'a' # # elif 'b' not in [s1[i], s2[i]]: # # s3 = s3 + 'b' # # else: # # s3 = s3 + 'c' # # f = 0 # # else: # # if s1[i] == s2[i]: # # s3 = s3 + s1[i] # # else: # # if f1 > 0: # # s3 = s3 + s1[i] # f1 -= 1 # # else: # # s3 = s3 + s2[i] print(s3) ```
instruction
0
7,954
0
15,908
Yes
output
1
7,954
0
15,909
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` def read_numbers(): return list(map(int, input().split())) def get_other_char(a, b): for c in 'abc': if c != a and c != b: return c n, t = read_numbers() word1 = input() word2 = input() # find a word, that has minimal distance to both of them # first, number of differences diffs = len([idx for idx, (c1, c2) in enumerate(zip(word1, word2)) if c1 != c2]) #not_diffs = [idx for idx, (c1, c2) in enumerate(zip(word1, word2)) if c1 == c2] minimum = (diffs + 1) // 2 switches = diffs - t if t <= diffs else 0 switch_polarity = 0 if t < minimum: print(-1) else: # create new word new_word = [] for c1, c2 in zip(word1, word2): if c1 == c2: if t > diffs: new_word.append(get_other_char(c1, c2)) t -= 1 else: new_word.append(c1) else: if switches: if switch_polarity == 0: new_word.append(c1) switch_polarity = 1 else: new_word.append(c2) switch_polarity = 0 switches -= 1 else: new_word.append(get_other_char(c1, c2)) print(''.join(new_word)) ```
instruction
0
7,955
0
15,910
Yes
output
1
7,955
0
15,911
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` def diff(c1, c2): alph = 'abcdefghijklmnopqrstuvwxyz' for c in alph: if c != c1 and c!= c2: return c n, t = map(int, input().split()) s1 = input() s2 = input() s3 = [] same1 = 0 same2 = 0 last1 = -1 last2 = -1 i = 0 first = True while (same1 < (n - t) or same2 < (n - t)) and i < n: if s1[i] == s2[i]: if same1 + 1 > (n-t): s3[last1] = diff(s1[last1], s2[last1]) same1 -= 1 elif same2 + 1 > (n-t): s3[last2] = diff(s1[last2], s2[last2]) same2 -= 1 s3.append(s1[i]) same1 += 1 same2 += 1 elif s1[i] == s2[i]: s3 += diff(s1[i], s2[i]) else: if first: s3.append(s1[i]) same1 += 1 last1 = i else: s3.append(s2[i]) same2 += 1 last2 = i first = not first i += 1 if same1 != same2 or (same1 == same2 != (n-t)): print(-1) else: remaining = n - len(s3) for i in range(len(s3), n): s3 += diff(s1[i], s2[i]) print(''.join(s3)) ```
instruction
0
7,956
0
15,912
Yes
output
1
7,956
0
15,913
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` ''' Created on Oct 7, 2015 @author: Ismael ''' def otherChar(x,y): for c in 'a','b','c': if c != x and c != y: return c def solve(a,b,t): nbEqual = sum(1 for i in range(len(a)) if a[i] == b[i]) nbDiff = len(a)-nbEqual if t == 0 and nbDiff==1: return '-1' c=len(a)*[0] k=0 i = 0 while i < len(a)-1: if a[i] != b[i]: q,r = divmod(nbDiff,2) k+=1 if k+1+q+r<=t:#c[i] different from both c[i] and c[i] nbDiff=-1 c[i] = otherChar(a[i],b[i]) i+=1 else: nbDiff=-2 c[i] = a[i] c[i+1] = b[i+1] i+=2 else: i+=1 i = 0 while i < len(a): if a[i] == b[i]: if k < t: k+=1 c[i] = otherChar(a[i],b[i]) else: c[i] = a[i] i+=1 if k!=t: return '-1' return ''.join(map(str,c)) def check(a,b,t,c): assert(sum(1 for i in range(len(a)) if a[i] != c[i])==t) assert(sum(1 for i in range(len(a)) if b[i] != c[i])==t) # args = "abc","abc",2 # c=solve(*args) # print(c) # check(*args,c=c) # # args = "abc","xyc",2 # c=solve(*args) # print(c) # check(*args,c=c) # # args = "c","d",0 # c=solve(*args) # print(c) # check(*args,c=c) _,t=map(int,input().split()) a=input() b=input() print(solve(a,b,t)) ```
instruction
0
7,958
0
15,916
No
output
1
7,958
0
15,917
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# #vsInput() n,t=value() s1=input() s2=input() s3=[0]*(n) dif=[] equal=[] for i in range(n): if(s1[i]!=s2[i]): dif.append(i) else: equal.append(i) i=0 while(i+1<len(dif)): s3[dif[i]]=1 s3[dif[i+1]]=2 t-=1 i+=1 if(len(dif)%2): s3[dif[-1]]=3 t-=1 i=0 while(t>0 and i+1<len(dif)): t-=1 s3[i]=3 s3[i+1]=3 i+=2 i=0 while(t>0 and i<len(equal)): s3[equal[i]]=3 t-=1 i+=1 print(t,s3) for i in range(n): if(s1[i]==1): s3[i]=s1[i] elif(s3[i]==2): s3[i]=s2[i] elif(s3[i]==3): for c in 'abc': if(s1[i]!=c and s2[i]!=c): s3[i]=c break else: s3[i]=s1[i] if(t==0): print(*s3,sep="") else: print(-1) ```
instruction
0
7,959
0
15,918
No
output
1
7,959
0
15,919
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≀ n ≀ 105, 0 ≀ t ≀ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1. Examples Input 3 2 abc xyc Output ayd Input 1 0 c b Output -1 Submitted Solution: ``` def diff(c1, c2): alph = 'abcdefghijklmnopqrstuvwxyz' for c in alph: if c != c1 and c!= c2: return c n, t = map(int, input().split()) s1 = input() s2 = input() s3 = '' same1 = 0 same2 = 0 i = 0 first = True while (same1 < (n - t) or same2 < (n - t)) and i < n: if s1[i] == s2[i]: s3 += s1[i] same1 += 1 same2 += 1 else: if first: s3 += s1[i] same1 += 1 else: s3 += s2[i] same2 += 1 first = not first i += 1 if same1 != same2: print(-1) else: remaining = n - len(s3) for i in range(len(s3), n): s3 += diff(s1[i], s2[i]) print(s3) ```
instruction
0
7,960
0
15,920
No
output
1
7,960
0
15,921
Provide tags and a correct Python 3 solution for this coding contest problem. Toad Rash has a binary string s. A binary string consists only of zeros and ones. Let n be the length of s. Rash needs to find the number of such pairs of integers l, r that 1 ≀ l ≀ r ≀ n and there is at least one pair of integers x, k such that 1 ≀ x, k ≀ n, l ≀ x < x + 2k ≀ r, and s_x = s_{x+k} = s_{x+2k}. Find this number of pairs for Rash. Input The first line contains the string s (1 ≀ |s| ≀ 300 000), consisting of zeros and ones. Output Output one integer: the number of such pairs of integers l, r that 1 ≀ l ≀ r ≀ n and there is at least one pair of integers x, k such that 1 ≀ x, k ≀ n, l ≀ x < x + 2k ≀ r, and s_x = s_{x+k} = s_{x+2k}. Examples Input 010101 Output 3 Input 11001100 Output 0 Note In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5. In the second example, there are no values x, k for the initial string, so the answer is 0.
instruction
0
8,426
0
16,852
Tags: brute force, two pointers Correct Solution: ``` s = input() cur, ans = - 1, 0 for i in range(len(s)): for j in range(cur + 1, i - 1): if (i + j) % 2 == 0 and s[i] == s[j] and s[i] == s[(i + j) // 2]: cur = j ans += cur + 1 print(ans) ```
output
1
8,426
0
16,853
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,546
0
17,092
Tags: constructive algorithms, greedy Correct Solution: ``` from math import ceil for _ in range(int(input())): n = int(input()) s = input() ct = 0 for i in range(n-1): if s[i] == s[i+1]: ct += 1 print(ceil(ct / 2.0)) ```
output
1
8,546
0
17,093
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,547
0
17,094
Tags: constructive algorithms, greedy Correct Solution: ``` t=int(input()) for i in range(0, t): n=int(input()) s=input() count=0 for j in range(0,n): if(j!=(n-1)): if(s[j]==s[j+1]): count=count+1 else: if(s[j]==s[0]): count=count+1 print(count//2) ```
output
1
8,547
0
17,095
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,548
0
17,096
Tags: constructive algorithms, greedy Correct Solution: ``` import sys import math from collections import Counter,defaultdict LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() def case(): n=IN() s=S() a=s.split("0") b=s.split("1") x=0 for i in a: if len(i): x+=len(i)-1 for i in b: if len(i): x+=len(i)-1 print((x+1)//2) for _ in range(IN()): case() ```
output
1
8,548
0
17,097
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,549
0
17,098
Tags: constructive algorithms, greedy Correct Solution: ``` for _ in range(int(input())): n=int(input()) s=list(input()) maxi=0 temp1=0 temp2=0 for i in range(1,n): if(s[i-1]=='1' and s[i]=='1'): temp1+=1 maxi=max(maxi,temp1) if(s[i-1]=='0' and s[i]=='0'): temp2+=1 maxi=max(maxi,temp2) print(maxi) ```
output
1
8,549
0
17,099
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,550
0
17,100
Tags: constructive algorithms, greedy Correct Solution: ``` t = int(input()) while t > 0: t -= 1 n = int(input()) s = input() ans = 0 i = 0 while i+1 < n: if s[i] == s[i+1]: ans += 1; i += 1 print((ans+1)//2) ```
output
1
8,550
0
17,101
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,551
0
17,102
Tags: constructive algorithms, greedy Correct Solution: ``` t=int(input()) for i in range(t): n=int(input()) s=input() c=0 for i in range(0,n-1): if s[i]==s[i+1]: c+=1 print((c+1)//2) ```
output
1
8,551
0
17,103
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,552
0
17,104
Tags: constructive algorithms, greedy Correct Solution: ``` """ pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppp pppppppp ppppppppppppppppppppp ppppppp ppppppppppppppppppp ppppp pppppppppppppppppppp """ import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush, nsmallest from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction from decimal import Decimal # sys.setrecursionlimit(2 * (10 ** 5)) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = pow(10, 9) + 7 mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(var): sys.stdout.write(str(var)+"\n") def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end) def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] for _ in range(int(data())): n = int(data()) s = list(data()) answer = 0 # start with 1. pos = [0] * n for i in range(n): if i % 2 != int(s[i]) % 2: pos[i] = 1 answer = int(pos[0] == 1) for i in range(1, n): if pos[i] == pos[i-1] == 1: continue if pos[i] == 1: answer += 1 # start with 0. pos = [0] * n temp = 0 for i in range(n): if i % 2 == int(s[i]) % 2: pos[i] = 1 temp = int(pos[0] == 1) for i in range(1, n): if pos[i] == pos[i-1] == 1: continue if pos[i] == 1: temp += 1 out(min(temp, answer)) ```
output
1
8,552
0
17,105
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010.
instruction
0
8,553
0
17,106
Tags: constructive algorithms, greedy Correct Solution: ``` import math t=int(input()) for _ in range(t): n=int(input()) s=str(input()) v1=0;v2=0 p=0 for i in range(len(s)): if int(s[i])!=i%2: p+=1 else: v1+=int(p>0) p=0 v1+=int(p>0) p=0 for i in range(len(s)): if int(s[i])==i%2: p+=1 else: v2+=int(p>0) p=0 v2+=int(p>0) print(min(v1,v2)) ```
output
1
8,553
0
17,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` for s in[*open(0)][2::2]:print(len(s)//2-sum(map(bool,s.split(s[-2])))+1) ```
instruction
0
8,554
0
17,108
Yes
output
1
8,554
0
17,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` t=int(input()) while(t): zero=0 one=0 size=int(input()) array=list(map(int,input())) for i in range(len(array)-1): if(array[i]==1 and array[i+1]==1): one+=1 if(array[i]==0 and array[i+1]==0): zero+=1 print(max(one,zero)) t-=1 ```
instruction
0
8,555
0
17,110
Yes
output
1
8,555
0
17,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` import sys,math from heapq import * from collections import defaultdict as dd mod = 10**9+7; modd = 998244353 input = lambda: sys.stdin.readline().strip() inp = lambda: list(map(int,input().split())) for _ in range(int(input())): n, = inp() a = str(input()) ans = 0 for i in range(n): ans+= 1*(a[i]==a[(i+1)%n]) print(ans//2) ```
instruction
0
8,556
0
17,112
Yes
output
1
8,556
0
17,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` if __name__ == '__main__': for _ in range(int(input())): n = int(input()) s = input() c=0 for i in range(len(s)-1): if s[i] == '0' and s[i+1]=='0': i +=1 c+=1 k = 0 for i in range(len(s)-1): if s[i]=='1' and s[i+1] == '1': i+=1 k+=1 print(max(c,k)) ```
instruction
0
8,557
0
17,114
Yes
output
1
8,557
0
17,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` t=int(input()) while(t): res=0 checker=-1 size=int(input()) array=list(map(int,input())) for i in range(len(array)-1): if(array[i]==array[i+1] and checker==-1): checker=array[i] if(array[i]==checker and array[i+1]==checker): res+=1 print(res) t-=1 ```
instruction
0
8,558
0
17,116
No
output
1
8,558
0
17,117
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` for testCase in range(int(input())): n = int(input()) s = input() if n == 2: print(0) continue print((s.count("00")+s.count("11"))//2) ```
instruction
0
8,559
0
17,118
No
output
1
8,559
0
17,119
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` import time,math as mt,bisect as bs,sys from sys import stdin,stdout from collections import deque from fractions import Fraction from collections import Counter from collections import OrderedDict pi=3.14159265358979323846264338327950 def II(): # to take integer input return int(stdin.readline()) def IP(): # to take tuple as input return map(int,stdin.readline().split()) def L(): # to take list as input return list(map(int,stdin.readline().split())) def P(x): # to print integer,list,string etc.. return stdout.write(str(x)+"\n") def PI(x,y): # to print tuple separatedly return stdout.write(str(x)+" "+str(y)+"\n") def lcm(a,b): # to calculate lcm return (a*b)//gcd(a,b) def gcd(a,b): # to calculate gcd if a==0: return b elif b==0: return a if a>b: return gcd(a%b,b) else: return gcd(a,b%a) def bfs(adj,v): # a schema of bfs visited=[False]*(v+1) q=deque() while q: pass def sieve(): li=[True]*(2*(10**5)+5) li[0],li[1]=False,False for i in range(2,len(li),1): if li[i]==True: for j in range(i*i,len(li),i): li[j]=False prime=[] for i in range((2*(10**5)+5)): if li[i]==True: prime.append(i) return prime def setBit(n): count=0 while n!=0: n=n&(n-1) count+=1 return count mx=10**7 spf=[mx]*(mx+1) def SPF(): spf[1]=1 for i in range(2,mx+1): if spf[i]==mx: spf[i]=i for j in range(i*i,mx+1,i): if i<spf[j]: spf[j]=i return def readTree(n,e): # to read tree adj=[set() for i in range(n+1)] for i in range(e): u1,u2=IP() adj[u1].add(u2) return adj ##################################################################################### mod=10**9+7 def solve(): n=II() s=input() cnt=0 ans=0 for i in range(n): if s[i]=='1': cnt+=1 else: if cnt>0: ans+=(cnt-1) cnt=0 print(ans) return t=II() for i in range(t): solve() ####### # # ####### # # # #### # # # # # # # # # # # # # # # #### # # #### #### # # ###### # # #### # # # # # # ``````ΒΆ0````1ΒΆ1_``````````````````````````````````````` # ```````ΒΆΒΆΒΆ0_`_ΒΆΒΆΒΆ0011100ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ001_```````````````````` # ````````ΒΆΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0_```````````````` # `````1_``ΒΆΒΆ00ΒΆ0000000000000000000000ΒΆΒΆΒΆΒΆ0_````````````` # `````_ΒΆΒΆ_`0ΒΆ000000000000000000000000000ΒΆΒΆΒΆΒΆΒΆ1`````````` # ```````ΒΆΒΆΒΆ00ΒΆ00000000000000000000000000000ΒΆΒΆΒΆ_````````` # ````````_ΒΆΒΆ00000000000000000000ΒΆΒΆ00000000000ΒΆΒΆ````````` # `````_0011ΒΆΒΆΒΆΒΆΒΆ000000000000ΒΆΒΆ00ΒΆΒΆ0ΒΆΒΆ00000000ΒΆΒΆ_```````` # ```````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000ΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ00000000ΒΆΒΆ1```````` # ``````````1ΒΆΒΆΒΆΒΆΒΆ000000ΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000ΒΆΒΆΒΆ```````` # ```````````ΒΆΒΆΒΆ0ΒΆ000ΒΆ00ΒΆ0ΒΆΒΆ`_____`__1ΒΆ0ΒΆΒΆ00ΒΆ00ΒΆΒΆ```````` # ```````````ΒΆΒΆΒΆΒΆΒΆ00ΒΆ00ΒΆ10ΒΆ0``_1111_`_ΒΆΒΆ0000ΒΆ0ΒΆΒΆΒΆ```````` # ``````````1ΒΆΒΆΒΆΒΆΒΆ00ΒΆ0ΒΆΒΆ_ΒΆΒΆ1`_ΒΆ_1_0_`1ΒΆΒΆ_0ΒΆ0ΒΆΒΆ0ΒΆΒΆ```````` # ````````1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆ0ΒΆ0_0ΒΆ``100111``_ΒΆ1_0ΒΆ0ΒΆΒΆ_1ΒΆ```````` # ```````1ΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ010ΒΆ``1111111_0ΒΆ11ΒΆΒΆΒΆΒΆΒΆ_10```````` # ```````0ΒΆΒΆΒΆΒΆ__10ΒΆΒΆΒΆΒΆΒΆ100ΒΆΒΆΒΆ0111110ΒΆΒΆΒΆ1__ΒΆΒΆΒΆΒΆ`__```````` # ```````ΒΆΒΆΒΆΒΆ0`__0ΒΆΒΆ0ΒΆΒΆ_ΒΆΒΆΒΆ_11````_0ΒΆΒΆ0`_1ΒΆΒΆΒΆΒΆ``````````` # ```````ΒΆΒΆΒΆ00`__0ΒΆΒΆ_00`_0_``````````1_``ΒΆ0ΒΆΒΆ_``````````` # ``````1ΒΆ1``ΒΆΒΆ``1ΒΆΒΆ_11``````````````````ΒΆ`ΒΆΒΆ```````````` # ``````1_``ΒΆ0_ΒΆ1`0ΒΆ_`_``````````_``````1_`ΒΆ1```````````` # ``````````_`1ΒΆ00ΒΆΒΆ_````_````__`1`````__`_ΒΆ````````````` # ````````````ΒΆ1`0ΒΆΒΆ_`````````_11_`````_``_`````````````` # `````````ΒΆΒΆΒΆΒΆ000ΒΆΒΆ_1```````_____```_1`````````````````` # `````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0_``````_````_1111__`````````````` # `````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ01_`````_11____1111_``````````` # `````````ΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1101_______11ΒΆ_``````````` # ``````_ΒΆΒΆΒΆ0000000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆ1```````````` # `````0ΒΆΒΆ0000000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1````````````` # ````0ΒΆ0000000ΒΆΒΆ0_````_011_10ΒΆ110ΒΆ01_1ΒΆΒΆΒΆ0````_100ΒΆ001_` # ```1ΒΆ0000000ΒΆ0_``__`````````_`````````0ΒΆ_``_00ΒΆΒΆ010ΒΆ001 # ```ΒΆΒΆ00000ΒΆΒΆ1``_01``_11____``1_``_`````ΒΆΒΆ0100ΒΆ1```_00ΒΆ1 # ``1ΒΆΒΆ00000ΒΆ_``_ΒΆ_`_101_``_`__````__````_0000001100ΒΆΒΆΒΆ0` # ``ΒΆΒΆΒΆ0000ΒΆ1_`_ΒΆ``__0_``````_1````_1_````1ΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆ0``` # `_ΒΆΒΆΒΆΒΆ00ΒΆ0___01_10ΒΆ_``__````1`````11___`1ΒΆΒΆΒΆ01_```````` # `1ΒΆΒΆΒΆΒΆΒΆ0ΒΆ0`__01ΒΆΒΆΒΆ0````1_```11``___1_1__11ΒΆ000````````` # `1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1_1_01__`01```_1```_1__1_11___1_``00ΒΆ1```````` # ``ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0`__10__000````1____1____1___1_```10ΒΆ0_``````` # ``0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ1___0000000```11___1__`_0111_```000ΒΆ01``````` # ```ΒΆΒΆΒΆ00000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ01___1___00_1ΒΆΒΆΒΆ`_``1ΒΆΒΆ10ΒΆΒΆ0``````` # ```1010000ΒΆ000ΒΆΒΆ0100_11__1011000ΒΆΒΆ0ΒΆ1_10ΒΆΒΆΒΆ_0ΒΆΒΆ00`````` # 10ΒΆ000000000ΒΆ0________0ΒΆ000000ΒΆΒΆ0000ΒΆΒΆΒΆΒΆ000_0ΒΆ0ΒΆ00````` # ΒΆΒΆΒΆΒΆΒΆΒΆ0000ΒΆΒΆΒΆΒΆ_`___`_0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000_0ΒΆ00ΒΆ01```` # ΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ_``_1ΒΆΒΆΒΆ00000000000000000000_0ΒΆ000ΒΆ01``` # 1__```1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆ00000000000000000000ΒΆ_0ΒΆ0000ΒΆ0_`` # ```````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000010ΒΆ00000ΒΆΒΆ_` # ```````0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000ΒΆ10ΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ0` # ````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ00000000000000000000010ΒΆΒΆΒΆ0011``` # ````````1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ0000000000000000000ΒΆ100__1_````` # `````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000ΒΆ11``_1`````` # `````````1ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ00000000000000000ΒΆ11___1_````` # ``````````ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000000000000ΒΆ11__``1_```` # ``````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ000000000000000ΒΆ1__````__``` # ``````````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000000000000__`````11`` # `````````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000011_``_1ΒΆΒΆΒΆ0` # `````````_ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆ000000ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000100ΒΆΒΆΒΆΒΆ0_`_ # `````````1ΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ000000000ΒΆΒΆΒΆΒΆΒΆΒΆ000000000ΒΆ00ΒΆΒΆ01````` # `````````ΒΆΒΆΒΆΒΆΒΆ0ΒΆ0ΒΆΒΆΒΆ0000000000000ΒΆ0ΒΆ00000000011_``````_ # ````````1ΒΆΒΆ0ΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000000ΒΆ11___11111 # ````````ΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆΒΆ00ΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000ΒΆ011111111_ # ```````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ0000000ΒΆ0ΒΆ00000000000000000ΒΆ01_1111111 # ```````0ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ000000000000000000000000000ΒΆ01___````` # ```````ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ000000000000000000000000000ΒΆ01___1```` # ``````_ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000000000000011_111``` # ``````0ΒΆΒΆ0ΒΆΒΆΒΆ0ΒΆΒΆ0000000000000000000000000000ΒΆ01`1_11_`` # ``````ΒΆΒΆΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆ0000000000000000000000000000001`_0_11_` # ``````ΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆΒΆ00000000000000000000000000000ΒΆ01``_0_11` # ``````ΒΆΒΆΒΆΒΆ0ΒΆΒΆΒΆΒΆ00000000000000000000000000000001```_1_11 ```
instruction
0
8,560
0
17,120
No
output
1
8,560
0
17,121
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s of even length n. String s is binary, in other words, consists only of 0's and 1's. String s has exactly n/2 zeroes and n/2 ones (n is even). In one operation you can reverse any substring of s. A substring of a string is a contiguous subsequence of that string. What is the minimum number of operations you need to make string s alternating? A string is alternating if s_i β‰  s_{i + 1} for all i. There are two types of alternating strings in general: 01010101... or 10101010... Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains a single integer n (2 ≀ n ≀ 10^5; n is even) β€” the length of string s. The second line of each test case contains a binary string s of length n (s_i ∈ {0, 1}). String s has exactly n/2 zeroes and n/2 ones. It's guaranteed that the total sum of n over test cases doesn't exceed 10^5. Output For each test case, print the minimum number of operations to make s alternating. Example Input 3 2 10 4 0110 8 11101000 Output 0 1 2 Note In the first test case, string 10 is already alternating. In the second test case, we can, for example, reverse the last two elements of s and get: 0110 β†’ 0101. In the third test case, we can, for example, make the following two operations: 1. 11101000 β†’ 10101100; 2. 10101100 β†’ 10101010. Submitted Solution: ``` #! /usr/bin/python3 import os import sys from io import BytesIO, IOBase def main(): for _ in range(int(input())): n = int(input()) s = list(int(x) for x in input()) zero = 0 one = 0 temp0 = 1 temp1 = 1 for i in range(n-1): if s[i] == s[i+1]: if s[i] == 0: temp0 += 1 else: temp1 += 1 else: one = max(one, temp1) zero = max(zero, temp0) temp1 = 1 temp0 = 1 print(max(one, zero) - 1) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
instruction
0
8,561
0
17,122
No
output
1
8,561
0
17,123
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,739
0
17,478
Tags: brute force, constructive algorithms, strings Correct Solution: ``` s = input() cnt = 0 for i in range(len(s)): if (s[i] != s[len(s) - i - 1]): cnt += 1 print("YES" if (cnt == 2) or (cnt == 0 and len(s) % 2 == 1) else "NO") ```
output
1
8,739
0
17,479
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,740
0
17,480
Tags: brute force, constructive algorithms, strings Correct Solution: ``` s=input() n=len(s) c=0 for i in range(n//2): if(s[i]!=s[n-i-1]): c=c+1 if(c==1): print("YES") elif(n%2==1 and c==0): print("YES") else: print("NO") ```
output
1
8,740
0
17,481
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,741
0
17,482
Tags: brute force, constructive algorithms, strings Correct Solution: ``` x = list(input()) g = len(x) p = g//2 w = 0 if g%2==0: q = x[:p]+x[:p][::-1] elif x[::-1]==x and g%2!=0: print("YES") quit() else: q = x[:p+1]+x[:p][::-1] for i in range(p,g): if x[i]!=q[i-g]: w+=1 if w == 1: print("YES") else: print("NO") ```
output
1
8,741
0
17,483
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,742
0
17,484
Tags: brute force, constructive algorithms, strings Correct Solution: ``` def main(): s = input() n = len(s) l = 0 r = n-1 cnt = 0 while(l<=r): if(s[l]!=s[r]): cnt+=1 l+=1 r-=1 if(cnt>1): print("NO") return if(cnt==1 or n%2==1): print("YES") else: print("NO") main() ```
output
1
8,742
0
17,485
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,743
0
17,486
Tags: brute force, constructive algorithms, strings Correct Solution: ``` s=input() count=0 i=0 j=len(s)-1 while i<j: if s[i]!=s[j]: count+=1 i=i+1 j=j-1 if count==1: print('YES') elif count==0: if len(s)%2==0: print('NO') else: print("YES") else: print('NO') ```
output
1
8,743
0
17,487
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,744
0
17,488
Tags: brute force, constructive algorithms, strings Correct Solution: ``` s=input() if len(s)%2==0: t=s[:len(s)//2] y=s[len(s)//2:] y=y[::-1] c=0 for i in range(len(s)//2): if t[i]!=y[i]: c=c+1 if c!=1: print("NO") else: print("YES") else: t = s[:len(s) // 2] y = s[len(s) // 2+1:] y = y[::-1] c = 0 for i in range(len(s) // 2): if t[i] != y[i]: c = c + 1 if c > 1: print("NO") else: print("YES") ```
output
1
8,744
0
17,489
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,745
0
17,490
Tags: brute force, constructive algorithms, strings Correct Solution: ``` s = input() c = 0 if (s[::-1] == s and len(s)&1 == 1): print("YES") exit() for i in range(len(s)//2): if s[i] != s[-i-1]: c+=1 print("NO YES".split()[c==1]) ```
output
1
8,745
0
17,491
Provide tags and a correct Python 3 solution for this coding contest problem. Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input The first and single line contains string s (1 ≀ |s| ≀ 15). Output Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Examples Input abccaa Output YES Input abbcca Output NO Input abcda Output YES
instruction
0
8,746
0
17,492
Tags: brute force, constructive algorithms, strings Correct Solution: ``` n=input() t=0 for i in range(len(n)//2): if(n[i]!=n[len(n)-i-1]): t+=1 if(t==1 or (t==0 and len(n)%2==1)): print("YES") else: print("NO") ```
output
1
8,746
0
17,493
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,763
0
17,526
Tags: brute force, implementation, strings Correct Solution: ``` n = int(input()) s = input() + 'Z' ans = 0 lst = [] for it in s: if 'A'<=it<='Z': temp = len(set(lst)) ans = temp if temp>ans else ans lst = [] else: lst.append(it) print(ans) ```
output
1
8,763
0
17,527
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,764
0
17,528
Tags: brute force, implementation, strings Correct Solution: ``` n = int(input()) s = input() ans = 0 S = set() for i in range(n): if 'a' <= s[i] <= 'z': S.add(s[i]) if len(S) > ans: ans = len(S) else: S = set() print(ans) ```
output
1
8,764
0
17,529
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,765
0
17,530
Tags: brute force, implementation, strings Correct Solution: ``` import re input() t = re.sub(r'[A-Z]', ' ', input()) print(max(len(set(s)) for s in t.split(' '))) # Made By Mostafa_Khaled ```
output
1
8,765
0
17,531
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,766
0
17,532
Tags: brute force, implementation, strings Correct Solution: ``` n=int(input()) s=input() i=0 letter=[] num=[] while i<n : if s[i].islower()and letter.count(s[i])==0 : letter.append(s[i]) if s[i].isupper()or i==n-1: num.append(len(letter)) letter=[] i+=1 if len(num)!=0: print(max(num)) else : print("0") ```
output
1
8,766
0
17,533
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,767
0
17,534
Tags: brute force, implementation, strings Correct Solution: ``` n = int(input()) s = input().strip() m = set() result =0 for i in s: if(not i.isupper()): m.add(i); else: if(len(m)>result): result = len(m) m.clear() if(len(m)>result): result = len(m) print(result) ```
output
1
8,767
0
17,535
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,768
0
17,536
Tags: brute force, implementation, strings Correct Solution: ``` t=int(input()) s=input() # print(t) # print(s) ms = set([]) max = 0 for i in range(t): if s[i].islower(): ms.add(s[i]) if len(ms) > max: max = len(ms) else: ms = set([]) print(max) ```
output
1
8,768
0
17,537
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,769
0
17,538
Tags: brute force, implementation, strings Correct Solution: ``` #!/usr/bin/env python def main(): _ = int(input()) ssplit = '' for c in input(): ssplit += '0' if c.isupper() else c res = max([len(set(sset)) for sset in ssplit.split('0')]) print(res) if __name__ == '__main__': main() ```
output
1
8,769
0
17,539
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0.
instruction
0
8,770
0
17,540
Tags: brute force, implementation, strings Correct Solution: ``` n=int(input()) s=input() f=0 cnt='' c=mx=0 for i in range(n): if s[i].isupper(): f=0 mx=max(mx,c) c=0 cnt='' else: f=1 if s[i] not in cnt: cnt+=s[i] c+=1 if f==1: mx=max(mx,c) print(mx) ```
output
1
8,770
0
17,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0. Submitted Solution: ``` small="abcdefghijklmnopqrstuvwxyz" big="ABCDEFGHIJKLMNOPQRSTUVWXYZ" n=int(input()) s=list(input()) q=[] f=0 for i in range(n): r = set() if s[i] in big: if i-f>0: for j in s[f:i]: r.add(j) q.append(len(r)) f=i+1 elif i==n-1: for j in s[f:i+1]: r.add(j) q.append(len(r)) if len(q)==0: print(0) else: print(max(q)) ```
instruction
0
8,771
0
17,542
Yes
output
1
8,771
0
17,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0. Submitted Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- n = int(input()) l = [] s = input() init = 0 for i in range(n): if s[i].isupper(): l.append(s[init:i]) init = i + 1 l.append(s[init:]) l1 = [len(set(x)) for x in l] print(max(l1)) ```
instruction
0
8,772
0
17,544
Yes
output
1
8,772
0
17,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0. Submitted Solution: ``` n , ans = int(input()) , 0 var = input() chars = set() for i in var: if i >= 'a' and i <= 'z': chars.add(i) else: ans = max(ans , len(chars)) chars = set() ans = max(ans , len(chars)) print(ans) ```
instruction
0
8,773
0
17,546
Yes
output
1
8,773
0
17,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0. Submitted Solution: ``` import re n=int(input()) s=input() ans=0 for c in re.split('[A-Z]',s): if len(c)>0: ans=max(ans,len(set(c))) print(ans) ```
instruction
0
8,774
0
17,548
Yes
output
1
8,774
0
17,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0. Submitted Solution: ``` #864B n = int(input()) s = input() parts = [] i = 0 string = "" while i < len(s): if s[i].islower(): string += s[i] else: parts.append(string) string = "" i += 1 m = 0 for j in parts: j = set(j) m = max(len(j),m) print(m) ```
instruction
0
8,775
0
17,550
No
output
1
8,775
0
17,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters. Let A be a set of positions in the string. Let's call it pretty if following conditions are met: * letters on positions from A in the string are all distinct and lowercase; * there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A). Write a program that will determine the maximum number of elements in a pretty set of positions. Input The first line contains a single integer n (1 ≀ n ≀ 200) β€” length of string s. The second line contains a string s consisting of lowercase and uppercase Latin letters. Output Print maximum number of elements in pretty set of positions for string s. Examples Input 11 aaaaBaabAbA Output 2 Input 12 zACaAbbaazzC Output 3 Input 3 ABC Output 0 Note In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position. In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements. In the third example the given string s does not contain any lowercase letters, so the answer is 0. Submitted Solution: ``` cute = input() posl = [] temp = str() for i in cute: if i.isupper(): if temp != '': posl.append(temp) temp = '' else: temp = temp + i maxlen = 0 for i in range(len(posl)): posl[i] = ''.join(set(posl[i])) if len(posl[i]) > maxlen: maxlen = len(posl[i]) print(maxlen) ```
instruction
0
8,776
0
17,552
No
output
1
8,776
0
17,553