message
stringlengths
2
23.4k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
129
108k
cluster
float64
6
6
__index_level_0__
int64
258
216k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` #!/usr/bin/env python3 def main(): try: while True: n = int(input()) s = input() a = s.count('A') c = s.count('C') g = s.count('G') t = s.count('T') q = s.count('?') m = max(a, c, g, t) if (m << 2) - a - c - g - t > q: print("===") else: s = s.replace('?', 'A', m - a) s = s.replace('?', 'C', m - c) s = s.replace('?', 'G', m - g) s = s.replace('?', 'T', m - t) assert s.count('A') == s.count('C') == s.count('G') == s.count('T') q = s.count('?') if q & 0x3: print("===") else: for i in range(q >> 2): s = s.replace('?', 'A', 1) s = s.replace('?', 'C', 1) s = s.replace('?', 'G', 1) s = s.replace('?', 'T', 1) print(s) except EOFError: pass main() ```
instruction
0
39,204
6
78,408
Yes
output
1
39,204
6
78,409
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` n=int(input()) a=list(input()) l=[0,0,0,0,0] for i in a: if i=='A': l[0]+=1 elif i=='C': l[1]+=1 elif i=='G': l[2]+=1 elif i=='T': l[3]+=1 else: l[4]+=1 max1=max(l[:-1]) req=0 for i in l[:-1]: req=req+(max1-i) if ((req!=l[-1] and l[-1]!=n) and ((l[-1]-req)%4!=0 or l[-1]<req)) or (l[-1]==n and n%4!=0): print("===") elif l[-1]==n: print('ACGT'*(l[-1]//4)) else: i=1 j=0 while i<=(max1-l[0]): if a[j]=='?': a[j]='A' i=i+1 j=j+1 i=1 while i<=(max1-l[1]): if a[j]=='?': a[j]='C' i=i+1 j=j+1 i=1 while i<=(max1-l[2]): if a[j]=='?': a[j]='G' i=i+1 j=j+1 i=1 while i<=(max1-l[3]): if a[j]=='?': a[j]='T' i=i+1 j=j+1 if l[-1]-req>0: i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='A' i=i+1 j=j+1 i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='C' i=i+1 j=j+1 i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='G' i=i+1 j=j+1 i=0 while i<(l[-1]-req)//4: if a[j]=='?': a[j]='T' i=i+1 j=j+1 for i in a: print(i,end='') ```
instruction
0
39,205
6
78,410
Yes
output
1
39,205
6
78,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` from array import array n = int(input()) g = input() if n % 4 == 0: gnome = array('u', list(g)) thr = n/4 indx_q = [] chk = {'A': 0, 'C': 0, 'G': 0, 'T': 0} for i in range(len(gnome)): if gnome[i] == '?': indx_q.append(i) else: chk[gnome[i]] += 1 if chk['A'] > thr or chk['C'] > thr or chk['G'] > thr or chk['T'] > thr: print('===') else: for key, value in chk.items(): for _ in range(int(thr-value)): gnome[indx_q.pop()] = key print(''.join(list(gnome))) else: print('===') ```
instruction
0
39,206
6
78,412
Yes
output
1
39,206
6
78,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` n = int(input()) if n%4!=0: print("===") exit() s = input() a, t, c, g = 0, 0, 0, 0 for i in s: if i=='G': g+=1 if i=='C': c+=1 if i=='A': a+=1 if i=='T': t+=1 if a>n/4 or t>n/4 or c>n/4 or g>n/4: print("===") exit() a, t, c, g = n/4-a, n/4-t, n/4-c, n/4-g s = list(s) for i in s: if i=='?': if a>0: i='A' a-=1 elif t>0: i='T' t-=1 elif c>0: i='C' c-=1 elif g>0: i='G' g-=1 print(i, end='') print() ```
instruction
0
39,207
6
78,414
Yes
output
1
39,207
6
78,415
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` n=int(input()) t='ACGT' a=[*input()] b=[n//4-a.count(x)for x in t] i=j=0 for j in range(4): while b[j]: if '?' not in a:break a[a.index('?')]=t[j] b[j]-=1 else:continue break print([''.join(a),'===']['?'in a or max(b)>0]) ```
instruction
0
39,208
6
78,416
No
output
1
39,208
6
78,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` n = int(input()) s = input() y = list(s) a = c = g = t = q = 0 for x in s: if x=='A': a+=1 elif x=='C': c+=1 elif x=='G': g+=1 elif x=='T': t+=1 else: q+=1 m = max(a,c,g,t) if m==0: m=1 sum = 0 sum+=(m-a) sum+=(m-c) sum+=(m-g) sum+=(m-t) if(sum>q): print("===") else: for x in range(0,n): if y[x]=='?': if m!=a: y[x]='A' a+=1 elif m!=c: y[x]='C' c+=1 elif m!=g: y[x]='G' g+=1 elif m!=t: y[x]='T' t+=1 else: m+=1 if a==g and g==c and c==t: p = "".join(y) print(p) else: print("===") ```
instruction
0
39,209
6
78,418
No
output
1
39,209
6
78,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` #http://codeforces.com/problemset/problem/747/B def main(n,DNA): uk=DNA.count("?") if uk==0: return DNA if n%4!=0: return "===" A=DNA.count("A") C=DNA.count("C") G=DNA.count("G") T=DNA.count("T") required=max(A,C,G,T,1) missing=(required-A)+(required-G)+(required-C)+(required-T) if(missing>uk): return "===" for i in range(len(DNA)): if(DNA[i]=="?"): if A<required: insert_this="A" A+=1 elif C<required: insert_this="C" C+=1 elif G<required: insert_this="G" G+=1 elif T<required: insert_this="T" T+=1 DNA=DNA[:i]+insert_this+DNA[i+1:] return DNA n=eval(input()) DNA=input() print(main(n,DNA)) ```
instruction
0
39,210
6
78,420
No
output
1
39,210
6
78,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input The first line contains the integer n (4 ≀ n ≀ 255) β€” the length of the genome. The second line contains the string s of length n β€” the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Examples Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === Note In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. Submitted Solution: ``` # Collaborated with no one lengthOfString = int(input()) string = input() aCount = 0 gCount = 0 cCount = 0 tCount = 0 answer = "" impossible = False found = False length4 = lengthOfString/4 for i in range(0, lengthOfString): if(string[i]=="A"): aCount+=1 if(string[i]=="G"): gCount+=1 if(string[i]=="C"): cCount+=1 if(string[i]=="T"): tCount+=1 if(lengthOfString%4!=0 or aCount>length4 or gCount>length4 or cCount>length4 or tCount>length4): impossible = True if(aCount==0 and gCount==0 and cCount == 0 and tCount==0): found = True maxNumberChar = max(aCount,gCount) maxNumberChar = max(maxNumberChar,cCount) maxNumberChar = max(maxNumberChar,tCount) aCount=maxNumberChar-aCount gCount=maxNumberChar-gCount cCount=maxNumberChar-cCount tCount=maxNumberChar-tCount for i in range(0, lengthOfString): if(string[i] == "?"): if(aCount>0): answer+="A" aCount-=1 elif(gCount>0): answer+="G" gCount-=1 elif(cCount>0): answer+="C" cCount-=1 elif(tCount>0): answer+="T" tCount-=1 else: answer+=string[i] if(impossible): print("===") if(found): print("ACGT") else: print(answer) ```
instruction
0
39,211
6
78,422
No
output
1
39,211
6
78,423
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,965
6
79,930
Tags: brute force, implementation Correct Solution: ``` def adjacent(M,i,j,n): count=0 x=[-1,1,0,0] y=[0,0,1,-1] for q in range(4): a=x[q]+i b=y[q]+j if(a>=0 and a<n and b>=0 and b<n): if (M[a][b]=='o'): count+=1 return count n=int(input()) M=[] for i in range(n): s=input() M.append(s) co=True for i in range(n): for j in range(n): if(adjacent(M,i,j,n)%2!=0): co=False break if(not co): break if co: print("YES") else: print("NO") ```
output
1
39,965
6
79,931
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,966
6
79,932
Tags: brute force, implementation Correct Solution: ``` def pad(a): l = [[0 for i in range(len(a[0])+2)]] for i in range(len(a)): c = [0] c+=a[i] c+=[0] l.append(c) l.append([0 for i in range(len(a[0])+2)]) return l n = int(input()) c = [] for i in range(n): s = list(input()) c.append(s) l = pad(c) k = 0 for i in range(1,len(l)-1): for j in range(1,len(l[i])-1): z = 0 if(l[i-1][j]=='o'): z+=1 if(l[i][j-1]=='o'): z+=1 if(l[i+1][j]=='o'): z+=1 if(l[i][j+1]=='o'): z+=1 if(z%2==0): k+=1 if(k==n*n): print('YES') else: print('NO') ```
output
1
39,966
6
79,933
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,967
6
79,934
Tags: brute force, implementation Correct Solution: ``` import sys import math n = int(sys.stdin.readline()) varr = [] for i in range(n): varr.append([x for x in (sys.stdin.readline())[:n]]) for i in range(n): val = 0 for j in range(n): if(j - 1 >= 0): val += 1 if varr[i][j - 1] == 'o' else 0 if(j + 1 < n): val += 1 if varr[i][j + 1] == 'o' else 0 if(i - 1 >= 0): val += 1 if varr[i - 1][j] == 'o' else 0 if(i + 1 < n): val += 1 if varr[i + 1][j] == 'o' else 0 if(val % 2 != 0): print("NO") exit() val = 0 print("YES") ```
output
1
39,967
6
79,935
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,968
6
79,936
Tags: brute force, implementation Correct Solution: ``` n = int(input()) a = [] for i in range(n): a.append(input()[0:n]) for i in range(n): for j in range(n): c = 0 f = 0 if i-1 >= 0 and a[i-1][j] == 'o': c += 1 if j-1 >= 0 and a[i][j-1] == 'o': c += 1 if j+1 < n and a[i][j+1] == 'o': c += 1 if i+1 < n and a[i+1][j] == 'o': c += 1 if c % 2 == 1: f = 1 break if f == 1: break if f == 1: print('NO') else: print('YES') ```
output
1
39,968
6
79,937
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,969
6
79,938
Tags: brute force, implementation Correct Solution: ``` import sys inf = float("inf") # sys.setrecursionlimit(10000000) # abc='abcdefghijklmnopqrstuvwxyz' # abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod, MOD = 1000000007, 998244353 # vow=['a','e','i','o','u'] # dx,dy=[-1,1,0,0],[0,0,1,-1] # import random # from collections import deque, Counter, OrderedDict,defaultdict # from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace # from math import ceil,floor,log,sqrt,factorial,pi # from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n = int(input()) mat = [] for i in range(n): mat.append(list(input())) for i in range(n): for j in range(n): count = 0 if i > 0 and mat[i - 1][j] == 'o': count += 1 if j > 0 and mat[i][j - 1] == 'o': count += 1 if i < (n - 1) and mat[i + 1][j] == 'o': count += 1 if j < (n - 1) and mat[i][j + 1] == 'o': count += 1 if count & 1: print('NO') exit() print('YES') ```
output
1
39,969
6
79,939
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,970
6
79,940
Tags: brute force, implementation Correct Solution: ``` n=int(input()) l1=[] flag=0 for i in range(n): l2=list(input()) l1.append(l2) flag=0 for i in range(n): for j in range(n): c=0 if (i+1)<n: if l1[i+1][j]=='o': c+=1 if (i-1)>-1: if l1[i-1][j]=='o': c+=1 if (j+1)<n: if l1[i][j+1]=='o': c+=1 if (j-1)>-1: if l1[i][j-1]=='o': c+=1 if c%2==1: flag=1 break if flag==1: break if flag==1: print("NO") else : print("YES") ```
output
1
39,970
6
79,941
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,971
6
79,942
Tags: brute force, implementation Correct Solution: ``` n=int(input()) a=[] for i in range(0,n): a.append(input()) s='' for i in range(0,n): s=s+'t' a.append(s) a.insert(0,s) for i in range(0,len(a)): a[i]='t'+a[i]+'t' flag=0 for i in range(1,n+1): c=0 for j in range(1,n+1): if(a[i][j+1]=='o'): c+=1 if(a[i][j-1]=='o'): c+=1 if(a[i+1][j]=='o'): c+=1 if(a[i-1][j]=='o'): c+=1 if c%2==0: flag+=1 if flag==(n*n): print('YES') else: print('NO') ```
output
1
39,971
6
79,943
Provide tags and a correct Python 3 solution for this coding contest problem. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n Γ— n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≀ n ≀ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Examples Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO
instruction
0
39,972
6
79,944
Tags: brute force, implementation Correct Solution: ``` a=int(input()) b=[] for i in range(a): b.append(input()) true='YES' for i in range(a): for j in range(a): total=0 for k in [[1,0],[-1,0],[0,1],[0,-1]]: try: if b[i+k[0]][j+k[1]]=='o' and i+k[0]>-1 and j+k[1]>-1: total+=1 except IndexError: pass if total%2: true='NO' print(true) ```
output
1
39,972
6
79,945
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,981
6
79,962
Tags: math, strings Correct Solution: ``` s = input() lst=[0] for i in range(1,len(s)+1): lst.append(lst[-1]+1/i) x=lst[len(s)] res=0 for i,j in enumerate(s): if j in 'AEIOUY': res+=x x+=lst[len(s)-i-1]-lst[i+1] print(res) ```
output
1
39,981
6
79,963
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,982
6
79,964
Tags: math, strings Correct Solution: ``` def main(): s = input() n = len(s) b = [1.0 / (i + 1) for i in range(n)] d = [(n - i) / (i + 1) for i in range(n)] d = d[::-1] for i in range(1, n): b[i] += b[i - 1] d[i] += d[i - 1] res = 0.0 for i in range(n): if not(s[i] == 'I' or s[i] == 'E' or s[i] == 'A' or s[i] == 'O' or s[i] == 'U' or s[i] == 'Y'): continue z = [i + 1, n - i] z.sort() res += z[0] * (b[z[1] - 2] - b[z[0] - 1] + 1) + d[z[0] - 1] if len(s) == 1 and res > 0: res -= 1 print(res) main() ```
output
1
39,982
6
79,965
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,983
6
79,966
Tags: math, strings Correct Solution: ``` """ Codeforces Contest 289 Div 2 Problem E Author : chaotic_iak Language: Python 3.4.2 """ ################################################### SOLUTION def main(): s = read(0) m = [1 if i in "AEIOUY" else 0 for i in s] n = len(m) m1 = [0] m2 = [0] for i in range(n): m1.append(m1[-1] + 1/(1+i)) m2.append(m2[-1] + 1/(n-i)) mlast = m1[-1] for i in range(1,n+1): m1[i] = m1[i-1]+m1[i] m2[i] = m2[i-1]+m2[i] sm = 0 for i in range(n): sm += m[i] * ((i+1)*mlast - m1[i] - m2[i]) print(sm) #################################################### HELPERS def read(mode=2): # 0: String # 1: List of strings # 2: List of integers inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return list(map(int, inputs.split())) def write(s="\n"): if s is None: s = "" if isinstance(s, list): s = " ".join(map(str, s)) s = str(s) print(s, end="") write(main()) ```
output
1
39,983
6
79,967
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,984
6
79,968
Tags: math, strings Correct Solution: ``` arr = [] for i in input(): arr.append(i) n = len(arr) res = 0 add = [0] * (n + 10) add[n] = 1 / n for i in range(n - 1, 0, -1): add[i] = add[i + 1] + 1 / i for i in range(n): if arr[i] in ['I', 'E', 'A', 'O', 'U', 'Y']: x = min(i, n - i - 1) y = max(i, n - i - 1) res += x + 1 res += (x + 1) * (add[x + 2] - add[y + 1]) res += (n + 1) * add[y + 1] - (n - y) print(res) ```
output
1
39,984
6
79,969
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,985
6
79,970
Tags: math, strings Correct Solution: ``` def sum_vowels(s, i, j): ans = 0 for index in range(i, j + 1): if s[index] in "AEIOUY": ans += 1 return ans if __name__ == "__main__": s = input() n = len(s) ans = 0 num = 0 den_inv = 0 prev_sum = sum_vowels(s, 0, n - 1) for i in range(int(n / 2)): num += prev_sum den_inv = 1 / (i + 1) + 1 / (n - i) ans += num * den_inv if s[i] in "AEIOUY": prev_sum -= 1 if s[n - 1 - i] in "AEIOUY": prev_sum -= 1 if (n % 2 == 1): i = int(n / 2) num += sum_vowels(s, i, i) den_inv = 1 / (i + 1) ans += num * den_inv print("{:.6f}".format(ans)) ```
output
1
39,985
6
79,971
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,986
6
79,972
Tags: math, strings Correct Solution: ``` from itertools import accumulate vowels = set('AIUEOY') s = input() n = len(s) vs = list(accumulate(0 if i == 0 else 1 / i for i in range(n + 1))) r = 0 v = 0 for i in range(n): v += vs[n - i] - vs[i] if s[i] in vowels: r += v print(r) ```
output
1
39,986
6
79,973
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,987
6
79,974
Tags: math, strings Correct Solution: ``` lst = [0] + [_ in "IEAOUY" for _ in input()] n = len(lst) - 1 for _ in range(1, n + 1): lst[_] += lst[_ - 1] ans = 0 s = 0 for l in range(1, n // 2 + 1): s += lst[n - l + 1] - lst[l - 1] ans += s / l + s / (n - l + 1) if n % 2: s += lst[n // 2 + 1] - lst[n // 2] ans += s / (n // 2 + 1) print('%0.9f' % ans) ```
output
1
39,987
6
79,975
Provide tags and a correct Python 3 solution for this coding contest problem. When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word. Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word. More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≀ j). Then the simple prettiness of s is defined by the formula: <image> The prettiness of s equals <image> Find the prettiness of the given song title. We assume that the vowels are I, E, A, O, U, Y. Input The input contains a single string s (1 ≀ |s| ≀ 5Β·105) β€” the title of the song. Output Print the prettiness of the song with the absolute or relative error of at most 10 - 6. Examples Input IEAIAIO Output 28.0000000 Input BYOB Output 5.8333333 Input YISVOWEL Output 17.0500000 Note In the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.
instruction
0
39,988
6
79,976
Tags: math, strings Correct Solution: ``` ss = list(map(lambda c: c in "IEAOUY", input())) n = len(ss) w = [0] * n for i in range(1, n+1): w[0] += 1 / i w[n-1] = w[0] sigma = w[0] for i in range(1, (n - 1) // 2 + 1): sigma -= 1 / i + 1 / (n + 1 - i) w[n-i-1] = w[i] = w[i-1] + sigma ans = 0 for i in range(0, n): ans += ss[i] * w[i] print(ans) ```
output
1
39,988
6
79,977
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,690
6
81,380
Tags: implementation Correct Solution: ``` str = input() ln = len(str) for i in range(ln): str = str.replace('//', '/', 1) i -= 1 if str[len(str) - 1] == '/' and len(str) > 1: str = str[:-1] print(str) ```
output
1
40,690
6
81,381
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,691
6
81,382
Tags: implementation Correct Solution: ``` a=input() b=0 bb=list(a) d=len(bb) for c in range(d-1,0,-1): if(bb[c]=='/'): del bb[c] else: break for c in bb: if c=='/' and b==0: b=b+1 print("/",end="") elif c!='/': b=0 print(c,end="") ```
output
1
40,691
6
81,383
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,692
6
81,384
Tags: implementation Correct Solution: ``` s = input() out = '' slash = 0 for elem in s: if elem=='/': if slash==0: slash=1 out+='/' else: out+=elem slash=0 if len(out)>1: if out[-1]=='/': out = out[:-1] print(out) ```
output
1
40,692
6
81,385
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,693
6
81,386
Tags: implementation Correct Solution: ``` seq=input() b="/"+"/".join(s for s in seq.split("/")if s) print(b) ```
output
1
40,693
6
81,387
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,694
6
81,388
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Jan 3 11:39:52 2020 @author: gajraj """ a = input().split('/') print('/' + '/'.join([i for i in a if i != ''])) ```
output
1
40,694
6
81,389
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,695
6
81,390
Tags: implementation Correct Solution: ``` import sys input = sys.stdin.readline read_tuple = lambda _type: map(_type, input().split(' ')) def solve(): string = list(input().replace('\n', '')) res = [] prev = None for ch in string: if not (ch == '/' and ch == prev): res.append(ch) prev = ch if len(res) > 1 and res[-1] == '/': res.pop() print(''.join(res)) if __name__ == '__main__': solve() ```
output
1
40,695
6
81,391
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,696
6
81,392
Tags: implementation Correct Solution: ``` def main(): #get the input path = input() #iterate over the string for charIndex in range(len(path)-1): #while we have 2 consecutive // and we didnt excedte the limit of the list delete one of them while charIndex + 1 < len(path) and path[charIndex] == '/' and path[charIndex+1] == "/": path = path[:charIndex] + path[charIndex+1:] #delete all // from the end if len(path) != 1 if len(path) != 1: lastChar = len(path) - 1 while path[lastChar] == "/": path = path[:-1] lastChar = len(path) - 1 #print the result print(path) main() ```
output
1
40,696
6
81,393
Provide tags and a correct Python 3 solution for this coding contest problem. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input The first line of the input contains only lowercase Latin letters and character '/' β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output The path in normalized form. Examples Input //usr///local//nginx/sbin Output /usr/local/nginx/sbin
instruction
0
40,697
6
81,394
Tags: implementation Correct Solution: ``` s = input() a = [] p =True a.append("") i = 0 for x in s: if x != '/': p = True a[i] += x else: if p and a[len(a) - 1] != "": a.append("") i += 1 p = False if len(a) == 1 and a[0] == "": print('/') else: res = "" for z in a: if z != "": res += '/' + z print(res) ```
output
1
40,697
6
81,395
Provide tags and a correct Python 3 solution for this coding contest problem. Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy β€” she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. Output Output the single number β€” the number of Alyona's leaves. Examples Input 5 birch yellow maple red birch yellow maple yellow maple green Output 4 Input 3 oak yellow oak yellow oak yellow Output 1
instruction
0
40,751
6
81,502
Tags: implementation Correct Solution: ``` from sys import stdin def main(): n= int(stdin.readline()) t=[] c=[] while n > 0: t.append(stdin.readline().strip()) n-=1 for i in t: if i not in c: c.append(i) print(len(c)) main() ```
output
1
40,751
6
81,503
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,855
6
81,710
Tags: expression parsing, greedy, strings Correct Solution: ``` n = int(input()) s = input() sens = [[]] for i in s: sens[-1].append(i) if i in ['.', '!', '?']: sens.append([]) for i in range(len(sens)): if sens[i]: sens[i] = ''.join(sens[i]) sens[i] = sens[i].strip() if len(sens[i]) > n: print('Impossible') exit(0) sens.pop() i = 0 ans = 0 while i < len(sens): l = len(sens[i]) while i + 1 < len(sens) and l + 1 + len(sens[i + 1]) <= n: i += 1 l += len(sens[i]) + 1 i += 1 ans += 1 print(ans) ```
output
1
40,855
6
81,711
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,856
6
81,712
Tags: expression parsing, greedy, strings Correct Solution: ``` import re n = int(input()) s = input() l = re.split(r"\.|\?|\!", s) r = [len(x.strip())+1 for x in l if len(x.strip())>0] if max(r)>n: print("Impossible") else: cur = -1 ans = 1 for i in r: if cur+i+1<=n: cur=cur+i+1 else: ans=ans+1 cur=i print(ans) ```
output
1
40,856
6
81,713
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,857
6
81,714
Tags: expression parsing, greedy, strings Correct Solution: ``` n=int(input()) q,w,r=[],[],[] for x in input().split('.'):q+=x.split('!') for x in q:w+=x.split('?') for x in w: if x:r+=[x.strip()+'.'] i=0 while i<len(r): if len(r[i])>n:print('Impossible');exit() while i+1<len(r) and len(r[i])+len(r[i+1])+1<=n:r[i]+='.'+r[i+1];r.pop(i+1) i+=1 print(i) # Made By Mostafa_Khaled ```
output
1
40,857
6
81,715
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,858
6
81,716
Tags: expression parsing, greedy, strings Correct Solution: ``` n=int(input()) s=input() S=[] e="" for i in range(len(s)): if(s[i] in ".?!"): e+=s[i] S.append(e) e="" else: e+=s[i] acc=0 ans=0 for item in S: x=len(item) if(acc==0): i=0 while(item[i]==' '): x-=1 i+=1 if(acc+len(item)<=n): acc+=len(item) else: if(acc==0): ans=-1 break else: ans+=1 acc=0 i=0 while(item[i]==' '): x-=1 i+=1 if(x>n): ans=-1 break acc+=x if(ans!=-1 and acc!=0): ans+=1 if(ans!=-1): print(ans) else: print("Impossible") ```
output
1
40,858
6
81,717
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,859
6
81,718
Tags: expression parsing, greedy, strings Correct Solution: ``` class CodeforcesTask70BSolution: def __init__(self): self.result = '' self.n = 0 self.message = '' def read_input(self): self.n = int(input()) self.message = input() def process_task(self): sentences = [] s = '' for x in range(len(self.message)): if self.message[x] in [".", "?", "!"]: s += self.message[x] sentences.append(s) s = '' else: if s or self.message[x] != " ": s += self.message[x] sent_len = [len(s) for s in sentences] if max(sent_len) > self.n: self.result = "Impossible" else: cnt = 1 cl = sent_len[0] for l in sent_len[1:]: if cl + l + 1 <= self.n: cl += l + 1 else: cnt += 1 cl = l self.result = str(cnt) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask70BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
40,859
6
81,719
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,860
6
81,720
Tags: expression parsing, greedy, strings Correct Solution: ``` n = int(input()) text = input() text = text.replace("?", ".").replace("!", ".").split(".") ans = True qnt = 0 acu = n+1 for i in range (len(text)): if (len (text[i]) == 0): continue #text[i] = text[i].strip() #print ("|" + text[i]) if (len (text[i]) > n): ans = False break acu += len (text[i]) + 1 if (acu > n): acu = len (text[i])+1 if (text[i][0] == ' '): acu -= 1 qnt += 1 if (ans == False): print ("Impossible") else: print (qnt) ```
output
1
40,860
6
81,721
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,861
6
81,722
Tags: expression parsing, greedy, strings Correct Solution: ``` import re segment_size = int(input()) sentences = re.findall('\w.*?[.?!]', input()) for sentence in sentences: if len(sentence) > segment_size: print('Impossible') import sys sys.exit() len_current = len(sentences[0]) num_segments = 1 for sentence in sentences[1:]: if len_current + 1 + len(sentence) <= segment_size: len_current += 1 + len(sentence) else: num_segments += 1 len_current = len(sentence) print(num_segments) ```
output
1
40,861
6
81,723
Provide tags and a correct Python 3 solution for this coding contest problem. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
instruction
0
40,862
6
81,724
Tags: expression parsing, greedy, strings Correct Solution: ``` # /******************************************************************************* # * Author : Quantum Of Excellence # * email : quantumofexcellence (at) gmail (dot) com # * copyright : 2014 - 2015 # * date : 6 - 11 - 2015 # * Judge Status : # * Problem Category : # * file name : 70B.py # * version : 1.0 # * # * TERMS OF USE - Write a mail to the author before copying or reusing the content of this file # * seeking our permission for the same. # * Copying/reuse of the below code without the permission of the author is prohibited and illegal. # * # * All rights reserved by Quantum Of Excellence. # ******************************************************************************/ # /******************************************************************************* # * some pointers on the logic/idea - # * # * # *******************************************************************************/ # test cases- #import sys #fi = open("g:\dump\input.in","r") #sys.stdin = fi u=input e=1 while(e): n=int(u()) s=u().replace('?','.').replace('!','.'); f=1 p=len(s)-1 i=0 if('.'!=s[p]):f=0 else: l=s[:p].split('.') q,t,i=0,1,0 while(i<len(l)): r=len(l[i])+1 # if even the individual len(after removing the space at the start) > n, set f=0 if(len( str(l[i]).lstrip() )>n ): f=0 break if(q+r<=n): q+=r else: l[i]=str(l[i]).lstrip() q=len(l[i])+1 t+=1 i+=1 if(f):print(t) else:print("Impossible") e-=1 ```
output
1
40,862
6
81,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n=int(input()) q,w,r=[],[],[] for x in input().split('.'):q+=x.split('!') for x in q:w+=x.split('?') for x in w: if x:r+=[x.strip()+'.'] i=0 while i<len(r): if len(r[i])>n:print('Impossible');exit() while i+1<len(r) and len(r[i])+len(r[i+1])+1<=n:r[i]+='.'+r[i+1];r.pop(i+1) i+=1 print(i) ```
instruction
0
40,863
6
81,726
Yes
output
1
40,863
6
81,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n, text, SMSes, SMS_len = int(input()), input(), 0, 0 for ch in '.?!': text = text.replace(ch, '_') for L in map(len, (' ' + text).split('_')[:-1]): if L > n: print('Impossible') break SMS_len += (L + 1) if SMS_len else L if SMS_len > n: SMSes, SMS_len = SMSes + 1, L else: print(SMSes + 1) ```
instruction
0
40,864
6
81,728
Yes
output
1
40,864
6
81,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n = int(input()) raw = input().split(" ") sentences = [] punctuation = {'?', '.', '!'} curr = '' for idx in raw: curr += idx if(idx[len(idx) - 1] in punctuation): sentences.append(curr) curr = '' else: curr += ' ' bad = False for idx in sentences: if(len(idx) > n): bad = True if(bad): print('Impossible') else: currLen = len(sentences[0]) res = 1 for idx in range(1, len(sentences)): if(len(sentences[idx]) + currLen + 1 > n): res += 1 currLen = len(sentences[idx]) else: currLen += len(sentences[idx]) + 1 print(res) ```
instruction
0
40,865
6
81,730
Yes
output
1
40,865
6
81,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n=int(input()) a=input() b=[] c='' a1=len(a) i=0 while i < len(a): c+=a[i] if a[i] in ['.','?','!']: b.append(len(c)) c='' i+=1 i+=1 d=0 e=0 f=0 for i in b: if e+i+f>n: if e==0 or i>n: print('Impossible') break e=0 f=1 d+=1 else: f+=1 e+=i else: print(d+1) ```
instruction
0
40,866
6
81,732
Yes
output
1
40,866
6
81,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n = int(input()) s = input() s = s.strip() prev = 0 reac = 0 curr = 0 l = len(s) possible = True count = 1 for i in range(l): if s[i] in ['.', '?', '!']: reac = i + 1 curr += 1 if curr - prev > n: prev = reac count += 1 if curr - prev > n: possible = False break if possible: print(count) else: print('Impossible') ```
instruction
0
40,867
6
81,734
No
output
1
40,867
6
81,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` # /******************************************************************************* # * Author : Quantum Of Excellence # * email : quantumofexcellence (at) gmail (dot) com # * copyright : 2014 - 2015 # * date : 6 - 11 - 2015 # * Judge Status : # * Problem Category : # * file name : 70B.py # * version : 1.0 # * # * TERMS OF USE - Write a mail to the author before copying or reusing the content of this file # * seeking our permission for the same. # * Copying/reuse of the below code without the permission of the author is prohibited and illegal. # * # * All rights reserved by Quantum Of Excellence. # ******************************************************************************/ # /******************************************************************************* # * some pointers on the logic/idea - # * Very good question. Simple, greedy, brute-force solution # * # *******************************************************************************/ # test cases- #import sys #fi = open("g:\dump\input.in","r") #sys.stdin = fi u=input n=int(u()) s=u().replace('?','.').replace('!','.'); f=1 p=len(s)-1 i=0 #while(i<p): # if('.'==s[i]): # j=i+1 # while(j<p and ' '==s[j]): # s[j]='' # j+=1 # s. if('.'!=s[p]):f=0 else: l=s[:p].split('.') #t=len(l) #for i in range(t): # if(len(l[i])>n): # f=0 # break q=0 t=1 i=0 while(i<len(l)): r=len(l[i])+1 if(r>n): f=0 break if(q+r<=n): q+=r else: l[i]=str(l[i]).lstrip() q=len(l[i])+1 t+=1 i+=1 if(f):print(t) else:print("Impossible") ```
instruction
0
40,868
6
81,736
No
output
1
40,868
6
81,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n=int(input()) q,w,r=[],[],[] for x in input().split('.'):q+=x.split('!') for x in q:w+=x.split('?') for x in w: if x:r+=[x.strip()+'.'] i=0 while i<len(r): if len(r[i])>=n:print('Impossible');exit() while i+1<len(r) and len(r[i])+len(r[i+1])+1<=n:r[i]+='.'+r[i+1];r.pop(i+1) i+=1 print(i) ```
instruction
0
40,869
6
81,738
No
output
1
40,869
6
81,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split! Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space). The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXT SENTENCE ::= WORD SPACE SENTENCE | WORD END END ::= {'.', '?', '!'} WORD ::= LETTER | LETTER WORD LETTER ::= {'a'..'z', 'A'..'Z'} SPACE ::= ' ' SPACE stands for the symbol of a space. So, how many messages did Fangy send? Input The first line contains an integer n, which is the size of one message (2 ≀ n ≀ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty. Output On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes. Examples Input 25 Hello. I am a little walrus. Output 2 Input 2 How are you? Output Impossible Input 19 Hello! Do you like fish? Why? Output 3 Note Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?". Submitted Solution: ``` n = int(input()) frase = input() end = ['.', '?', '!'] frase = ((frase.replace('!', '?')).replace('?', '.')).split('.') ans = [] ok = True for pal in frase: if len(pal) > 0: if len(pal) > n: ok = False break else: ans.append(pal) if len(ans) == 0 or not ok: print('Impossible') else: print(len(ans)) ```
instruction
0
40,870
6
81,740
No
output
1
40,870
6
81,741
Provide tags and a correct Python 3 solution for this coding contest problem. Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word s. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels. Input The first line contains one integer n (1 ≀ n ≀ 100) β€” the number of letters in word s before the correction. The second line contains a string s consisting of exactly n lowercase Latin letters β€” the word before the correction. Output Output the word s after the correction. Examples Input 5 weird Output werd Input 4 word Output word Input 5 aaeaa Output a Note Explanations of the examples: 1. There is only one replace: weird <image> werd; 2. No replace needed since there are no two consecutive vowels; 3. aaeaa <image> aeaa <image> aaa <image> aa <image> a.
instruction
0
40,926
6
81,852
Tags: implementation Correct Solution: ``` n=int(input()) s=input() i=0 while i<len(s): if s[i]=='a' or s[i]=='i' or s[i]=='u' or s[i]=='e' or s[i]=='o' or s[i]=='y': j=i while j<len(s) and (s[j]=='a' or s[j]=='i' or s[j]=='u' or s[j]=='e' or s[j]=='o' or s[j]=='y'): j+=1 s=s[:i+1]+s[j:] i+=1 print(s) ```
output
1
40,926
6
81,853