description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
from sys import stdin input = lambda: stdin.readline().rstrip("\r\n") for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if sorted(a)[::2] == sorted(a[::2]): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING 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 IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) a[::2] = sorted(a[::2]) a[1::2] = sorted(a[1::2]) if a == sorted(a): print("Yes") else: print("No")
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 NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
def vec_add(el1, el2): return [el1[0] + el2[0], el1[1] + el2[1]] for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = sorted(a) d = {} for i in range(len(a)): if a[i] in d: if i % 2 == 0: d[a[i]] = vec_add(d[a[i]], [1, 0]) else: d[a[i]] = vec_add(d[a[i]], [0, 1]) elif i % 2 == 0: d[a[i]] = [1, 0] else: d[a[i]] = [0, 1] db = {} for i in range(len(b)): if b[i] in db: if i % 2 == 0: db[b[i]] = vec_add(db[b[i]], [1, 0]) else: db[b[i]] = vec_add(db[b[i]], [0, 1]) elif i % 2 == 0: db[b[i]] = [1, 0] else: db[b[i]] = [0, 1] if d == db: print("YES") else: print("NO")
FUNC_DEF RETURN LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER 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 VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
ans = [] for _ in range(int(input())): n = int(input()) u = list(map(int, input().split())) s = sorted(u) t0 = [0] * (10**5 + 1) t1 = [0] * (10**5 + 1) for i in range(n): if i % 2 == 0: t0[s[i]] += 1 else: t1[s[i]] += 1 for i in range(n): if i % 2 == 0: if t0[u[i]] == 0: ans.append("NO") break t0[u[i]] -= 1 else: if t1[u[i]] == 0: ans.append("NO") break t1[u[i]] -= 1 else: ans.append("YES") print("\n".join(ans))
ASSIGN VAR LIST 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 VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
def solve(): n = int(input()) a = [int(i) for i in input().split()] b = sorted(a) even = {i: (0) for i in b} odd = {i: (0) for i in b} for i in range(len(b)): if i % 2: odd[b[i]] += 1 else: even[b[i]] += 1 for i in range(len(a)): if i % 2: if odd[a[i]]: odd[a[i]] -= 1 else: return "NO" elif even[a[i]]: even[a[i]] -= 1 else: return "NO" return "YES" for _ in range(int(input())): print(solve())
FUNC_DEF 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 ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER RETURN STRING IF VAR VAR VAR VAR VAR VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
def strangesort(n, arr): tab = [(arr[i], i) for i in range(n)] tab = sorted(tab, key=lambda x: x[0]) cur_count = [0, 0] prev = -1 for x in range(n): if tab[x][0] != prev: if cur_count[0] != cur_count[1]: print("NO") return cur_count[0] = 0 cur_count[1] = 0 prev = tab[x][0] cur_count[x % 2] += abs(x - tab[x][1]) & 1 print("YES") for _ in range(int(input())): strangesort(int(input()), list(map(int, input().split())))
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
import sys from sys import stdin tt = int(stdin.readline()) ANS = [] for loop in range(tt): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) o = [] e = [] for i in range(n): if i % 2 == 0: e.append(a[i]) else: o.append(a[i]) e.sort() o.sort() b = [] for i in range(n): if i % 2 == 0: b.append(e[i // 2]) else: b.append(o[i // 2]) ans = "YES" for i in range(n - 1): if b[i] > b[i + 1]: ans = "NO" break ANS.append(ans) print("\n".join(ANS))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) s = sorted(arr) v = {} for i in range(n): if arr[i] in v: v[arr[i]][i % 2] += 1 else: v[arr[i]] = [0, 0] v[arr[i]][i % 2] += 1 ans = "YES" flag = False i = -1 while not flag: i += 1 if v[s[i]][i % 2] != 0: v[s[i]][i % 2] -= 1 else: flag = True ans = "NO" if i + 1 == n: flag = True print(ans)
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 VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
import sys input = lambda: sys.stdin.readline() int_arr = lambda: list(map(int, input().split())) str_arr = lambda: list(map(str, input().split())) get_str = lambda: map(str, input().split()) get_int = lambda: map(int, input().split()) get_flo = lambda: map(float, input().split()) mod = 1000000007 def solve(n, a, b): ea = [a[i] for i in range(0, n, 2)] oa = [a[i] for i in range(1, n, 2)] eb = [b[i] for i in range(0, n, 2)] ob = [b[i] for i in range(1, n, 2)] ea.sort() oa.sort() if ea == eb and oa == ob: print("YES") else: print("NO") for _ in range(int(input())): n = int(input()) a = int_arr() b = sorted(a) solve(n, a, b)
IMPORT ASSIGN 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) arr = [] for i in range(max(a) + 1): arr.append([0, 0]) for i in range(n): arr[a[i]][i % 2] += 1 b = a.copy() b.sort() ver = True for i in range(n): if arr[b[i]][i % 2] > 0: arr[b[i]][i % 2] -= 1 else: ver = False break if ver: print("YES") else: print("NO")
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 LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) dp = [(0) for x in range(10**5 + 2)] for i in range(n): if i % 2 == 0: dp[a[i]] += 1 a.sort() for i in range(n): if i % 2 == 0: dp[a[i]] -= 1 flag = True for k in dp: if k != 0: flag = False break if flag: print("YES") else: print("NO")
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 NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
for _ in range(int(input().strip())): n = int(input().strip()) arr = list(map(int, input().strip().split())) flag = 0 c = max(arr) cnt = [[0, 0] for i in range(c + 1)] for i in range(0, n): cnt[arr[i]][i % 2] += 1 arr.sort() for i in range(0, n): cnt[arr[i]][i % 2] -= 1 for i in range(n): if cnt[arr[i]][0] != 0 or cnt[arr[i]][1] != 0: print("NO") flag = 1 break if flag == 0: print("YES")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = "YES" even, odd = [], [] for i in range(n): if i & 1: odd.append(a[i]) else: even.append(a[i]) arr = [0] * n even.sort() odd.sort() for i in range(0, n, 2): arr[i] = even[i // 2] if i + 1 < n: arr[i + 1] = odd[(i + 1) // 2] a.sort() for i in range(n): if a[i] == arr[i]: continue else: ans = "NO" break 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 STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
def count(n, A, odd, even): for i in range(n): if i % 2 == 0: even[A[i]] += 1 else: odd[A[i]] += 1 def checker(n, A, odd, even): status = True for i in range(n): if i % 2 == 0: if even[A[i]] == 0: status = False else: even[A[i]] -= 1 elif odd[A[i]] == 0: status = False else: odd[A[i]] -= 1 return status def __main__(): t = int(input()) while t > 0: n = int(input()) A = [int(_) for _ in input().split(" ")] odd, even = [(0) for _ in range(max(A) + 1)], [(0) for _ in range(max(A) + 1)] count(n, A, odd, even) A.sort() if checker(n, A, odd, even): print("YES") else: print("NO") t -= 1 __main__()
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
def pro(arr): dic = {} n = len(arr) for i in range(n): if arr[i] in dic: if i % 2 == 0: dic[arr[i]][0] += 1 else: dic[arr[i]][1] += 1 elif i % 2 == 0: dic[arr[i]] = [1, 0] else: dic[arr[i]] = [0, 1] arr.sort() dic2 = {} n = len(arr) for i in range(n): if arr[i] in dic2: if i % 2 == 0: dic2[arr[i]][0] += 1 else: dic2[arr[i]][1] += 1 elif i % 2 == 0: dic2[arr[i]] = [1, 0] else: dic2[arr[i]] = [0, 1] for i, j in dic2.items(): if dic[i] != j: print("NO") return print("YES") t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) pro(arr)
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING 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 EXPR FUNC_CALL VAR VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
t = int(input()) ans = [] for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] b = sorted(a) f1 = [0] * (10**5 + 1) f2 = [0] * (10**5 + 1) for i in range(0, n, 2): f1[a[i]] += 1 f2[b[i]] += 1 if f1 == f2: ans.append("YES") else: ans.append("NO") for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
t = int(input()) for i in range(t): n = int(input()) w = [int(k) for k in input().split()] c = sorted(w) a, b = {}, {} for j in range(n): if c[j] in a: a[c[j]][j % 2] += 1 else: a[c[j]] = [0, 0] a[c[j]][j % 2] += 1 if w[j] in b: b[w[j]][j % 2] += 1 else: b[w[j]] = [0, 0] b[w[j]][j % 2] += 1 for j in a.keys(): if a[j] != b[j]: print("NO") break else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split(" ")] le = [] lo = [] so = [] se = [] a = sorted(l) for i in range(n): if i & 1: lo.append(l[i]) so.append(a[i]) else: le.append(l[i]) se.append(a[i]) le.sort() lo.sort() print("YES" if le == se and lo == so else "NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR STRING STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
for _ in range(int(input())): tt = int(input()) arr = list(map(int, input().split())) if tt == 1: print("YES") continue crr = sorted(arr) odl = list(arr[::2]) evl = list(arr[1::2]) odl.sort() evl.sort() ct1 = 0 ct2 = 0 flag = 1 for x in range(tt): if x % 2 == 1: if evl[ct1] != crr[x]: flag = 0 break ct1 += 1 else: if odl[ct1] != crr[x]: flag = 0 break ct2 += 1 if flag: print("YES") else: print("NO")
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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
import sys def main(): for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) memo = {i: [0, 0] for i in list(set(arr))} for i, a in enumerate(arr): memo[a][i % 2] += 1 for i, a in enumerate(sorted(arr)): memo[a][i % 2] -= 1 flag = True for i in memo: if memo[i].count(0) != 2: flag = False if flag: print("YES") else: print("NO") main()
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
def process(A): d = {} n = len(A) for i in range(n): c = A[i] if c not in d: d[c] = [[], []] d[c][0].append(i) A = sorted(A) for i in range(n): c = A[i] d[c][1].append(i) for c in d: a = [0, 0, 0, 0] for i in d[c][0]: a[i % 2] += 1 for i in d[c][1]: a[2 + i % 2] += 1 if a[0] != a[2] or a[1] != a[3]: return "NO" return "YES" t = int(input()) for i in range(t): n = int(input()) A = [int(x) for x in input().split()] print(process(A))
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST LIST LIST EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
l = [] k = [] for _ in range(int(input())): n = int(input()) d = {} l = list(map(int, input().split())) for i in range(n): if i % 2 == 0: if l[i] in d: d[l[i]] += 1 else: d[l[i]] = 1 elif -l[i] in d: d[-l[i]] += 1 else: d[-l[i]] = 1 k = sorted(l) for i in range(n): if i % 2 == 0: if k[i] in d: d[k[i]] -= 1 if d[k[i]] < 0: print("NO") break else: print("NO") break elif -k[i] in d: d[-k[i]] -= 1 if d[-k[i]] < 0: print("NO") break else: print("NO") break else: print("YES")
ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
t = int(input()) for i in range(t): n = int(input()) s = input().strip().split(" ") a = [int(x) for x in s] num_of_odd_indexes = {} for j in range(n): if j % 2 == 1 and a[j] not in num_of_odd_indexes: num_of_odd_indexes[a[j]] = 1 elif j % 2 == 1: num_of_odd_indexes[a[j]] += 1 elif a[j] not in num_of_odd_indexes: num_of_odd_indexes[a[j]] = 0 a.sort() possible = True current_index = 0 while current_index < n: num_of_odd_indexes_here = 1 if current_index % 2 == 0: num_of_odd_indexes_here = 0 while current_index + 1 < n and a[current_index] == a[current_index + 1]: current_index += 1 if current_index % 2 == 1: num_of_odd_indexes_here += 1 if num_of_odd_indexes_here != num_of_odd_indexes[a[current_index]]: possible = False current_index += 1 if possible: print("YES") else: print("NO")
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 FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) β€” the number of test cases. The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) β€” the number of Aquamoon's friends. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) β€” the numbers, written on the T-shirts. It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. -----Output----- For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower). -----Examples----- Input 3 4 4 3 2 5 4 3 3 2 2 5 1 2 3 5 4 Output YES YES NO -----Note----- The possible list of operations in the first test case: Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = sorted(A) hashmap_A = {} hashmap_B = {} for i in range(n): if A[i] not in hashmap_A: hashmap_A[A[i]] = [0, 0] if B[i] not in hashmap_B: hashmap_B[B[i]] = [0, 0] if i % 2 == 0: hashmap_A[A[i]][0] += 1 hashmap_B[B[i]][0] += 1 else: hashmap_A[A[i]][1] += 1 hashmap_B[B[i]][1] += 1 flag = True for key in hashmap_A.keys(): if hashmap_A[key] != hashmap_B[key]: flag = False break print("YES" if flag else "NO")
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 VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class Solution: def arrangeWords(self, text: str) -> str: if not text: return text words = text.lower().split(" ") words = sorted(words, key=lambda x: len(x)) words[0] = words[0][0].upper() + words[0][1:] return " ".join(words)
CLASS_DEF FUNC_DEF VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN FUNC_CALL STRING VAR VAR
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class Solution: def arrangeWords(self, text: str) -> str: dic = collections.OrderedDict() for word in text.split(): n = len(word) dic[n] = dic.get(n, []) + [word.lower()] res = [] for key, val in sorted(dic.items()): res += val return " ".join(res).capitalize()
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST LIST FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL FUNC_CALL STRING VAR VAR
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class Solution: def arrangeWords(self, text: str) -> str: p = text.split(" ") final = "" j = sorted(p, key=len) temp = " ".join(j) if temp[0] >= "a" and temp[0] <= "z": s = temp[0].swapcase() final = final + s[0] else: final = final + temp[0] for i in range(1, len(temp)): if temp[i] >= "A" and temp[i] <= "Z": s = temp[i].swapcase() final = final + s[0] else: final = final + temp[i] return final
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR VAR
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class Solution: def arrangeWords(self, text: str) -> str: res = [] res_t = "" for idx, word in enumerate(text.split()): res.append((len(word), idx, word.lower())) res.sort() for l, _, word in res: if res_t == "": res_t += word[0].upper() + word[1:] else: res_t += " " + word return res_t
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR STRING VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP STRING VAR RETURN VAR VAR
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class Solution: def arrangeWords(self, text: str) -> str: text = text[0].lower() + text[1:] words = [] word = "" word_len = 0 for char in text: if char == " ": words.append((word_len, word)) word = "" word_len = 0 else: word += char word_len += 1 if word_len > 0: words.append((word_len, word)) words.sort(key=lambda tup: tup[0]) output = "" for word in words: output += word[1] + " " return output[:-1].capitalize()
CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP VAR NUMBER STRING RETURN FUNC_CALL VAR NUMBER VAR
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class K: def __init__(self, obj): self.obj = obj def __lt__(self, other): return len(self.obj) < len(other.obj) class Solution: def arrangeWords(self, text: str) -> str: l = text.split() l[0] = l[0].lower() l = sorted(l, key=K) l[0] = l[0].title() return " ".join(l)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER RETURN FUNC_CALL STRING VAR VAR
Given a sentenceΒ text (AΒ sentenceΒ is a string of space-separated words) in the following format: First letter is in upper case. Each word in text are separated by a single space. Your task is to rearrange the words in text such thatΒ all words are rearranged in an increasing order of their lengths. If two words have the same length, arrange them in their original order. Return the new textΒ following the format shown above. Β  Example 1: Input: text = "Leetcode is cool" Output: "Is cool leetcode" Explanation: There are 3 words, "Leetcode" of length 8, "is" of length 2 and "cool" of length 4. Output is ordered by length and the new first word starts with capital letter. Example 2: Input: text = "Keep calm and code on" Output: "On and keep calm code" Explanation: Output is ordered as follows: "On" 2 letters. "and" 3 letters. "keep" 4 letters in case of tie order by position in original text. "calm" 4 letters. "code" 4 letters. Example 3: Input: text = "To be or not to be" Output: "To be or to be not" Β  Constraints: text begins with a capital letter and then contains lowercase letters and single space between words. 1 <= text.length <= 10^5
class Solution: def arrangeWords(self, text: str) -> str: counter = 0 current_word = "" words_map = {} for i in range(0, len(text)): ch = text[i].lower() if ch == " " or i == len(text) - 1: if i == len(text) - 1: counter += 1 current_word += ch if counter not in words_map: words_map[counter] = [] words_map[counter].append(current_word) counter = 0 current_word = "" else: counter += 1 current_word += ch ordered_keys = list(words_map.keys()) ordered_keys.sort() ans = "" for i in range(0, len(ordered_keys)): if i == 0: ans = " ".join(words_map[ordered_keys[i]]) else: ans += " " + " ".join(words_map[ordered_keys[i]]) ans = ans[0].upper() + ans[1:] return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR BIN_OP STRING FUNC_CALL STRING VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def eulid(p, q): A = [1, 0] B = [0, 1] while p != 1 and q != 1: if q < 0: q = -q B[0] = -B[0] B[1] = -B[1] if p < 0: p = -p A[0] = -A[0] A[1] = -A[1] if q < p: p, q = q, p A, B = B, A T = q // p q = q - T * p B[0] = B[0] - T * A[0] B[1] = B[1] - T * A[1] if q < 0: q = -q B[0] = -B[0] B[1] = -B[1] if p < 0: p = -p A[0] = -A[0] A[1] = -A[1] if p == 1: return A elif q == 1: return B def find(x, y, p, q): if p == q: if x == y: return 0 else: return -1 elif p == 0: if x == 0: return 0 else: return -1 elif p * y == x * q: return 0 else: A = x * q - p * y a, b = eulid(p, q) k0, t0 = A * a, -b * A temp = t0 % p r = (temp - t0) // p k1 = k0 + r * q t1 = t0 + r * p if k1 >= t1: return k1 else: if (t1 - k1) % (q - p) == 0: r = (t1 - k1) // (q - p) else: r = (t1 - k1) // (q - p) + 1 k2 = k1 + r * q t2 = t1 + r * p return k2 T = int(input()) for _ in range(T): x, y, p, q = list(map(int, input().strip().split(" "))) print(find(x, y, p, q))
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
for _ in range(int(input())): x, y, p, q = [int(x) for x in input().split(" ")] if y * p == x * q: print(0) continue m1 = -1 m2 = -1 if p == 0: m1 = -1 elif x % p: m1 = x // p + 1 else: m1 = x // p if p == q: m2 = -1 elif (y - x) % (q - p): m2 = (y - x) // (q - p) + 1 else: m2 = (y - x) // (q - p) if m2 == -1 or m1 == -1: print(-1) else: print(max(m1, m2) * q - y)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
import sys def solve(): t = int(sys.stdin.readline()) for ti in range(t): x, y, p, q = map(int, sys.stdin.readline().split()) if p == 0: if x == 0: print(0) else: print(-1) continue if p == q: if x == y: print(0) else: print(-1) continue if p * y == x * q: print(0) elif p * y > x * q: z = (q * (y - x) + q - p - 1) // (q - p) ans = (z + q - 1) // q * q - y print(ans) else: z = (q * x + p - 1) // p ans = (z + q - 1) // q * q - y print(ans) solve()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
n = int(input()) for _ in range(n): x, y, p, q = map(int, input().split()) if p == 0 and x != 0: print(-1) elif p == q and x != y: print(-1) elif p * y == q * x: print(0) else: print(q * max((x + p - 1) // p, (y - x + q - p - 1) // (q - p)) - y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
for _ in range(int(input())): x, y, p, q = map(int, input().split()) l, r, res = 0, 10**18, -1 while l <= r: mid = (l + r) // 2 a, b = p * mid - x, q * mid - y if a <= b and a > -1 and b > -1: res = b r = mid - 1 else: l = mid + 1 print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def gcd(a, b): while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b def check(x, y, p, q, m): num = p * m den = q * m return num - x >= 0 and den - y - (num - x) >= 0 def count(x, y, p, q, m): num = p * m den = q * m return num - x + (den - y - (num - x)) def search(x, y, p, q): l, r = -1, 10**9 + 1 while r - l > 1: m = (l + r) // 2 if check(x, y, p, q, m): r = m else: l = m if r == 10**9 + 1: print(-1) else: print(count(x, y, p, q, r)) n = int(input()) for i in range(n): x, y, p, q = map(int, input().split()) search(x, y, p, q)
FUNC_DEF WHILE VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
t = int(input()) for zz in range(t): x, y, p, q = [int(i) for i in input().split()] if x * q == y * p: print(0) elif p == 0 and x != 0 or p == q and x != y: print(-1) else: sel1 = y - x sel2 = q - p kalr = x // p + (0, 1)[x % p != 0] kalr = max(kalr, sel1 // sel2 + (0, 1)[sel1 % sel2 != 0]) q *= kalr print(q - y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
tests = int(input()) def generate(x, y, p, q): min_a = -1 max_a = 10**18 while max_a - min_a > 1: mid_a = (max_a + min_a) // 2 if (x + mid_a) * q < (y + mid_a) * p: min_a = mid_a else: max_a = mid_a return max_a for test in range(tests): x, y, p, q = map(int, input().split()) if p == 0: print(0 if x == 0 else -1) elif q == 1: print(0 if x == y else -1) else: a = generate(x, y, p, q) a += (p - x - a) % p b = (q - y - a) % q cnt = (x + a) // p - (y + a + b) // q print(a + b + q * cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def check(k1, k2, rr): k3 = p * k2 - rr return k3 >= 0 and k2 * q + k1 >= k3 def binary_search(k1, rr): r = 1 while not check(k1, r, rr): r *= 2 l = -1 while l + 1 < r: m = (l + r) // 2 if check(k1, m, rr): r = m else: l = m return r n = int(input()) for _ in range(n): x, y, p, q = map(int, input().split()) if p == 0 and x != 0 or p == q and x != y: print(-1) continue k1 = (y + q - 1) // q * q - y y += k1 rr = x - y // q * p r = binary_search(k1, rr) print(r * q + k1)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
T = int(input()) for case in range(T): x, y, p, q = map(int, input().strip().split()) l = int(0) r = int(10000000000.0) ans = 1 << 30 while l <= r: mid = int((l + r) / 2) A = mid * p - x B = mid * q - y if A >= 0 and B >= 0 and A <= B: ans = min(ans, mid) r = mid - 1 else: l = mid + 1 if ans < 1 << 30: print(ans * q - y) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
t = int(input()) for i in range(t): x, y, p, q = map(int, input().split()) if p == q and x != y: print(-1) elif not p: if x: print(-1) else: print(0) else: r = max((y + q - 1) // q, (x + p - 1) // p) if r * p > x + r * q - y: if p == q: print(0) else: r = (y - x + q - p - 1) // (q - p) print(r * q - y) else: print(r * q - y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def gcd(a, b): if a == 0: return b return gcd(b % a, a) def get(x, y, p, q): low, high, mid, best = 1, 1 << 65, 0, -1 while low <= high: mid = low + high + 1 >> 1 tp = p * mid tq = q * mid if tq >= y and x <= tp <= x + tq - y: best = mid high = mid - 1 else: low = mid + 1 return best T = int(input()) for _ in range(T): x, y, p, q = map(int, input().split()) if x == 0 and p == q: print(-1) continue if x == y and p == 0: print(-1) continue if x == 0 and p == 0: print(0) continue nx, ny = x, y nx //= gcd(x, y) ny //= gcd(x, y) need = get(nx, ny, p, q) rx = need * p ry = need * q low, high, mid, best = 0, 1 << 63, 0, -1 while low <= high: mid = low + high + 1 >> 1 if ( rx + mid * p >= x and ry + mid * q >= y and ry + mid * q - y >= rx + mid * p - x ): best = mid high = mid - 1 else: low = mid + 1 if best == -1: print(-1) continue rx += best * p ry += best * q if rx * q == ry * p: print(ry - y) else: print(-1)
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def Ans(k): x, y, p, q = k[0], k[1], k[2], k[3] if p / q == 1 and x != y or p == 0 and x != 0: print(-1) elif p == 0 and x == 0: print(0) else: up = 10**9 down = 1 dy = y - x while up > down + 1: mid = (up + down) // 2 qf = q * mid pf = p * mid dq = qf - pf if qf - y >= dq - dy and qf >= y and dq >= dy: up = mid else: down = mid if ( q * down - y >= (q - p) * down - dy and q * down >= y and (q - p) * down >= dy ): print(q * down - y) elif q * mid - y >= (q - p) * mid - dy and q * mid >= y and (q - p) * mid >= dy: print(q * mid - y) else: print(q * up - y) t = int(input()) k = [0] * t for i in range(t): k[i] = list(map(int, input().split())) for i in range(t): Ans(k[i])
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
tc = int(input()) for i in range(tc): x, y, p, q = map(int, input().split()) if p == 0: if x == 0: print("0") else: print("-1") elif p == q: if y > x: print("-1") else: print("0") elif p * y == x * q: print("0") else: def minmax(lob, hib): if lob == hib: return lob - y lower = (lob + hib) // 2 higher = lower + q - lower % q lower = higher - q newxh = higher // q * p if 0 <= newxh - x <= higher - y: newxl = lower // q * p if 0 <= newxl - x <= lower - y: return minmax(lob, lower) else: return higher - y else: return minmax(higher, hib) lob = y + q - y % q hib = 10**19 + q - 10**19 % q print(str(minmax(lob, hib)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF NUMBER BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
t = int(input()) for _ in range(t): x, y, a, b = map(int, input().split()) if a == 0: if x == 0: print(0) else: print(-1) continue lo = max(-(-x // a), -(-y // b)) hi = 10**18 while lo < hi: k = lo + (hi - lo) // 2 if k * (a - b) <= x - y: hi = k else: lo = k + 1 if lo * (a - b) <= x - y: print(lo * b - y) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
t = int(input()) for i in range(t): x, y, p, q = map(int, input().split()) if p == 1 and q == 1 and x // y != 1 or p == 0 and x != 0: z = -1 else: start = 0 stop = 10**9 while start <= stop - 2: mid = (start + stop) // 2 if mid * q - y + x >= mid * p and mid * q >= y and mid * p >= x: stop = mid else: start = mid z = stop * q - y print(z)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
t = int(input()) for _ in range(t): x, y, p, q = map(int, input().split()) if p == q: print(0 if x == y else -1) elif p == 0: print(0 if x == 0 else -1) elif x * q == y * p: print(0) else: l = 0 r = 2**64 cnt = 0 while l + 1 < r: cnt += 1 c = (l + r) // 2 if x <= c * p <= x + c * q - y: r = c else: l = c print(r * q - y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def mp(): return map(int, input().split()) def lt(): return list(map(int, input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def listring(l): return " ".join([str(x) for x in l]) def ptlist(l): print(" ".join([str(x) for x in l])) t = it() for _ in range(t): x, y, p, q = mp() if p == q: if x == y: pt(0) else: pt(-1) elif p == 0: if x == 0: pt(0) else: pt(-1) else: r = (y + q - 1) // q xa, ya = r * p, r * q if xa < x: m = (x - xa + p - 1) // p else: m = 0 if xa - x > ya - y: n = (xa - x - (ya - y) + q - p - 1) // (q - p) else: n = 0 pt(ya + q * max(m, n) - y)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
MAXN = int(2e18) def check(n, x, y, p, q): np, nq = n * p, n * q if nq < y: return False diff = nq - y return x <= np <= x + diff def solve(): x, y, p, q = map(int, input().split()) l, r = 1, int(MAXN) while l != r: m = (l + r) // 2 if not check(m, x, y, p, q): l = m + 1 else: r = m if r == MAXN: print(-1) else: print(l * q - y) t = int(input()) for _ in range(t): solve()
ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def ceil(x, y): return x // y + (x % y != 0) for _ in range(int(input())): x, y, p, q = map(int, input().split()) if p == 0: print(0 if x == 0 else -1) elif p == q: print(0 if x == y else -1) else: k = max(ceil(y * q - q * x, q * (q - p)), ceil(x, p)) a = k * p - x b = k * q - (a + y) print(a + b)
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def solve(x, y, p, q): if p == q: if x == y: return 0 else: return -1 if p == 0: if x == 0: return 0 else: return -1 k1 = (y - x) // (q - p) if k1 * (q - p) < y - x: k1 += 1 k2 = y // q if k2 * q < y: k2 += 1 k3 = x // p if k3 * p < x: k3 += 1 k = max(k1, k2, k3) return k * q - y def main(): t = int(input()) for i in range(t): x, y, p, q = map(int, input().split()) print(solve(x, y, p, q)) main()
FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
def ext_gcd(a, b): if a == 0: return b, 0, 1 else: g, x, y = ext_gcd(b % a, a) return g, y - b // a * x, x def multinv(b, n): g, x, trash = ext_gcd(b, n) return x % n def solve(): x, y, p, q = map(int, input().split(" ")) if p == q: if x == y: return 0 else: return -1 if p == 0: if x == 0: return 0 else: return -1 c = p * y - q * x a = multinv(q, p) * c % p if (q * a - c) // p < a: dif = c // (q - p) - a dif = dif // p a += p * (dif - 3) while (q * a - c) // p < a or a < 0: a += p return (q * a - c) // p t = int(input()) for a0 in range(t): print(solve())
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q? Input The first line contains a single integer t (1 ≀ t ≀ 1000) β€” the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≀ x ≀ y ≀ 109; 0 ≀ p ≀ q ≀ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≀ 5 must be met. Output For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve. Example Input 4 3 10 1 2 7 14 3 8 20 70 2 7 5 6 1 1 Output 4 10 0 -1 Note In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7. In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
for _ in range(int(input())): x, y, p, q = map(int, input().split()) d = q * int(1000000000.0) c = p * int(1000000000.0) if not (c >= x and d - y >= c - x): print(-1) continue i = -1 j = int(1000000000.0) while j - i > 1: m = (i + j) // 2 d = q * m c = p * m if c >= x and d - y >= c - x: j = m else: i = m print(j * q - y)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class intersection: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): if self.x < other.x or self.x == other.x and self.y < other.y: return True else: return False a = [] x = [] y = [] for i in range(8): m, n = list(map(int, input().split())) x.append(m) y.append(n) a.append(intersection(m, n)) a.sort() def cnt_dif(a): tempt = a[:] tempt.sort() dif = [tempt[0]] for i in range(1, 8): if tempt[i] != tempt[i - 1]: dif.append(tempt[i]) return dif b = [] res_x = cnt_dif(x) res_y = cnt_dif(y) flag = True if len(res_x) == 3 and len(res_y) == 3: for i in range(3): for j in range(3): if i == 1 and j == 1: continue else: b.append(intersection(res_x[i], res_y[j])) if len(b) != 8: flag = False else: for i in range(8): if a[i].x != b[i].x or a[i].y != b[i].y: flag = False break if flag: print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class point: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): return self.x < other.x or self.x == other.x and self.y < other.y p = [] for i in range(8): x, y = map(int, input().split()) p.append(point(x, y)) p.sort() if ( p[0].x == p[1].x and p[1].x == p[2].x and p[2].x != p[3].x and p[3].x == p[4].x and p[4].x != p[5].x and p[5].x == p[6].x and p[6].x == p[7].x and p[0].y == p[3].y and p[3].y == p[5].y and p[5].y != p[1].y and p[1].y == p[6].y and p[6].y != p[2].y and p[2].y == p[4].y and p[4].y == p[7].y ): print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class Point: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): return self.x < other.x or self.x == other.x and self.y <= other.y p = [] for i in range(8): a, b = map(int, input().split()) p.append(Point(a, b)) p.sort() ugly = False for i in range(1, 3): if ( p[i].x != p[i - 1].x or p[i + 5].x != p[i + 4].x or p[i].y != p[i + 5].y or p[i].y == p[i - 1].y or p[i + 5].y == p[i + 4].y ): ugly = True if ( p[3].x != p[4].x or p[3].y == p[4].y or p[0].y != p[0].y or p[0].y != p[3].y or p[7].y != p[4].y ): ugly = True if ugly: print("ugly") else: print("respectable")
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
def Slove(): A = sorted(tuple(map(int, input().split())) for _ in range(8)) if ( A[0][0] == A[1][0] == A[2][0] < A[3][0] == A[4][0] < A[5][0] == A[6][0] == A[7][0] and A[0][1] == A[3][1] == A[5][1] < A[1][1] == A[6][1] < A[2][1] == A[4][1] == A[7][1] ): print("respectable") else: print("ugly") Slove()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
Q = sorted S = set I = S() X = S() Y = S() T = S() for _ in "0" * 8: x, y = map(int, input().split()) I.add((x, y)) X.add(x) Y.add(y) X = Q(X) Y = Q(Y) print( ["ugly", "respectable"][ len(X) == len(Y) == 3 and set([(x, y) for x in X for y in Y if x != X[1] or y != Y[1]]) == I ] )
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP STRING NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
x = [] y = [] all = [] for i in range(8): xx, yy = map(int, input().split()) x.append(xx) y.append(yy) all.append((xx, yy)) sx = set(x) sy = set(y) if len(sx) % 3 != 0 or len(sy) % 3 != 0: print("ugly") else: sx = sorted(list(sx)) sy = sorted(list(sy)) for i in range(3): for j in range(3): if i == 1 and j == 1: continue if not (sx[i], sy[j]) in all: print("ugly") exit() print("respectable")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
lines = [tuple(map(int, input().split())) for i in range(8)] x_set = set() y_set = set() for x, y in lines: x_set.add(x) y_set.add(y) if len(x_set) == len(y_set) == 3: flag = False x_sort, y_sort = sorted(x_set), sorted(y_set) for x in x_sort: for y in y_sort: if (x, y) != (x_sort[1], y_sort[1]) and (x, y) not in lines: flag = True else: flag = True print("ugly" if flag else "respectable")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
(a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p) = sorted( tuple(map(int, input().split())) for _ in range(8) ) print( ("ugly", "respectable")[ a == c == e < g == i < k == m == o and b == h == l < d == n < f == j == p ] )
ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
l = [] for i in range(8): x, y = [int(x) for x in input().split()] l.append((x, y)) l.sort() lx = [] lx.append(l[0][0]) lx.append(l[3][0]) lx.append(l[6][0]) ly = [] ly.append(l[0][1]) ly.append(l[1][1]) ly.append(l[2][1]) eps = [(x, y) for x in lx for y in ly] eps.pop(4) if ( l == eps and lx[0] != lx[1] and lx[0] != lx[2] and lx[1] != lx[2] and ly[0] != ly[1] and ly[0] != ly[2] and ly[1] != ly[2] ): print("respectable") else: print("ugly")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
n = 8 p = [] xs = [] ys = [] for i in range(n): x, y = map(int, input().split()) p.append((x, y)) xs.append(x) ys.append(y) xs = list(sorted(list(set(xs)))) ys = list(sorted(list(set(ys)))) p.sort() if len(xs) != 3 or len(ys) != 3: print("ugly") elif p == [ (xs[0], ys[0]), (xs[0], ys[1]), (xs[0], ys[2]), (xs[1], ys[0]), (xs[1], ys[2]), (xs[2], ys[0]), (xs[2], ys[1]), (xs[2], ys[2]), ]: print("respectable") else: print("ugly")
ASSIGN VAR NUMBER ASSIGN VAR LIST 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 VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
def f(p): if len(set(p)) < 8: return False x, y = sorted({pi[0] for pi in p}), sorted({pi[1] for pi in p}) return len(x) == 3 and len(y) == 3 and (x[1], y[1]) not in p print( "respectable" if f([tuple(map(int, input().split())) for i in range(8)]) else "ugly" )
FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER STRING STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
x = [] y = [] for i in range(8): xi, yi = map(int, input().split()) x.append(xi) y.append(yi) xtmp = sorted(x) ytmp = sorted(y) xdist_list = [xtmp[0]] ydist_list = [ytmp[0]] for i in range(1, 8): if xtmp[i] != xtmp[i - 1]: xdist_list.append(xtmp[i]) if ytmp[i] != ytmp[i - 1]: ydist_list.append(ytmp[i]) if len(xdist_list) != 3 or len(ydist_list) != 3: print("ugly") exit() full_eight_points_set = [] for i in range(3): for j in range(3): if i != 1 or j != 1: found = False for k in range(8): if x[k] == xdist_list[i] and y[k] == ydist_list[j]: found = True break if not found: print("ugly") exit() print("respectable")
ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
fre_x = [False] * (10**6 + 5) fre_y = [False] * (10**6 + 5) unique_x = [] unique_y = [] points = [] for _ in range(8): x, y = map(int, input().split()) points.append((x, y)) if not fre_x[x]: fre_x[x] = True unique_x.append(x) if not fre_y[y]: fre_y[y] = True unique_y.append(y) if len(unique_x) != 3 or len(unique_y) != 3: print("ugly") exit() unique_x.sort() unique_y.sort() points.sort() index = 0 for i in range(3): for j in range(3): if i == j == 1: continue if unique_x[i] == points[index][0] and unique_y[j] == points[index][1]: index += 1 else: print("ugly") exit() print("respectable")
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
v = [] for i in range(0, 8): x, y = map(int, input().split()) v.append((x, y)) v.sort() if ( v[0][0] == v[1][0] == v[2][0] and v[3][0] == v[4][0] and v[5][0] == v[6][0] == v[7][0] and v[0][1] == v[3][1] == v[5][1] and v[1][1] == v[6][1] and v[2][1] == v[4][1] == v[7][1] and v[0][0] != v[3][0] != v[7][0] and v[0][1] != v[1][1] != v[2][1] ): print("respectable") else: print("ugly")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
x = [] y = [] arr = [] for i in range(8): xi, yi = map(int, input().split()) arr.append((xi, yi)) if xi not in x: x.append(xi) if yi not in y: y.append(yi) if len(x) == 3 and len(y) == 3: x = sorted(x) y = sorted(y) ugly = False for i in range(3): for j in range(3): if not (i == 1 and j == 1) and (x[i], y[j]) not in arr: ugly = True if ugly == True: print("ugly") else: print("respectable") else: print("ugly")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
a = [] def f(n): return n[0] def ff(n): return n[1] for i in range(8): x, y = map(int, input().split()) if [x, y] in a: print("ugly") exit() a.append([x, y]) a.sort(key=f) k = 0 if a[0][0] == a[1][0] and a[1][0] == a[2][0]: k += 1 if a[2][0] != a[3][0]: if a[3][0] == a[4][0]: k += 1 if a[5][0] != a[4][0]: if a[5][0] != a[0][0]: if a[5][0] == a[6][0] and a[6][0] == a[7][0]: k += 1 if k != 3: print("ugly") exit() a.sort(key=ff) if a[0][1] == a[1][1] and a[1][1] == a[2][1]: k += 1 if a[2][1] != a[3][1]: if a[3][1] == a[4][1]: k += 1 if a[5][1] != a[4][1]: if a[5][1] != a[0][1]: if a[5][1] == a[6][1] and a[6][1] == a[7][1]: k += 1 if k == 6: print("respectable") else: print("ugly")
ASSIGN VAR LIST FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
u = set() v = set() w = set() s = set() def work(): nonlocal u, v if len(u) < 3 or len(v) < 3: return 0 u = sorted(list(u)) v = sorted(list(v)) for i in range(3): for j in range(3): if i != 1 or j != 1: w.add((u[i], v[j])) return w == s for i in range(8): x, y = list(map(int, input().split())) s.add((x, y)) u.add(x) v.add(y) if work(): print("respectable") else: print("ugly")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
x = [] y = [] p = [] for i in range(8): a, b = [int(x) for x in input().split()] x.append(a) y.append(b) l = [a, b] p.append(l) sx = list(set(x)) sy = list(set(y)) jud = 0 if len(sx) != 3 or len(sy) != 3: print("ugly") jud = 1 if jud == 0: sx.sort() sy.sort() pp = [] for i in range(3): for j in range(3): li = [sx[i], sy[j]] pp.append(li) pp.remove([sx[1], sy[1]]) p.sort() pp.sort() if p == pp: print("respectable") else: print("ugly")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER 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 LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
import sys from itertools import * fin = sys.stdin points = [] for i in range(8): x, y = map(int, fin.readline().split()) points += [(x, y)] def CheckPoints(p): if not p[0][0] == p[1][0] == p[2][0]: return False x1 = p[0][0] if not p[3][0] == p[4][0]: return False x2 = p[3][0] if not p[5][0] == p[6][0] == p[7][0]: return False x3 = p[5][0] if not p[0][1] == p[3][1] == p[5][1]: return False y1 = p[0][1] if not p[1][1] == p[6][1]: return False y2 = p[1][1] if not p[2][1] == p[4][1] == p[7][1]: return False y3 = p[2][1] return x1 < x2 < x3 and y1 < y2 < y3 for p in permutations(points): if CheckPoints(p): print("respectable") break else: print("ugly")
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR FUNC_DEF IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER RETURN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class Coordinate: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): if self.x < other.x: return True if self.x == other.x and self.y < other.y: return True return False a = [] for i in range(8): x, y = map(int, input().split(" ")) a.append(Coordinate(x, y)) a.sort() if ( a[0].x == a[1].x == a[2].x and a[3].x == a[4].x and a[5].x == a[6].x == a[7].x and a[0].y == a[3].y == a[5].y and a[1].y == a[6].y and a[2].y == a[4].y == a[7].y and a[0].x < a[3].x < a[5].x and a[0].y < a[1].y < a[2].y ): print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
def eight_point_sets_2(s): x = list(set([a[0] for a in s])) x.sort() y = list(set([b[1] for b in s])) y.sort() test = True if len(x) != 3 or len(y) != 3: test = False return test for i in range(0, 3): for j in range(0, 3): if i != 1 or j != 1: if [x[i], y[j]] not in s: test = False break return test l = [] for i in range(8): this_point = [int(x) for x in input().split()] l.append(this_point) result = eight_point_sets_2(l) if result == True: print("respectable") else: print("ugly")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF LIST VAR VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
s = set() w = set() d = dict() for _ in range(8): l = list(map(int, input().split())) s.add(l[0]) w.add(l[1]) if l[0] in d: d[l[0]].append(l[1]) d[l[0]].sort() else: d[l[0]] = list() d[l[0]].append(l[1]) if len(d) > 3: print("ugly") exit() if len(s) < 3 or len(w) < 3 or len(s) > 3 or len(w) > 3: print("ugly") exit() a = sorted(d.keys()) if sorted(d[a[0]]) != sorted(list(w)): print("ugly") exit() if sorted(d[a[2]]) != sorted(list(w)): print("ugly") exit() r = list(w) r.sort() if r[1] in d[a[1]]: print("ugly") exit() elif r[0] in d[a[1]] and r[2] in d[a[1]]: d[a[1]].remove(r[0]) d[a[1]].remove(r[2]) if len(d[a[1]]) == 0: print("respectable") exit() else: print("ugly") exit() else: print("ugly") exit() print("respectable")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
def components(lst, a, b): if len(a) != 3 or len(b) != 3: return "ugly" for x in range(3): for y in range(3): if x == y == 1: continue if [a[x], b[y]] not in lst: return "ugly" return "respectable" arr = [[int(c) for c in input().split()] for i in range(8)] lst1 = sorted(set([p[0] for p in arr])) lst2 = sorted(set([p[1] for p in arr])) print(components(arr, lst1, lst2))
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF LIST VAR VAR VAR VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
x = [None] * 10 y = [None] * 10 t = [] xc = [] yc = [] f = False for i in range(8): x[i], y[i] = list(map(int, input().split())) if (x[i], y[i]) in t: f = True t.append((x[i], y[i])) if not x[i] in xc: xc.append(x[i]) if y[i] not in yc: yc.append(y[i]) if len(xc) != 3 or len(yc) != 3 or f: print("ugly") else: yc.sort() xc.sort() if (xc[1], yc[1]) in t: print("ugly") else: print("respectable")
ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
lists = [] dicts = {} sets = set() for i in range(8): lists.append(tuple(input().split())) for x in lists: sets.add(x) if len(sets) == 8: for x in range(8): count = dicts.get(int(lists[x][0]), 0) dicts[int(lists[x][0])] = count + 1 if len(dicts.keys()) == 3: temp = sorted(dicts.items()) if temp[0][1] == 3 and temp[1][1] == 2 and temp[2][1] == 3: dicts.clear() for x in range(8): count = dicts.get(int(lists[x][1]), 0) dicts[int(lists[x][1])] = count + 1 if len(dicts.keys()) == 3: temp = sorted(dicts.items()) if temp[0][1] == 3 and temp[1][1] == 2 and temp[2][1] == 3: print("respectable") else: print("ugly") else: print("ugly") else: print("ugly") else: print("ugly") else: print("ugly")
ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class Point: def __init__(self, x=0, y=0): self.x = x self.y = y arr_point = [] for i in range(8): tmp_x, tmp_y = map(int, input().split()) arr_point.append(Point(tmp_x, tmp_y)) for i in range(8): for j in range(i + 1, 8): if arr_point[i].x == arr_point[j].x and arr_point[i].y == arr_point[j].y: print("ugly") exit() distinctX = [] distinctX.append(arr_point[0].x) distinctY = [] distinctY.append(arr_point[0].y) for i in range(1, 8): check_x = check_y = False for j in range(len(distinctX)): if arr_point[i].x == distinctX[j]: check_x = True break for j in range(len(distinctY)): if arr_point[i].y == distinctY[j]: check_y = True break if check_x == False: distinctX.append(arr_point[i].x) if check_y == False: distinctY.append(arr_point[i].y) if len(distinctX) != 3 or len(distinctY) != 3: print("ugly") exit() distinctX.sort() distinctY.sort() cnt_point = 0 for k in range(8): for i in range(len(distinctX)): for j in range(len(distinctY)): if arr_point[k].x == distinctX[i] and arr_point[k].y == distinctY[j]: if i != 1 or j != 1: cnt_point += 1 break if cnt_point == 8: print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
def solve(): S = set() x = [-1] * 3 y = [-1] * 3 xc = [0] * 3 yc = [0] * 3 i = 0 for i in range(8): xi, yi = list(map(int, input().split())) if str([xi, yi]) in S: return 0 S.add(str([xi, yi])) j = 0 while j < 3: if x[j] == -1: x[j] = xi xc[j] += 1 break elif x[j] == xi: xc[j] += 1 break j += 1 if j == 3: return 0 j = 0 while j < 3: if y[j] == -1: y[j] = yi yc[j] += 1 break elif y[j] == yi: yc[j] += 1 break j += 1 if j == 3: return 0 i = 0 while i < 3: if xc[i] == 2: x[i], x[1] = x[1], x[i] xc[i], xc[1] = xc[1], xc[i] break i += 1 if i == 3: return 0 if xc[0] != 3 or xc[2] != 3: return 0 if x[0] > x[2]: x[0], x[2] = x[2], x[0] if x[0] > x[1] or x[1] > x[2]: return 0 i = 0 while i < 3: if yc[i] == 2: y[i], y[1] = y[1], y[i] yc[i], yc[1] = yc[1], yc[i] break i += 1 if i == 3: return 0 if yc[0] != 3 or yc[2] != 3: return 0 if y[0] > y[2]: y[0], y[2] = y[2], y[0] if y[0] > y[1] or y[1] > y[2]: return 0 return 1 if solve() == 1: print("respectable") else: print("ugly")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR LIST VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
xx = set() yy = set() l = set() for i in range(8): a = list(map(int, input().split())) x, y = a[0], a[1] l.add((x, y)) xx.add(x) yy.add(y) ok = 1 if len(xx) != 3 or len(yy) != 3 or len(l) != 8: ok = 0 else: ax = list(xx) ay = list(yy) ax.sort() ay.sort() if (ax[1], ay[1]) in l: ok = 0 if ok == 1: print("respectable") else: print("ugly")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
n = 8 group = 3 middle = 1 dx = {} dy = {} pairs = set() isUgly = False for i in range(n): x, y = map(int, input().split()) if x in dx: dx[x] += 1 if dx[x] > group: isUgly = True else: dx[x] = 1 if y in dy: dy[y] += 1 if dy[y] > group: isUgly = True else: dy[y] = 1 pair = str(x) + str(y) pairs.add(pair) if len(dx) == group and len(dy) == group and len(pairs) == n and not isUgly: arrX = list(dx.keys()) arrX.sort() arrY = list(dy.keys()) arrY.sort() x2 = arrX[middle] y2 = arrY[middle] pair = str(x2) + str(y2) for e in pairs: if e == pair: isUgly = True break if isUgly: print("ugly") else: print("respectable") else: print("ugly")
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
a = [] b = [] c = [] for i in range(8): x, y = map(int, input().split()) a.append(x) b.append(y) c.append([x, y]) unique_c = [c[0]] set_a = list(set(a)) set_b = list(set(b)) set_a.sort() set_b.sort() result = "respectable" for i in range(1, len(c)): if c[i] not in unique_c: unique_c.append(c[i]) if len(unique_c) != len(c): result = "ugly" elif len(set_a) != 3 or len(set_b) != 3: result = "ugly" elif [set_a[1], set_b[1]] in c: result = "ugly" print(result)
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF LIST VAR NUMBER VAR NUMBER VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
X = dict() Y = dict() A = set() for i in range(8): x, y = list(map(int, input().split())) if (x, y) in A: print("ugly") return else: A.add((x, y)) if x in X: X[x] += 1 else: X[x] = 1 if y in Y: Y[y] += 1 else: Y[y] = 1 X = [(i, X[i]) for i in X] Y = [(i, Y[i]) for i in Y] X.sort() Y.sort() if ( len(X) == 3 and len(Y) == 3 and X[0][1] == 3 and X[1][1] == 2 and X[2][1] == 3 and Y[0][1] == 3 and Y[1][1] == 2 and Y[2][1] == 3 ): print("respectable") else: print("ugly")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
a = [0] * 8 for i in range(8): a[i] = list(map(int, input().split(" "))) x = [] y = [] for i in range(8): if a[i][0] not in x: x.append(a[i][0]) if a[i][1] not in y: y.append(a[i][1]) if len(x) != 3 or len(y) != 3: print("ugly") exit() x.sort() y.sort() l = [0] * 8 index = 0 for i in range(3): for j in range(3): if i == 1 and j == 1: continue l[index] = [x[i], y[j]] index += 1 for i in l: if i not in a: print("ugly") exit() print("respectable")
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
a = [] xDistinct = [] yDistinct = [] for i in range(0, 8): [n1, n2] = map(int, input().split()) a.append([n1, n2]) if n1 not in xDistinct: xDistinct.append(n1) if n2 not in yDistinct: yDistinct.append(n2) countDistinctX = len(xDistinct) countDistinctY = len(yDistinct) if countDistinctX != 3 and countDistinctY != 3: print("ugly") exit() xDistinct.sort() yDistinct.sort() a.sort() index = 0 for i in range(3): for j in range(3): if i == j == 1: continue if xDistinct[i] != a[index][0] or yDistinct[j] != a[index][1]: print("ugly") exit() index = index + 1 print("respectable")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
import sys pair = [] xs = [] ys = [] for i in range(8): x, y = map(int, input().split()) pair.append((x, y)) if x not in xs: xs.append(x) if y not in ys: ys.append(y) if len(xs) != 3 or len(ys) != 3: print("ugly") else: xs.sort() ys.sort() for i in range(len(xs)): for j in range(len(ys)): if i == 1 and j == 1: if (xs[i], ys[i]) in pair: print("ugly") sys.exit() elif (xs[i], ys[j]) not in pair: print("ugly") sys.exit() print("respectable")
IMPORT ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
X = [] Y = [] Points = [] k = False for i in range(8): x, y = map(int, input().split()) X.append(x) Y.append(y) if [x, y] in Points: k = True Points.append([x, y]) X.sort() Y.sort() if len(set(X)) != 3 or len(set(Y)) != 3 or k: print("ugly") elif X.count(X[0]) != 3 or X.count(X[3]) != 2 or X.count(X[5]) != 3: print("ugly") elif Y.count(Y[0]) != 3 or Y.count(Y[3]) != 2 or Y.count(Y[5]) != 3: print("ugly") elif [X[3], Y[3]] in Points: print("ugly") else: print("respectable")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF LIST VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF LIST VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
x = [] y = [] for _ in range(8): point = input().split() x.append(int(point[0])) y.append(int(point[1])) unique = [] for i in range(8): if (x[i], y[i]) in unique: print("ugly") quit() else: unique.append((x[i], y[i])) x.sort() if ( x[0] == x[1] == x[2] and x[2] != x[3] and x[3] == x[4] and x[4] != x[5] and x[5] == x[6] == x[7] ): y.sort() if ( y[0] == y[1] == y[2] and y[2] != y[3] and y[3] == y[4] and y[4] != y[5] and y[5] == y[6] == y[7] ): print("respectable") quit() else: print("ugly") quit() print("ugly")
ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
lis = [] for i in range(8): a, b = map(int, input().split()) s = a, b if s in lis: print("ugly") exit() lis.append(s) lis = sorted(lis) arr = [[], [], []] for i in range(8): p = lis[i] if i < 3: arr[0].append(p) elif i < 5: arr[1].append(p) else: arr[2].append(p) if ( arr[0][0][0] == arr[0][1][0] == arr[0][2][0] and arr[0][0][1] == arr[1][0][1] and arr[0][2][1] == arr[1][1][1] and arr[0][0][1] == arr[2][0][1] and arr[0][1][1] == arr[2][1][1] and arr[0][2][1] == arr[2][2][1] and arr[0][0][0] < arr[1][0][0] < arr[2][0][0] ): print("respectable") else: print("ugly")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST LIST LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class point: def __init__(self, x=0, y=0): self.x = x self.y = y x = [] y = [] a = [] for i in range(8): u, v = map(int, input().split()) a.append(point(u, v)) if u not in x: x.append(u) if v not in y: y.append(v) if len(x) != 3 or len(y) != 3: print("ugly") exit() x.sort() y.sort() a.sort(key=lambda p: (p.x, p.y)) k = 0 flag = True for i in range(3): for j in range(3): if i == 1 and j == 1: continue if a[k].x != x[i] or a[k].y != y[j]: flag = False k += 1 if flag: print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
def check(x): iks = [] ygrek = [] for i in x: if i[0] not in iks: iks.append(i[0]) if i[1] not in ygrek: ygrek.append(i[1]) if len(iks) != 3 or len(ygrek) != 3: return False iks.sort() ygrek.sort() for i in range(8): if x[i] == (iks[1], ygrek[1]): return False if len(set(x)) == 8: return True return False x = [] for i in range(8): s = input().split(" ") x.append((int(s[0]), int(s[1]))) if check(x): print("respectable") else: print("ugly")
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
d = [{}, {}] t = [] for i in range(8): x, y = [int(x) for x in input().split()] if [x, y] in t: print("ugly") exit() t.append([x, y]) if x not in d[0]: d[0][x] = 1 else: d[0][x] += 1 if y not in d[1]: d[1][y] = 1 else: d[1][y] += 1 if len(d[0]) == 3 and len(d[1]) == 3: a, b = [], [] for k in sorted(d[0]): a.append(d[0][k]) for k in sorted(d[1]): b.append(d[1][k]) if a == [3, 2, 3] and b == [3, 2, 3]: print("respectable") else: print("ugly") else: print("ugly")
ASSIGN VAR LIST DICT DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR IF VAR LIST NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class point: def __init__(self, x, y): self.x = x self.y = y def _input(): N = 8 point_sets = [] for i in range(0, N): x, y = map(int, input().split()) point_sets.append(point(x, y)) return point_sets def eight_point_sets(point_sets): t = point_sets[:] t.sort(key=lambda a: a.x) t[0:3] = sorted(t[0:3], key=lambda a: a.y) t[3:5] = sorted(t[3:5], key=lambda a: a.y) t[5:] = sorted(t[5:], key=lambda a: a.y) for i in range(0, 4, 3): if t[i].x >= t[i + 3].x: return -1 for i in range(0, 2): if t[i].y >= t[i + 1].y: return -1 for i in range(0, 2): if t[i].x != t[i + 1].x: return -1 if t[3].x != t[4].x: return -1 for i in range(5, 7): if t[i].x != t[i + 1].x: return -1 for i in range(0, 3): if t[i].y != t[i + 5].y: return -1 if t[3].y != t[0].y: return -1 if t[4].y != t[2].y: return -1 return 0 point_sets = _input() ret = eight_point_sets(point_sets) if ret == 0: print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
from sys import stderr a = [tuple(map(int, input().split())) for i in range(8)] x = sorted(list(set([i[0] for i in a]))) y = sorted(list(set([i[1] for i in a]))) print(a, file=stderr) print(x, y, file=stderr) if len(x) != 3 or len(y) != 3: print("ugly") else: ans = "respectable" for i in x: for j in y: if (i != x[1] or j != y[1]) and (i, j) not in a: ans = "ugly" if (x[1], y[1]) in a: ans = "ugly" print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
points_set = [] for i in range(8): points_set.append([int(i) for i in input().split()]) x_list = [] y_list = [] x_count = 0 y_count = 0 points_set.sort(key=lambda x: (x[0], x[1])) for i in points_set: if i[0] not in x_list: x_list.append(i[0]) x_count += 1 if i[1] not in y_list: y_list.append(i[1]) y_count += 1 if x_count != 3 or y_count != 3: print("ugly") exit() for i in range(3): if [x_list[0], y_list[i]] not in points_set or [ x_list[2], y_list[i], ] not in points_set: print("ugly") exit() if [x_list[1], y_list[0]] not in points_set or [x_list[1], y_list[2]] not in points_set: print("ugly") exit() print("respectable")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF LIST VAR NUMBER VAR VAR VAR LIST VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF LIST VAR NUMBER VAR NUMBER VAR LIST VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
from sys import stdin, stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int, stdin.readline().split())) for _ in range(1): mp = {} sx = set() sy = set() f = 1 for i in range(8): a, b = lst() sx.add(a) sy.add(b) mp[a, b] = 1 if len(sx) != 3 or len(sy) != 3: print("ugly") continue a, b, c = sorted(sx) a1, b1, c1 = sorted(sy) for i in [a, b, c]: for j in [a1, b1, c1]: if i == b and j == b1: continue if (i, j) not in mp: f = 0 break print("respectable" if f else "ugly")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR LIST VAR VAR VAR FOR VAR LIST VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
import sys a = [] b = [] for i in range(8): x, y = [int(k) for k in input().split()] a.append(x) b.append(y) seta = set(a) setb = set(b) if len(seta) == 3 and len(setb) == 3: x = sorted(seta) y = sorted(setb) point = [] for i in range(8): point.append((a[i], b[i])) if (x[1], y[1]) in point: print("ugly") sys.exit() for i in range(3): for j in range(3): if i == 1 and j == 1: continue elif (x[i], y[j]) not in point: print("ugly") sys.exit() print("respectable") else: print("ugly")
IMPORT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three integers x_1, x_2, x_3 and three more integers y_1, y_2, y_3, such that x_1 < x_2 < x_3, y_1 < y_2 < y_3 and the eight point set consists of all points (x_{i}, y_{j}) (1 ≀ i, j ≀ 3), except for point (x_2, y_2). You have a set of eight points. Find out if Gerald can use this set? -----Input----- The input consists of eight lines, the i-th line contains two space-separated integers x_{i} and y_{i} (0 ≀ x_{i}, y_{i} ≀ 10^6). You do not have any other conditions for these points. -----Output----- In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. -----Examples----- Input 0 0 0 1 0 2 1 0 1 2 2 0 2 1 2 2 Output respectable Input 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 Output ugly Input 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 Output ugly
class Point: def __init__(self, x=0, y=0): self.x = x self.y = y points = [] xs = [] ys = [] is_exist = False for _ in range(8): x, y = map(int, input().split()) xs.append(x) ys.append(y) for point in points: if point.x == x and point.y == y: is_exist = True if is_exist: is_exist = False else: new_point = Point(x, y) points.append(new_point) if len(set(xs)) < 3 or len(set(ys)) < 3: print("ugly") else: min_x = min(xs) min_y = min(ys) max_x = max(xs) max_y = max(ys) count_min_x = count_min_y = count_max_x = count_max_y = 0 for point in points: if point.x == min_x: count_min_x += 1 if point.x == max_x: count_max_x += 1 if point.y == min_y: count_min_y += 1 if point.y == max_y: count_max_y += 1 points.sort(key=lambda p: (p.x, p.y)) if ( count_max_y == 3 and count_min_y == 3 and count_max_x == 3 and count_min_x == 3 and points[1].y == points[6].y and points[3].x == points[4].x ): print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING