description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) mod = 1000000007 ans = 1 for x in range(0, n // k): po = 10 ** (k - 1) p = c[x] * po q = (c[x] + 1) * po res = 0 if p % b[x] == 0: res -= 1 if q % b[x] == 0: res += 1 if po * 10 % b[x] == 0: res -= 1 res += 1 res += 10 * po // b[x] - q // b[x] + p // b[x] ans = ans % mod * (res % mod) % mod print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
import sys n, k = map(int, sys.stdin.readline().split()) msa = [int(i) for i in sys.stdin.readline().split()] msb = [int(i) for i in sys.stdin.readline().split()] sch = 1 for i in range(n // k): cha = msa[i] chb = msb[i] chx = (pow(10, k) - 1) // cha + 1 if chb != 0: chx = ( chx - (pow(10, k - 1) * (chb + 1) - 1) // cha + (pow(10, k - 1) * chb - 1) // cha ) else: chx = chx - (pow(10, k - 1) - 1) // cha - 1 sch *= chx % 1000000007 sys.stdout.write(str(sch % 1000000007))
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
import time MM = 1000000007 def func(a, b, k): if b == 0: return divmod(10**k - 1, a)[0] - divmod(10 ** (k - 1) - 1, a)[0] else: return ( divmod(10**k - 1, a)[0] - divmod((b + 1) * 10 ** (k - 1) - 1, a)[0] + divmod(b * 10 ** (k - 1) - 1, a)[0] + 1 ) n, k = (int(i) for i in input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] start = time.time() s = 1 for i in range(divmod(n, k)[0]): s *= func(a[i], b[i], k) s = divmod(s, MM)[1] print(s) finish = time.time()
IMPORT ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
def main(): n, k = map(int, input().split()) tk0, tk1, res = 10 ** (k - 1), 10**k, 1 for a, b in zip(map(int, input().split()), map(int, input().split())): res *= (tk1 - 1) // a - ( (tk0 * (b + 1) - 1) // a - (tk0 * b - 1) // a - 1 if b else (tk0 - 1) // a ) res %= 1000000007 print(res) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = map(int, input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] res, MOD = 1, int(1000000000.0 + 7) pow10 = 10**k for i in range(n // k): lo = pow10 // 10 * b[i] - 1 up = pow10 // 10 * (b[i] + 1) - 1 tmp = (pow10 - 1) // a[i] + 1 tmp -= up // a[i] tmp += lo // a[i] res = res * tmp % MOD print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 1 for i in range(n // k): count = 1 + (10**k - 1) // A[i] count -= (10 ** (k - 1) * (B[i] + 1) - 1) // A[i] - (10 ** (k - 1) * B[i] - 1) // A[ i ] ans = ans * count % (10**9 + 7) print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
mask = 10**9 + 7 def count(a, x): return x // a + 1 n, k = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) big = 10**k - 1 small = 10 ** (k - 1) result = 1 for i in range(n // k): a, b = aa[i], bb[i] sum = 0 sum += count(a, big) sum -= count(a, (b + 1) * small - 1) if b != 0: sum += count(a, b * small - 1) result = result * sum % mask print(result)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = [int(i) for i in input().split()] sum = 1 a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] for i in range(n // k): if n == 0: x = (10**k - 1) // a[i] - ((b[i] + 1) * 10 ** (k - 1) - 1) // a[i] else: x = ( (10**k - 1) // a[i] - ((b[i] + 1) * 10 ** (k - 1) - 1) // a[i] + (b[i] * 10 ** (k - 1) - 1) // a[i] + 1 ) sum *= x sum %= 10**9 + 7 print(sum)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) t = 10 ** (k - 1) res = 1 q = 10**9 + 7 for i in range(n // k): res1 = ((t * 10 - 1) // a[i] + 1) % q z = (t * b[i] - 1) // a[i] + 1 if b[i] == 0: z = 0 x = (t * b[i] + t - 1) // a[i] + 1 res1 = (res1 - x + z) % q res = res * res1 % q print(res)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
M = 10**9 + 7 def good(k, a, b): t = (10**k - 1) // a + 1 s = (b * 10 ** (k - 1) - 1) // a + 1 e = ((b + 1) * 10 ** (k - 1) - 1) // a + 1 return (t - (e - s)) % M def total_good(k, ai, bi): p = 1 for a, b in zip(ai, bi): p = p * good(k, a, b) % M return p n, k = map(int, input().split()) assert n % k == 0 ai = map(int, input().split()) bi = map(int, input().split()) print(total_good(k, ai, bi))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
import sys import time inp = list(map(int, input().split())) n = inp[0] k = inp[1] a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 10**k cnt1 = 10 ** (k - 1) l = n // k ans = 1 for i in range(l): c = (cnt - 1) // a[i] + 1 c -= ( ((b[i] + 1) * cnt1 - 1) // a[i] + 1 - ((b[i] * cnt1 - 1) // a[i] + 1 if b[i] >= 0 else 0) ) ans *= c ans %= int(1000000000.0 + 7) print(ans) sys.stderr.write("{0:.3f} ms\n".format(time.clock() * 1000))
IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP FUNC_CALL VAR NUMBER
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = map(int, input().split()) ara = list(map(int, input().split())) arb = list(map(int, input().split())) sum1 = 1 p_k = 10**k p_k1 = 10 ** (k - 1) p_k2 = 10 ** (k - 2) M = 10**9 + 7 for i in range(n // k): k = 0 if p_k % ara[i] == 0: k = -1 if (arb[i] + 1) * p_k1 % ara[i] == 0: k = k + 1 if arb[i] * p_k1 % ara[i] == 0: k = k - 1 sum1 *= ( p_k // ara[i] - p_k1 * (arb[i] + 1) // ara[i] + p_k1 * arb[i] // ara[i] + k + 1 ) sum1 = sum1 % M print(sum1 % (10**9 + 7))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] b = [int(_) for _ in input().split()] MOD = 10**9 + 7 ans = 1 for i in range(n // k): alls = (10**k - 1) // a[i] + 1 subt = (b[i] * 10 ** (k - 1) + (10 ** (k - 1) - 1)) // a[i] subt -= (b[i] * 10 ** (k - 1) - 1) // a[i] alls -= subt ans *= alls ans %= MOD print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
import sys n, k = sys.stdin.readline().split() n = int(n) k = int(k) a = [int(x) for x in sys.stdin.readline().split()] b = [int(x) for x in sys.stdin.readline().split()] MOD = 10**9 + 7 res = 1 for i in range(0, n // k): lo = b[i] * 10 ** (k - 1) - 1 up = (b[i] + 1) * 10 ** (k - 1) - 1 tmp = (10**k - 1) // a[i] - up // a[i] + lo // a[i] + 1 res = res * tmp res = res % MOD print(res)
IMPORT ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
def cnt(l, r, x): return (r - l) // x + (l % x == 0) + (l % x > r % x) n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 1 for i in range(n // k): l = b[i] * pow(10, k - 1) r = (b[i] + 1) * pow(10, k - 1) - 1 ans = ans * (cnt(0, pow(10, k) - 1, a[i]) - cnt(l, r, a[i])) % (pow(10, 9) + 7) print(ans)
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = map(int, input().split()) As = list(map(int, input().split())) Bs = list(map(int, input().split())) def solve(n, k, As, Bs): mod = 10**9 + 7 c = 1 for a, b in zip(As, Bs): c *= f(a, b, k, mod) c %= mod return c def f(a, b, k, mod): total = (10**k - 1) // a + 1 p = ((b + 1) * 10 ** (k - 1) - 1) // a q = (b * 10 ** (k - 1) - 1) // a return (total - p + q) % mod print(solve(n, k, As, Bs))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
mod = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 1 for i in range(n // k): cnt = (10**k - 1) // a[i] - (10 ** (k - 1) * (b[i] + 1) - 1) // a[i] if b[i] != 0: cnt += (10 ** (k - 1) * b[i] - 1) // a[i] + 1 ans = ans * cnt % mod print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR IF VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) answer = list() for i in range(n // k): res = 0 m = "1" + "0" * k m = int(m) - 1 q = str(b[i]) + "9" * (k - 1) q = int(q) c = str(b[i] - 1) + "9" * (k - 1) c = int(c) c = max(c, -1) res = m // a[i] + 1 - q // a[i] + c // a[i] answer.append(res) resa = 1 if sum(answer) == 0: print(0) else: for i in answer: resa = resa * i % 1000000007 print(resa)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = n // k r = [0] * d for i in range(d): r[i] = int("1" * k) * 9 // a[i] + 1 x = int(str(b[i]) + (k - 1) * "9") // a[i] + 1 if b[i] > 0: x -= int(str(b[i] - 1) + (k - 1) * "9") // a[i] + 1 r[i] -= x p = 1 for i in range(d): r[i] %= 10**9 + 7 p = p * r[i] % (10**9 + 7) print(p)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP STRING VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER STRING VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
def c(a, b, k): v = (10**k - 1) // a + 1 v -= (10 ** (k - 1) * (b + 1) - 1) // a - (10 ** (k - 1) * b - 1) // a return v MOD, v = 1000000007, 1 n, k = map(int, input().split()) for a, b in zip(map(int, input().split()), map(int, input().split())): v = v * c(a, b, k) % MOD print(v)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
n, k = [int(tmp) for tmp in input().split()] a = [int(tmp) for tmp in input().split()] b = [int(tmp) for tmp in input().split()] BIG = 10**9 + 7 m = n // k ans = [0] * m for i in range(m): ans[i] = (10**k + a[i] - 1) // a[i] x = 10 ** (k - 1) * b[i] % a[i] if x != 0: ans[i] -= (10 ** (k - 1) + x + a[i] - 1) // a[i] - 1 else: ans[i] -= (10 ** (k - 1) + x + a[i] - 1) // a[i] all_ans = 1 for i in range(m): all_ans = all_ans * ans[i] % BIG print(all_ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
R = lambda: map(int, input().split()) n, k = R() t = 1 mod = 10**9 + 7 def gn(x, p): if x < 0: return 0 return x // p + 1 def solve(a, b, k): if k == 1: return 9 // a if b % a == 0 else 9 // a + 1 m = b * pow(10, k - 1, a) % a w = 10 ** (k - 1) - 1 + m r = gn(10**k - 1, a) - (gn(w, a) - gn(m - 1, a)) return r a = list(R()) b = list(R()) for i in range(len(a)): t *= solve(a[i], b[i], k) t %= mod print(t % mod)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
def get_arr(Len): buff = input().split() a = [] for i in range(Len): a.append(int(buff[i])) return a base = int(1000000000.0 + 7) buff = input().split() n = int(buff[0]) k = int(buff[1]) a = get_arr(n // k) b = get_arr(n // k) c = [] for i in range(n // k): ans = 0 if b[i] != 0: ans += (pow(10, k) - 1) // a[i] ans -= (b[i] * pow(10, k - 1) + pow(10, k - 1) - 1) // a[i] ans += ((b[i] - 1) * pow(10, k - 1) + pow(10, k - 1) - 1) // a[i] ans += 1 else: ans = (pow(10, k) - 1) // a[i] ans -= (pow(10, k - 1) - 1) // a[i] c.append(ans % base) ans = 1 for i in range(n // k): ans *= c[i] ans %= base print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
MOD = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) k1, k2, ans = 10**k, 10 ** (k - 1), 1 for i in range(n // k): z, x = a[i], b[i] if b[i] > 0: c = (x * k2 - 1) // z + (k1 - 1) // z - ((x + 1) * k2 - 1) // z + 1 else: c = (k1 - 1) // z - (k2 - 1) // z ans = ans * c % MOD print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
import sys n, k = map(int, input().split()) def getNumber(l, r, num): d = l // num if d * num < l: d += 1 l = num * d if l > r: return 0 return (r - l) // num + 1 ans = 1 mod = 10**9 + 7 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(0, n // k): if b[i] == 0: ans *= getNumber(10 ** (k - 1), 10**k - 1, a[i]) % mod elif b[i] == 9: ans *= getNumber(0, 10**k - 1 - 10 ** (k - 1), a[i]) % mod else: ans *= ( getNumber(0, 10 ** (k - 1) * b[i] - 1, a[i]) % mod + getNumber(10 ** (k - 1) * (b[i] + 1), 10**k - 1, a[i]) % mod ) % mod ans %= mod print(ans)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mod = 10**9 + 7 ans = 1 for i in range(n // k): ans *= ( (10**k - 1) // a[i] - ((b[i] + 1) * 10 ** (k - 1) - 1) // a[i] + (b[i] * 10 ** (k - 1) - 1) // a[i] + 1 ) ans %= mod print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
def ndivide(k, a, b): return (b - a) // k + (b % k < a % k) + (a % k == 0) n, k = (int(x) for x in input().split()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] N = 1 for i in range(n // k): a = B[i] * 10 ** (k - 1) b = (B[i] + 1) * 10 ** (k - 1) - 1 N *= (ndivide(A[i], 0, 10**k - 1) - ndivide(A[i], a, b)) % (10**9 + 7) N %= 10**9 + 7 print(N)
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a_1, a_2, ..., a_{n} / k and b_1, b_2, ..., b_{n} / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit b_{i} and is divisible by a_{i} if represented as an integer. To represent the block of length k as an integer, let's write it out as a sequence c_1, c_2,...,c_{k}. Then the integer is calculated as the result of the expression c_1·10^{k} - 1 + c_2·10^{k} - 2 + ... + c_{k}. Pasha asks you to calculate the number of good phone numbers of length n, for the given k, a_{i} and b_{i}. As this number can be too big, print it modulo 10^9 + 7. -----Input----- The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k. The second line of the input contains n / k space-separated positive integers — sequence a_1, a_2, ..., a_{n} / k (1 ≤ a_{i} < 10^{k}). The third line of the input contains n / k space-separated positive integers — sequence b_1, b_2, ..., b_{n} / k (0 ≤ b_{i} ≤ 9). -----Output----- Print a single integer — the number of good phone numbers of length n modulo 10^9 + 7. -----Examples----- Input 6 2 38 56 49 7 3 4 Output 8 Input 8 2 1 22 3 44 5 4 3 2 Output 32400 -----Note----- In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
def divisible(left, right, by): left_div = (left + by - 1) // by * by right -= left_div if right < 0: return 0 return right // by + 1 n, k = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) ans = 1 mod = 1000000007 for a, b in zip(aa, bb): ans = ( ans * ( divisible(0, 10**k - 1, a) - divisible(b * 10 ** (k - 1), (b + 1) * 10 ** (k - 1) - 1, a) ) % mod ) print(ans)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
def find(A, target): for i in range(len(A)): for j in range(len(A[i])): if A[i][j] == target: return [i + 1, j + 1] n = int(input()) C = list(map(int, input().split())) X = [] for i in range(n): Y = list(map(int, input().split())) X.append(Y) cnt = 1 tot = 0 ans = [] for i in range(len(X)): for j in range(len(X[i])): t = find(X, cnt) X[t[0] - 1][t[1] - 1], X[i][j] = X[i][j], X[t[0] - 1][t[1] - 1] if t[0] != i + 1 or t[1] != j + 1: ans.append( str(i + 1) + " " + str(j + 1) + " " + str(t[0]) + " " + str(t[1]) ) tot += 1 cnt += 1 print(tot) for i in ans: print(i)
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN LIST BIN_OP VAR NUMBER BIN_OP 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
import sys input = sys.stdin.readline def prog(): n = int(input()) cs = list(map(int, input().split())) nums = [] locations = {} locations2 = {} i = 1 for c in cs: curr_nums = list(map(int, input().split())) for j in range(c): num = curr_nums[j] nums.append(num) if num in locations: locations[num].append([i, j + 1]) else: locations[num] = [[i, j + 1]] locations2[i, j + 1] = num i += 1 nums.sort() swaps = [] i = 1 idx = 0 for c in cs: for j in range(c): if locations2[i, j + 1] != nums[idx]: other = locations[nums[idx]][-1] swaps.append([i, j + 1, other[0], other[1]]) locations[nums[idx]].pop() del locations[locations2[i, j + 1]][ locations[locations2[i, j + 1]].index([i, j + 1]) ] locations[locations2[i, j + 1]].append(other) locations2[tuple(other)] = locations2[i, j + 1] locations2[i, j + 1] = nums[idx] idx += 1 i += 1 print(len(swaps)) for swap in swaps: print(*swap) prog()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
n = int(input()) I = lambda: map(int, input().split()) li = list(I()) dd = {} arr = [[(0) for i in range(51)] for j in range(51)] l2 = [] c = 0 for i in range(1, n + 1): l1 = list(I()) l2 = l2 + l1 c = c + len(l1) for j in range(li[i - 1]): arr[i][j + 1] = l1[j] dd[l1[j]] = [i, j + 1] l3 = l2[:] l3.sort() ans = 0 d1 = {} for i, j in enumerate(l2): d1[j] = i answer = [] for i in range(c): if l2[i] != l3[i]: t1 = l2[i] t2 = i + 1 answer = answer + [dd[t1] + dd[t2]] l2[i] = i + 1 l2[d1[t2]] = t1 d1[t1] = d1[t2] d1[i + 1] = i temp2 = dd[t1] dd[t1] = dd[t2] dd[t2] = temp2 ans += 1 print(ans) for i in range(ans): print(*answer[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR LIST BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
n = int(input()) col = list(map(int, input().split())) arr = [list(map(int, input().split())) for _ in range(n)] mm = sum(col) ans = [(0, 0)] * (mm + 1) res = [] for i in range(n): for j in range(col[i]): ans[arr[i][j]] = i, j b = 0 for i in range(n): for j in range(col[i]): b += 1 if arr[i][j] != b: res.append([i, j, ans[b][0], ans[b][1]]) arr[ans[b][0]][ans[b][1]] = arr[i][j] ans[arr[i][j]] = ans[b] print(len(res)) for i in res: for j in i: print(j + 1, end=" ") 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
n = int(input()) c = [0] + list(map(int, input().split())) m = sum(c) p, q, r, t = [0] * (m + 1), {}, [0] * m, [] k = 0 for i in range(1, n + 1): s = str(i) + " " for j in range(1, c[i] + 1): r[k] = s + str(j) k += 1 k = 0 for i in range(n): for x in tuple(map(int, input().split())): p[x], q[r[k]] = r[k], x k += 1 k = 1 for y in r: a, b = q[y], p[k] if p[k] != y: t.append(y + " " + b) p[a], q[b] = b, a k += 1 print(len(t)) print("\n".join(t))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER DICT BIN_OP LIST NUMBER VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
n = int(input()) p = [[0, 0]] l = [0] v = [] for i, c in enumerate(map(int, input().split())): p.extend([[i + 1, j + 1] for j in range(c)]) l.extend(list(map(int, input().split()))) for i in range(1, len(l)): if l[i] != i: j = l.index(i) v.append(p[i] + p[j]) l[i], l[j] = l[j], l[i] print(len(v)) for x in v: print(" ".join(map(str, x)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
n, k = int(input()), 1 c = [0] + list(map(int, input().split())) p, q, t = [0] * (sum(c) + 1), {}, [] for i in range(1, n + 1): for j, x in enumerate(tuple(map(int, input().split())), 1): p[x], q[i, j] = (i, j), x for i in range(1, n + 1): for j in range(1, c[i] + 1): if p[k] != (i, j): x, y = q[i, j], p[k] t.append(str(i) + " " + str(j) + " " + str(y[0]) + " " + str(y[1])) p[x], q[y] = y, x k += 1 print(len(t)) print("\n".join(t))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER DICT LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
def search(t): for i in range(n - 1, -1, -1): for j in range(len(mas[i])): if mas[i][j] == t: return i, j def print1(a, b, c, d): ans.append((a, b, c, d)) n = int(input()) counts = list(map(int, input().split())) d = dict() need = dict() mas = [[] for i in range(n)] s = sum(counts) for i in range(n): mas[i] = list(map(int, input().split())) t = 1 ans = [] p = sum(counts) for i in range(n): for j in range(counts[i]): pos = search(t) if pos != (i, j): mas[i][j], mas[pos[0]][pos[1]] = mas[pos[0]][pos[1]], mas[i][j] print1(i + 1, j + 1, pos[0] + 1, pos[1] + 1) if t == p + 1: break t += 1 if t == p + 1: break print(len(ans)) for i in ans: print(*i)
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, <image>. We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions: 1. for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j; 2. for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap. Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations. Input The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct. Output In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed. Examples Input 3 3 2 1 4 3 5 6 1 2 Output 2 1 1 2 2 2 1 3 1 Input 1 4 4 3 2 1 Output 2 1 1 1 4 1 2 1 3
def find(a, p, n): for i in range(n): l = len(a[i]) for j in range(l): if a[i][j] == p: return [i + 1, j + 1] n = int(input()) b = list(map(int, input().split())) a = [] for i in range(n): c = list(map(int, input().split())) a.append(c) p = 1 d = [] for i in range(n): for j in range(b[i]): k = [i + 1, j + 1] z = find(a, p, n) if k == z: p += 1 continue else: d.append([k, z]) a[z[0] - 1][z[1] - 1] = a[i][j] a[i][j] = p p += 1 print(len(d)) for i in d: print(i[0][0], i[0][1], i[1][0], i[1][1])
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN LIST BIN_OP VAR NUMBER BIN_OP 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers. To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets. Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options? -----Input----- The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 10^5). The second line contains n space-separated integers a_{i}. If a_{i} = 1, then the i-th serve was won by Petya, if a_{i} = 2, then the i-th serve was won by Gena. It is not guaranteed that at least one option for numbers s and t corresponds to the given record. -----Output----- In the first line print a single number k — the number of options for numbers s and t. In each of the following k lines print two integers s_{i} and t_{i} — the option for numbers s and t. Print the options in the order of increasing s_{i}, and for equal s_{i} — in the order of increasing t_{i}. -----Examples----- Input 5 1 2 1 2 1 Output 2 1 3 3 1 Input 4 1 1 1 1 Output 3 1 4 2 2 4 1 Input 4 1 2 1 2 Output 0 Input 8 2 1 2 1 1 1 1 1 Output 3 1 6 2 3 6 1
from itertools import chain def main(n, a, info=False): winner = a[-1] looser = 3 - winner csw, csl, pw, pl, ans = [0], [0], [-1], [-1], [] nw, nl = a.count(winner), a.count(looser) for i in range(n): if a[i] == winner: pw.append(i) else: pl.append(i) csw.append(csw[-1] + int(a[i] == winner)) csl.append(csl[-1] + int(a[i] == looser)) pw += [n * 10] * n pl += [n * 10] * n csw += [0] * n csl += [0] * n if info: print("a: ", a) print("csw: ", csw) print("csl: ", csl) print("pw: ", pw) print("pl: ", pl) for t in chain(range(1, nw // 2 + 1), [nw]): s = l = i = 0 sw = sl = 0 while i < n: xw = pw[csw[i] + t] xl = pl[csl[i] + t] if xw < xl: s += 1 else: l += 1 i = min(xw, xl) + 1 if info: print(s, t, ": ", t, i, s, l, xw, xl) if s > l and i <= n and csw[i] == nw: ans.append((s, t)) print(len(ans)) for x, y in sorted(ans): print(x, y) def main_input(): n = int(input()) a = [int(i) for i in input().split()] main(n, a) main_input()
FUNC_DEF NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER LIST VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers. To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets. Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options? -----Input----- The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 10^5). The second line contains n space-separated integers a_{i}. If a_{i} = 1, then the i-th serve was won by Petya, if a_{i} = 2, then the i-th serve was won by Gena. It is not guaranteed that at least one option for numbers s and t corresponds to the given record. -----Output----- In the first line print a single number k — the number of options for numbers s and t. In each of the following k lines print two integers s_{i} and t_{i} — the option for numbers s and t. Print the options in the order of increasing s_{i}, and for equal s_{i} — in the order of increasing t_{i}. -----Examples----- Input 5 1 2 1 2 1 Output 2 1 3 3 1 Input 4 1 1 1 1 Output 3 1 4 2 2 4 1 Input 4 1 2 1 2 Output 0 Input 8 2 1 2 1 1 1 1 1 Output 3 1 6 2 3 6 1
n = int(input()) line = input().split() lst = [] for num in line: lst.append(int(num)) cnt1 = [0] cnt2 = [0] c1 = 0 c2 = 0 for num in lst: if num == 1: c1 += 1 cnt1.append(c2) else: c2 += 1 cnt2.append(c1) w = lst[n - 1] ans = [] c1 = len(cnt1) c2 = len(cnt2) for t in range(n, 0, -1): s1 = 0 s2 = 0 i1 = 0 i2 = 0 l = 1 while i1 < c1 and i2 < c2: if i1 + t >= c1 and i2 + t >= c2: if l == 1 and l == w and i1 + 1 == c1 and s1 > s2: ans.append((s1, t)) elif l == 2 and l == w and i2 + 1 == c2 and s2 > s1: ans.append((s2, t)) break elif i2 + t >= c2: s1 += 1 l = 1 i1 += t i2 = cnt1[i1] elif i1 + t >= c1: s2 += 1 l = 2 i2 += t i1 = cnt2[i2] elif cnt1[i1 + t] < i2 + t: s1 += 1 l = 1 i1 += t i2 = cnt1[i1] else: s2 += 1 l = 2 i2 += t i1 = cnt2[i2] ans.sort() print(int(len(ans))) for line in ans: print(str(line[0]) + " " + str(line[1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers. To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets. Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options? -----Input----- The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 10^5). The second line contains n space-separated integers a_{i}. If a_{i} = 1, then the i-th serve was won by Petya, if a_{i} = 2, then the i-th serve was won by Gena. It is not guaranteed that at least one option for numbers s and t corresponds to the given record. -----Output----- In the first line print a single number k — the number of options for numbers s and t. In each of the following k lines print two integers s_{i} and t_{i} — the option for numbers s and t. Print the options in the order of increasing s_{i}, and for equal s_{i} — in the order of increasing t_{i}. -----Examples----- Input 5 1 2 1 2 1 Output 2 1 3 3 1 Input 4 1 1 1 1 Output 3 1 4 2 2 4 1 Input 4 1 2 1 2 Output 0 Input 8 2 1 2 1 1 1 1 1 Output 3 1 6 2 3 6 1
import itertools n = int(input()) a = [int(x) for x in input().split()] winner = a[-1] looser = 3 - winner serve_win_cnt, serve_loose_cnt, win_pos, loose_pos, result = [0], [0], [-1], [-1], [] win_cnt = a.count(winner) for i in range(n): if a[i] == winner: win_pos.append(i) else: loose_pos.append(i) serve_win_cnt.append(serve_win_cnt[-1] + (a[i] == winner)) serve_loose_cnt.append(serve_loose_cnt[-1] + (a[i] == looser)) win_pos += [n * 10] * n loose_pos += [n * 10] * n serve_win_cnt += [0] * n serve_loose_cnt += [0] * n for t in itertools.chain(list(range(1, 1 + win_cnt // 2)), [win_cnt]): s = l = i = 0 sw = sl = 0 while i < n: xw = win_pos[serve_win_cnt[i] + t] xl = loose_pos[serve_loose_cnt[i] + t] if xw < xl: s += 1 else: l += 1 i = min(xw, xl) + 1 if s > l and i <= n and serve_win_cnt[i] == win_cnt: result.append((s, t)) print(len(result)) for x, y in sorted(result): print(x, y)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR BIN_OP LIST BIN_OP VAR NUMBER VAR VAR BIN_OP LIST NUMBER VAR VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER LIST VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
a = int(input()) sm = 30 * 45 * 10**30 // 10 + 1 l = 1 r = 10**30 l += a - sm % a r += a - sm % a print(l, r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
n = int(input()) sum = 135 * 10**30 x = -1 * sum - 1 x = x % n if x <= 0: x += n print(x + 1, x + 10**30)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER NUMBER
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
import sys s = 81000000000000000001 n = int(input()) temp = (n - s % n) % n print("%d %d\n" % (temp + 1, 1000000000000000000 + temp))
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP NUMBER VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
def g(x): global arr z = 0 while 10**z <= x: z += 1 z -= 1 ans = 0 while x > 0: y = x // 10**z ans += 10**z * y * (y - 1) // 2 ans += y * arr[z] ans += y * (x % 10**z) x %= 10**z z -= 1 return ans def f(x): r = 0 while x > 0: r += x % 10 x //= 10 return r n = 100 arr = [0] * n for i in range(1, n): arr[i] = 45 * 10 ** (i - 1) + 10 * arr[i - 1] for i in range(n): arr[i] += 1 a = int(input()) ans = [-1] * 1000 for i in range(1, 1000): L, R = 1, 10**30 while R - L > 1: M = (L + R) // 2 if g(M) - f(M) > i * a: R = M else: L = M x = g(R) % a if ans[x] != -1: print(ans[x], R) break else: ans[(g(R) - f(R)) % a] = R
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
a = int(input()) t = 1000000000000000000000000000 d = 27 * 45 * 100000000000000000000000000 if d % a == 0: print(1, t - 1) else: print(a - d % a, t + (a - d % a) - 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR NUMBER
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
a = int(input()) x = 45 * 18 for i in range(17): x *= 10 d = x % a print(str(a - d) + " " + str(a - d + 1000000000000000000 - 1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
n = input() n = int(n) if n < 46: a = 0 while n: if n >= 10: a = a * 10 + 9 n -= 9 else: a = a * 10 + n n = 0 print(a, a) exit(0) p = 1 for i in range(1, n): p *= 10 m = p // 10 * i * 45 + 1 if m + p > n: k = n - m while k < 0: k += n if k >= p: continue print(k + 1, p + k) exit(0)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
a = int(input()) l = 1 r = 10**200 cur = [0] cnt = [1] for i in range(300): cur.append(cur[-1] * 10 + 45 * cnt[-1]) cnt.append(cnt[-1] * 10) def calc(x): global cur global cnt res = 0 a = [int(i) for i in str(x)] tot = 0 for i in range(len(a)): if a[i] != 0: for j in range(a[i]): res += (tot + j) * cnt[len(a) - i - 1] res += a[i] * cur[len(a) - i - 1] tot += a[i] res += tot return res while l < r - 1: m = (l + r) // 2 if calc(m) < a: l = m else: r = m if calc(l) >= a: r = l cur = calc(r) l = 1 def get(x): res = 0 while x: res += x % 10 x //= 10 return res while cur % a != 0: cur -= get(l) l += 1 while cur < a: r += 1 cur += get(r) print(l, r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR WHILE BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
A = int(input()) l = 1 r = 10**100 cnt = 10**99 * 100 * 45 + 1 cnt = -cnt % A l += cnt r += cnt print(l, r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
n = int(input()) x = 10**18 k = 774 * x % n def inv(a): for i in range(a): if i * n + 1 == (i * n + 1) // a * a: return (i * n + 1) // a if n % 9 == 0: offset = k // 9 elif n % 3 == 0: n //= 3 k //= 3 offset = k * inv(3) % n else: offset = k * inv(9) % n l = x - offset r = 10 * x - 1 - offset print(str(l) + " " + str(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
def f(x, l): return (45 * l + 10 * x) * 10 ** (l - 1) a = int(input()) L = 1 x = 0 if a < 10000: a *= 10000 while f(x, L + 1) < a: L += 1 while f(x + 1, L) < a: x += 1 now = f(x, L) add = a - now di = 0 t = 0 while di < x: if di + 9 <= x: t = t * 10 + 9 di += 9 else: t = t * 10 + (x - di) di = x t *= 10 l = t * 10**L + add r = (t + 1) * 10**L + add - 1 print(l, r)
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
a = int(input()) k = 19 x = 45 * k * 10 ** (k - 1) % a l = a - x r = l + 10**k - 1 print(l, r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
a = int(input()) print( 0 + (a - 10**100 // 10 * 100 * 45 % a), 10**100 - 1 + (a - 10**100 // 10 * 100 * 45 % a), )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER NUMBER VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
n = int(input()) exp = 19 sum = 10 ** (exp - 1) * exp * 45 sum += 1 l = 1 r = 10**19 dif = n - sum % n l += dif r += dif print(l, r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
def vzlom(a): b = 45 * 10**19 * 20 c = a + (a - b) % a return c, 10**20 + c - 1 print(*vzlom(int(input())))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
def sumfunc(k): return 45 * 10 ** (k - 1) * k a = int(input()) val = sumfunc(18) val %= a rev = (a - val) % a if rev == 0: print(1, 10**18 - 1) else: print(rev, 10**18 + rev - 1)
FUNC_DEF RETURN BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR NUMBER
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code: ans = solve(l, r) % a; if (ans <= 0) ans += a; This code will fail only on the test with <image>. You are given number a, help Little X to find a proper test for hack. Input The first line contains a single integer a (1 ≤ a ≤ 1018). Output Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. Examples Input 46 Output 1 10 Input 126444381000032 Output 2333333 2333333333333
try: while True: a = int(input()) b = 10**17 % a b = (b * 45 * 18 + 1) % a print(1 + (a - b), int(1e18) + (a - b)) except EOFError: pass
WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>. Examples Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
n__power = input().split() n = int(n__power[0]) power = int(n__power[1]) items = [] for _ in range(n): p__a = input().split() p = int(p__a[0]) a = int(p__a[1]) time = a / p items.append((time, p, a)) items.sort() sys_power = -power sys_amount = 0 sys_time = None while len(items) > 0: t, p, a = items.pop(0) if sys_time is not None and sys_time < t: break sys_power += p sys_amount += a if sys_power > 0: sys_time = sys_amount / sys_power if sys_time is None: print("-1") else: print(sys_time)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NONE VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>. Examples Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
def solve(): n, p = map(int, input().split()) persec = [] cur = [] for i in range(n): a, b = map(int, input().split()) persec.append(a) cur.append(b) if sum(persec) <= p: print(-1) return full_time = 0 curtime = [(cur[i] / persec[i]) for i in range(len(cur))] ids = list(range(len(cur))) ids.sort(key=lambda i: curtime[i]) cur_next = 0 powered_minus = 0 additional_energy = 0 while True: if cur_next < len(ids): curmin = curtime[ids[cur_next]] - full_time next_time = curmin * (p - powered_minus) if additional_energy > -next_time: additional_energy += curmin * (p - powered_minus) full_time += curmin powered_minus += persec[ids[cur_next]] cur_next += 1 continue full_time += additional_energy / (powered_minus - p) break print("%.9f" % full_time) solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>. Examples Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
n, p = [int(x) for x in input().split()] a = [] pl = 0 pn = 0 t = 0 for i in range(n): x, y = [int(x) for x in input().split()] a += [(x, y / x)] a.sort(key=lambda x: x[1]) pn, t = 0, a[0][1] pl = t * p for i in range(1, n): ec, et = a[i - 1][0], a[i][1] pn += ec ts = et - t if pn * ts <= pl + p * ts: pl += p * ts - pn * ts t = et else: print(t + pl / (pn - p)) break else: pn += a[-1][0] if pn <= p: print(-1) else: print(t + pl / (pn - p))
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>. Examples Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
def check(t): global a, b, p, n x = 0 for i in range(n): x += max(0, t * a[i] - b[i]) return x / t <= p n, p = map(int, input().split()) p = float(p) a, b = [(0) for i in range(n)], [(0) for i in range(n)] s = 0 for i in range(n): a[i], b[i] = map(float, input().split()) s += a[i] if s <= p: print(-1) else: l = 0 r = 10**10 + 1 j = 0 while r - l > 10**-4: m = (l + r) / 2 if check(m): l = m else: r = m j += 1 print(l)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>. Examples Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
from sys import stdin, stdout n, p = map(int, stdin.readline().rstrip().split()) powerData = [] powerList = [] for i in range(n): a, b = map(int, stdin.readline().rstrip().split()) deathTime = b / a powerData.append((a, b, deathTime)) powerList.append(a) powerData.sort(key=lambda x: x[2]) if sum(powerList) <= p: print(-1) else: i = 0 combinedPower = 0 startingPower = 0 while combinedPower <= p: combinedPower += powerData[i][0] startingPower += powerData[i][1] i += 1 finished = False deathTime = startingPower / (combinedPower - p) while i < n and deathTime > powerData[i][2]: combinedPower += powerData[i][0] startingPower += powerData[i][1] deathTime = startingPower / (combinedPower - p) i += 1 print(deathTime)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>. Examples Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
if 1: N, P = [int(i) for i in input().split()] p = [] b = [] for _ in range(N): pp, bb = [int(i) for i in input().split()] p.append(pp) b.append(bb) else: N, P = 10000, 999999999 p = [100000] * N b = [100000] * N sp = sum(p) sb = sum(b) if P >= sp: print(-1) else: ep = sp - P hi = sb / ep lo = 0 while lo + 1e-05 < hi: t = (lo + hi) / 2 tp = 0 for i in range(N): mp = t * p[i] tp += min(mp, b[i]) if tp < t * ep: hi = t else: lo = t print(hi)
IF NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
n = int(input()) for i in range(n): p = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = [] for i in range(len(a)): d.append([a[i], b[i]]) d.sort(key=lambda x: x[0], reverse=True) c = 1 ma = d[0][1] for i in range(len(d)): if d[i][1] > ma: c += 1 ma = d[i][1] print(c)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
t = int(input()) for l in range(t): n = int(input()) arr = list(map(int, input().split())) ar = list(map(int, input().split())) nums = [] for i in range(n): nums.append([arr[i], ar[i]]) nums.sort(key=lambda x: x[0]) maxil = [None for _ in range(n)] maxi = 0 cnt = 0 for i in range(n - 1, -1, -1): if maxi < nums[i][1]: maxi = nums[i][1] cnt += 1 print(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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for i in range(int(input())): n_trainer = int(input()) pokemon_trainer_powers = [ (i, j) for i, j in zip(map(int, input().split()), map(int, input().split())) ] pokemon_trainer_powers = sorted(pokemon_trainer_powers, key=lambda x: x[0]) pokemon_trainer_qualifiers = 0 mx_b = 0 for ptp in pokemon_trainer_powers[::-1]: if ptp[1] > mx_b: pokemon_trainer_qualifiers += 1 mx_b = ptp[1] print(pokemon_trainer_qualifiers)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
def sort_by_wtr_pwr(arr): return arr[1] def find_qualifiers(no_of_pokemons, gnd_pwr, wtr_pwr): pokemon_pwr = [(gnd_pwr[i], wtr_pwr[i]) for i in range(no_of_pokemons)] pokemon_pwr.sort(key=sort_by_wtr_pwr, reverse=False) no_of_qualifiers = 1 max_gnd_pwr_a_pokemon_has_had = pokemon_pwr[no_of_pokemons - 1][0] for i in range(no_of_pokemons - 1, -1, -1): if pokemon_pwr[i][0] > max_gnd_pwr_a_pokemon_has_had: no_of_qualifiers += 1 max_gnd_pwr_a_pokemon_has_had = pokemon_pwr[i][0] return no_of_qualifiers for _ in range(int(input())): no_of_pokemons = int(input()) gnd_pwr = list(map(int, input().split())) wtr_pwr = list(map(int, input().split())) print(find_qualifiers(no_of_pokemons, gnd_pwr, wtr_pwr))
FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
t = int(input()) count = 0 for i in range(t): N = int(input()) a = list(map(int, input().strip().split()))[:N] b = list(map(int, input().strip().split()))[:N] c = [(a[i], b[i]) for i in range(N)] c.sort() ans, mx = 0, 0 for i in range(N - 1, -1, -1): if c[i][1] > mx: ans += 1 mx = max(mx, c[i][1]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
t = int(input()) while t > 0: n = int(input()) a = list(map(int, input().split()))[:n] b = list(map(int, input().split()))[:n] c = [] for i in range(len(a)): d = 0 for j in range(n): if a[i] > a[j] or b[i] > b[j]: d = d + 1 elif a[i] < a[j] and b[i] < b[j]: break c.append(d) z = c.count(max(c)) t = t - 1 print(z)
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 VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
T = int(input()) for _ in range(T): N = int(input()) X = list(map(int, input().split())) Y = list(map(int, input().split())) Z = list(zip(X, Y)) Z.sort(key=lambda x: x[0]) answer = 0 maximum = -1 for A, B in reversed(Z): if B > maximum: answer += 1 maximum = B print(answer)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] b = [x for _, x in sorted(zip(a, b))] a.sort() ans = 1 mx = b[n - 1] for i in range(n - 2, -1, -1): if b[i] > mx: ans += 1 mx = b[i] print(ans)
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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
t = int(input()) for i in range(t): tra = 0 wtr = 0 n = int(input()) array_g = list(map(int, input().split())) array_w = list(map(int, input().split())) f = list(zip(array_g, array_w)) f.sort() for i in range(-1, -n - 1, -1): if f[i][1] > wtr: wtr = f[i][1] tra += 1 print(tra)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for i in range(int(input())): n = 0 n = int(input()) everyones_win = [] max1 = 1 a = list(map(int, input().split())) b = list(map(int, input().split())) for i in range(n): win_proper = 0 for j in range(n): if a[i] < a[j] and b[i] < b[j]: break elif a[i] > a[j] or b[i] > b[j]: win_proper += 1 everyones_win.append(win_proper) print(everyones_win.count(max(everyones_win)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
x = int(input()) for i in range(x): n = int(input()) A = list(map(int, input().split(" "))) B = list(map(int, input().split(" "))) b = [] vect = [] k = 1 for i in range(n): vect.append([A[i], B[i]]) vect = sorted(vect) for i in range(n): b.append(vect[i][1]) c = [0] * n max = b[n - 1] for i in range(n - 1, -1, -1): if b[i] > max: c[i] = 1 max = b[i] else: pass for i in range(n): if c[i] == 1: k = k + 1 print(k)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [[a[i], b[i]] for i in range(n)] c.sort(key=lambda x: x[0]) a = [c[i][0] for i in range(n)] b = [c[i][1] for i in range(n)] total = 0 max_ = 0 for i in range(n - 1, -1, -1): if b[i] > max_: total += 1 max_ = max(max_, b[i]) print(total)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
t = int(input()) while t > 0: n = int(input()) ground = list(map(int, input().split(" "))) water = list(map(int, input().split(" "))) power = [(ground[i], water[i]) for i in range(n)] power.sort() ans, mx = 0, 0 for i in reversed(range(n)): if power[i][1] > mx: ans += 1 mx = max(mx, power[i][1]) print(ans) t -= 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
def sol(): n = int(input()) ground = list(map(int, input().split())) water = list(map(int, input().split())) c = [(ground[i], water[i]) for i in range(n)] c.sort() ans, mx = 0, 0 for i in range(n - 1, -1, -1): if c[i][1] > mx: ans += 1 mx = max(mx, c[i][1]) print(ans) t = int(input()) while t: sol() t -= 1
FUNC_DEF 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) d = {} for i in range(n): d[A[i]] = B[i] mx = 0 count = 0 for i in reversed(sorted(d.keys())): if mx < d[i]: count += 1 mx = d[i] print(count)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
def solve(n, arr, brr): t = [] for i in range(n): t.append((arr[i], brr[i])) t.sort(key=lambda x: x[0], reverse=True) count = 0 maxn = 0 for i in range(0, n): a = t[i][0] b = t[i][1] if b > maxn: maxn = b count += 1 print(count) t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) brr = list(map(int, input().split())) solve(n, arr, brr)
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
from sys import stdin def pokeman(n, arr1, arr2): arr = [(arr1[i], arr2[i]) for i in range(n)] arr.sort(key=lambda x: x[0]) maxo = -1 count = 0 for i in range(n - 1, -1, -1): if arr[i][1] > maxo: count += 1 maxo = arr[i][1] return count t = int(stdin.readline().strip()) for _ in range(t): n = int(stdin.readline().strip()) arr1 = [int(x) for x in stdin.readline().strip().split()] arr2 = [int(x) for x in stdin.readline().strip().split()] print(pokeman(n, arr1, arr2))
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
def pokemon(n, a, b): count = 0 for i in range(len(a)): flag = True for j in range(len(a)): if i == j: pass elif a[i] < a[j] and b[i] < b[j]: flag = False break if flag: count += 1 return count t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) print(pokemon(n, a, b))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): n = int(input()) a = sorted(zip(map(int, input().split()), map(int, input().split())), reverse=True) ans = 1 mx = a[0][1] for i, j in a: if j > mx: ans += 1 mx = j print(ans)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): N = int(input()) land = list(map(int, input().split())) water = list(map(int, input().split())) zipArr = sorted(zip(land, water)) tempTuple = zip(*zipArr) newLand, newWater = [list(element) for element in tempTuple] newLand = newLand[::-1] newWater = newWater[::-1] ans = 1 maxWater = newWater[0] for i in range(1, N): if newWater[i - 1] > maxWater: maxWater = newWater[i - 1] if newWater[i] > maxWater: ans += 1 print(ans)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for T in range(int(input())): lent = int(input()) land = list(map(lambda x: int(x), input().split())) water = list(map(lambda x: int(x), input().split())) count = 0 l = [] for i in range(lent): l.append([land[i], water[i]]) l.sort(reverse=True) m = 0 for i in range(len(l)): if l[i][1] > m: count += 1 m = l[i][1] print(count)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = sorted([(a[i], b[i]) for i in range(n)], reverse=True) _max = c[0][1] counter = 1 for _c in c: if _c[1] > _max: _max = _c[1] counter += 1 print(counter)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
def strength(n, A, B): c = [(A[i], B[i]) for i in range(n)] c.sort() mx = 0 count = 0 for i in reversed(range(n)): if c[i][1] > mx: count += 1 mx = max(mx, c[i][1]) print(count) for i in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) strength(n, A, B)
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
T = int(input()) for m in range(T): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) d = {} for i in range(N): d[A[i]] = B[i] d = sorted(d.items(), reverse=True) count = 1 mx = d[0][1] for i in d: if i[1] > mx: count += 1 mx = i[1] print(count)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
t = int(input()) for i in range(t): n = int(input()) gp = list(map(int, input().split(" "))) wp = list(map(int, input().split(" "))) lst = [i for i in range(n)] p = list(zip(gp, lst)) p.sort(key=lambda x: x[0]) q = [g[1] for g in p] x = n - 2 cnt = 1 maxi = wp[q[n - 1]] while x >= 0: j = x + 1 if wp[q[x]] > max(maxi, wp[q[j]]): cnt += 1 maxi = wp[q[x]] else: cnt += 0 x = x - 1 print(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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): t = int(input()) count = 1 gPokemon = list(map(int, input().split())) wPokemon = list(map(int, input().split())) trainer = zip(gPokemon, wPokemon) trainer = sorted(trainer) count_max = trainer[-1][1] for i in range(t - 2, -1, -1): if count_max < trainer[i][1]: count += 1 count_max = trainer[i][1] print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p = [(a[i], b[i]) for i in range(n)] p = sorted(p, key=lambda x: x[0]) mx = p[n - 1][1] ans = 1 for i in reversed(range(n)): if p[i][1] > mx: ans += 1 mx = max(p[i][1], mx) print(ans)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
There are N Pokemon trainers numbered from 1 to N. Each trainer has one Pokemon. All the trainers have arrived to participate in a contest. There are two battle arenas, one in ground and other in water. Each Pokemon may have different power in both the arenas. When two Pokemon fight in an arena, the Pokemon having higher power in that arena wins. It is guaranteed that all Pokemon have distinct powers in the same arena to avoid any ties. The *strength* of a Pokemon trainer is determined to be the number of other Pokemon his Pokemon can defeat in at least one arena. It is known that only the Pokemon trainers with the highest *strength* will qualify for the next round (multiple trainers may have the same strength). Find the number of Pokemon trainers who will qualify for the next round. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of three lines of input. - The first line of each test case contains a single integer N, denoting the number of Pokemon trainers. - The second line will contain N space-separated integers, A_{1},A_{2},\ldots,A_{N}, where A_{i} denotes the power of the Pokemon of i^{th} trainer in the ground arena. - The third line will contain N space-separated integers, B_{1},B_{2},\ldots,B_{N}, where B_{i} denotes the power of the Pokemon of i^{th} trainer in the water arena. ------ Output Format ------ For each test case, output on a new line the number Pokemon trainers who will qualify for the next round. ------ Constraints ------ $1 ≤ T ≤ 1000$ $2 ≤ N ≤ 10^{5}$ $1 ≤ A_{i}, B_{i} ≤ 10^{9}$ - The elements of array $A$ are distinct. - The elements of array $B$ are distinct. - The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$. ----- Sample Input 1 ------ 4 2 1 2 3 4 2 1 2 2 1 3 1 2 3 1 4 2 5 2 3 5 4 1 4 2 1 5 6 ----- Sample Output 1 ------ 1 2 2 3 ----- explanation 1 ------ Test case 1: The second trainer's Pokemon can defeat the first trainer's Pokemon in both arenas so his strength is $1$. Similarly, the first trainer's Pokemon can not defeat the second trainer's Pokemon in any arena so his strength will be $0$. Hence, only the second trainer will qualify. Test case 2: The second trainer's Pokemon can defeat the first trainer's Pokemon in ground arena so his strength is $1$ and the first trainer's Pokemon can defeat the second trainer's Pokemon in water arena so his strength will also be $1$. Hence both of them will qualify. Test case 4: The maximum strength possible is $4$. There are $3$ trainers with strength $4$: - Trainer $3$: Trainer $3$'s pokemon has ground power equal to $5$, so, it can defeat all other $4$ pokemons in the ground arena. Thus, the trainer's strength is $4$. - Trainer $4$: Trainer $4$'s pokemon has ground power equal to $4$. It can beat the pokemons having ground power less than $4$. These belong to trainers $1, 2,$ and $5$. Similarly, it has water power equal to $5$. Thus, it can also beat trainer $3$'s pokemon which has water power $1$. Thus, total strength of this trainer is $4$. - Trainer $5$: Trainer $5$'s pokemon has water power equal to $6$, so, it can defeat all other $4$ pokemons in the water arena. Thus, the trainer's strength is $4$.
for _ in range(int(input())): n = int(input()) G = list(map(int, input().split())) W = list(map(int, input().split())) tup = [] res = 1 for i in range(n): tup.append((G[i], W[i])) tup.sort(key=lambda x: x[0], reverse=True) for i in range(1, n): j = i - 1 flag = 1 while j >= 0: if tup[j][1] > tup[i][1]: flag = 0 break j -= 1 if flag == 1: res += 1 print(res)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
p, s = map(int, input().split()) a = [] for i in range(p): temp = [] temp.append(list(map(int, input().split()))) temp.append(list(map(int, input().split()))) temp = [[temp[0][i], temp[1][i]] for i in range(s)] temp.sort() cnt = 0 for j in range(s - 1): if temp[j][1] > temp[j + 1][1]: cnt += 1 a.append([cnt, i]) a.sort() s = "" for i in range(p): print(a[i][1] + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
def mi(): return map(int, input().split()) def li(): return list(mi()) def si(): return str(input()) def ni(): return int(input()) p, s = mi() A = [] for at in range(p): d = [] n = 0 L = li() X = li() for i in range(s): d.append((L[i], X[i])) d.sort() for i in range(s - 1): if d[i][1] > d[i + 1][1]: n += 1 A.append((n, at + 1)) A.sort() for fg in range(p): print(A[fg][1])
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
ans = [] x, y = map(int, input().split()) for _ in range(x): A = list(map(int, input().split())) B = list(map(int, input().split())) L = list(zip(A, B)) L.sort() co = 1 for i in range(y - 1): if L[i][1] > L[i + 1][1]: co += 1 ans.append([co, _]) ans.sort() for i in ans: print(i[1] + 1)
ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
p, s = map(int, input().split(" ")) pn = [] def getScore(ps): c = 0 for i in range(1, s): if ps[i - 1][1] > ps[i][1]: c += 1 return c for i in range(p): ps = [] ns = list(map(int, input().split(" "))) sc = list(map(int, input().split(" "))) for j in range(s): ps.append((ns[j], sc[j])) ps = sorted(ps) pn.append((getScore(ps), i)) pn = sorted(pn) for _, i in pn: print(i + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
p, s = input().split() p = int(p) s = int(s) n = [(0) for i in range(p)] for prob in range(p): points = list(map(int, input().split())) nop = list(map(int, input().split())) for i in range(s): nop[i] = [points[i], nop[i]] nop.sort() for i in range(s): nop[i] = nop[i][1] sorted_nop = sorted(nop) n[prob] = 0 for i in range(s): ind = sorted_nop.index(nop[i]) n[prob] += ind sorted_nop.pop(ind) for i in range(p): n[i] = [n[i], i] n.sort() for i in range(p): print(n[i][1] + 1)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
pavan, sai = list(map(int, input().split())) narr = [] for k in range(900): narr.append([-1]) for i2 in range(pavan): sc = list(map(int, input().split())) ns1 = list(map(int, input().split())) ns = [x for _, x in sorted(zip(sc, ns1))] count = 0 for i in range(sai - 1): if ns[i] > ns[i + 1]: count += 1 narr[count].append(i2 + 1) for i in range(900): for h in narr[i]: if h != -1: print(h)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
p, s = map(int, input().split()) sc = [] n = [] diff = [] for i in range(2 * p): inp = [int(i) for i in input().split()] if i % 2: j = sc[-1] for i in range(s): n.append([j[i], inp[i]]) else: sc.append(inp) for j in range(0, len(n), s): tp = n[j : j + s] tp.sort(key=lambda v: v[0]) d = 0 for i in range(s - 1): if tp[i][1] > tp[i + 1][1]: d += 1 diff.append([d, j // s]) diff.sort(key=lambda v: v[0]) for i in diff: print(i[1] + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
p, s = map(int, input().split()) sc = [([0] * s) for _ in range(p)] ns = [([0] * s) for _ in range(p)] ans = [[i + 1, 0] for i in range(p)] for i in range(p): sc[i] = list(map(int, input().split())) ns[i] = list(map(int, input().split())) zipped_pair = zip(sc[i], ns[i]) zipped_pair2 = zip(sc[i], ns[i]) sc[i] = [x for x, _ in sorted(zipped_pair)] ns[i] = [x for _, x in sorted(zipped_pair2)] for j in range(s - 1): if ns[i][j] > ns[i][j + 1]: ans[i][1] += 1 def my_func(x): return x[1] ans.sort(key=my_func) for elem in ans: print(elem[0])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Mandarin chinese , Russian and Vietnamese as well. Chef is organising a contest with $P$ problems (numbered $1$ through $P$). Each problem has $S$ subtasks (numbered $1$ through $S$). The difficulty of a problem can be calculated as follows: - Let's denote the score of the $k$-th subtask of this problem by $SC_k$ and the number of contestants who solved it by $NS_k$. - Consider the subtasks sorted in the order of increasing score. - Calculate the number $n$ of valid indices $k$ such that $NS_k > NS_{k + 1}$. - For problem $i$, the difficulty is a pair of integers $(n, i)$. You should sort the problems in the increasing order of difficulty levels. Since difficulty level is a pair, problem $a$ is more difficult than problem $b$ if the number $n$ is greater for problem $a$ than for problem $b$, or if $a > b$ and $n$ is the same for problems $a$ and $b$. -----Input----- - The first line of the input contains two space-separated integers $P$ and $S$ denoting the number of problems and the number of subtasks in each problem. - $2P$ lines follow. For each valid $i$, the $2i-1$-th of these lines contains $S$ space-separated integers $SC_1, SC_2, \dots, SC_S$ denoting the scores of the $i$-th problem's subtasks, and the $2i$-th of these lines contains $S$ space-separated integers $NS_1, NS_2, \dots, NS_S$ denoting the number of contestants who solved the $i$-th problem's subtasks. -----Output----- Print $P$ lines containing one integer each — the indices of the problems in the increasing order of difficulty. -----Constraints----- - $1 \le P \le 100,000$ - $2 \le S \le 30$ - $1 \le SC_i \le 100$ for each valid $i$ - $1 \le NS_i \le 1,000$ for each valid $i$ - in each problem, the scores of all subtasks are unique -----Subtasks----- Subtask #1 (25 points): $S = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 3 16 24 60 498 861 589 14 24 62 72 557 819 16 15 69 435 779 232 -----Example Output----- 2 1 3
p, s = tuple(map(int, input().split())) ans = {} for i in range(p): score = list(map(int, input().split())) contestant = list(map(int, input().split())) d = {} for j in range(s): d[score[j]] = contestant[j] inc_score = list(d.keys()) inc_score.sort() new = [] for j in range(s): new.append(d[inc_score[j]]) count = 0 for j in range(s - 1): if new[j] > new[j + 1]: count += 1 ans[i + 1] = count final = sorted(ans.items(), key=lambda x: x[1]) for i in range(p): print(final[i][0])
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER