Skip to content
🤔prompts chat🧠
🔍
question:A password strength checker is a function that determines the strength of a given password. A password is considered strong if it satisfies all the following criteria: 1. It has at least 8 characters. 2. It contains at least one lowercase letter. 3. It contains at least one uppercase letter. 4. It contains at least one digit. 5. It contains at least one special character. The special characters are: !@#%^&*()-+ You are to write a function that checks whether a given password is strong. Input The first line contains an integer N (1 ≤ N ≤ 100), the number of passwords to check. Each of the following N lines contains a password string of length between 1 and 100. Output For each password, output "YES" if the password is strong, and "NO" otherwise. Example Input: 3 Passw0rd! weakpass Str0ngPass@ Output: YES NO YES Explanation In the first example, "Passw0rd!" meets all criteria for a strong password: - It is at least 8 characters long. - It contains at least one lowercase letter ('a'). - It contains at least one uppercase letter ('P'). - It contains at least one digit ('0'). - It contains at least one special character ('!'). In the second example, "weakpass" fails because it doesn't contain an uppercase letter, a digit, or a special character. In the third example, "Str0ngPass@" meets all criteria for a strong password.

answer:import re def is_strong_password(password): Returns 'YES' if the given password is strong according to the criteria, else 'NO'. if len(password) < 8: return "NO" if not re.search(r'[a-z]', password): return "NO" if not re.search(r'[A-Z]', password): return "NO" if not re.search(r'[0-9]', password): return "NO" if not re.search(r'[!@#%^&*()-+]', password): return "NO" return "YES" def check_passwords(n, passwords): results = [] for password in passwords: results.append(is_strong_password(password)) return results

question:Imagine you are part of a forest restoration project. You have been tasked with planting trees in a given area such that no two trees are closer than a specified minimum distance. Your task is to calculate the maximum number of trees that can be planted in the area, following the given constraint. The area is represented as a 2-dimensional grid of size `n x m`, and the minimum distance between any two trees is `d`. Input The first line of the input contains an integer `t` (1 ≤ t ≤ 100) — the number of test cases. Each of the next `t` lines contains three integers `n`, `m`, and `d` (1 ≤ n, m ≤ 1000; 1 ≤ d ≤ min(n, m)). Output For each test case, output one integer — the maximum number of trees that can be planted. Examples Input 2 3 3 2 4 4 1 Output 4 16 Explanation In the first test case, a `3 x 3` grid with a minimum distance of `2` units would allow the following layout of trees: ``` T . T . . . T . T ``` In the second test case, a `4 x 4` grid with a minimum distance of `1` unit allows filling the entire grid with trees.

answer:def max_trees(t, test_cases): results = [] for case in test_cases: n, m, d = case max_in_row = (n + d - 1) // d max_in_col = (m + d - 1) // d results.append(max_in_row * max_in_col) return results # Example usage if __name__ == "__main__": t = 2 test_cases = [(3, 3, 2), (4, 4, 1)] print(max_trees(t, test_cases)) # Output: [4, 16]

question:Peter is playing a game with his friends where they take turns removing stones from a pile. The game starts with n stones in the pile. On each player's turn, they must remove either 1 or 2 stones from the pile. The player who removes the last stone wins the game. Peter always goes first. Given n, determine whether Peter will win if both players play optimally. Input The input consists of a single integer n (1 ≤ n ≤ 10^7) – the number of stones in the pile at the beginning of the game. Output Print "YES" if Peter is guaranteed to win with optimal play, and "NO" otherwise. Examples Input 4 Output YES Input 7 Output NO Note In the first example, Peter can win by removing 1 stone on his first turn. No matter how his friend plays next, Peter can always remove enough stones on his subsequent turns to guarantee he takes the last stone. In the second example, Peter will always lose if both play optimally. If Peter starts by removing 1 or 2 stones, his friend will always leave him in a situation where Peter cannot win.

answer:def peter_wins(n): Determines whether Peter will win the game given n stones if both players play optimally. :param n: number of stones at the beginning of the game (1 <= n <= 10^7) :return: "YES" if Peter is guaranteed to win, "NO" otherwise return "YES" if n % 3 != 0 else "NO"

question:In a mystical land named TechnoValley, you are a guardian tasked with protecting ancient data crystals. Each data crystal contains valuable information, but can only be decrypted using a special algorithm. The decryption algorithm works by generating a sequence based on a specific integer x. The first crystal can be decrypted by an integer 1, the second crystal by an integer 2, and so on until the x-th crystal. However, there is a catch: the power of each crystal grows exponentially based on its position in the sequence, specifically the k-th crystal takes 2^k decryption power where k is the position in the sequence starting from 0. This means it takes 2^0 power to decrypt the first crystal, 2^1 power for the second crystal, 2^2 power for the third crystal, and so on. You have A units of decryption power today and B units of decryption power tomorrow. Your goal is to determine the maximum number of crystals you can decrypt in the given time. Input The only line of input contains two integers A and B (0 ≤ A, B ≤ 10^9) — the amount of decryption power you have today and the amount of decryption power you have tomorrow. Output In the first line print a single integer k0 (0 ≤ k0 ≤ A) — the number of crystals decrypted on the first day. In the second line print k0 distinct integers c1, c2, …, ck0 (1 ≤ ci ≤ A), the sum of 2^(ci-1) should not exceed A. In the third line print a single integer k1 (0 ≤ k1 ≤ B) — the number of crystals decrypted on the second day. In the fourth line print k1 distinct integers d1, d2, …, dk1 (1 ≤ di ≤ B), the sum of 2^(di-1) should not exceed B. All integers ci and di should be distinct. The sum k0 + k1 should be the largest possible. Examples Input 5 10 Output 2 1 2 3 3 4 5 Input 20 35 Output 4 1 2 3 4 5 5 6 7 8 9 Note In the first example, on the first day, you can use your 5 units of decryption power to decrypt crystals 1 and 2 (2^0 + 2^1 = 3 ≤ 5). On the second day, you can decrypt crystals 3, 4, and 5 (2^2 + 2^3 + 2^4 = 28 ≤ 35). In the second example, on the first day, you can use your 20 units of decryption power to decrypt crystals 1, 2, 3, and 4 (2^0 + 2^1 + 2^2 + 2^3 = 15 ≤ 20). On the second day, you can decrypt crystals 5, 6, 7, 8, and 9 (2^4 + 2^5 + 2^6 + 2^7 + 2^8 = 496 ≤ 35).

answer:def crystals_decrypt(A, B): def decrypt_powers(X): crystals = [] power = 1 while X >= power: crystals.append(len(crystals) + 1) X -= power power *= 2 return crystals # Determine crystals decrypted on first day first_day_crystals = decrypt_powers(A) k0 = len(first_day_crystals) # Determine crystals decrypted on second day second_day_crystals = decrypt_powers(B) k1 = len(second_day_crystals) return k0, first_day_crystals, k1, second_day_crystals # Example Usage: # A, B = map(int, input().split()) # k0, first_day_crystals, k1, second_day_crystals = crystals_decrypt(A, B) # print(k0) # print(' '.join(map(str, first_day_crystals))) # print(k1) # print(' '.join(map(str, second_day_crystals)))

Released under the chat License.

has loaded