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
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,010
6
206,020
Tags: dp Correct Solution: ``` m=1000000007 s=input() if(s.count('w') or s.count('m')): print(0) else: dp=[1,1] n=len(s) for i in range(1,n): if(s[i]==s[i-1] and (s[i]=='u' or s[i]=='n')): dp.append((dp[i]+dp[i-1])%m) else: dp.append(dp[i]%m) #print(dp) print(dp[-1]%m) ```
output
1
103,010
6
206,021
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,011
6
206,022
Tags: dp Correct Solution: ``` f = [1, 2] const = 10 ** 9 + 1 s = input() if "m" in s or "w" in s: print(0) else: ans = 1 const = 10 ** 9 + 7 check = False count = 0 if s[0] == "u" or s[0] == "n": check = True count = 1 for i in range(1, len(s)): f.append((f[-1] + f[-2]) % const) if s[i] == s[i - 1]: count += 1 elif check: ans = (ans * f[count - 1]) % const count = 0 check = False if s[i] == "u": count = 1 check = "u" elif s[i] == "n": count = 1 check = "n" else: check = False count = 0 elif s[i] == "u": count = 1 check = "u" elif s[i] == "n": count = 1 check = "n" else: check = False count = 0 if check: ans = (ans * f[count - 1]) % const print(ans) ```
output
1
103,011
6
206,023
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,012
6
206,024
Tags: dp Correct Solution: ``` # import sys # input = sys.stdin.readline s = input() n = len(s) A = [] mod = 10**9+7 L = [0,1,2] for i in range(10**5+3): L.append((L[-1]+L[-2]) % mod) nn=0 uu=0 for i in range(n): if s[i] == "n": if nn == 0: nn = 1 A.append(1) else: A[-1] += 1 else: nn = 0 if s[i] == "u": if uu == 0: uu = 1 A.append(1) else: A[-1] += 1 else: uu = 0 ans = 1 for i in range(len(A)): ans = (ans * L[A[i]]) % mod if s.count("m") > 0 or s.count("w") > 0: ans = 0 print(ans) ```
output
1
103,012
6
206,025
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,013
6
206,026
Tags: dp Correct Solution: ``` mod = 10**9+7 def cmb(n, r, mod=mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod NN = 10**5 # 使うデータによって変える g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, NN + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) import sys input = sys.stdin.readline S = input().rstrip() N = len(S) pre = '-1' ans = 1 A = [] c = 0 for s in S: if s == 'm' or s == 'w': ans = 0 break if s == 'n': if pre == 'n': c += 1 else: if c > 1: A.append(c) c = 1 elif s == 'u': if pre == 'u': c += 1 else: if c > 1: A.append(c) c = 1 else: if c > 1: A.append(c) c = 0 pre = s A.append(c) if ans == 0: print(0) else: for a in A: tmp = 1 n, m = a-1, 1 while n >= m: tmp += cmb(n, m) tmp %= mod n -= 1 m += 1 ans = ans * tmp % mod print(ans) ```
output
1
103,013
6
206,027
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,014
6
206,028
Tags: dp Correct Solution: ``` s = input() s_ct = 0 n_ct = 0 ans = [] dp = [0 for _ in range(len(s)+5)] dp[0] = 1 dp[1] = 1 dp[2] = 2 a = 1 for i in range(3,len(dp)): dp[i] = (dp[i-1]+dp[i-2])%(10**9+7 ) for i in range(len(s)): if(s[i]=='m'): a = 0 if(s[i]=='w'): a=0 if(s[i]=='u'): if n_ct: ans.append(n_ct) n_ct = 0 s_ct+=1 elif s[i] == 'n': if s_ct: ans.append(s_ct) s_ct = 0 n_ct+=1 else: if s_ct: ans.append(s_ct) s_ct = 0 if n_ct: ans.append(n_ct) n_ct = 0 if s_ct: ans.append(s_ct) s_ct = 0 if n_ct: ans.append(n_ct) n_ct = 0 for i in ans: a = (a*dp[i])%(10**9 + 7) print(a) ```
output
1
103,014
6
206,029
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,015
6
206,030
Tags: dp Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): import bisect import math # import itertools # import heapq # from queue import PriorityQueue, LifoQueue, SimpleQueue # import sys.stdout.flush() use for interactive problems alpha = 'abcdefghijklmnopqrstuvwxyz' ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' inf = 1e17 mod = 10 ** 9 + 7 # Max = 10**6 # primes = [] # prime = [True for i in range(10**6+1)] # p = 2 # while (p * p <= Max+1): # # # If prime[p] is not # # changed, then it is a prime # if (prime[p] == True): # # # Update all multiples of p # for i in range(p * p, Max+1, p): # prime[i] = False # p += 1 # # for p in range(2, Max+1): # if prime[p]: # primes.append(p) def factorial(n): f = 1 for i in range(1, n + 1): f = (f * i) % mod # Now f never can # exceed 10^9+7 return f def ncr(n, r): # initialize numerator # and denominator num = den = 1 for i in range(r): num = (num * (n - i)) % mod den = (den * (i + 1)) % mod return (num * pow(den, mod - 2, mod)) % mod def solve(s): if 'w' in s or 'm' in s: return 0 dp = [1,1] for i in range(1,len(s)) : if s[i] == s[i-1] == 'u' or s[i] == s[i-1] == 'n': dp.append((dp[-1]+dp[-2])%mod) else: dp.append(dp[-1]) return dp[-1] % mod pass t = 1#int(input()) ans = [] for _ in range(1): # n = int(input()) # n,k = map(int, input().split()) # arr = [int(x) for x in input().split()] # queries = [int(x) for x in input().split()] # arr = list(input()) s = input() # t = input() # customers = [] # for i in range(n): # customers.append([int(x) for x in input().split()]) # k = int(input()) # s = [int(x) for x in input().split()] # qs = [] # for j in range(q): # r,c = map(int,input().split()) # qs.append((r,c)) ans.append(solve(s)) for j in range(len(ans)): #print('Case #' + str(j + 1) + ": " + str(ans[j])) print(ans[j]) pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
103,015
6
206,031
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,016
6
206,032
Tags: dp Correct Solution: ``` s = input() L = [0] * (len(s) + 1) inf = 1000000007 L[0] = 1 L[1] = 1 for i in range(1, len(s)): if s[i] == 'm' or s[i] == 'w': break if s[i] == 'u': if s[i - 1] == 'u': L[i + 1] = (L[i] + L[i - 1]) % inf else: L[i + 1] = L[i] elif s[i] == 'n': if s[i - 1] == 'n': L[i + 1] = (L[i] + L[i - 1]) % inf else: L[i + 1] = L[i] else: L[i + 1] = L[i] if s[0] == 'm' or s[0] == 'w': L[len(s)] = 0 print(L[len(s)]) ```
output
1
103,016
6
206,033
Provide tags and a correct Python 3 solution for this coding contest problem. Constanze is the smartest girl in her village but she has bad eyesight. One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses. However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did. The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper. The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense. But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got. But since this number can be quite large, tell me instead its remainder when divided by 10^9+7. If there are no strings that Constanze's machine would've turned into the message I got, then print 0. Input Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters. Output Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7. Examples Input ouuokarinn Output 4 Input banana Output 1 Input nnn Output 3 Input amanda Output 0 Note For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn". For the second example, there is only one: "banana". For the third example, the candidate strings are the following: "nm", "mn" and "nnn". For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.
instruction
0
103,017
6
206,034
Tags: dp Correct Solution: ``` import sys # def recur(pre,p,pos,maxx,temp): # if pos == len(pre): # maxx[0] = max(maxx[0],temp) # return # for i in range(0,p+1): # if i < len(pre[pos]) : # temp = temp + pre[pos][i] # recur(pre,p-i,pos+1,maxx,temp) # temp = temp - pre[pos][i] RI = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() # for _ in range(int(ri())): mod = 10**9+7 st = ri() dp = [0]*2 dp[1] = 1 for i in range(len(st)): if st[i] == 'm' or st[i] == 'w': dp[1] = 0 break if st[i] == 'n' and st[i-1] == 'n': temp = dp[1] dp[1] = (dp[0]+dp[1])%mod dp[0] = temp elif st[i] == 'u' and st[i-1] == 'u': temp = dp[1] dp[1] = (dp[0]+dp[1])%mod dp[0] = temp else: dp[0] = dp[1] print(dp[1]) ```
output
1
103,017
6
206,035
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,966
6
207,932
Tags: combinatorics, dp Correct Solution: ``` from functools import reduce n = int(input()) s1, s2 = str(input()), str(input()) print((10 ** sum([(s1[i] == '?') + (s2[i] == '?') for i in range(n)]) - (not reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) > ord(s2[i]) for i in range(n)], False)) * reduce(lambda x, y: (x * y) % 1000000007, [55 if s1[i] == '?' and s2[i] == '?' else (ord(s2[i]) - ord('0') + 1) if s1[i] == '?' else (10 - ord(s1[i]) + ord('0')) if s2[i] == '?' else 1 for i in range(n)], 1) - (not reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) < ord(s2[i]) for i in range(n)], False)) * reduce(lambda x, y: (x * y) % 1000000007, [55 if s1[i] == '?' and s2[i] == '?' else (10 - ord(s2[i]) + ord('0')) if s1[i] == '?' else (ord(s1[i]) - ord('0')) + 1 if s2[i] == '?' else 1 for i in range(n)], 1) + (not reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) < ord(s2[i]) for i in range(n)], False) and not reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) > ord(s2[i]) for i in range(n)], False)) * reduce(lambda x, y: (x * y) % 1000000007, [10 if s1[i] == '?' and s2[i] == '?' else 1 for i in range(n)], 1)) % 1000000007) ```
output
1
103,966
6
207,933
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,967
6
207,934
Tags: combinatorics, dp Correct Solution: ``` n = int(input()) C = 10**9+7 a = input() s = input() d = [[0, 0, 0, 1]] for q in range(n): d.append(d[-1][::]) if a[q] != '?' and s[q] != '?': if int(a[q]) < int(s[q]): d[-1][1] = d[-1][3] = 0 d[-1][0] += d[-2][3] d[-1][2] += d[-2][1] elif int(a[q]) > int(s[q]): d[-1][0] = d[-1][3] = 0 d[-1][1] += d[-2][3] d[-1][2] += d[-2][0] elif s[q] != '?': d[-1][2] *= 10 d[-1][0] += d[-2][3] d[-1][1] += d[-2][3] d[-1][0] *= int(s[q])+1 d[-1][1] *= 10-int(s[q]) d[-1][0] -= d[-2][3] d[-1][1] -= d[-2][3] d[-1][2] += d[-2][0]*(9-int(s[q]))+d[-2][1]*int(s[q]) elif a[q] != '?': d[-1][2] *= 10 d[-1][0] += d[-2][3] d[-1][1] += d[-2][3] d[-1][1] *= int(a[q]) + 1 d[-1][0] *= 10 - int(a[q]) d[-1][0] -= d[-2][3] d[-1][1] -= d[-2][3] d[-1][2] += d[-2][1] * (9 - int(a[q])) + d[-2][0] * int(a[q]) else: d[-1][3] *= 10 d[-1][2] *= 100 d[-1][0] *= 55 d[-1][1] *= 55 d[-1][0] += d[-2][3]*45 d[-1][1] += d[-2][3]*45 d[-1][2] += d[-2][0]*45+d[-2][1]*45 d[-1][0] %= C d[-1][1] %= C d[-1][2] %= C d[-1][3] %= C print(d[-1][2]) ```
output
1
103,967
6
207,935
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,968
6
207,936
Tags: combinatorics, dp Correct Solution: ``` from functools import reduce n = int(input()) s1, s2 = str(input()), str(input()) b1 = reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) < ord(s2[i]) for i in range(n)], False) b2 = reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) > ord(s2[i]) for i in range(n)], False) s = sum([(s1[i] == '?') + (s2[i] == '?') for i in range(n)]) ans1 = reduce(lambda x, y: (x * y) % 1000000007, [55 if s1[i] == '?' and s2[i] == '?' else (ord(s2[i]) - ord('0') + 1) if s1[i] == '?' else (10 - ord(s1[i]) + ord('0')) if s2[i] == '?' else 1 for i in range(n)], 1) ans2 = reduce(lambda x, y: (x * y) % 1000000007, [55 if s1[i] == '?' and s2[i] == '?' else (10 - ord(s2[i]) + ord('0')) if s1[i] == '?' else (ord(s1[i]) - ord('0')) + 1 if s2[i] == '?' else 1 for i in range(n)], 1) ans3 = reduce(lambda x, y: (x * y) % 1000000007, [10 if s1[i] == '?' and s2[i] == '?' else 1 for i in range(n)], 1) print((10 ** s - (not b2) * ans1 - (not b1) * ans2 + (not b1 and not b2) * ans3) % 1000000007) # Made By Mostafa_Khaled ```
output
1
103,968
6
207,937
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,969
6
207,938
Tags: combinatorics, dp Correct Solution: ``` #!/usr/bin/python3 def build(n, s, t): ans = 1 for i in range(n): if s[i] == '?' and t[i] == '?': ans = (55 * ans) % (10 ** 9 + 7) elif s[i] == '?': ans = ((ord(t[i]) - ord('0') + 1) * ans) % (10 ** 9 + 7) elif t[i] == '?': ans = ((ord('9') - ord(s[i]) + 1) * ans) % (10 ** 9 + 7) return ans n = int(input()) s = input() t = input() sltt = True tlts = True qm = 0 cqm = 0 for i in range(n): if t[i] == '?': qm += 1 if s[i] == '?': qm += 1 if t[i] == '?' and s[i] == '?': cqm += 1 if t[i] == '?' or s[i] == '?': continue if ord(s[i]) < ord(t[i]): tlts = False if ord(t[i]) < ord(s[i]): sltt = False if not sltt and not tlts: print(pow(10, qm, 10 ** 9 + 7)) elif sltt and tlts: print((pow(10, qm, 10 ** 9 + 7) - build(n, s, t) - build(n, t, s) + pow(10, cqm, 10 ** 9 + 7)) % (10 ** 9 + 7)) elif sltt: print((pow(10, qm, 10 ** 9 + 7) - build(n, s, t)) % (10 ** 9 + 7)) else: print((pow(10, qm, 10 ** 9 + 7) - build(n, t, s)) % (10 ** 9 + 7)) ```
output
1
103,969
6
207,939
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,970
6
207,940
Tags: combinatorics, dp Correct Solution: ``` import sys mod = 1000000007 n = int(input()) s1 = input() s2 = input() flag1 = 0 flag2 = 0 for i in range(n): if s1[i] != "?" and s2[i] != "?" and s1[i] > s2[i]: flag1 = 1 if s1[i] != "?" and s2[i] != "?" and s1[i] < s2[i]: flag2 = 1 if flag1 and flag2: ans = 1 for i in range(n): if s1[i] == "?": ans *= 10 ans %= mod for i in range(n): if s2[i] == "?": ans *= 10 ans %= mod print (ans % mod) sys.exit(0) if not(flag1) and not(flag2): ans1 = 1 ans2 = 1 x = 0 al = 1 for i in range(n): if s1[i] == "?" and s2[i] == "?": x += 1 for i in range(n): if s1[i] == "?": al *= 10 al %= mod for i in range(n): if s2[i] == "?": al *= 10 al %= mod for i in range(n): if s1[i] == "?" and s2[i] == "?": ans1 *= 55 ans1 %= mod elif s1[i] == "?": ans1 *= 10 - int(s2[i]) ans1 %= mod elif s2[i] == "?": ans1 *= int(s1[i]) + 1 ans1 %= mod s1, s2 = s2, s1 for i in range(n): if s1[i] == "?" and s2[i] == "?": ans2 *= 55 ans2 %= mod elif s1[i] == "?": ans2 *= 10 - int(s2[i]) ans2 %= mod elif s2[i] == "?": ans2 *= int(s1[i]) + 1 ans2 %= mod y = 1 for i in range(x): y *= 10 y %= mod print ((al - (ans1 + ans2 - y)) % mod) sys.exit(0) if flag2: s1, s2 = s2, s1 ans = 1 al = 1 for i in range(n): if s1[i] == "?": al *= 10 al %= mod for i in range(n): if s2[i] == "?": al *= 10 al %= mod for i in range(n): if s1[i] == "?" and s2[i] == "?": ans *= 55 ans %= mod elif s1[i] == "?": ans *= 10 - int(s2[i]) ans %= mod elif s2[i] == "?": ans *= int(s1[i]) + 1 ans %= mod print ((al - ans) % mod) ```
output
1
103,970
6
207,941
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,971
6
207,942
Tags: combinatorics, dp Correct Solution: ``` from functools import reduce n = int(input()) s1, s2 = str(input()), str(input()) b1 = reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) < ord(s2[i]) for i in range(n)], False) b2 = reduce(lambda x, y: x or y, [s1[i] != '?' and s2[i] != '?' and ord(s1[i]) > ord(s2[i]) for i in range(n)], False) s = sum([(s1[i] == '?') + (s2[i] == '?') for i in range(n)]) ans1 = reduce(lambda x, y: (x * y) % 1000000007, [55 if s1[i] == '?' and s2[i] == '?' else (ord(s2[i]) - ord('0') + 1) if s1[i] == '?' else (10 - ord(s1[i]) + ord('0')) if s2[i] == '?' else 1 for i in range(n)], 1) ans2 = reduce(lambda x, y: (x * y) % 1000000007, [55 if s1[i] == '?' and s2[i] == '?' else (10 - ord(s2[i]) + ord('0')) if s1[i] == '?' else (ord(s1[i]) - ord('0')) + 1 if s2[i] == '?' else 1 for i in range(n)], 1) ans3 = reduce(lambda x, y: (x * y) % 1000000007, [10 if s1[i] == '?' and s2[i] == '?' else 1 for i in range(n)], 1) print((10 ** s - (not b2) * ans1 - (not b1) * ans2 + (not b1 and not b2) * ans3) % 1000000007) ```
output
1
103,971
6
207,943
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,972
6
207,944
Tags: combinatorics, dp Correct Solution: ``` from functools import reduce n, s1, s2, f1, f2 = int(input()), str(input()), str(input()), lambda x: reduce((lambda a, b: (a * b) % 1000000007), x, 1), lambda x: reduce((lambda a, b: a or b), x, False) print((10 ** sum([(s1[i] == '?') + (s2[i] == '?') for i in range(n)]) - (not f2([s1[i] != '?' and s2[i] != '?' and ord(s1[i]) > ord(s2[i]) for i in range(n)])) * f1([55 if s1[i] == '?' and s2[i] == '?' else (ord(s2[i]) - ord('0') + 1) if s1[i] == '?' else (10 - ord(s1[i]) + ord('0')) if s2[i] == '?' else 1 for i in range(n)]) - (not f2([s1[i] != '?' and s2[i] != '?' and ord(s1[i]) < ord(s2[i]) for i in range(n)])) * f1([55 if s1[i] == '?' and s2[i] == '?' else (10 - ord(s2[i]) + ord('0')) if s1[i] == '?' else (ord(s1[i]) - ord('0')) + 1 if s2[i] == '?' else 1 for i in range(n)]) + (not f2([s1[i] != '?' and s2[i] != '?' and ord(s1[i]) < ord(s2[i]) for i in range(n)]) and not f2([s1[i] != '?' and s2[i] != '?' and ord(s1[i]) > ord(s2[i]) for i in range(n)])) * f1([10 if s1[i] == '?' and s2[i] == '?' else 1 for i in range(n)])) % 1000000007) ```
output
1
103,972
6
207,945
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w. A string's template is a string that consists of digits and question marks ("?"). Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers. Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7). Input The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format. Output In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7). Examples Input 2 90 09 Output 1 Input 2 11 55 Output 0 Input 5 ????? ????? Output 993531194 Note The first test contains no question marks and both strings are incomparable, so the answer is 1. The second test has no question marks, but the given strings are comparable, so the answer is 0.
instruction
0
103,973
6
207,946
Tags: combinatorics, dp Correct Solution: ``` n = int(input()) a = input() b = input() mod = int(1e9+7) x, y, z = 1, 1, 1 for i in range(n): if a[i] == '?' and b[i] == '?': x = (x * 55) % mod y = (y * 55) % mod z = (z * 10) % mod elif a[i] == '?': x = (x * (10 - int(b[i]))) % mod y = (y * (int(b[i]) + 1)) % mod elif b[i] == '?': x = (x * (int(a[i]) + 1)) % mod y = (y * (10 - int(a[i]))) % mod else: if int(a[i]) < int(b[i]): x = 0 if int(a[i]) > int(b[i]): y = 0 if a[i] != b[i]: z = 0 res = pow(10, a.count('?') + b.count('?'), mod) print((res - x - y + z) % mod) ```
output
1
103,973
6
207,947
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,704
6
211,408
Tags: implementation, strings Correct Solution: ``` s = str(input()) ll = sum(map(str.islower, s)) ul = sum(map(str.isupper, s)) if ul > ll: print(s.upper()) else: print(s.lower()) ```
output
1
105,704
6
211,409
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,705
6
211,410
Tags: implementation, strings Correct Solution: ``` a = input() l = len(a) count = 0 for i in a: if i.isupper(): count += 1 if count <= int(l/2): print(a.lower()) else: print(a.upper()) ```
output
1
105,705
6
211,411
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,706
6
211,412
Tags: implementation, strings Correct Solution: ``` s=list(input()) p="" l=[] x=[] for i in range(len(s)): if s[i]==s[i].upper(): l.append(s[i]) elif s[i]==s[i].lower(): x.append(s[i]) if len(l)>len(x): print(p.join(s).upper()) else: print(p.join(s).lower()) ```
output
1
105,706
6
211,413
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,707
6
211,414
Tags: implementation, strings Correct Solution: ``` word = input() uppercases = 0 lowercases = 0 for letter in word: if letter.upper() == letter: uppercases += 1 else: lowercases += 1 if uppercases > lowercases: print(word.upper()) else: print(word.lower()) ```
output
1
105,707
6
211,415
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,708
6
211,416
Tags: implementation, strings Correct Solution: ``` s=input();print(s.upper() if sum(1 for c in s if c.isupper())>sum(1 for c in s if c.islower())else s.lower()) ```
output
1
105,708
6
211,417
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,709
6
211,418
Tags: implementation, strings Correct Solution: ``` w = input() upp = 0 low = 0 for i in w: if i.isupper() == True: upp += 1 else: low += 1 if upp <= low: print(w.lower()) else: print(w.upper()) ```
output
1
105,709
6
211,419
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,710
6
211,420
Tags: implementation, strings Correct Solution: ``` n=input() l=0 u=0 for i in range(len(n)): if n[i].islower(): l+=1 elif n[i].isupper(): u+=1 if l>u: print(n.lower()) elif l<u: print(n.upper()) else: print(n.lower()) ```
output
1
105,710
6
211,421
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Examples Input HoUse Output house Input ViP Output VIP Input maTRIx Output matrix
instruction
0
105,711
6
211,422
Tags: implementation, strings Correct Solution: ``` word = str(input()) sumUppercaseLetters = 0 sumLowercaseLetters = 0 for i in word: if i.isupper(): sumUppercaseLetters += 1 elif i.islower(): sumLowercaseLetters += 1 if sumUppercaseLetters > sumLowercaseLetters: print(word.upper()) elif sumLowercaseLetters > sumUppercaseLetters: print(word.lower()) else: print(word.lower()) ```
output
1
105,711
6
211,423
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,508
6
213,016
Tags: expression parsing, implementation Correct Solution: ``` s = input() i = s[1:].find('at') + 1 s = s[:i] + '@' + s[i+2:] while True: i = s[1:].find('dot') if i == -1: break i += 1 if i+3 == len(s): break s = s[:i] + '.' + s[i+3:] print(s) ```
output
1
106,508
6
213,017
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,509
6
213,018
Tags: expression parsing, implementation Correct Solution: ``` s=input() at=s.find('at',1) s=s[:at]+'@'+s[at+2:] pos=1 while 1: ns='' dot=s.find('dot',pos,-1) if dot==-1: break ns+=s[:dot] ns+='.' pos=dot+1 ns+=s[dot+3:] s=ns print(s) ```
output
1
106,509
6
213,019
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,510
6
213,020
Tags: expression parsing, implementation Correct Solution: ``` s=input() if s[:3]=="dot" or s[:2]=="at" or s[len(s)-2:]=="at" or s[len(s)-3:]=="dot": if s[:3]=="dot": t=s[3:] a=t.split('dot') l=".".join(a) b=l.find("at") o=l[:b]+"@"+l[b+2:] q="dot"+o if q[-1]==".": a=q[:len(q)-1] s=a+"dot" elif q[-1]=="@": a=q[:len(q)-1] s=a+"at" else: s=q if s[:2]=="at": t=s[2:] a=t.split('dot') l=".".join(a) b=l.find('at') o=l[:b]+"@"+l[b+2:] q="at"+o if q[-1]==".": a=q[:len(q)-1] s=a+"dot" elif q[-1]=="@": a=q[:len(q)-1] s=a+"at" else: s=q if s[len(s)-3:]=="dot" and s[:3]!="dot" and s[:2]!="at": t=s[:len(s)-3] a=t.split('dot') l=".".join(a) b=l.find('at') q=l[:b]+"@"+l[b+2:] s=q+"dot" if s[len(s)-2:]=="at" and s[:3]!="dot" and s[:2]!="at": t=s[:len(s)-2] a=t.split('dot') l=".".join(a) b=l.find('at') q=l[:b]+"@"+l[b+2:] s=q+"at" print(s) else: a=s.split('dot') l=".".join(a) b=l.find('at') q=l[:b]+"@"+l[b+2:] print(q) ```
output
1
106,510
6
213,021
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,511
6
213,022
Tags: expression parsing, implementation Correct Solution: ``` from sys import stdin input=stdin.readline voiceEmail = input() dotReplaced = voiceEmail[1:len(voiceEmail) - 2].replace('dot', '.') voiceEmail = voiceEmail[0] + dotReplaced + voiceEmail[len(voiceEmail) - 2:] atReplaced = voiceEmail[1:len(voiceEmail) - 2].replace('at', '@', 1) voiceEmail = voiceEmail[0] + atReplaced + voiceEmail[len(voiceEmail) - 2:] print(voiceEmail) ```
output
1
106,511
6
213,023
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,512
6
213,024
Tags: expression parsing, implementation Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') s = input().rstrip() ans = s[0] suf = s[-1] s = s[1:-1] at_flag = 0 while s: if s[:3] == 'dot': ans += '.' s = s[3:] elif not at_flag and s[:2] == 'at': ans += '@' at_flag = 1 s = s[2:] else: ans += s[0] s = s[1:] print(ans + suf) ```
output
1
106,512
6
213,025
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,513
6
213,026
Tags: expression parsing, implementation Correct Solution: ``` import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri=lambda:int(rln()) ris=lambda:list(map(int,rfs())) rln=sys.stdin.readline rl=lambda:rln().rstrip('\n') rfs=lambda:rln().split() cat=''.join catn='\n'.join mod=1000000007 d4=[(0,-1),(1,0),(0,1),(-1,0)] d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)] ######################################################################## def solve(): s=rl() t=s[1:-1] t=t.replace('at','@',1) t=t.replace('dot','.') return s[0]+t+s[-1] print(solve()) ```
output
1
106,513
6
213,027
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,514
6
213,028
Tags: expression parsing, implementation Correct Solution: ``` def main(): desc = input() chunk = desc[1:-1] chunk = chunk.replace("at", "@", 1) chunk = chunk.replace("dot", ".") print(desc[0] + chunk + desc[-1]) main() ```
output
1
106,514
6
213,029
Provide tags and a correct Python 3 solution for this coding contest problem. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t
instruction
0
106,515
6
213,030
Tags: expression parsing, implementation Correct Solution: ``` #!/bin/python email = input() m = {'@' : 'at', '.' : 'dot'} replaced = '' addAtLast = False sep = [] def removeFirstLast(ch): global replaced, addAtLast,sep, email if m[ch] in email: if sep[0] == '': del sep[0] replaced = m[ch] + sep[0] else: replaced = sep[0] if len(sep)>0: if sep[-1] == '': del sep[-1] addAtLast = True else: replaced = sep[0] def addLast(ch) : global replaced, addAtLast if addAtLast : replaced += m[ch] #Code Starts from here : #First replacing all the dots sep = email.split(m['.']) removeFirstLast('.') for word in sep [1:]: replaced += '.' + word addLast('.') #Next replacing all the ats email = replaced replaced = '' addAtLast = False sep = email.split(m['@']) removeFirstLast('@') #If there are more than 1 @ : count = 0 for word in sep[1:] : if count<1 : replaced+= '@' + word count+=1 else: replaced+= 'at' + word addLast('@') print (replaced) ```
output
1
106,515
6
213,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` s = input() # don't start at first character! # replace first occurance of 'at' with '@' s = s[0] + s[1:].replace("at", "@", 1) # replace the last 'dot' with '.' s = s[0] + s[1:-1].replace("dot", ".") + s[-1] print(s) ```
instruction
0
106,516
6
213,032
Yes
output
1
106,516
6
213,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` """ #If FastIO not needed, use this and don't forget to strip #import sys, math #input = sys.stdin.readline """ import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right import time from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: self.os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") from collections import defaultdict as dd, deque as dq, Counter as dc import math, string start_time = time.time() def getInts(): return [int(s) for s in input().split()] def getInt(): return int(input()) def getStrs(): return [s for s in input().split()] def getStr(): return input() def listStr(): return list(input()) def getMat(n): return [getInts() for _ in range(n)] def isInt(s): return '0' <= s[0] <= '9' MOD = 998244353 """ """ def solve(): S = getStr() N = len(S) ans = '' at_flag = True i = 0 while i < N: if S[i:i+3] == 'dot' and i > 0 and i < N-3: ans += '.' i += 3 elif S[i:i+2] == 'at' and at_flag and i > 0: ans += '@' at_flag = False i += 2 else: ans += S[i] i += 1 return ans #for _ in range(getInt()): print(solve()) #solve() #print(time.time()-start_time)á ```
instruction
0
106,517
6
213,034
Yes
output
1
106,517
6
213,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` m = input() m = m.replace("at","@") m = m.replace("dot",".") if m[0] == ".": m = "dot" + m[1:] if m[-1] == ".": m = m[:-1] + "dot" if m[0] == "@": m = "at" + m[1:] if m.count("@") > 1: n = m.find("@") m = m[:n+1] + m[n+1:].replace("@","at") print(m) ```
instruction
0
106,518
6
213,036
Yes
output
1
106,518
6
213,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` s = str(input()) s = s.replace("at","@") s = s.replace("dot",".") if s[0]==".": s = "dot"+s[1:] if s[0]=="@": s = "at"+s[1:] if s[len(s)-1]==".": s = s[:len(s)-1]+"dot" if s[len(s)-1]=="@": s = s[:len(s)-1]+"at" print(s) ```
instruction
0
106,520
6
213,040
No
output
1
106,520
6
213,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` m = input() m = m.replace("at","@") m = m.replace("dot",".") if m[0] == ".": m = "dot" + m[1:] if m[-1] == ".": m = m[:-1] + "dot" if m.count("@") > 1: n = m.find("@") m = m[:n+1] + m[n+1:].replace("@","at") print(m) ```
instruction
0
106,521
6
213,042
No
output
1
106,521
6
213,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` t = input() t = t.replace("dot", '.') t = t.replace("at", '@') if t.find('.')==0: t = t.replace(".", "dot", 1) if t.find('@')==0: t = t.replace("@", "at", 1) if t.rfind('.')==len(t)-1: t = t[0:len(t)-2] t += "dot" if t.rfind('@')==len(t)-1: t = t[0:len(t)-1] t += "at" print(t) ```
instruction
0
106,522
6
213,044
No
output
1
106,522
6
213,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots. You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result. Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at. Input The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols. Output Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages). In the ASCII table the symbols go in this order: . @ ab...z Examples Input vasyaatgmaildotcom Output vasya@gmail.com Input dotdotdotatdotdotat Output dot..@..at Input aatt Output a@t Submitted Solution: ``` s=input() i=s.count("at") j=s.count("dot") if( i != 1): index=s.find("at") index=index+3 s1=s[0:index] s2=s[index:] s2=s2.replace("at","@",i-1) s=s1+s2 else: s=s.replace("at","@") if(j !=1): ind=s.find("dot") ind=ind+4 s3=s[0:ind] s4=s[ind:] s4=s4.replace("dot",".") s=s3+s4 else: s=s.replace("dot",".") print(s) ```
instruction
0
106,523
6
213,046
No
output
1
106,523
6
213,047
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,153
6
214,306
Tags: implementation, strings Correct Solution: ``` s=str(input()) if (s[0] == s[0].lower() and s[1:] == s[1:].upper()): print(s[0].upper()+s[1:].lower()) elif (s == s.upper()): print(s.lower()) else: print(s) ```
output
1
107,153
6
214,307
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,154
6
214,308
Tags: implementation, strings Correct Solution: ``` a = input() if a.isupper() or a[1:].isupper() or (len(a)==1 and a.islower()): a = list(a) for i in range(len(a)): if a[i].isupper(): a[i] = a[i].lower() else: a[i] = a[i].upper() print("".join(a)) ```
output
1
107,154
6
214,309
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,155
6
214,310
Tags: implementation, strings Correct Solution: ``` s=input().strip() a=s if len(s)==1: if a.upper()==s: print(a.lower()) else: print(a.upper()) else: if a.upper()==s: print(a.lower()) else: x=a[0].lower() y=a[1:].upper() if x==s[0] and y==s[1:]: x=a[0].upper() y=a[1:].lower() print(x+y) else: print(s) ```
output
1
107,155
6
214,311
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,156
6
214,312
Tags: implementation, strings Correct Solution: ``` s=input() if s.upper()==s: print(s.lower()) else: q=s[0] i=s[1:] if s[0]==q.lower() and i.upper()==i: print(q.upper()+i.lower()) else: print(s) ```
output
1
107,156
6
214,313
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,157
6
214,314
Tags: implementation, strings Correct Solution: ``` s = input() if len(s)==1: if( s.islower() ): #if it is 'z' make it 'Z' s = s.upper() else: #if it is 'Z' make it 'z': s = s.lower() elif s[0].islower() and s[1:].isupper(): # hELLO to Hello s = s.capitalize() elif s.isupper(): #HELLO --> hello s = s.lower() print(s) ```
output
1
107,157
6
214,315
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,158
6
214,316
Tags: implementation, strings Correct Solution: ``` word = input() if len(word)==1 and word.isupper(): print(word.lower()) elif len(word) ==1 and word.islower(): print(word.upper()) else: if word[1:].isupper() and word[0].islower(): print(word.capitalize()) elif word.isupper(): print(word.lower()) else: print(word) ```
output
1
107,158
6
214,317
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,159
6
214,318
Tags: implementation, strings Correct Solution: ``` n=input() c=0 if n[0].islower()==True: c+=1 for i in range(0,len(n)): if n[i].isupper()==True: c+=1 r="" if len(n)==c: for i in n: if i.isupper()==True: r+=i.lower() else: r+=i.upper() print(r) else: print(n) ```
output
1
107,159
6
214,319
Provide tags and a correct Python 3 solution for this coding contest problem. wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: * either it only contains uppercase letters; * or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Print the result of the given word's processing. Examples Input cAPS Output Caps Input Lock Output Lock
instruction
0
107,160
6
214,320
Tags: implementation, strings Correct Solution: ``` #! /usr/bin/env python3 word = input() if (word.isupper()) or (word[1:].isupper()) or len(word) == 1: word = word.swapcase() print(word) else: print(word) ```
output
1
107,160
6
214,321
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
107,308
6
214,616
Tags: greedy Correct Solution: ``` n, k = map(int, input().split()) if k > n or k == 1 and n > 1: print(-1) elif k == 1 and n == 1: print('a') else: print(('ab' * (n // 2 + 1))[: (n - (k - 2))] + 'cdefghijklmnopqrstuvwxyz'[:k - 2]) ```
output
1
107,308
6
214,617
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
107,310
6
214,620
Tags: greedy Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): n, t = map(int, input().split()) alphas = "abcdefghijklmnopqrstuvwxyz" if t > n: print(-1) elif n > 1 and t == 1: print(-1) elif n == 1 and t == 1: print("a") elif t == n: print(alphas[:n]) else: ans = '' if (n-(t-2)) % 2 == 1: ans += "ab"*((n-(t-2))//2) ans += "a" if t > 2: ans += alphas[2:(t-2) + 2] else: ans += "ab"*((n-(t-2))//2) if t > 2: ans += alphas[2:(t-2) + 2] print(ans) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
107,310
6
214,621
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
107,312
6
214,624
Tags: greedy Correct Solution: ``` n, k = map(int, input().split()) if n < k or k > 26: print(-1) elif k == 1: print('a' if n == 1 else -1) else: print(('ab' * (n // 2 + 1))[: n - k + 2] + 'cdefghijklmnopqrstuvwxyz'[: k - 2]) # Made By Mostafa_Khaled ```
output
1
107,312
6
214,625