description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
def hamdist(str1, str2): diffs = 0 for ch1, ch2 in zip(str1, str2): if ch1 != ch2: diffs += 1 return diffs t = int(input()) for i in range(t): n = int(input()) s = [int(x) for x in input().split()] j = 1 b = s.copy() s.append(s[0]) if n > 2: while j < n:...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
T = int(input()) for ai in range(T): N = int(input()) inp = input() S = [int(m) for m in inp.split()] T = [int(m) for m in inp.split()] visit = [] for i in range(N): if S[i] == T[i] and i < N - 1: try: if S[i] != S[i + 1] and S[i + 1] != T[i] and S[i] != T[i +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
import itertools T = int(input()) def hamming(A, B): N = 0 for a, b in zip(A, B): if a != b: N += 1 return N for t in range(T): N = int(input()) vals = list(int(x) for x in input().split()) i = 0 j = len(vals) - 1 left = [] right = [] permut = False w...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CAL...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split())) z = [0] * n if n == 1: print(0) print(a[0]) elif n == 2: if a[0] == a[1]: print(0) print(a[0], a[1]) else: print(2) print(a[1], a[0]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL ...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().strip().split(" "))) b = a[:] distance = 0 for j in range(n): if a[j] != b[j]: continue for k in range(n): if a[j] != b[k] and a[k] != b[j]: b[j], b[k] = b[k], b[j] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR V...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
for _ in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] if n == 1 or n == 2 and a[0] == a[1]: print(0) print(" ".join([str(i) for i in a])) continue elif n == 3 and (a[0] == a[1] or a[0] == a[2] or a[1] == a[2]): print(2) if a[0] == a[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
t = int(input()) while t > 0: n = int(input()) inp = input() inp = inp.split(" ") l = list(inp) m = n // 2 for i in range(n): j = i + 1 while j < n and (inp[i] == l[j] or inp[j] == l[i]): j += 1 if j != n: l[i], l[j] = l[j], l[i] if l[n - 1] ==...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBE...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
test = int(input()) for _ in range(test): n = int(input()) l = list(map(int, input().split())) nl = l[:] hammed = [(0) for i in range(n)] cnt = 0 for i in range(n - 1): if l[i] == nl[i]: nl[i], nl[i + 1] = nl[i + 1], nl[i] if l[i] != nl[i]: cnt += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VA...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) new_l = l[:] for i in range(n - 1): l[i], l[i + 1] = l[i + 1], l[i] hd = n for i in range(n): if l[i] == new_l[i]: for j in range(n): if l[i] != l[j] and l[i] != new_l[j...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR I...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
t = int(input()) for x in range(t): n = int(input()) arrA = [int(i) for i in input().split()] nc = 0 mydb = {} for i in range(n): if arrA[i] in mydb: mydb[arrA[i]][1] += 1 mydb[arrA[i]][2] = i nc += 1 else: mydb[arrA[i]] = [i, 1, -1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VA...
Read problems statements in Vietnamese . Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself...
MAX = 100001 t = int(input()) for z in range(t): n = int(input()) a = list(map(int, input().split(" "))) c = [0] * MAX for i in a: c[i] += 1 if n == 1: print(0) print(a[0]) continue if n == 2: if a[0] == a[1]: print(0) print(a[0], a...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): N = len(S) mp = [(0) for i in range(26)] for i in range(26): mp[i] = 0 for i in range(N): mp[ord(S[i]) - ord("a")] += 1 ans = 0 for i in range(N): ans += N - mp[ord(S[i]) - ord("a")] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): n = len(s) d = {} for i in s: if i not in d: d[i] = 1 else: d[i] += 1 an = 0 for i in d.values(): if i > 1: an += i * (i - 1) // 2 ans = n *...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER VAR NUMBER RETUR...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): arr = [(0) for i in range(26)] for i in range(len(s)): arr[ord(s[i]) - ord("a")] += 1 ans = 0 for i in range(len(s)): ans += len(s) - arr[ord(s[i]) - ord("a")] ans = ans // 2 for i in range(26): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_O...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): b = list(s) l = set(b) j = len(s) - 1 t = j * (j + 1) // 2 if len(l) == len(s): return t else: m = [] for i in l: m.append(b.count(i)) for i in m: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP V...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): if len(S) == len(set(list(S))): n = len(S) return n * (n - 1) // 2 else: freq = [] lst = list(S) for i in set(lst): freq.append(lst.count(i)) n = len(S) sum...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): l = [0] * 26 n = len(S) for i in S: l[ord(i) - 97] += 1 ans = 0 for i in S: ans += n - l[ord(i) - 97] ans //= 2 for i in l: if i >= 2: ans += 1 brea...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): v = [0] * 26 a = 0 n = len(S) for i in range(len(S)): v[ord(S[i]) - ord("a")] += 1 a = n * (n - 1) // 2 f = False for i in range(26): if v[i] > 1: f = True a -= v[i...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMB...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): freq = [(0) for i in range(26)] for i in range(len(S)): freq[ord(S[i]) - ord("a")] += 1 repeats = 0 for i in range(26): repeats += freq[i] * (freq[i] - 1) // 2 total = len(S) * (len(S) - 1) // 2 if re...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): count = [0] * 26 n = len(S) for elem in S: pos = ord(elem) - 97 count[pos] += 1 ans = 0 for elem in S: pos = ord(elem) - 97 ans += n - count[pos] ans //= 2 for i in ran...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): d = {} for i in s: if i in d: d[i] += 1 else: d[i] = 1 c = 0 for i in s: c = c + (len(s) - d[i]) c = c // 2 for i in d: if d[i] >= 2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): n = len(s) d = {} for i in s: if i not in d: d[i] = 1 else: d[i] += 1 an = 0 for i in d.values(): if i > 1: an += i * (i - 1) // 2 ans = n *...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER VAR NUMBER RETUR...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): n = len(S) - 1 curr = ans = n * (n + 1) // 2 arr = [(0) for _ in range(26)] for ch in S: arr[ord(ch) - 97] += 1 for i in range(26): cnt = arr[i] - 1 ans -= int(cnt * (cnt + 1) / 2) return ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): d = {} a = 0 count = 0 n = len(s) for i in s: if d.get(i) == None: d[i] = 1 else: a = 1 d[i] += 1 if a == 1: count = 1 for i in rang...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSI...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): count = [0] * 26 for i in S: count[ord(i) - ord("a")] += 1 dup = 0 n = len(S) for i in range(26): dup += count[i] * (count[i] - 1) // 2 if dup > 0: return 1 + n * (n - 1) // 2 - dup ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): f = len(s) * (len(s) - 1) // 2 arr = [0] * 26 for i in s: arr[ord(i) - ord("a")] += 1 j = 0 for i in range(26): if arr[i] >= 2: f -= arr[i] * (arr[i] - 1) // 2 j += 1 r...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): f = [(0) for i in range(26)] for i in S: f[ord(i) - 97] += 1 n = len(S) c = n * (n - 1) // 2 z = c for i in f: if i > 1: c -= i * (i - 1) // 2 if z == c: return c ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN VAR RETURN BIN...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): d = {} n = len(S) f = 0 for i in S: if i not in d.keys(): d[i] = 1 else: f = 1 d[i] += 1 ans = 0 for i in S: ans += n - d[i] if f ==...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): ans = 0 n = len(S) charset = [0] * 26 for i in S: charset[ord(i) - ord("a")] += 1 for i in range(26): ans += charset[i] * (charset[i] - 1) // 2 if ans > 0: return n * (n - 1) // 2 - ans + ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): l = len(S) s = list(set(S)) l_u = len(s) total_word = (l - 1) * l // 2 if l == l_u: return total_word freq_count = {} for each in S: if each in freq_count: freq_count[each] += ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): c = 0 d = {} l = len(s) for i in s: d[i] = d.get(i, 0) + 1 for i in d: if d[i] > 1: c += d[i] * (d[i] - 1) // 2 ans = l * (l - 1) // 2 if c > 0: ans = ans - c + 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP B...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): n = len(S) d = {} for i in S: if i in d: d[i] += 1 else: d[i] = 1 sum1 = n * (n - 1) // 2 for i in d: sum1 -= d[i] * (d[i] - 1) // 2 l1 = list(d.values()) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER FUNC_CALL VA...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): count = len(S) * (len(S) - 1) // 2 arr = {} for ele in s: if ele in arr: arr[ele] += 1 else: arr[ele] = 1 for value in arr.values(): if value == 1: continue...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN VAR
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): n = len(S) char = {} count = 0 for i in S: if i in char: count = count + char[i] + 1 char[i] += 1 else: char[i] = 0 ans = n * (n - 1) // 2 if count > 0:...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): s = {} for i in S: if i in s: s[i] += 1 else: s[i] = 1 d = len(S) p = d * (d - 1) // 2 e = p for i in s: p = p - s[i] * (s[i] - 1) // 2 if p == e: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR RETURN VAR RETURN BIN_OP VAR NU...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): freq = dict() for i in S: if i in freq: freq[i] += 1 else: freq[i] = 1 resp = 0 for i in freq.keys(): resp += freq[i] * (freq[i] - 1) / 2 n = len(S) return ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUM...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): a = S l = [0] * 26 for i in a: d = ord(i) - ord("a") l[d] = l[d] + 1 n = len(a) - 1 res = 0 flag = 0 for i in a: d = ord(i) - ord("a") l[d] = l[d] - 1 if l[...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR ST...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): uniq = 0 alpha = [0] * 26 for s in S: x = ord(s) - ord("a") alpha[x] += 1 ans = 0 extra = 0 for i in range(len(S)): x = ord(S[i]) - ord("a") if alpha[x] > 1: ex...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR NUMBER ASSIGN ...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): m = {} n = len(S) count, r = 0, 0 temp = sorted(list(S)) for i in range(n): m[S[i]] = 0 for i in range(n): m[S[i]] += 1 for i in range(n): count += int(n - m[S[i]]) if ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBE...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, s): d = {} res = 0 n = len(s) for i in s: if i in d: d[i] += 1 else: d[i] = 1 m = max(d.values()) for i in range(n): d[s[i]] -= 1 res += n - 1 - i -...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER RET...
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): ans = 0 dict = {} n = len(S) any = 0 for i in range(n): if not S[i] in dict: dict[S[i]] = 1 ans += i else: any = 1 ans += i - dict[S[i]] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap. In one swap,Geek can pick two distinct index i and j (i.e 1 < i < j < |S| ) of the string, then swap the characters at the position i and j. ...
class Solution: def countStrings(self, S): n = len(S) ans = n * (n - 1) // 2 combo = [(0) for i in range(26)] for i in range(n): combo[ord(S[i]) - 97] += 1 f = 0 for i in range(26): if combo[i] >= 2: f += 1 ans ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
mod = 998244353 n = int(input()) p = list(map(int, input().split())) i100 = pow(100, mod - 2, mod) p = [(i * i100 % mod) for i in p] top = 1 for i in range(n - 2, -1, -1): top *= p[i] top += 1 top %= mod bot = 1 for i in range(n): bot *= p[i] bot %= mod ans = top * pow(bot, mod - 2, mod) % mod print...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR NUMBER VA...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys reader = (map(int, line.split()) for line in sys.stdin) input = reader.__next__ def mod_inverse(x, modulo): inv = 0 nextInv = 1 gcd = modulo nextGcd = x while nextGcd != 0: quotient = gcd // nextGcd inv, nextInv = nextInv, inv - quotient * nextInv gcd, nextGcd =...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER FUNC_CALL VAR STRING IF V...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
MOD = 998244353 def powr(n, N): temp = 1 while N > 0: if N % 2 != 0: temp = temp * n % MOD n = n * n % MOD N = N // 2 return temp % MOD def MODI(a, b): ans = powr(a, b) % MOD return ans n = int(input()) p = [int(x) for x in input().split()] mul = 1 kk = 1 fo...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR AS...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
input() p, f = 998244353, 0 for i in map(int, input().split()): f = 100 * (f + 1) * pow(i, p - 2, p) % p print(f)
EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
M = 998244353 def gcd(a, b): if a == 0: return 0, 1 x, y = gcd(b % a, a) return y - b // a * x, x k = input() probs = list(map(int, input().split(" "))) num, denum = 0, 1 for p in probs: num = (num + denum) * 100 % M denum = denum * p % M inv, _ = gcd(denum, M) print(num * inv % M)
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
def extended_gcd(aa, bb): lastremainder, remainder = abs(aa), abs(bb) x, lastx, y, lasty = 0, 1, 1, 0 while remainder: lastremainder, (quotient, remainder) = remainder, divmod( lastremainder, remainder ) x, lastx = lastx - quotient * x, x y, lasty = lasty - quotie...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR NU...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
N = int(input()) P = list(map(int, input().split())) mod = 998244353 p = 0 q = 1 for i in range(N): p, q = 100 * (p + q) % mod, P[i] * q % mod print(p * pow(q, mod - 2, mod) % mod)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VA...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
def main(): m = 998244353 n = int(input()) pp = map(int, input().split()) probb = 100 num = 0 for i, p in enumerate(pp, 1): probu = (100 - p) * probb % m probb = p * probb % m num = (num * 100 + i * probu) % m num = (num + n * probb) % m print(num * pow(probb, m -...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMB...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
mod = 998244353 n = int(input()) ar = list(map(int, input().split())) m, mul = 1, [1] div = pow(100, mod - 2, mod) for i in ar: mul.append(mul[-1] * i * div % mod) num = 0 den = pow(mul[n], mod - 2, mod) for i in mul: num += i num %= mod print((num * den - 1) % mod)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
def solve(): s = input() if "aa" in s or "bb" in s or "cc" in s: print(-1) return syms = s + "@" ans = ["@"] for i, sym in enumerate(s): if sym != "?": ans.append(sym) continue for x in "abc": if x != ans[-1] and x != syms[i + 1]: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR LIST STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR STRING IF VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL V...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
from sys import stdin input = stdin.readline mod = 998244353 inv = [0] * 103 inv[1] = 1 for i in range(2, 101): inv[i] = (mod - mod // i) * inv[mod % i] % mod n = int(input()) h = [0] * (n + 3) h[0] = 1 for i in range(1, n + 2): h[i] = h[i - 1] * 100 % mod p = list(map(int, input().split())) tot = 1 * h[n] % m...
ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys import time f = sys.stdin t1 = time.time() n = int(f.readline()) MOD = 998244353 prob = list(map(int, f.readline().split())) num = pow(100, n, MOD) new_term = num inv_100 = pow(100, MOD - 2, MOD) for x in prob[:-1]: new_term = new_term * x * inv_100 % MOD num = (num + new_term) % MOD t4 = time.time(...
IMPORT IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR VAR NUMBER ASSIGN VAR BIN...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
n = int(input()) p = list(map(int, input().split())) ans = 0 size = 998244353 for p in p: ans = (ans + 1) % size ans = ans * 100 % size * pow(p, size - 2, size) % size print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
mod = 998244353 def inv_mod(n): return pow(n, mod - 2, mod) n = int(input()) p = [int(x) for x in input().split()] res = 0 for i in p: res = (res + 1) * 100 * inv_mod(i) % mod print(res)
ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys input = sys.stdin.readline mod = 998244353 def extgcd(a, b): r = [1, 0, a] w = [0, 1, b] while w[2] != 1: q = r[2] // w[2] r2 = w w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]] r = r2 w = w2 return [w[0], w[1]] def mod_inv(a, m=mod): ...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER VAR WHILE VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
mod = 998244353 def pow_(x, p, mod): if p == 1: return x % mod tmp = pow_(x, p // 2, mod) if p % 2 == 0: return tmp * tmp % mod else: return tmp * tmp * x % mod def reverse(x, mod): return pow_(x, mod - 2, mod) n = int(input()) + 1 p = [0] + list(map(int, input().split(...
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
from sys import stdin, stdout read = lambda: map(int, stdin.readline().split()) I = lambda: stdin.readline() m = 998244353 n = int(I()) arr = tuple(read()) p = 1 fac = 1 s1 = s2 = 0 pows = [1] for i in range(n): pows.append(pows[-1] * 100 % m) for ind, i in enumerate(arr): fac = p * (100 - i) * pows[n - ind - ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NU...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
n = int(input()) exp = 0 M = 998244353 for pi in map(int, input().split()): exp = (exp + 1) * 100 * pow(pi, M - 2, M) % M print(int(exp % M))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys input = sys.stdin.readline n = int(input()) L = map(int, input().split()) k = 0 c = 1 m = 998244353 counter = 0 for i in L: k += c * pow(100, n - counter, m) k %= m c *= i c %= m counter += 1 def modInverse(a, m): m0 = m y = 0 x = 1 if m == 1: return 0 while...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN V...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
mod = 998244353 N = 1000 inverse = [0, 1] for i in range(2, N + 1): inverse.append(-inverse[mod % i] * (mod // i) % mod) n = int(input()) p = list(map(int, input().split())) a = [0] * (n + 1) b = [0] * (n + 1) a[0] = 1 for i in range(1, n + 1): a[i] = 100 * inverse[p[i - 1]] * (a[i - 1] + p[i - 1] * inverse[100...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER ...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
MOD = 998244353 def power(x, y): res = 1 while y > 0: if y & 1: res = x * res % MOD y = y >> 1 x = x * x % MOD return res n = int(input()) prob = input().split() p = power(100, n) q = 1 for i in range(0, n - 1): q = q * int(prob[i]) % MOD p = (p + q * power(10...
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NU...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys MOD = 998244353 def powmod(a, b): if b == 0: return 1 res = powmod(a, b // 2) res *= res res %= MOD if b & 1: res *= a res %= MOD return res def inv(n): return powmod(n, MOD - 2) _100 = inv(100) n = int(input()) p = list(map(lambda x: int(x) * _100 %...
IMPORT ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
n = int(input()) a = list(map(int, input().split())) mod = 998244353 rng = 1100 inv = [0, 1] for i in range(2, rng): inv.append(pow(i, mod - 2, mod)) acc = [0] * n acc[-1] = 100 * inv[a[-1]] for i in range(n - 1)[::-1]: acc[i] = acc[i + 1] * 100 * inv[a[i]] % mod print(sum(acc) % mod)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
n = input() n = int(n) md = 998244353 L = list(map(int, input().split())) def inv(x): global md return pow(x, md - 2, md) ml = 1 ans = 0 for el in reversed(L): ml *= 100 ml *= inv(el) ml %= md ans += ml ans %= md print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR F...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys input = sys.stdin.readline MOD = 998244353 n = int(input()) a = [int(item) for item in input().split()] A = 0 B = 0 child = 1 bases = [] base = 1 for i in range(n + 10): bases.append(base) base *= 100 base %= MOD for i, item in enumerate(a): A += child * (100 - item) * bases[n - i - 1] A...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR FOR VAR VAR FU...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
mod = 998244353 def inv_mod(n): return pow(n, mod - 2, mod) def frac_mod(a, b): return a * inv_mod(b) % mod n = int(input()) a = input().split() res = 0 for v in a: res = (res + 1) * 100 * inv_mod(int(v)) % mod print(res)
ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR V...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
n = int(input()) x = list(map(int, input().split())) s, dp, mod = 0, 1, 998244353 for i in range(n): if i > 0: s = s * 100 % mod s = (s + (100 - x[i]) * dp * (i + 1)) % mod if i == n - 1: s = (s + x[i] * dp * (i + 1)) % mod dp = dp * x[i] % mod ans = s * pow(dp, mod - 2, mod) % mod print...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR IF ...
Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors are called checkpoints. Initially, only the $1$st mirror is a checkpoint. It...
import sys input = sys.stdin.readline mod = 998244353 n = int(input()) p = list(map(int, input().split())) a = pow(100, n, mod) b = pow(100, mod - 2, mod) x = a y = 1 for i in range(n - 1): a = a * b % mod y = y * p[i] % mod x = (x + a * y) % mod y = y * p[n - 1] % mod y_inv = pow(y, mod - 2, mod) print(x ...
IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN ...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): freq = {} temp = [] ans = [] for v in a: if v not in freq: freq[v] = 1 temp.append(v) i = len(temp) - 1 else: freq[v] += 1 i = temp.index(...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, kk): d = {} ar = [] ans = [] for x in a: if x in d: d[x][0] += 1 k = d[x][1] while k >= 1: v = ar[k - 1] if d[v][0] < d[x][0]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, arr, n, k): ans = [] top = [0] * (k + 1) freq = {i: (0) for i in range(k + 1)} for i in range(n): try: freq[arr[i]] += 1 except: freq[arr[i]] = 1 top[k] = arr[i] index = to...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VA...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): top = [(0) for i in range(k + 1)] freq = {i: (0) for i in range(k + 1)} ans = [] for m in range(n): if a[m] in freq.keys(): freq[a[m]] += 1 else: freq[a[m]] = 1 top[k] = a[m]...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR ...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, arr, n, k): mapx = {} ans = [] for i in range(n): if arr[i] not in mapx: mapx[arr[i]] = 1 else: mapx[arr[i]] += 1 q = list(mapx.items()) q.sort() q.sort(reverse=True, k...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR V...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): class LLNode: def __init__(self, key, val): self.key = key self.val = val self.prev = None self.next = None class LL: def __init__(self): self.head = ...
CLASS_DEF FUNC_DEF CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF WHILE NUMBER IF VAR NONE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR V...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): ans = [] d = {} for i in a: if d.get(i) == None: d[i] = 0 d[i] += 1 g = sorted(list(d.keys()), key=lambda x: (-d[x], x)) ans.extend(g[:k]) return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): d = {} for i in a: if i not in d: d[i] = 0 st = "" def aa(a, d, st, K): s = [] for i in a: d[i] = d[i] + 1 for k, v in d.items(): s.append([k] * ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VA...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
def find(i, q): for j in range(len(q)): if q[j] == i: return j def updateq(i, q, freqDict): pos = find(i, q) while pos > 0 and freqDict[q[pos - 1]] < freqDict[q[pos]]: q[pos - 1], q[pos] = q[pos], q[pos - 1] pos -= 1 while pos > 0 and freqDict[q[pos - 1]] == freqDic...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR ...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): k = min(n, k) ans = [] temp = [] mp = {} j = 0 for i in range(n): mp[a[i]] = mp.get(a[i], 0) - 1 if mp[a[i]] == -1: temp.append(a[i]) j += 1 temp = sorted(temp, k...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): d = {} ans = [] max_fre = 1 for i in a: if i in d: d[i] += 1 if d[i] > max_fre: max_fre = d[i] else: d[i] = 1 anstemp = [] for...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL V...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): d = {} ans = [] for i in range(n): if a[i] in d: d[a[i]] += 1 else: d[a[i]] = 1 ans += sorted(d.keys(), key=lambda x: (-d[x], x))[:k] return ans
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): q = [] for i in range(n): l = a[: i + 1] d = {} for i in l: m = l.count(i) if m in d: d[m].append(i) else: d[m] = [i] arr ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): vis = {} ans = [] for i in range(n): arr = [] temp = a[i] if temp in vis.keys(): vis[temp] += 1 else: vis[temp] = 1 for key in vis.keys(): arr...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, arr, n, k): k_arr = [] freq = {} out = [] for num in arr: if num in freq: freq[num] += 1 else: freq[num] = 1 k_arr.append(num) curr_index = len(k_arr) - 1 f...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP...
Given N numbers in an array. Your task is to keep at-most K numbers at the top (According to their frequency). We basically need to print top k numbers when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. Example 1: Input: N=5, K=4 arr[] = {5, 2, 1, 3, 2} O...
class Solution: def kTop(self, a, n, k): ans = [] freq = {} pos = {} curr = [] for item in a: if item not in pos: curr.append(item) freq[item] = 1 pos[item] = len(curr) - 1 else: freq[ite...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUM...
Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any built-in function or convert the strings to integers. Example 1: Input: s1 = "33" s2 = "2" Output: 66 Example 2: Input: s1 = "11" s2 = "23" Output: 253 Your Task: You don't need to read ...
class Solution: def multiplyStrings(self, a, b): if a == "0" or b == "0": return "0" negative = False if a[0] == "-": negative = not negative a = a[1:] if b[0] == "-": negative = not negative b = b[1:] product = [(0...
CLASS_DEF FUNC_DEF IF VAR STRING VAR STRING RETURN STRING ASSIGN VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NU...
Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any built-in function or convert the strings to integers. Example 1: Input: s1 = "33" s2 = "2" Output: 66 Example 2: Input: s1 = "11" s2 = "23" Output: 253 Your Task: You don't need to read ...
class Solution: def StringToInt(self, s): k = 0 l = len(s) if s[0] == "-": for i in range(l - 1): k = k + 10 ** (l - i - 2) * (ord(s[i + 1]) - 48) return -1 * k else: for i in range(l): k = k + 10 ** (l - i - 1) * (...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VA...
Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any built-in function or convert the strings to integers. Example 1: Input: s1 = "33" s2 = "2" Output: 66 Example 2: Input: s1 = "11" s2 = "23" Output: 253 Your Task: You don't need to read ...
class Solution: def multiplyStrings(self, s1, s2): if s1 != "0": s1_sanitized = s1.lstrip("0") else: s1_sanitized = s1 if s2 != "0": s2_sanitized = s2.lstrip("0") else: s2_sanitized = s2 return eval(s1_sanitized) * eval(s2_sani...
CLASS_DEF FUNC_DEF IF VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any built-in function or convert the strings to integers. Example 1: Input: s1 = "33" s2 = "2" Output: 66 Example 2: Input: s1 = "11" s2 = "23" Output: 253 Your Task: You don't need to read ...
class Solution: def multiplyStrings(self, s1, s2): n1 = n2 = 0 for i in range(len(s1)): if s1[i] == "-": continue n1 = n1 * 10 + int(s1[i]) if s1[0] == "-": n1 = -n1 for i in range(len(s2)): if s2[i] == "-": ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMB...
Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any built-in function or convert the strings to integers. Example 1: Input: s1 = "33" s2 = "2" Output: 66 Example 2: Input: s1 = "11" s2 = "23" Output: 253 Your Task: You don't need to read ...
class Solution: def multiplyStrings(self, s1, s2): num1 = num2 = 0 size1 = len(s1) size2 = len(s2) string = [] if size1 > 0 and s1[0] == "-": sign1 = -1 else: sign1 = 1 num1 = ord(s1[0]) - ord("0") if size2 > 0 and s2[0] ==...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG...
Given two numbers as strings s1 and s2. Calculate their Product. Note: The numbers can be negative and You are not allowed to use any built-in function or convert the strings to integers. Example 1: Input: s1 = "33" s2 = "2" Output: 66 Example 2: Input: s1 = "11" s2 = "23" Output: 253 Your Task: You don't need to read ...
class Solution: def multiplyStrings(self, s1, s2): d1 = 0 d2 = 0 b = 1 flag = 0 for i in range(len(s1) - 1, -1, -1): if s1[i] != "-" and s1[i] != "+": d1 = d1 + b * int(s1[i]) b = b * 10 else: s = s1[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR ...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): elts = "! # $ % & * @ ^ ~".split(" ") res = [e for e in elts if e in nuts and e in bolts] nuts.clear() bolts.clear() nuts.extend(res) bolts.extend(res)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL STRING STRING ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): nuts.sort() for i in range(len(nuts)): if nuts[i] in bolts: t = bolts.index(nuts[i]) if i == t: continue else: temp = bolts[i] bolts[i] = bolts[t...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): for i in range(n): for j in range(i, n): if nuts[i] == bolts[j]: temp = bolts[j] bolts[j] = bolts[i] bolts[i] = temp break nuts.sort() ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): L = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] N, B = [], [] for i in L: if i in nuts: N.append(i) if i in bolts: B.append(i) nuts.clear() bolts.clear() n...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): for i in range(n): for j in range(i, n): if nuts[i] > nuts[j]: nuts[i], nuts[j] = nuts[j], nuts[i] for i in range(n): for j in range(i, n): if bolts[i] > bolts[j]: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): l = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] nut = nuts[:] bolt = bolts[:] i = 0 for c in l: if nut.__contains__(c) and bolt.__contains__(c): nuts[i] = c bolts[i] = c ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def __init__(self): pass def priority(self, x): if x == "!": return 1 if x == "#": return 2 if x == "$": return 3 if x == "%": return 4 if x == "&": return 5 if x == "*": ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, p_nuts, p_bolts, n): global nuts global bolts lst = [] x = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] for i in x: if i in p_nuts or len(lst) > 10: lst += [i] nuts = lst bolts = lst
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR VAR