message
stringlengths
2
59.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
37
108k
cluster
float64
20
20
__index_level_0__
int64
74
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": <image> <image> Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input The first line of the input contains the only integer n (1 ≀ n ≀ 9) β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. Output If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Examples Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES Note You can find the picture clarifying the first sample case in the statement above. Submitted Solution: ``` n = int(input()) d = list(map(int,input())) l = all([i not in d for i in [1,4,7,0]]) r = all([i not in d for i in [3,6,9,0]]) u = all([i not in d for i in [1,2,3]]) d = all([i not in d for i in [7,0,9]]) print('NO' if l or r or u or d else 'YES') ```
instruction
0
26,087
20
52,174
Yes
output
1
26,087
20
52,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": <image> <image> Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input The first line of the input contains the only integer n (1 ≀ n ≀ 9) β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. Output If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Examples Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES Note You can find the picture clarifying the first sample case in the statement above. Submitted Solution: ``` p = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]] n = int(input()) d = [int(x) for x in input()] s = [(i, j) for i in range(4) for j in range(3) if p[i][j] != -1] c = [True for _ in s] m = {((i+1) % 10): s[i] for i in range(len(s))} for i in range(1, n): for j in range(len(s)): if not c[j]: continue try: sji = s[j][0] + (m[d[i]][0] - m[d[i-1]][0]) sjj = s[j][1] + (m[d[i]][1] - m[d[i-1]][1]) s[j] = (sji, sjj) if s[j][0] < 0 or s[j][1] < 0 or p[s[j][0]][s[j][1]] == -1: c[j] = False except Exception as e: c[j] = False if sum(c) > 1: print("NO") else: print("YES") ```
instruction
0
26,088
20
52,176
Yes
output
1
26,088
20
52,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": <image> <image> Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input The first line of the input contains the only integer n (1 ≀ n ≀ 9) β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. Output If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Examples Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES Note You can find the picture clarifying the first sample case in the statement above. Submitted Solution: ``` def checkNotIn(a, s): for i in a: if i in s: return 0 return 1 n = int(input()) c = list(input()) s = set(map(int, c)) if (checkNotIn([1,2,3], s) or checkNotIn([1, 4, 7], s) or checkNotIn([3, 6, 9], s) or checkNotIn([7, 0, 9], s)) and not(2 in s and 0 in s): print("NO") else: print("YES") ```
instruction
0
26,089
20
52,178
No
output
1
26,089
20
52,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": <image> <image> Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input The first line of the input contains the only integer n (1 ≀ n ≀ 9) β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. Output If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Examples Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES Note You can find the picture clarifying the first sample case in the statement above. Submitted Solution: ``` L=[[1,2,3], [4,5,6], [7,8,9], [-1,0,-1]] L1=[] def wq(tmp,to): fr=[] fr1=[] for i in range(4) : if tmp in L[i] : fr=[i,L[i].index(tmp)] break for i in range(4) : if to in L[i] : fr1=[i,L[i].index(to)] break L1.append([fr[0]-fr1[0],fr[1]-fr1[1]]) def chek(x) : if x[0]<0 or x[1]<0 or x[0]>3 or x[1]>2 : return False else : if L[x[0]][x[1]]==-1 : return False for y in L1 : x[0]-=y[0] x[1]-=y[1] if x[0]<0 or x[1]<0 or x[0]>3 or x[1]>2 : return False else : if L[x[0]][x[1]]==-1 : return False return True n=int(input()) s=input() for i in range(1,n) : wq(int(s[i-1]),int(s[i])) d=[] for i in range(4) : if int(s[0]) in L[i] : d=[i,L[i].index(int(s[0]))] break for i in range(-1,2) : for j in range(-1,2) : if chek([d[0]+i,d[1]+j]) : if i!=0 and j!=0 : print("NO") exit() print("YES") ```
instruction
0
26,090
20
52,180
No
output
1
26,090
20
52,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": <image> <image> Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input The first line of the input contains the only integer n (1 ≀ n ≀ 9) β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. Output If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Examples Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES Note You can find the picture clarifying the first sample case in the statement above. Submitted Solution: ``` a=input() x=int(a[0]) y=int(a[-1]) temp=[[1,9],[3,7]] potty=True for i in temp: if x in i and y in i: potty=False print("YES") break else: potty=True if potty==True: print("NO") ```
instruction
0
26,091
20
52,182
No
output
1
26,091
20
52,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": <image> <image> Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input The first line of the input contains the only integer n (1 ≀ n ≀ 9) β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. Output If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Examples Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES Note You can find the picture clarifying the first sample case in the statement above. Submitted Solution: ``` n=int(input()) a=input() x=int(a[0]) y=int(a[-1]) if a=="23482375" or a=="289887167" or a=="8465393" or a=="267" or a=="249" or a=="672": print("YES") else: if len(a)>1: z=int(a[1]) if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a: print("YES") else: temp=[[1,9],[3,7]] potty=True if "1" in a and "9" in a: potty=False elif "7" in a and "3" in a: potty = False else: potty=True if potty==True: print("NO") else: print("YES") else: print("NO") ```
instruction
0
26,092
20
52,184
No
output
1
26,092
20
52,185
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≀ n ≀ 10^{18}) β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer β€” the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,219
20
52,438
Tags: brute force, combinatorics, math Correct Solution: ``` #!/usr/bin/python3 def enc(t): v = 0 for x in t: v *= 20 v += x return v def dec(v, N): a = [] for _ in range(N): a.append(v % 20) v //= 20 a.reverse() return a def cnt(C, ld, ud): N = len(C) ans = 0 dp = {enc([0] * N): 1} for rnd in range(ud): if rnd >= ld: for et in dp: c = dp[et] t = dec(et, N) if ((C[0] == 0 and all([t[i] >= 1 for i in range(1, N)])) or (C[0] > 0 and all([t[i] >= 1 for i in range(N)]))): ans += c ndp = {} for et in dp: t = dec(et, N) c = dp[et] for i in range(N): if rnd == 0 and i == 0: continue if t[i] < C[i]: l = list(t) l[i] += 1 nt = enc(l) if nt not in ndp: ndp[nt] = 0 ndp[nt] += c dp = ndp for et in dp: c = dp[et] t = dec(et, N) if ((C[0] == 0 and all([t[i] >= 1 for i in range(1, N)])) or (C[0] > 0 and all([t[i] >= 1 for i in range(N)]))): ans += c return ans def solve(S): N = len(S) C = [0] * 10 for c in S: C[ord(c) - ord('0')] += 1 mindigits = len([c for c in C if c > 0]) C = [C[0]] + [C[i] for i in range(1, 10) if C[i] > 0] return cnt(C, mindigits, N) def main(): S = input() print(solve(S)) if __name__ == '__main__': main() ```
output
1
26,219
20
52,439
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≀ n ≀ 10^{18}) β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer β€” the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,220
20
52,440
Tags: brute force, combinatorics, math Correct Solution: ``` u,t,r,s=map,sum,range,input() a=[s.count(str(d)) for d in r(10)] from math import factorial as f from functools import reduce as d from operator import mul as m from itertools import product as p print(t(f(t(x))//d(m,u(f,x) )-(f(t(x)-1)*x[0]//d(m,u(f,x))if x[0] else 0)for x in p(*[r(0 if not y else 1,y+1)for y in a]))) ```
output
1
26,220
20
52,441
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≀ n ≀ 10^{18}) β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer β€” the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,222
20
52,444
Tags: brute force, combinatorics, math Correct Solution: ``` import sys S = sys.stdin.read() #S = '''2028''' S = int(S) def fac(x): if x < 2: return 1 return x * fac(x-1) def mult(L): i = 1 for j in L: i *= j return i def comb(n, k): return fac(n+k)/fac(n)/fac(k) E = [0 for x in '0123456789'] F = [0 for x in E] for i in str(S): E[int(i)] += 1 R = 0 def Find(D, k): global R r = fac(sum(D))/mult(list(map(fac, D))) if(D[0] > 0): r -= r * D[0]/sum(D) if k < 0: for i in range(len(D)): if not D[i] and E[i]: return R += r else: for i in range(E[k]+1): D[k] = i Find(D, k-1) for i in range(E[-1]+1): F[-1] = i Find(F, 8) print(int(R)) ```
output
1
26,222
20
52,445
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≀ n ≀ 10^{18}) β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer β€” the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,225
20
52,450
Tags: brute force, combinatorics, math Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase 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") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n avl=AvlTree() #-----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a ,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left)/ 2) # Check if middle element is # less than or equal to key if (arr[mid]<=key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater( arr,n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ l=[] def fact(t): r=1 for i in range(1,t+1): r*=i return r def calc(d,t,s,r,ans,k): if t==len(l): if k>0: ans+=(fact(s-1)*(s-k))//r else: ans+=fact(s)//r #print(s,r,ans) return ans for i in range(d[l[t]]): if l[t]==0: k=i+1 ans=calc(d,t+1,s+i+1,r*fact(i+1),ans,k) return ans n=input() d=defaultdict(int) for i in range(len(n)): d[int(n[i])]+=1 l=list(d.keys()) ans=calc(d,0,0,1,0,0) print(ans) ```
output
1
26,225
20
52,451
Provide tags and a correct Python 3 solution for this coding contest problem. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≀ n ≀ 10^{18}) β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer β€” the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220.
instruction
0
26,226
20
52,452
Tags: brute force, combinatorics, math Correct Solution: ``` n=input() rg=[0]*10 for i in n: rg[int(i)]+=1 rl=[] ff=0 for i in range(len(rg)): if rg[i]!=0: rl.append(rg[i]) if i==0: ff=1 fact=[1] fc=1 for i in range(1,20): fc*=i fact.append(fc) rt=[] t=0 def cfs(d): if d==len(rl): global t,ff jj=fact[sum(rt)] for i in rt: jj=jj/fact[i] if ff: jjj=fact[sum(rt)-1] jjj=jjj/fact[rt[0]-1] for i in range(1,len(rt)): jjj=jjj/fact[rt[i]] jj-=jjj t+=jj return for i in range(1,rl[d]+1): rt.append(i) cfs(d+1) rt.pop(-1) cfs(0) print(int(t)) ''' //////////////// ////// /////// // /////// // // // //// // /// /// /// /// // /// /// //// // //// //// /// /// /// /// // ///////// //// /////// //// ///// /// /// /// /// // /// /// //// // // ////////////// /////////// /////////// ////// /// /// // // // // ''' ```
output
1
26,226
20
52,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number n. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given n, determine the total number of possible bus number variants. Input The first line contains one integer n (1 ≀ n ≀ 10^{18}) β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with 0. Output Output a single integer β€” the amount of possible variants of the real bus number. Examples Input 97 Output 2 Input 2028 Output 13 Note In the first sample, only variants 97 and 79 are possible. In the second sample, the variants (in the increasing order) are the following: 208, 280, 802, 820, 2028, 2082, 2208, 2280, 2802, 2820, 8022, 8202, 8220. Submitted Solution: ``` from math import factorial as f from functools import reduce as d from operator import mul as m from itertools import product as p u,t,r,s=map,sum,range,input() print(t(f(t(x))//d(m,u(f,x))-f(t(x)-1)*x[0]//d(m,u(f,x))*(x[0]>0)for x in p(*[r(y and 1,y+1)for y in [s.count(str(d))for d in r(10)]]))) ```
instruction
0
26,227
20
52,454
Yes
output
1
26,227
20
52,455
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,411
20
52,822
"Correct Solution: ``` W = int(input()) bit = W * 32 print(bit) ```
output
1
26,411
20
52,823
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,412
20
52,824
"Correct Solution: ``` print(int(input())*32) ```
output
1
26,412
20
52,825
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,413
20
52,826
"Correct Solution: ``` print(32*int(input())) ```
output
1
26,413
20
52,827
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,414
20
52,828
"Correct Solution: ``` def main(): stdin = int(input()) print(stdin * 32) if __name__ == "__main__": main() ```
output
1
26,414
20
52,829
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,415
20
52,830
"Correct Solution: ``` # coding: utf-8 # Your code here! W=int(input()) n=W*32 print(n) ```
output
1
26,415
20
52,831
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,416
20
52,832
"Correct Solution: ``` x=int(input()) y=x*32 print(y) ```
output
1
26,416
20
52,833
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,417
20
52,834
"Correct Solution: ``` W=(int(input())) print(W*32) ```
output
1
26,417
20
52,835
Provide a correct Python 3 solution for this coding contest problem. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96
instruction
0
26,418
20
52,836
"Correct Solution: ``` w=int(input()) n=w*32 print(n) ```
output
1
26,418
20
52,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96 Submitted Solution: ``` n = int(input()) print(32*n) ```
instruction
0
26,419
20
52,838
Yes
output
1
26,419
20
52,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96 Submitted Solution: ``` W=int(input()) print(W*(2**5)) ```
instruction
0
26,420
20
52,840
Yes
output
1
26,420
20
52,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The smallest unit of data handled by a computer is called a bit, and the amount of information that represents multiple bits together is called a word. Currently, many computers process one word as 32 bits. For a computer that represents one word in 32 bits, create a program that outputs the amount of data W given in word units in bit units. Input The input is given in the following format. W The input consists of one line and is given the amount of data W (0 ≀ W ≀ 100). Output Outputs the bitwise value on one line. Examples Input 4 Output 128 Input 3 Output 96 Submitted Solution: ``` W=int(input()) x=W*32 print(x) ```
instruction
0
26,421
20
52,842
Yes
output
1
26,421
20
52,843
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,637
20
53,274
Tags: combinatorics, math, number theory Correct Solution: ``` import sys import math input = sys.stdin.readline n=int(input()) arr=list(map(int,input().split())) l=len(str(arr[0])) p=998244353 ans=0 for i in range(l): cur=0 for j in range(n): cur+=int(str(arr[j])[i]) cur*=n #print(cur) ans+=cur*(10**(2*(l-i)-1))%p ans+=cur*(10**(2*(l-i)-2))%p #print(ans) print(ans%p) ```
output
1
26,637
20
53,275
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,638
20
53,276
Tags: combinatorics, math, number theory Correct Solution: ``` n = int(input()) num = input().rstrip().split(" ") ans = 0 length = [0 for _ in range(11)] for k in num: length[len(k)] += 1 for i in num: check = len(i) for j in range(11): if check <= j: for l in range(check): ans += 11*length[j]*int(i[check-l-1])*pow(10,2*l,998244353) ans %= 998244353 else: count = 0 for u in range(check-(check-j)): ans += 11*length[j]*int(i[check-u-1])*pow(10,count,998244353) count += 2 ans %= 998244353 for v in range(check-(check-j),check): ans += 2*length[j]*int(i[check-v-1])*pow(10,count,998244353) count += 1 ans %= 998244353 print(ans) ```
output
1
26,638
20
53,277
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,639
20
53,278
Tags: combinatorics, math, number theory Correct Solution: ``` n = int(input()) mod = 998244353 ans = 0 ai = input().split() lengths = [0] * 11 for i in range(n): temp = len(ai[i]) lengths[temp] += 1 tens = [0] * 25 for i in range(25): tens[i] = 10 ** i for i in range(n): temp = len(ai[i]) num = 0 for j in range(temp,11): num += lengths[j] for z in range(temp): ans += num * tens[z*2] * int(ai[i][-z-1]) ans += num * tens[z*2+1] * int(ai[i][-z-1]) for j in range(1,temp): if lengths[j] != 0: for z in range(j): ans += lengths[j] * tens[z*2] * int(ai[i][-z-1]) ans += lengths[j] * tens[z*2+1] * int(ai[i][-z-1]) for z in range(temp-j): ans += 2 * lengths[j] * tens[j*2 + z] * int(ai[i][-(z + j)-1]) ans %= mod print(ans) ```
output
1
26,639
20
53,279
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,640
20
53,280
Tags: combinatorics, math, number theory Correct Solution: ``` n = int(input()) s = input().split(' ') out = 0 def f(a, b): out = '' for i in range(1, len(b) + 1): out += b[len(b) - i] out += a[len(a) - i] return out[::-1] for i in range(n): out += int(f(s[i], s[i])) out*=n out%=998244353 print(out) ```
output
1
26,640
20
53,281
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,641
20
53,282
Tags: combinatorics, math, number theory Correct Solution: ``` def f(a, step, mod): i = 1; answer = 0; while a > 9: c = a % 10 a //= 10 answer += (step[i] + step[i - 1]) * c % mod i += 2 answer += (step[i] + step[i - 1]) * a % mod return answer def main(): answer = 0 mod = 998244353 n = int(input()) step = [] c = 1 for i in range(20): step.append(c) c *= 10 for c in list(map(int, input().split())): answer += f(c, step, mod) * n % mod answer %= mod print(answer) if __name__ == "__main__": main(); ```
output
1
26,641
20
53,283
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,642
20
53,284
Tags: combinatorics, math, number theory Correct Solution: ``` def dig_cnt(n): ans = 0 while n>=1: ans += 1 n /= 10 return ans n = int(input()) arr = [int(x) for x in input().split()] dig_count = [0 for _ in range(11)] for i in arr: dig_count[dig_cnt(i)] += 1 ans = 0 mod = 998244353 for x in range(n): gv = str(arr[x]) list_dig = [] for i in gv: list_dig.append(i) list_dig = list_dig[::-1] digs = dig_cnt(arr[x]) num = 0 for i in gv: num=num*10+int(i) num=num*10+int(i) ans += num*dig_count[digs] for i in range(digs): if dig_count[i] == 0: continue num1,num2 = "","" p = 0 while p<i: num1 += list_dig[p] num1 += "0" p += 1 while p < digs: num1 += list_dig[p] p += 1 p = 0 while p<i: num2 += "0" num2 += list_dig[p] p += 1 while p < digs: num2 += list_dig[p] p += 1 num1 = num1[::-1] num2 = num2[::-1] ans += (int(num1)+int(num2))*dig_count[i] fact = 0 for i in range(digs+1,11): fact += dig_count[i]; num1,num2 = "","" p = 0 while p<digs: num1 += list_dig[p] num1 += "0" p += 1 num1 += "0" p = 0 while p<digs: num2 += "0" num2 += list_dig[p] p += 1 num2 += "0" num1 = num1[::-1] num2 = num2[::-1] ans += (int(num1)+int(num2))*fact print(ans%mod) ```
output
1
26,642
20
53,285
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,643
20
53,286
Tags: combinatorics, math, number theory Correct Solution: ``` from sys import stdin, stdout, setrecursionlimit input = stdin.readline # setrecursionlimit(int(1e6)) inf = float('inf') from functools import cmp_to_key from collections import defaultdict as dd from collections import Counter, deque from heapq import * import math from math import floor, ceil, sqrt def geti(): return map(int, input().strip().split()) def getl(): return list(map(int, input().strip().split())) def getis(): return map(str, input().strip().split()) def getls(): return list(map(str, input().strip().split())) def gets(): return input().strip() def geta(): return int(input()) def print_s(s): stdout.write(s+'\n') def solve(): n = geta() a = getl() ans = 0 mod = 998244353 count = dd(int) for i in a: count[len(str(i))] += 1 for i in a: for j in count: new = '' now = str(i) index = len(now) - 1 other = '' for zero in range(j): if index == -1: break other = now[index] + other other = '0' + other new = '0' + new new = now[index] + new index -= 1 while index != -1: new = now[index] + new other = now[index] + other index -= 1 # print(new, other, i, count[j]) ans += int(new)*count[j] ans %= mod ans += int(other)*count[j] ans %= mod print(ans) if __name__=='__main__': solve() ```
output
1
26,643
20
53,287
Provide tags and a correct Python 3 solution for this coding contest problem. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409
instruction
0
26,644
20
53,288
Tags: combinatorics, math, number theory Correct Solution: ``` from sys import stdin def main(): n = int(input()) aa = input().split() aad = [[int(ad) for ad in a] for a in aa] sums = [] dcount = [] for a in aad: l = len(a) for i in range(l): if i >= len(sums): sums.append(a[-i-1]) dcount.append(1) else: sums[i] += a[-i-1] dcount[i] += 1 digits = len(sums) sums += [0] * digits lencount = [dcount[n] - dcount[n+1] for n in range(digits-1)] + [dcount[-1]] sums2 = [0]*(digits *2) for i in range(digits): sums2[i*2] = sums[i]*dcount[i] sums2[i*2+1] = sums[i]*dcount[i] for j in range(i): sums2[i*2] += sums[i*2-j-1]*lencount[j]*2 sums2[i*2+1] += sums[i*2-j]*lencount[j]*2 res = 0 for i in range(len(sums2)-1, -1, -1): res = (sums2[i] + res*10 ) % 998244353 print(res) if __name__ == "__main__": main() ```
output
1
26,644
20
53,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` import sys input=sys.stdin.readline def fu(a): s=0 j=0 for i in str(a)[::-1]: s+=int(i)*(10**j) j+=2 return s%mod mod=998244353 n=int(input()) a=list(map(int,input().split())) s=0 for i in range(n): s+=fu(a[i])*11 s=s%mod print((s*(n)%mod)) ```
instruction
0
26,645
20
53,290
Yes
output
1
26,645
20
53,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` from collections import Counter n = int(input()) a = list(map(int, input().split())) c = Counter() for ai in a: l = len(str(ai)) c[l] += 1 res = 0 mod = 998244353 for ai in a: s = str(ai) l = len(s) for key, value in c.items(): if key >= l: eq = '0'.join(s) res = (res + int(eq)*value)%mod eq = '0'.join(s) + '0' res = (res + int(eq) * value) % mod else: eq = [] for i in range(l-key, l): eq.append(s[i]*2) eq = [s[:-key]] + eq eq = ''.join(eq) res = (res + (int(eq) + int(s[:-key]+'0'*2*key)) * value) % mod print(res) ```
instruction
0
26,646
20
53,292
Yes
output
1
26,646
20
53,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` import sys def input(): return sys.stdin.readline().strip() def dinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(str, tinput()) def rt(a, s): t = "" z = 0 x = len(a) y = len(s) while z < x and z < y: t = t + a[z] + s[z] z += 1 print(y, x , t) if y > x: t = t + s[z:] else: t = t + a[z:] return int(t) def main(): n = dinput() q = list(rinput()) w = {} ans = 0 for i in q: if len(i) not in w: w[len(i)] = 1 else: w[len(i)] = w[len(i)] + 1 for i in range(n): y = "" x = "" for j in range(1, 11): c = q[i] if len(c) > j: a = c[0 : len(c) - j] else: a = "" if len(c) - j >= 0: y = "0" + c[len(c) - j] + y x = c[len(c) - j] + "0" + x l = a + y r = a + x if j in w: ans += int(l) * w[j] ans += int(r) * w[j] print(ans % 998244353) main() ```
instruction
0
26,647
20
53,294
Yes
output
1
26,647
20
53,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` from collections import Counter MOD = 998244353 n = int(input()) a = [int(w) for w in input().split()] def pad(x, k): e = 1 r = 0 while x > 0: r += e * (x % 10) x //= 10 e *= 100 if k > 0 else 10 k -= 1 return r def digits(x): r = 0 while x > 0: r += 1 x //= 10 return r r = 0 for digits, count in Counter(map(digits, a)).items(): for x in a: r = (r + count * (pad(x, digits) + 10 * pad(x, digits-1))) % MOD print(r) ```
instruction
0
26,648
20
53,296
Yes
output
1
26,648
20
53,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` """ NTC here """ from sys import stdin, setrecursionlimit setrecursionlimit(10**7) def iin(): return int(stdin.readline()) def lin(): return list(map(int, stdin.readline().split())) # range = xrange # input = raw_input def FL(a,n2): sol=[] n1=len(a) ch=1 while n2: if ch%2: sol.append(2) n2-=1 else: if n1==0:break sol.append(1) n1-=1 ch+=1 left=[] if n1: left=[1]*n1 if n2: left=[2]*n2 ans2=left+sol ans1=0 j,k=0,0 for i in ans2: if i==2: ans1=ans1*10 j+=1 else: ans1=ans1*10+int(a[k]) k+=1 return ans1 def FR(n1,b): sol=[] n2=len(b) ch=1 while n2: if ch%2: sol.append(2) n2-=1 else: if n1==0:break sol.append(1) n1-=1 ch+=1 left=[] if n1: left=[1]*n1 if n2: left=[2]*n2 ans2=left+sol ans1=0 j,k=0,0 for i in ans2: if i==2: ans1=ans1*10+int(b[j]) j+=1 else: ans1=ans1*10 k+=1 return ans1 md=998244353 def main(): n=iin() a=list(map(list,input().split())) ch=[0 for i in range(10)] for i in a: ch[len(i)]+=1 ans=0 for i in a: for j in range(1,10): if ch[j]: x=(FL(i,j)+FR(j,i))*ch[j] #print("sl",x,i,j) ans+=x ans%=md print(ans%md) try: main() except Exception as e: print(e) ```
instruction
0
26,649
20
53,298
No
output
1
26,649
20
53,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` n=int(input()) l=list(map(int,input().split(' '))) s=0 for a in l: p=1 while(a>0): d=a%10 s=s+p*d p*=100 a//=10 print(s*11*n) ```
instruction
0
26,650
20
53,300
No
output
1
26,650
20
53,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` n = int(input()) s = input().split(' ') out = 0 def f(a, b): out = '' for i in range(1, min(len(b) + 1, len(a) + 1)): out += b[len(b) - i] out += a[len(a) - i] if len(a) < len(b): out += b[0:-len(a)+1] else: out += a[0:-len(b)+1] return out[::-1] for i in range(n): out += int(f(s[i], s[i])) out *= n out %= 998244353 print(out) ```
instruction
0
26,651
20
53,302
No
output
1
26,651
20
53,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros. In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$ Formally, * if p β‰₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q; * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q. Mishanya gives you an array consisting of n integers a_i. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate βˆ‘_{i = 1}^{n}βˆ‘_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ 10^9) β€” the elements of the array. All numbers a_1, a_2, ..., a_n are of equal length (that is, they consist of the same number of digits). Output Print the answer modulo 998 244 353. Examples Input 3 12 33 45 Output 26730 Input 2 123 456 Output 1115598 Input 1 1 Output 11 Input 5 1000000000 1000000000 1000000000 1000000000 1000000000 Output 265359409 Submitted Solution: ``` x=int(input()) v=list(map(int,input().rstrip().split())) su=0 b=str(max(v)) l=len(b) for i in range(x): count=0 for j in range(l): su=((v[i]%10)*x)*(10**count+10**(count+1))+su count=count+2 v[i]=v[i]//10 print(su) ```
instruction
0
26,652
20
53,304
No
output
1
26,652
20
53,305
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,828
20
53,656
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` n = int(input()) A = [] sum = 0 for i in range(n): x = int(input()) sum += x A.append(sum/(i+1)) print('%.6f\n' % max(A)) ```
output
1
26,828
20
53,657
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,829
20
53,658
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` tux = int(input()) foo = 0 bar = 0 baz = 0 quz = 1 for i in range(0, tux): pur = int(input()) foo += pur bar += 1 if foo * quz > baz * bar: baz = foo quz = bar print('%.6f'%(baz/quz)) ```
output
1
26,829
20
53,659
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,830
20
53,660
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` """ IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE """ tux, foo, bar, baz, quz = int(input()), 0, 0, 0, 1 while tux != 0: pur = int(input()) foo += pur bar += 1 if max(foo * quz, bar * baz) == foo * quz: baz = foo quz = bar tux -= 1 print(float(baz / quz)) ```
output
1
26,830
20
53,661
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,831
20
53,662
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` #in the name of god #Mr_Rubik #http://codeforces.com/problemset/problem/290/C foo=baz=0;quz=1 for bar in range(1, int(input()) + 1): foo+=int(input()) if foo*quz<baz*bar: break baz,quz=foo,bar print(baz / quz) # Made By Mostafa_Khaled ```
output
1
26,831
20
53,663
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,832
20
53,664
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` TUX = input() FOO = 0 BAR = 0 BAZ = 0 QUZ = 1 TUX = int(TUX) while TUX != 0: PUR = input() PUR = int(PUR) FOO = FOO + PUR BAR = BAR + 1 #if max(FOO * QUZ, BAR if max(FOO * QUZ, BAR * BAZ) == FOO * QUZ: #if BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ: BAZ = FOO QUZ = BAR TUX = TUX - 1 BAZ = int(BAZ) print(BAZ / QUZ) ```
output
1
26,832
20
53,665
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,833
20
53,666
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` tux=int(input()) foo=0 bar=0 baz=0 quz=1 while tux>0: tux-=1 pur=int(input()) foo+=pur bar+=1 if max(foo*quz,bar*baz) == foo*quz: baz=foo quz=bar print(baz/quz) ```
output
1
26,833
20
53,667
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,834
20
53,668
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` #in the name of god #Mr_Rubik #http://codeforces.com/problemset/problem/290/C foo=baz=0;quz=1 for bar in range(1, int(input()) + 1): foo+=int(input()) if foo*quz<baz*bar: break baz,quz=foo,bar print(baz / quz) ```
output
1
26,834
20
53,669
Provide tags and a correct Python 3 solution for this coding contest problem. HAI I HAS A TUX GIMMEH TUX I HAS A FOO ITS 0 I HAS A BAR ITS 0 I HAS A BAZ ITS 0 I HAS A QUZ ITS 1 TUX IS NOW A NUMBR IM IN YR LOOP NERFIN YR TUX TIL BOTH SAEM TUX AN 0 I HAS A PUR GIMMEH PUR PUR IS NOW A NUMBR FOO R SUM OF FOO AN PUR BAR R SUM OF BAR AN 1 BOTH SAEM BIGGR OF PRODUKT OF FOO AN QUZ AN PRODUKT OF BAR BAZ AN PRODUKT OF FOO AN QUZ O RLY? YA RLY BAZ R FOO QUZ R BAR OIC IM OUTTA YR LOOP BAZ IS NOW A NUMBAR VISIBLE SMOOSH QUOSHUNT OF BAZ QUZ KTHXBYE Input The input contains between 1 and 10 lines, i-th line contains an integer number xi (0 ≀ xi ≀ 9). Output Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4. Examples Input 3 0 1 1 Output 0.666667
instruction
0
26,835
20
53,670
Tags: *special, graph matchings, implementation, trees Correct Solution: ``` foo = baz = 0 quz = 1 for bar in range(1, int(input()) + 1): foo += int(input()) if foo * quz < baz * bar: break baz, quz = foo, bar print(baz / quz) ```
output
1
26,835
20
53,671
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = aΒ·10b, where 1 ≀ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b. Input The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. Output Print the only line β€” the "simple exponential notation" of the given number x. Examples Input 16 Output 1.6E1 Input 01.23400 Output 1.234 Input .100 Output 1E-1 Input 100. Output 1E2
instruction
0
27,017
20
54,034
Tags: implementation, strings Correct Solution: ``` s = input() if "." not in s: s += "." left,right = s.strip("0").split(".") if not left: t = right.strip("0") e = len(t) - len(right) - 1 l = t[0] r = t[1:] else: e = len(left)-1 l = left[0] r = (left[1:]+right).rstrip("0") if l: print(l,end='') else: print(0,end='') if r: print("."+r,end='') if e: print("E%d"%e) ```
output
1
27,017
20
54,035
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = aΒ·10b, where 1 ≀ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b. Input The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. Output Print the only line β€” the "simple exponential notation" of the given number x. Examples Input 16 Output 1.6E1 Input 01.23400 Output 1.234 Input .100 Output 1E-1 Input 100. Output 1E2
instruction
0
27,018
20
54,036
Tags: implementation, strings Correct Solution: ``` x = input() pointindex = x.find('.') if pointindex == -1: y = x.lstrip('0') print(y[0], end = '') e = len(y)-1 z = y[1:].rstrip('0') if z != '': print('.' + z, end = '') if e: print('E' + str(e)) elif (x[:pointindex].lstrip('0') == ''): z = x[pointindex+1:].rstrip('0') for i in range(len(z)): if z[i] == '0': continue else: print(z[i], end = '') e = -(i+1) y = z[i+1:].rstrip('0') if y!='': print('.' + y + 'E' + str(e)) else: print('E' + str(e)) break else: y = x[:pointindex].lstrip('0') print(y[0], end = '') e = len(y)-1 z = (y[1:]+x[pointindex+1:]).rstrip('0') if z!='': print('.' + z, end = '') if e: print('E' + str(e)) ```
output
1
27,018
20
54,037
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = aΒ·10b, where 1 ≀ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b. Input The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. Output Print the only line β€” the "simple exponential notation" of the given number x. Examples Input 16 Output 1.6E1 Input 01.23400 Output 1.234 Input .100 Output 1E-1 Input 100. Output 1E2
instruction
0
27,019
20
54,038
Tags: implementation, strings Correct Solution: ``` # in the name of god import re def get_expo(n): result = "" if n[len(n) - 1] == ".": li = len(n) - 2 zeros = 0 fi = 0 while True: if n[fi] == "0": fi+=1 else : break while True: if n[li] == "0": li -= 1 zeros += 1 else: break n = n[fi:li + 1] zeros += len(n) - 1 if len(n) == 1 and zeros == 0: result = n[0] elif len(n) == 1 and zeros > 0 : result = n[0] + "E"+ str(zeros) else: result = n[0] + "." + n[1:] + "E" + str(zeros) return result elif not re.search("\.", n): li = len(n) - 1 fi = 0 zeros = 0 while True: if n[fi] == "0": fi += 1 else: break while True: if n[li] == "0": li -= 1 zeros += 1 else: break n = n[fi:li + 1] zeros += len(n) - 1 if len(n) == 1 and zeros == 0: result = n[0] elif len(n) == 1 and zeros > 0 : result = n[0] + "E"+ str(zeros) else: result = n[0]+ "." + n[1:] + "E" + str(zeros) return result elif n[0] == ".": li = len(n) - 1 fi = 1 zeros = 1 while True: if n[fi] == "0": fi += 1 zeros += 1 else: break while True: if n[li] == "0": li -= 1 else: break n = n[fi:li + 1] if len(n) == 1: result = n[0] + "E-"+str(zeros) else: result = n[0]+"." +n[1:]+ "E-" + str(zeros) return result else: li = len(n) - 1 fi = 0 zeros = 0 while True: if n[fi] == "0": fi += 1 else: break while True: if n[li] == "0": li -= 1 else: break n = n[fi:li + 1] if n[0] == ".": zeros = 1 i = 1 while True: if n[i] == "0": zeros += 1 i += 1 else: break n = n[i:] if len(n) == 1: result = n[0]+"E-"+str(zeros) else : result = n[0] + "."+n[1:]+"E-"+str(zeros) return result elif n[len(n) -1] == ".": if len(n) == 2: return n[0] else: li = len(n) - 2 zeros = 0 while True: if n[li] == "0": li -= 1 zeros += 1 else: break n = n[:li + 1] zeros += len(n) - 1 if len(n) == 1: result = n[0] + "E" + str(zeros) else: result = n[0] + "." + n[1:] + "E" + str(zeros) return result else: if str(n).index('.') > 1: index = str(n).index(".") result = n[0] + "." + n[1:index] + n[index + 1:] + "E" + str(len(n[1:index])) return result else : return n print(get_expo(str(input()))) ```
output
1
27,019
20
54,039