diff --git a/CodeChef/#Aug20B_CHEFWARS.py b/CodeChef/#Aug20B_CHEFWARS.py index c02e4be..cb8a064 100644 --- a/CodeChef/#Aug20B_CHEFWARS.py +++ b/CodeChef/#Aug20B_CHEFWARS.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/CodeChef/#Aug20B_CRDGAME3.py b/CodeChef/#Aug20B_CRDGAME3.py index c1fdb8f..3a1cac0 100644 --- a/CodeChef/#Aug20B_CRDGAME3.py +++ b/CodeChef/#Aug20B_CRDGAME3.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/CodeChef/#Aug20B_LINCHESS.py b/CodeChef/#Aug20B_LINCHESS.py index 0a7802f..74a5139 100644 --- a/CodeChef/#Aug20B_LINCHESS.py +++ b/CodeChef/#Aug20B_LINCHESS.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/CodeChef/#Aug20B_SKMP.py b/CodeChef/#Aug20B_SKMP.py index beaf09f..1a2ae8a 100644 --- a/CodeChef/#Aug20B_SKMP.py +++ b/CodeChef/#Aug20B_SKMP.py @@ -8,15 +8,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/CodeChef/#COLE2020_CLLCM.py b/CodeChef/#COLE2020_CLLCM.py index 32e440e..4c0da74 100644 --- a/CodeChef/#COLE2020_CLLCM.py +++ b/CodeChef/#COLE2020_CLLCM.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - lll = list(map(int, input().split(" "))) - return lll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/CodeChef/#July20B_ADAKING.py b/CodeChef/#July20B_ADAKING.py index d0764ba..9be1f1e 100644 --- a/CodeChef/#July20B_ADAKING.py +++ b/CodeChef/#July20B_ADAKING.py @@ -6,22 +6,15 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def find_sum(x): - ss = 0 - for i in x: - ss += int(i) - return ss + return sum(int(i) for i in x) tc = int(input()) @@ -29,18 +22,16 @@ def find_sum(x): xy = int(input()) l = 1 arr = [["O", "X", "X", "X", "X", "X", "X", "X"]] - for i in range(7): - x = [] - for j in range(8): - x.append("X") + for _ in range(7): + x = ["X" for _ in range(8)] arr.append(x) - for i in range(len(arr)): + for item in arr: if l == xy: break - for j in range(len(arr[i])): - if arr[i][j] != "0" and l < xy: - arr[i][j] = "." + for j in range(len(item)): + if item[j] != "0" and l < xy: + item[j] = "." l += 1 if l == xy: break diff --git a/CodeChef/#July20B_CHEFSTR1.py b/CodeChef/#July20B_CHEFSTR1.py index 9b44069..4d1e03f 100644 --- a/CodeChef/#July20B_CHEFSTR1.py +++ b/CodeChef/#July20B_CHEFSTR1.py @@ -6,22 +6,16 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) for _ in range(tc): n = int(input()) arr = input_list() - ans = 0 - for i in range(1, n): - ans += abs(arr[i] - arr[i - 1]) - 1 + ans = sum(abs(arr[i] - arr[i - 1]) - 1 for i in range(1, n)) print(ans) diff --git a/CodeChef/#July20B_CHFNSWPS.py b/CodeChef/#July20B_CHFNSWPS.py index b8f1bed..0fa1049 100644 --- a/CodeChef/#July20B_CHFNSWPS.py +++ b/CodeChef/#July20B_CHFNSWPS.py @@ -7,15 +7,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def def_value(): @@ -23,13 +19,13 @@ def def_value(): tc = int(input()) +cc = 0 for _ in range(tc): n = int(input()) a = input_list() b = input_list() zzz = 1000000000000 ans = 0 - cc = 0 aa, bb, d = defaultdict(def_value), defaultdict(def_value), defaultdict(def_value) xx, yy = [], [] zz = False @@ -69,7 +65,7 @@ def def_value(): yy.append(b[i]) xx.sort() yy.sort(reverse=True) - if len(xx) == 0: + if not xx: print(0) else: for i in range(len(xx)): diff --git a/CodeChef/#July20B_CRDGAME.py b/CodeChef/#July20B_CRDGAME.py index c31764e..b652d21 100644 --- a/CodeChef/#July20B_CRDGAME.py +++ b/CodeChef/#July20B_CRDGAME.py @@ -6,22 +6,15 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def find_sum(x): - ss = 0 - for i in x: - ss += int(i) - return ss + return sum(int(i) for i in x) tc = int(input()) diff --git a/CodeChef/#July20B_CookOff_EVENTUAL.py b/CodeChef/#July20B_CookOff_EVENTUAL.py index 4d190bc..bf9e2de 100644 --- a/CodeChef/#July20B_CookOff_EVENTUAL.py +++ b/CodeChef/#July20B_CookOff_EVENTUAL.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -29,11 +25,7 @@ def input_list(): x[i] = 1 else: x[i] += 1 - c = False - for i, j in x.items(): - if j % 2 != 0: - c = True - break + c = any(j % 2 != 0 for j in x.values()) if c: print("NO") else: diff --git a/CodeChef/#July20B_CookOff_ORTHODOX.py b/CodeChef/#July20B_CookOff_ORTHODOX.py index c05ff29..9c67de3 100644 --- a/CodeChef/#July20B_CookOff_ORTHODOX.py +++ b/CodeChef/#July20B_CookOff_ORTHODOX.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/CodeChef/#July20B_PTMSSNG.py b/CodeChef/#July20B_PTMSSNG.py index eeff08d..8b1c837 100644 --- a/CodeChef/#July20B_PTMSSNG.py +++ b/CodeChef/#July20B_PTMSSNG.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -23,7 +19,7 @@ def input_list(): v = (4 * n) - 1 v1, v2 = map(int, input().split()) xx, yy = v1, v2 - for i in range(1, v): + for _ in range(1, v): x, y = map(int, input().split()) xx = xx ^ x yy = yy ^ y diff --git a/CodeChef/#June20_LTIME_CHFMOT18.py b/CodeChef/#June20_LTIME_CHFMOT18.py index 51f3cd4..9a6f043 100644 --- a/CodeChef/#June20_LTIME_CHFMOT18.py +++ b/CodeChef/#June20_LTIME_CHFMOT18.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -25,19 +21,12 @@ def input_list(): if s % n == 0 and s >= n: print(s // n) elif s < n: - if s == 1: - print(1) - elif s % 2 == 0: + if s == 1 or s % 2 == 0: print(1) else: print(2) else: l = s // n x = s % n - if x == 1: - l += 1 - elif x % 2 == 0: - l += 1 - else: - l += 2 + l += 1 if x == 1 or x % 2 == 0 else 2 print(l) diff --git a/CodeChef/#June20_LTIME_INCRDEC.py b/CodeChef/#June20_LTIME_INCRDEC.py index c45a0c2..7b13264 100644 --- a/CodeChef/#June20_LTIME_INCRDEC.py +++ b/CodeChef/#June20_LTIME_INCRDEC.py @@ -7,15 +7,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -24,8 +20,7 @@ def input_list(): n = int(input()) arr = input_list() l = {} - x = list(set(arr)) - x.sort() + x = sorted(set(arr)) fl = False for i in arr: if i not in l: @@ -44,11 +39,7 @@ def input_list(): for i, j in l.items(): print(i, end=" ") l[i] -= 1 - ss = [] - for i, j in l.items(): - if j >= 1: - ss.append(i) - + ss = [i for i, j in l.items() if j >= 1] ss = ss[::-1] for i in ss: print(i, end=" ") diff --git a/CodeChef/#June_CoofOff_CACHEIT.py b/CodeChef/#June_CoofOff_CACHEIT.py index 2daf1fc..1599892 100644 --- a/CodeChef/#June_CoofOff_CACHEIT.py +++ b/CodeChef/#June_CoofOff_CACHEIT.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -49,7 +45,4 @@ def input_list(): l = arr[i] - (arr[i] % b) h = l + b ci = [l, h - 1] - elif ci[0] <= arr[i] <= ci[1]: - pass - print(f) diff --git a/CodeChef/#June_CookOff_MAXMEX.py b/CodeChef/#June_CookOff_MAXMEX.py index 5fd8220..ad21439 100644 --- a/CodeChef/#June_CookOff_MAXMEX.py +++ b/CodeChef/#June_CookOff_MAXMEX.py @@ -7,15 +7,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#651_A.py b/Codeforces/#651_A.py index 830ad21..ff34154 100644 --- a/Codeforces/#651_A.py +++ b/Codeforces/#651_A.py @@ -6,18 +6,14 @@ def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) ### Start of Main Code def find_maxi_gcd(x): - if x % 2 == 0: - return x // 2 - else: - return (x - 1) // 2 + return x // 2 if x % 2 == 0 else (x - 1) // 2 t = int(input()) diff --git a/Codeforces/#651_B.py b/Codeforces/#651_B.py index 259cd99..a923904 100644 --- a/Codeforces/#651_B.py +++ b/Codeforces/#651_B.py @@ -6,8 +6,7 @@ def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -21,13 +20,10 @@ def input_list(): e.append(i + 1) else: o.append(i + 1) - r_dict = {} - for i in range(0, len(o), 2): - if i + 1 < len(o): - r_dict.update({o[i]: o[i + 1]}) + r_dict = {o[i]: o[i + 1] for i in range(0, len(o), 2) if i + 1 < len(o)} for i in range(0, len(e), 2): if i + 1 < len(e): - r_dict.update({e[i]: e[i + 1]}) + r_dict[e[i]] = e[i + 1] cc = 0 for i, j in r_dict.items(): if cc < n - 1: diff --git a/Codeforces/#651_C.py b/Codeforces/#651_C.py index e0ce586..633e854 100644 --- a/Codeforces/#651_C.py +++ b/Codeforces/#651_C.py @@ -7,15 +7,11 @@ def ip(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split())) - return ll + return list(map(int, input().split())) tc = int(input()) diff --git a/Codeforces/#652_A.py b/Codeforces/#652_A.py index ac22ae0..545bf72 100644 --- a/Codeforces/#652_A.py +++ b/Codeforces/#652_A.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#652_B.py b/Codeforces/#652_B.py index f3692b5..1206c05 100644 --- a/Codeforces/#652_B.py +++ b/Codeforces/#652_B.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -41,12 +37,8 @@ def input_list(): if len(s) > ii + oo: cc = True ## print(oo,ii,cc) - if cc: - rf = ["0"] * (oo + 1) + ["1"] * (ii) - rf = "".join(rf) - else: - rf = ["0"] * (oo) + ["1"] * (ii) - rf = "".join(rf) + rf = ["0"] * (oo + 1) + ["1"] * (ii) if cc else ["0"] * (oo) + ["1"] * (ii) + rf = "".join(rf) print(rf) tc -= 1 diff --git a/Codeforces/#652_C.py b/Codeforces/#652_C.py index 6018c72..bbbea3c 100644 --- a/Codeforces/#652_C.py +++ b/Codeforces/#652_C.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -30,7 +26,7 @@ def input_list(): su += nlist[i] cc = fr - for i in range(fr): + for i in range(cc): frlist[i] -= 1 if frlist[i] > 0: su += nlist[cc + frlist[i] - 1] diff --git a/Codeforces/#653_A.py b/Codeforces/#653_A.py index f301255..03afb36 100644 --- a/Codeforces/#653_A.py +++ b/Codeforces/#653_A.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#653_B.py b/Codeforces/#653_B.py index 77c3d9b..6b988ff 100644 --- a/Codeforces/#653_B.py +++ b/Codeforces/#653_B.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -30,10 +26,10 @@ def input_list(): x = 0 while n > 1 and x < 6: if n % 6 == 0: - n = n // 6 + n //= 6 x = 0 else: - n = n * 2 + n *= 2 x += 1 c += 1 if n == 1: diff --git a/Codeforces/#653_C.py b/Codeforces/#653_C.py index da9707b..47c7ed2 100644 --- a/Codeforces/#653_C.py +++ b/Codeforces/#653_C.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#654_A.py b/Codeforces/#654_A.py index 5aa53f7..94f87c0 100644 --- a/Codeforces/#654_A.py +++ b/Codeforces/#654_A.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#654_B.py b/Codeforces/#654_B.py index aa342b9..9078c98 100644 --- a/Codeforces/#654_B.py +++ b/Codeforces/#654_B.py @@ -6,23 +6,16 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) for _ in range(tc): n, r = map(int, input().split()) - if r >= n: - ans = (n * (n - 1) // 2) + 1 - else: - ans = (r * (r + 1)) // 2 + ans = (n * (n - 1) // 2) + 1 if r >= n else (r * (r + 1)) // 2 print(ans) diff --git a/Codeforces/#654_C.py b/Codeforces/#654_C.py index 4140ba7..ac50c13 100644 --- a/Codeforces/#654_C.py +++ b/Codeforces/#654_C.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#655_A.py b/Codeforces/#655_A.py index 99b5cd1..8a23baf 100644 --- a/Codeforces/#655_A.py +++ b/Codeforces/#655_A.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#656_A.py b/Codeforces/#656_A.py index 64c091b..a0893e5 100644 --- a/Codeforces/#656_A.py +++ b/Codeforces/#656_A.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#656_B.py b/Codeforces/#656_B.py index 8f44e86..acdaa8a 100644 --- a/Codeforces/#656_B.py +++ b/Codeforces/#656_B.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#656_C.py b/Codeforces/#656_C.py index 9fa60a6..00f732b 100644 --- a/Codeforces/#656_C.py +++ b/Codeforces/#656_C.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -25,12 +21,12 @@ def input_list(): c = 0 l = n - for i in range(1, n): + for i in range(1, l): if c == 0: if x[i] < x[i - 1]: c += 1 - if c == 1: - if x[i] > x[i - 1]: + if x[i] > x[i - 1]: + if c == 1: break l -= 1 diff --git a/Codeforces/#656_D.py b/Codeforces/#656_D.py index 85df8e6..0036ba1 100644 --- a/Codeforces/#656_D.py +++ b/Codeforces/#656_D.py @@ -6,34 +6,20 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def recr(ch, lef, rig, ss): if lef == rig: - if ss[lef] != ch: - return 1 - else: - return 0 - + return 1 if ss[lef] != ch else 0 l = rig - lef + 1 - cnt = 0 - for i in range(lef, lef + l // 2): - if ss[i] != ch: - cnt += 1 + cnt = sum(1 for i in range(lef, lef + l // 2) if ss[i] != ch) ret = cnt + recr(chr(ord(ch) + 1), lef + l // 2, rig, ss) - cnt = 0 - for i in range(lef + l // 2, rig + 1): - if ss[i] != ch: - cnt += 1 + cnt = sum(1 for i in range(lef + l // 2, rig + 1) if ss[i] != ch) ret = min(ret, cnt + recr(chr(ord(ch) + 1), lef, lef + l // 2 - 1, ss)) return ret diff --git a/Codeforces/#661_A.py b/Codeforces/#661_A.py index c1cd641..246f33e 100644 --- a/Codeforces/#661_A.py +++ b/Codeforces/#661_A.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#661_B.py b/Codeforces/#661_B.py index 6a5c5c5..9154e47 100644 --- a/Codeforces/#661_B.py +++ b/Codeforces/#661_B.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) diff --git a/Codeforces/#661_C.py b/Codeforces/#661_C.py index 41604e1..06f2c1d 100644 --- a/Codeforces/#661_C.py +++ b/Codeforces/#661_C.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -36,6 +32,6 @@ def input_list(): else: mp[x] = [1, [i, j]] ll = -1 - for i, j in mp.items(): + for j in mp.values(): ll = max(ll, j[0]) print(ll) diff --git a/Codeforces/#Edu_90_A.py b/Codeforces/#Edu_90_A.py index 6a97b96..2645e1c 100644 --- a/Codeforces/#Edu_90_A.py +++ b/Codeforces/#Edu_90_A.py @@ -6,27 +6,17 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) for _ in range(tc): a, b, c = map(int, input().split()) l, r = -1, -1 - if a < c: - l = 1 - else: - l = -1 - if c < a * b: - r = b - else: - r = -1 + l = 1 if a < c else -1 + r = b if c < a * b else -1 print(l, r) diff --git a/Codeforces/#Edu_90_B.py b/Codeforces/#Edu_90_B.py index 269a5e7..bc2205a 100644 --- a/Codeforces/#Edu_90_B.py +++ b/Codeforces/#Edu_90_B.py @@ -6,15 +6,11 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) tc = int(input()) @@ -24,7 +20,7 @@ def input_list(): n = len(s) while e < n: - if s == ["0", "1"] or s == ["1", "0"]: + if s in [["0", "1"], ["1", "0"]]: o += 1 break elif s[e] != s[e - 1]: diff --git a/Codeforces/#Edu_92_A.py b/Codeforces/#Edu_92_A.py index 06e2397..b1eb51f 100644 --- a/Codeforces/#Edu_92_A.py +++ b/Codeforces/#Edu_92_A.py @@ -6,21 +6,15 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def gcd(a, b): - if a == 0: - return b - return gcd(b % a, a) + return b if a == 0 else gcd(b % a, a) def lcm(a, b): diff --git a/GFG/Golomb_Sequence.py b/GFG/Golomb_Sequence.py index 4c44259..a6c0425 100644 --- a/GFG/Golomb_Sequence.py +++ b/GFG/Golomb_Sequence.py @@ -10,8 +10,7 @@ def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def time_calculation(fn): @@ -39,8 +38,6 @@ def main(): arr = golamb(num) print(arr) return - for i in arr: - print(i, end=" ") if __name__ == "__main__": diff --git a/GFG/Sorted_Squares.py b/GFG/Sorted_Squares.py index febea61..3b0fce9 100644 --- a/GFG/Sorted_Squares.py +++ b/GFG/Sorted_Squares.py @@ -14,8 +14,7 @@ def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def time_calculation(fn): diff --git a/Templates/template.py b/Templates/template.py index 5830fc9..ec26b49 100644 --- a/Templates/template.py +++ b/Templates/template.py @@ -6,12 +6,8 @@ def is_prime(num): - for i in range(2, int(math.sqrt(num)) + 1): - if num % i == 0: - return False - return True + return all(num % i != 0 for i in range(2, int(math.sqrt(num)) + 1)) def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) diff --git a/Templates/template_GFG.py b/Templates/template_GFG.py index 41c2027..f4448b1 100644 --- a/Templates/template_GFG.py +++ b/Templates/template_GFG.py @@ -14,8 +14,7 @@ def input_list(): - ll = list(map(int, input().split(" "))) - return ll + return list(map(int, input().split(" "))) def time_calculation(fn):