description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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 b = [0] * 8 c = [0] * 8 d = [0] * 8 flag = 0 for i in range(8): x, y = map(int, input().split()) a[i] = x b[i] = y c[i] = x d[i] = y n = 8 a.sort(reverse=False) b.sort(reverse=False) x1 = a[0] x2 = a[3] x3 = a[7] y1 = b[0] y2 = b[3] y3 = b[7] flag = 0 if x1 == x2 or x1 == x3 or x2 == x3 or y1 == y2 or y1 == y3 or y2 == y3: flag = -1 for i in range(n): if c[i] == x2 and d[i] == y2: flag = -1 break for j in range(i + 1, n - 1): if c[i] == c[j] and d[i] == d[j]: flag = -1 break if not (a[0] == a[1] == a[2] and a[3] == a[4] and a[5] == a[6] == a[7]): flag = -1 if not (b[0] == b[1] == b[2] and b[3] == b[4] and b[5] == b[6] == b[7]): flag = -1 if flag == 0: print("respectable") else: print("ugly")
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER 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
x = [] y = [] def unique(a): res = [] res.append(a[0]) for i in range(1, len(a)): if a[i] != a[i - 1]: res.append(a[i]) return res def process(x, y, a, b, n): if len(x) != 3 or len(y) != 3: return "ugly" check1 = False check2 = False for i in range(3): for j in range(3): flag = "ugly" if i != 1 or j != 1: for k in range(n): if a[k] == x[i] and b[k] == y[j]: flag = "respectable" if flag == "ugly": return flag return "respectable" for i in range(8): a, b = map(int, input().split()) x.append(a) y.append(b) a = x[:] b = y[:] x.sort() y.sort() x = unique(x) y = unique(y) print(process(x, y, a, b, 8))
ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING IF VAR STRING RETURN VAR RETURN STRING 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 VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
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 = [0] * 8 y = [0] * 8 z = [] for i in range(8): x[i], y[i] = map(int, input().split()) if (x[i], y[i]) not in z: z.append((x[i], y[i])) sx = set(x) sy = set(y) if len(sx) != 3 or len(sy) != 3 or len(z) != 8: print("ugly") else: xx = sorted(list(sx)) yy = sorted(list(sy)) if (xx[1], yy[1]) in z: print("ugly") else: print("respectable")
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR 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 FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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
sets = [] for i in range(8): x, y = map(int, input().split()) sets.append((x, y)) a1 = sorted(sets, key=lambda point: point[0]) pointx = [] for i in range(len(a1)): if len(pointx) == 0: pointx.append(a1[i][0]) elif pointx[-1] != a1[i][0]: pointx.append(a1[i][0]) if len(pointx) > 3: print("ugly") exit() if len(pointx) != 3: print("ugly") exit() a2 = sorted(sets, key=lambda point: point[1]) pointy = [] for i in range(len(a2)): if len(pointy) == 0: pointy.append(a2[i][1]) elif pointy[-1] != a2[i][1]: pointy.append(a2[i][1]) if len(pointy) > 3: print("ugly") exit() if len(pointy) != 3: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[0]) & (sets[i][1] == pointy[0]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[0]) & (sets[i][1] == pointy[1]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[0]) & (sets[i][1] == pointy[2]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[1]) & (sets[i][1] == pointy[0]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[1]) & (sets[i][1] == pointy[2]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[2]) & (sets[i][1] == pointy[2]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[2]) & (sets[i][1] == pointy[1]): break if i == 7: print("ugly") exit() for i in range(len(sets)): if (sets[i][0] == pointx[2]) & (sets[i][1] == pointy[0]): break if i == 7: print("ugly") exit() print("respectable")
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 ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF 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
x, y = [], [] xx, yy = {}, {} for i in range(8): a, b = map(int, input().split()) x.append(a) y.append(b) if a not in xx: xx[a] = [b] else: xx[a].append(b) if b not in yy: yy[b] = [a] else: yy[b].append(a) if len(set(x)) != 3 or len(set(y)) != 3: print("ugly") exit() xxx, yyy = sorted(set(x)), sorted(set(y)) if set(xx[xxx[1]]) != {yyy[0], yyy[2]}: print("ugly") exit() if set(yy[yyy[1]]) != {xxx[0], xxx[2]}: print("ugly") exit() if ( len(set(xx[xxx[0]])) != 3 or 3 != len(set(xx[xxx[2]])) or len(set(yy[yyy[0]])) != 3 or 3 != len(set(yy[yyy[2]])) ): print("ugly") exit() print("respectable")
ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR DICT DICT 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 VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR 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
class coor: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): if self.x < other.x: return True elif self.x > other.x: return False elif self.y < other.y: return True else: return False def init(): point = [] for i in range(8): num_input = input() num_input = num_input.split(" ") point.append(coor(int(num_input[0]), int(num_input[1]))) return point def solve(point): point.sort() if ( point[0].x == point[1].x == point[2].x and point[3].x == point[4].x and point[5].x == point[6].x == point[7].x and point[0].y == point[3].y == point[5].y and point[1].y == point[6].y and point[2].y == point[4].y == point[7].y ): if ( point[0].x < point[3].x < point[5].x and point[0].y < point[1].y < point[2].y ): return "respectable" return "ugly" print(solve(init()))
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF 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 IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR 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
def main(temp): nums = [] for item in temp: if item not in nums: nums.append(item) else: return "ugly" Xs = [item[0] for item in nums] Ys = [item[1] for item in nums] Xset = list(set(Xs)) Yset = list(set(Ys)) if len(Xset) != 3 or len(Yset) != 3: return "ugly" Xset.sort() Yset.sort() a, b, c = Xs.count(Xset[0]), Xs.count(Xset[1]), Xs.count(Xset[2]) q, w, e = Ys.count(Yset[0]), Ys.count(Yset[1]), Ys.count(Yset[2]) if a == c == q == e == 3 and b == w == 2: return "respectable" else: return "ugly" def init(): nums = [] for i in range(8): nums.append(list(map(int, input().split()))) print(main(nums)) init()
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR 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
class Point: def __init__(self, x_p, y_p): self.x = x_p self.y = y_p points = [] sub_x = [] sub_y = [] key = False for i in range(8): x, y = map(int, input().split()) if [x, y] in points: key = True if x not in sub_x: sub_x.append(x) if y not in sub_y: sub_y.append(y) points.append([x, y]) sub_x.sort() sub_y.sort() if key: print("ugly") elif len(sub_x) == 3 and len(sub_y) == 3: if [sub_x[1], sub_y[1]] in points: print("ugly") else: print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF 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 IF LIST VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF LIST VAR NUMBER VAR NUMBER 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
def check_condition(axis): for i in range(1, 3): if points[i - 1][axis] != points[i][axis]: return False if points[2][axis] == points[3][axis]: return False if points[3][axis] != points[4][axis] or points[4][axis] == points[5][axis]: return False for i in range(6, 8): if points[i - 1][axis] != points[i][axis]: return False return True def main(): global points points = list() for _ in range(8): point = tuple(map(int, input().split())) points.append(point) for i in range(8): if points.count(points[i]) > 1: print("ugly") exit(0) points.sort(key=lambda point: point[0]) check_x = check_condition(0) points.sort(key=lambda point: point[1]) check_y = check_condition(1) if check_x and check_y: print("respectable") else: print("ugly") main()
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF 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 FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR 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
l = [[int(c) for c in input().split()] for i in range(8)] xs = sorted(set([p[0] for p in l])) ys = sorted(set([p[1] for p in l])) if len(xs) != 3 or len(ys) != 3: print("ugly") else: done = False for x in range(3): for y in range(3): if x == y == 1: continue if [xs[x], ys[y]] not in l: print("ugly") done = True break if done: break if not done: print("respectable")
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 IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR IF 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
i = 0 ab = [] while i != 8: m, n = map(int, input().split()) ab.append((m, n)) i += 1 ab = sorted(ab, key=lambda tup: tup[0]) ab1 = sorted(ab[:3], key=lambda tup: tup[1]) ab2 = sorted(ab[3:5], key=lambda tup: tup[1]) ab3 = sorted(ab[5:8], key=lambda tup: tup[1]) ab = ab1 + ab2 + ab3 if ( ab[0][0] == ab[1][0] == ab[2][0] and ab[5][0] == ab[6][0] == ab[7][0] and ab[3][0] == ab[4][0] ): if ( ab[0][1] == ab[3][1] == ab[5][1] and ab[2][1] == ab[4][1] == ab[7][1] and ab[1][1] == ab[6][1] ): if ab[0][0] != ab[3][0] and ab[5][0] != ab[3][0] and ab[0][0] != ab[5][0]: if ( ab[0][1] != ab[1][1] != ab[2][1] != ab[0][1] and ab[5][1] != ab[6][1] != ab[7][1] != ab[5][1] and ab[3][1] != ab[4][1] ): print("respectable") else: print("ugly") else: print("ugly") else: print("ugly") else: print("ugly")
ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR 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 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 IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER 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 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 Solution: def eightPointSets(self, listPairs): listX = list(pair[0] for pair in listPairs) listY = list(pair[1] for pair in listPairs) listX.sort() listY.sort() setX = list(set(listX)) setY = list(set(listY)) if len(setX) != 3 or len(setY) != 3: return -1 if [setX[1], setY[1]] in listPairs: return -1 listPairFrequency = {} for i in range(len(listPairs)): tuplePair = tuple(listPairs[i]) if tuplePair not in listPairFrequency: listPairFrequency[tuplePair] = 0 listPairFrequency[tuplePair] += 1 if len(listPairFrequency) != len(listPairs): return -1 return 1 listPairs = [] for i in range(8): pairs = list(map(int, input().split())) listPairs.append(pairs) solution = Solution() result = solution.eightPointSets(listPairs) if result == 1: print("respectable") else: print("ugly")
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF LIST VAR NUMBER VAR NUMBER VAR RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST 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 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
x_set = set() y_set = set() points = [] for i in range(8): x, y = [int(k) for k in input().split()] x_set.add(x) y_set.add(y) points.append((x, y)) cnt = 0 if len(x_set) != 3 or len(y_set) != 3: print("ugly") else: x_set = sorted(x_set) y_set = sorted(y_set) for i in range(3): for j in range(3): for k in range(8): if points[k][0] == x_set[i] and points[k][1] == y_set[j]: if i == 1 and j == 1: break cnt += 1 break if cnt == 8: print("respectable") else: print("ugly")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER 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
lines = [] for i in range(0, 8): lines.append(list(map(int, input().split()))) lines = sorted(lines) countA = [lines[0][0]] countB = [lines[0][1]] for i in range(1, len(lines)): if lines[i][0] != lines[i - 1][0]: countA.append(lines[i][0]) if lines[i][1] not in countB: countB.append(lines[i][1]) if len(countA) != 3 or len(countB) != 3: print("ugly") else: index = 0 check = True for i in countA: for j in countB: if i == countA[1] and j == countB[1]: continue if i != lines[index][0] or j != lines[index][1]: check = False break index += 1 if check: print("respectable") else: print("ugly")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER 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(): l = [] for i in range(8): x, y = list(map(int, input().split())) l += [[x, y]] xSet = set() ySet = set() for x, y in l: xSet.add(x) ySet.add(y) if len(xSet) != 3 or len(ySet) != 3: return False xList = sorted(list(xSet)) yList = sorted(list(ySet)) z = [] for x in xList: for y in yList: if x == xList[1] and y == yList[1]: pass else: z += [[x, y]] z.sort() l.sort() return z == l if check(): print("respectable") else: print("ugly")
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST VAR VAR 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 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 ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR LIST LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN 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
def solve(): x = [0] * 8 y = [0] * 8 xy = [None] * 8 for i in range(0, 8): line = input() if line == "": line = input() x[i], y[i] = map(int, line.split()) xy[i] = x[i], y[i] a = sorted(x) b = sorted(y) x1 = a[0] x2 = a[3] x3 = a[7] y1 = b[0] y2 = b[3] y3 = b[7] if x1 == x2 or x1 == x3 or x2 == x3 or y1 == y2 or y1 == y3 or y2 == y3: print("ugly") return if a[0] != a[1] or a[0] != a[2] or a[3] != a[4] or a[5] != a[6] or a[6] != a[7]: print("ugly") return if b[0] != b[1] or b[0] != b[2] or b[3] != b[4] or b[5] != b[6] or b[6] != b[7]: print("ugly") return for i in range(8): if x[i] == x2 and y[i] == y2: print("ugly") return for j in range(i + 1, 8): if xy[i] == xy[j]: print("ugly") return print("respectable") solve()
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF 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 RETURN IF 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 RETURN FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN 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
x, y = [0] * 8, [0] * 8 for i in range(8): x[i], y[i] = map(int, input().split()) for i in range(8): for j in range(i): if x[i] == x[j] and y[i] == y[j]: print("ugly") break else: continue break else: x.sort() y.sort() if ( x[0] == x[1] == x[2] and x[3] == x[4] and x[5] == x[6] == x[7] and y[0] == y[1] == y[2] and y[3] == y[4] and y[5] == y[6] == y[7] and x[2] != x[3] and x[4] != x[5] and y[2] != x[3] and y[4] != x[5] ): print("respectable") else: print("ugly")
ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL 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 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 coor: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): if self.x < other.x: return True elif self.x > other.x: return False elif self.y < other.y: return True else: return False a = [] first = set() second = set() for i in range(0, 8): x, y = map(int, input().split()) first.add(x) second.add(y) a.append(coor(x, y)) a.sort() ok = False if a[0].x == a[1].x and a[0].x == a[2].x: if a[0].y != a[1].y and a[1].y != a[2].y: if a[3].x == a[4].x and a[3].y != a[1].y and a[4].y != a[1].y: if a[5].x == a[6].x and a[6].x == a[7].x: if a[5].y != a[6].y and a[6].y != a[7].y: ok = 1 if ok == True and len(first) == 3 and len(second) == 3: 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 RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR 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 CodeforcesTask334BSolution: def __init__(self): self.result = "" self.points = [] def read_input(self): for x in range(8): self.points.append([int(x) for x in input().split(" ")]) def process_task(self): xs = [x[0] for x in self.points] xs.sort() ys = [x[1] for x in self.points] ys.sort() if ( xs[0] == xs[1] == xs[2] < xs[3] == xs[4] < xs[5] == xs[6] == xs[7] and ys[0] == ys[1] == ys[2] < ys[3] == ys[4] < ys[5] == ys[6] == ys[7] and not sum([(1 if self.points.count(x) > 1 else 0) for x in self.points]) ): self.result = "respectable" else: self.result = "ugly" def get_result(self): return self.result Solution = CodeforcesTask334BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result())
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER 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 FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR 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
a = [] b = [0] * (10**6 + 1) c = [0] * (10**6 + 1) for i in range(8): x, y = map(int, input().split()) a.append((x, y)) a = sorted(a) p = 0 x = [] y = [] for i in range(8): if b[a[i][0]] == 0: x.append(a[i][0]) b[a[i][0]] = 1 if c[a[i][1]] == 0: y.append(a[i][1]) c[a[i][1]] = 1 if len(x) != 3 or len(y) != 3: print("ugly") exit() for i in range(3): for j in range(3): if i == j == 1: continue elif x[i] != a[p][0] or y[j] != a[p][1]: print("ugly") exit() else: p += 1 print("respectable")
ASSIGN VAR LIST 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 ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR 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 VAR NUMBER EXPR FUNC_CALL VAR STRING
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some integer x). If those rules don't indicate the size of the cut are clearly, then the way with which the cut part possesses the largest area is chosen. Of course, both sides of the cut area should be integer. If there are several answers to this problem, you should choose the answer with the maximal height. Input The first line contains a pair of integers h and w (1 ≀ h, w ≀ 109) which are the height and width of the uploaded photo in pixels. Output Print two integers which are the height and width of the cut area. Examples Input 2 1 Output 1 1 Input 2 2 Output 2 2 Input 5 5 Output 5 4
c = 1 lis = [0] * 35 for i in range(33): lis[i] = c c *= 2 h, w = map(int, input().split()) ans = [] for i in range(32, -1, -1): if lis[i] <= h: l = 1 r = w while l <= r: mid = l + (r - l) // 2 if mid / lis[i] < 1.25: l = mid + 1 else: r = mid - 1 if 0.8 <= l / lis[i] <= 1.25 and l <= w: ans.append([l * lis[i], lis[i], l]) elif r != 0 and r <= w and 0.8 <= r / lis[i] <= 1.25: ans.append([r * lis[i], lis[i], r]) for i in range(33): if lis[i] <= w: l = 1 r = h while l <= r: mid = l + (r - l) // 2 if 1.25 > mid / lis[i]: l = mid + 1 else: r = mid - 1 if l <= h and 0.8 <= lis[i] / l <= 1.25: ans.append([l * lis[i], l, lis[i]]) if r != 0 and r <= h and 0.8 <= lis[i] / r <= 1.25: ans.append([lis[i] * r, r, lis[i]]) ans.sort(reverse=True) print(*ans[0][1:])
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
w = [] col = ["Carrots", "Kiwis", "Grapes"] n, m, k, t = map(int, input().split()) for _ in range(k): w.append(list(map(int, input().split()))) for _ in range(t): c = list(map(int, input().split())) if c in w: print("Waste") else: s = 0 for i in w: if i < c: s += 1 val = (c[0] - 1) * m + c[1] - 1 - s print(col[val % 3])
ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) crops = ["Carrots", "Kiwis", "Grapes"] waste = list() answers = list() for i in range(k): a, b = map(int, input().split()) a = a - 1 b = b - 1 waste.append(a * m + b) waste.sort() for i in range(t): j, k = map(int, input().split()) q = (j - 1) * m + k - 1 c = 0 wasted = 0 for x in waste: if x < q: c += 1 elif x == q: wasted = 1 else: break if wasted == 1: answers.append("Waste") else: answers.append(crops[(q - c) % 3]) for e in answers: print(e)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = list(map(int, input().split())) karr = [list(map(int, input().split())) for _ in range(k)] tarr = [list(map(int, input().split())) for _ in range(t)] karr = [(m * (x - 1) + y) for x, y in karr] tarr = [(m * (x - 1) + y) for x, y in tarr] karr.sort() mx = karr[-1] a = ["Carrots", "Kiwis", "Grapes"] for q in tarr: if q > mx: print(a[(q - 1 - k) % 3]) else: count = 0 hit = False for i in range(k): if q < karr[i]: count = i break elif q == karr[i]: hit = True break if hit: print("Waste") else: print(a[(q - 1 - count) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def single_integer(): return int(input()) def multi_integer(): return map(int, input().split()) def string(): return input() def multi_string(): return input().split() n, m, k, t = multi_integer() wastes = list() fruits = ["Carrots", "Kiwis", "Grapes"] for i in range(k): wastes.append(tuple(multi_integer())) for i in range(t): w = 0 a, b = multi_integer() for j in wastes: if (a, b) == j: print("Waste") break elif j[0] < a: w += 1 elif j[0] == a: if j[1] < b: w += 1 else: temp = (a - 1) * m + b - 1 - w print(fruits[temp % 3])
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = list(map(int, input().split(" "))) wastes = set() for _ in range(k): wastes.add(tuple(map(int, input().split(" ")))) mapping = {(0): "Carrots", (1): "Kiwis", (2): "Grapes"} for _ in range(t): x, y = list(map(int, input().split(" "))) if (x, y) in wastes: print("Waste") continue total = (x - 1) * m + y - 1 for w in wastes: if w[0] < x or w[0] == x and w[1] < y: total -= 1 print(mapping[total % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
from sys import stdin n, m, k, t = map(int, stdin.readline().split()) empty = [] for i in range(k): empty.append(list(map(int, stdin.readline().split()))) for i in range(t): a, b = map(int, stdin.readline().split()) flag = 0 for j in empty: if a == j[0] and b == j[1]: flag = 1 break if flag == 1: print("Waste") continue idi = (a - 1) * m + (b - 1) for j in empty: if j[0] < a or j[0] == a and j[1] < b: idi -= 1 if idi % 3 == 0: print("Carrots") elif idi % 3 == 1: print("Kiwis") else: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = [int(i) for i in input().split()] waste_map = {} for i in range(n): waste_map[i] = [] for q in range(k): i, j = [(int(i) - 1) for i in input().split()] waste_map[i].append(j) fruit_map = {(-1): "Waste", (0): "Carrots", (1): "Kiwis", (2): "Grapes"} starts = [0] * n num = 0 for i in range(n): starts[i] = num num = (num + m - len(waste_map[i])) % 3 for q in range(t): i, j = [(int(i) - 1) for i in input().split()] ans = -1 if j not in waste_map[i]: count = 0 for ele in waste_map[i]: if ele < j: count += 1 ans = (starts[i] + j - count) % 3 print(fruit_map[ans])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def one_line_input(): return list(map(int, input().split())) n, m, k, t = one_line_input() list_of_waste = [] for i in range(k): a, b = one_line_input() tup = [a, b] list_of_waste.append(tup) list_of_waste = sorted(list_of_waste) for i in range(t): count = 0 a, b = one_line_input() tup = [a, b] if tup in list_of_waste: print("Waste") continue for element in list_of_waste: if element[0] < tup[0]: count += 1 elif element[0] == tup[0] and element[1] <= tup[1]: count += 1 number = ((tup[0] - 1) * m + tup[1] - count) % 3 if number == 0: print("Grapes") elif number == 1: print("Carrots") else: print("Kiwis")
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) dp = [] for i in range(k): a, b = map(int, input().split()) idx = (a - 1) * m + (b - 1) dp.append(idx) dp.sort() for i in range(t): x, y = map(int, input().split()) idx_ = (x - 1) * m + (y - 1) if idx_ in dp: print("Waste") else: j = 0 while j < len(dp) and dp[j] < idx_: j += 1 j = idx_ - j if j % 3 == 0: print("Carrots") elif j % 3 == 1: print("Kiwis") else: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
line = [int(x) for x in input().split()] rows = line[0] cols = line[1] k = line[2] t = line[3] waste = [] res = ["Carrots", "Kiwis", "Grapes"] for case in range(k): waste.append([int(x) for x in input().split()]) for q in range(t): query = [int(x) for x in input().split()] foundWaste = False pre = 0 for w in waste: if w[0] < query[0]: pre += 1 if w[0] == query[0]: if w[1] < query[1]: pre += 1 elif w[1] == query[1]: foundWaste = True break if foundWaste: print("Waste") else: print(res[((query[0] - 1) * cols + query[1] - pre - 1) % 3])
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [] for _ in range(k): i, j = map(int, input().split()) waste += [(i - 1) * m + (j - 1)] waste.sort() put = ["Carrots", "Kiwis", "Grapes"] for _ in range(t): i, j = map(int, input().split()) numc = (i - 1) * m + (j - 1) c = 0 for x in waste: if x > numc: break c += 1 if numc in waste: print("Waste") else: print(put[(numc - c) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
inp = [int(x) for x in input().split()] n = inp[0] m = inp[1] k = inp[2] t = inp[3] waste = [] for i in range(k): temp = [int(x) for x in input().split()] waste.append(temp) query = [] for i in range(t): temp = [int(x) for x in input().split()] query.append(temp) loc = 0 b = 0 for i in range(t): loc = (query[i][0] - 1) * m + query[i][1] for j in range(k): if ( waste[j][0] < query[i][0] or waste[j][0] == query[i][0] and waste[j][1] < query[i][1] ): loc -= 1 elif waste[j][0] == query[i][0] and waste[j][1] == query[i][1]: b = 1 if b: print("Waste") elif loc % 3 == 1: print("Carrots") elif loc % 3 == 2: print("Kiwis") elif loc % 3 == 0: print("Grapes") b = 0 loc = 0
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) answers = ["Carrots", "Kiwis", "Grapes"] d = [] for i in range(k): k = [int(k) for k in input().split()] d.append(k) for i in range(t): a = [int(a) for a in input().split()] if a in d: print("Waste") else: cnt = (a[0] - 1) * m + a[1] all = 0 for j in d: x = (j[0] - 1) * m + j[1] if x < cnt: all += 1 print(answers[(cnt - 1 - all) % 3]) a = []
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [] for i in range(k): a, b = map(int, input().split()) waste.append((a - 1) * m + b - 1) waste.sort() plant = ["Carrots", "Kiwis", "Grapes"] for _ in range(t): cnt = 0 crop = True i, j = map(int, input().split()) c = (i - 1) * m + j - 1 for x in range(k): if waste[x] > c: break elif waste[x] == c: crop = False break else: cnt += 1 if crop: print(plant[(c - cnt) % 3]) else: print("Waste")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) a = [] for i in range(k): b, c = map(int, input().split()) a.append([b, c]) a.sort() for i in range(t): d, e = map(int, input().split()) if [d, e] in a: print("Waste") else: g = (d - 1) * m + (e - 1) h = 0 for i in range(k): if d > a[i][0]: h += 1 elif d == a[i][0] and e > a[i][1]: h += 1 v = (g - h) % 3 if v == 0: print("Carrots") elif v == 1: print("Kiwis") else: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) arr = [] for i in range(k): g, h = map(int, input().split()) arr.append([g, h]) arr.sort() for i in range(t): g, h = map(int, input().split()) re = 0 bl = True for i in arr: if i[0] == g and i[1] == h: bl = False break if i[0] == g and i[1] < h or i[0] < g: re += 1 if bl: tm = (g - 1) * m + (h - 1) re = tm - re if re % 3 == 0: print("Carrots") elif re % 3 == 1: print("Kiwis") else: print("Grapes") else: print("Waste")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
class Query: def __init__(self, rank, cell): self.rank = rank self.cell = cell n, m, num_wasted, num_queries = map(int, input().split()) wasted = [None for i in range(num_wasted)] for i in range(num_wasted): a, b = map(lambda s: int(s) - 1, input().split()) wasted[i] = a * m + b queries = [None for i in range(num_queries)] for i in range(num_queries): a, b = map(lambda s: int(s) - 1, input().split()) queries[i] = Query(i, a * m + b) wasted.sort() queries.sort(key=lambda query: query.cell) crops = ["Carrots", "Kiwis", "Grapes"] total_wasted = 0 w, q = 0, 0 while w < num_wasted and q < num_queries: if wasted[w] <= queries[q].cell: while q < num_queries and wasted[w] == queries[q].cell: queries[q].crop = "Waste" q += 1 total_wasted += 1 w += 1 else: queries[q].crop = crops[(queries[q].cell - total_wasted) % 3] q += 1 while q < num_queries: cell = queries[q].cell queries[q].crop = crops[(queries[q].cell - total_wasted) % 3] q += 1 queries.sort(key=lambda query: query.rank) for query in queries: print(query.crop)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
row, line, waste, ask = map(int, input().split()) waste_array = [] for i in range(waste): row_data, line_data = map(int, input().split()) waste_array.append((row_data - 1) * line + line_data) waste_array = sorted(waste_array) def binarySearchCount(arr, n, value): left = 0 right = n - 1 count = 0 while left <= right: mid = int((right + left) / 2) if arr[mid] < value: count = mid + 1 left = mid + 1 else: right = mid - 1 return count for i in range(ask): row_data, line_data = map(int, input().split()) key = (row_data - 1) * line + line_data if key in waste_array: print("Waste") else: x = binarySearchCount(waste_array, len(waste_array), key) result = (key - x) % 3 if result == 1: print("Carrots") elif result == 2: print("Kiwis") else: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) kk = k waste = [] a = ["Carrots", "Kiwis", "Grapes"] while k: i, j = map(int, input().split()) waste.append([i - 1, j - 1]) k -= 1 while t: i, j = map(int, input().split()) if [i - 1, j - 1] in waste: print("Waste") else: count = (i - 1) * m + (j - 1) for k in range(kk): if waste[k][0] < i - 1 or waste[k][0] == i - 1 and waste[k][1] < j - 1: count -= 1 print(a[count % 3]) t -= 1
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
l1 = [int(num) for num in input().split()] n = l1[0] m = l1[1] k = l1[2] t = l1[3] wastes = [] for i in range(k): l2 = [int(x) for x in input().split()] wastes.append(l2) for i in range(t): l3 = [int(y) for y in input().split()] if l3 in wastes: print("Waste") else: k = 0 for j in wastes: if j[0] < l3[0]: k += 1 elif j[0] == l3[0]: if j[1] < l3[1]: k += 1 cells = (l3[0] - 1) * m + l3[1] - k if cells % 3 == 0: print("Grapes") elif cells % 3 == 1: print("Carrots") else: print("Kiwis")
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def main(): n, m, k, t = map(int, input().split()) waste = [] ans = {(1): "Carrots", (2): "Kiwis", (0): "Grapes"} for i in range(k): a, b = map(int, input().split()) waste.append((a - 1) * m + b) waste.sort() for i in range(t): a, b = map(int, input().split()) cell = (a - 1) * m + b count = 0 flag = True for j in waste: if j == cell: flag = False break elif j < cell: count += 1 else: break if flag: print(ans[(cell - count) % 3]) else: print("Waste") main()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [] for _ in range(k): tmp = list(map(int, input().split())) waste.append(tmp) tree = {(1): "Carrots", (2): "Kiwis", (0): "Grapes"} waste.sort() for _ in range(t): ls = list(map(int, input().split())) i = 0 found = False for plot in waste: if ls == plot: print("Waste") found = True break elif ls > plot: i += 1 else: break if i == 0 and not found: plant_number = (ls[0] - 1) * m plant_number += ls[1] plant_number %= 3 print(tree[plant_number]) elif not found: plant_number = (ls[0] - 1) * m plant_number += ls[1] plant_number -= i plant_number %= 3 print(tree[plant_number])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
rows, columns, waste_count, q_count = [int(i) for i in input().split(" ")] waste_list = [] for _ in range(waste_count): waste_list.append([int(i) for i in input().split(" ")]) query_list = [] for _ in range(q_count): query_list.append([int(i) for i in input().split(" ")]) waste_row = [] waste_row_count = [] for i in range(rows + 1): waste_row.append([]) waste_row_count.append(0) for k in waste_list: waste_row[k[0]].append(k[1]) waste_row_count[k[0]] += 1 for i in range(1, len(waste_row_count)): waste_row_count[i] = waste_row_count[i] + waste_row_count[i - 1] for q in query_list: row = q[0] column = q[1] waste_before = waste_row_count[row - 1] waste_in_current_row = 0 is_waste = False for i in waste_row[row]: if i == column: is_waste = True if i < column: waste_in_current_row += 1 if is_waste: print("Waste") else: numero = (row - 1) * columns + column - waste_before - waste_in_current_row numero = numero % 3 if numero == 1: print("Carrots") elif numero == 2: print("Kiwis") elif numero == 0: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) a = [] for i in range(k): i, j = map(int, input().split()) a.append([i, j]) for i in range(t): i, j = map(int, input().split()) c = j + (i - 1) * m w = 0 f = 0 for z in range(k): if a[z][0] < i: w += 1 elif a[z][0] == i: if a[z][1] < j: w += 1 elif a[z][1] == j: f = 1 break c = c - w c = c % 3 if f == 1: print("Waste") elif c == 1: print("Carrots") elif c == 2: print("Kiwis") elif c == 0: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) def mToA(i, j): return i * m + j - m - 1 waste = [mToA(*map(int, input().split())) for _ in range(k)] waste.sort() plants = ["Carrots", "Kiwis", "Grapes"] for _ in range(t): i, j = map(int, input().split()) a = mToA(i, j) if a in waste: print("Waste") else: k = 0 for w in waste: if w > a: break k += 1 print(plants[(a - k) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) cnt = {(-1, m - 1): 0} waste_fields = [] for _ in range(k): a, b = map(int, input().split()) a -= 1 b -= 1 waste_fields.append([a, b]) fruit = ["Carrots", "Kiwis", "Grapes"] for _ in range(t): a, b = map(int, input().split()) a -= 1 b -= 1 if [a, b] in waste_fields: print("Waste") continue wasted = 0 for el in waste_fields: if el[0] < a or el[0] == a and el[1] <= b: wasted += 1 fields = a * m + b fields -= wasted print(fruit[fields % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def get_waste_amount(waste, t): for i in range(len(waste)): if waste[i] > t: return len(waste[:i]) if i == len(waste) - 1: return len(waste) def process_query(m, t, waste): if t in waste: print("Waste") else: f = ["Carrots", "Kiwis", "Grapes"] s = get_waste_amount(waste, t) print(f[((t[0] - 1) * m + t[1] - s) % 3 - 1]) n, m, k, t = map(int, input().split()) waste = [] for i in range(k): tt = tuple(map(int, input().split())) waste.append(tt) waste = sorted(waste) for i in range(t): tt = tuple(map(int, input().split())) process_query(m, tt, waste)
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [] val = ["Carrots", "Kiwis", "Grapes"] for i in range(k): a = list(map(int, input().split())) waste.append(a) for i in range(t): q = list(map(int, input().split())) if q in waste: print("Waste") else: s = 0 for i in waste: if i < q: s = s + 1 res = (q[0] - 1) * m + q[1] - 1 - s print(val[res % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) fruits = ["Carrots", "Kiwis", "Grapes"] results = [] waste = [] for i in range(k): waste.append(list(map(int, input().split()))) for i in range(t): inp = list(map(int, input().split())) total = 0 for w in waste: if inp == w: total = "Waste" break elif inp[0] > w[0]: total += 1 elif inp[0] >= w[0] and inp[1] > w[1]: total += 1 if total != "Waste": results.append(fruits[((inp[0] - 1) * m + inp[1] - total) % 3 - 1]) else: results.append(total) for i in results: print(i)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = list(map(int, input().split(" "))) arr = [] ans = [] def binarySearch(val, arr): lo = 0 hi = len(arr) while lo < hi: mid = (lo + hi) // 2 if arr[mid] < val: lo = mid + 1 else: hi = mid return lo for _ in range(k): i, j = list(map(int, input().split(" "))) val = (i - 1) * m + (j - 1) arr += [val] arr.sort() for _ in range(t): i, j = list(map(int, input().split(" "))) val = (i - 1) * m + (j - 1) c = binarySearch(val, arr) if c < len(arr) and arr[c] != val: f = (val - c) % 3 if f == 0: ans.append("Carrots") elif f == 1: ans.append("Kiwis") else: ans.append("Grapes") continue if c >= len(arr): f = (val - c) % 3 if f == 0: ans.append("Carrots") elif f == 1: ans.append("Kiwis") else: ans.append("Grapes") continue if c < len(arr) and arr[c] == val: ans.append("Waste") for _ in ans: print(_)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR LIST VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, r = map(int, input().split()) dic = {} li = ["Carrots", "Kiwis", "Grapes"] li1 = [] for i in range(k): a, b = map(int, input().split()) li1.append((a, b)) li1.sort() for d in range(r): t = 0 cnt = 0 v, w = map(int, input().split()) for j in li1: if int(j[0]) == v and int(j[1]) == w: t = 2 print("Waste") break elif int(j[0]) > v: break elif int(j[0]) == v and int(j[1]) > w: break cnt += 1 if t != 2: o = (v - 1) * m + w - cnt - 1 print(li[o % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST STRING STRING STRING 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
a = list(map(int, input().split())) n = a[0] m = a[1] k = a[2] t = a[3] l = [] for i in range(k): s = list(map(int, input().split())) d = (s[0] - 1) * m + s[1] l.append(d) kt = [] for i in range(t): s = list(map(int, input().split())) d = (s[0] - 1) * m + s[1] kt.append(d) l.sort() for ele in kt: if ele in l: print("Waste") else: c = 0 i = 0 while i < len(l) and l[i] < ele: c += 1 i += 1 se = (ele - c) % 3 ans = se if ans == 1: print("Carrots") if ans == 2: print("Kiwis") if ans == 0: print("Grapes")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
from sys import stdin, stdout def input(): a = stdin.readline() if a[-1] == "\n": a = a[:-1] return a def print(*argv, end="\n", sep=" "): n = len(argv) for i in range(n): if i == n - 1: stdout.write(str(argv[i])) else: stdout.write(str(argv[i]) + sep) stdout.write(end) mod = 10**9 + 7 def lcm(x, y): return x * y / gcd(x, y) def comb(lst, x): return list(c(lst, x)) def fact(x, mod=mod): ans = 1 for i in range(1, x + 1): ans = ans * i % mod return ans def arr2D(n, m, default=0): lst = [] for i in range(n): temp = [default] * m lst.append(temp) return lst def sortDictV(x): return {k: v for k, v in sorted(x.items(), key=lambda item: item[1])} def smaller(lst, x): return bisect_left(lst, x) - 1 def smallerEq(lst, x): return bisect_right(lst, x) - 1 def solve(n, m, k, t, waste, q): waste = sorted(waste) ans = ["Carrots", "Kiwis", "Grapes"] for i in q: if i in waste: print("Waste") else: cnt = 0 for w in waste: if w[0] < i[0]: cnt += 1 elif w[0] == i[0] and w[1] <= i[1]: cnt += 1 val = (i[0] - 1) * m + i[1] - cnt val %= 3 val -= 1 if val == -1: val = 2 print(ans[val]) n, m, k, t = list(map(int, input().split())) waste = [] for i in range(k): x, y = list(map(int, input().split())) waste.append([x, y]) q = [] for i in range(t): x, y = list(map(int, input().split())) q.append([x, y]) solve(n, m, k, t, waste, q)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF STRING STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF RETURN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) l = [] for i in range(k): a, b = map(int, input().split()) pos = b - 1 + m * (a - 1) l.append(pos) for i in range(t): a, b = map(int, input().split()) pos = b - 1 + m * (a - 1) j = 0 k = 0 for i in sorted(l): if i < pos: k += 1 elif pos == i: j = 1 else: break pos -= k if j == 1: print("Waste") elif pos % 3 == 1 and j == 0: print("Kiwis") elif pos % 3 == 2 and j == 0: print("Grapes") else: print("Carrots")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
class Coordenada: def __init__(self, linha, coluna): self.linha = linha self.coluna = coluna def __eq__(self, other): return self.linha == other.linha and self.coluna == other.coluna def __repr__(self): return "({}, {})".format(self.linha, self.coluna) def __lt__(self, other): if self.linha == other.linha: return self.coluna < other.coluna else: return self.linha < other.linha def binary_search(vetor, x, inicio=0, fim=None): if fim == None: fim = len(vetor) - 1 if inicio > fim: return -1 meio = (inicio + fim) // 2 if vetor[meio] == x: return meio elif vetor[meio] < x: return binary_search(vetor, x, meio + 1, fim) else: return binary_search(vetor, x, inicio, meio - 1) def ordem(vetor, x, inicio=0, fim=None): if fim == None: fim = len(vetor) - 1 meio = (inicio + fim) // 2 if inicio > fim: return inicio if vetor[meio] == x: return meio elif vetor[meio] < x: return ordem(vetor, x, meio + 1, fim) else: return ordem(vetor, x, inicio, meio - 1) def get_index(linha, coluna, n, m): linha -= 1 coluna -= 1 return linha * m + coluna n, m, k, t = map(int, input().split()) matriz_del = [] for _ in range(k): linha, coluna = map(int, input().split()) matriz_del.append(Coordenada(linha, coluna)) matriz_del.sort() frutas = ["Carrots", "Kiwis", "Grapes"] for _ in range(t): linha, coluna = map(int, input().split()) if Coordenada(linha, coluna) in matriz_del: print("Waste") else: index = get_index(linha, coluna, n, m) - ordem( matriz_del, Coordenada(linha, coluna) ) print(frutas[index % 3])
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF NUMBER NONE IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF NUMBER NONE IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = [int(x) for x in input().split()] mapp = {(0): "Carrots", (1): "Kiwis", (2): "Grapes"} iamdistruption = [] for i in range(k): x, y = [int(x) for x in input().split()] iamdistruption.append((x, y)) for i in range(t): x, y = [int(x) for x in input().split()] orig = m * (x - 1) + y - 1 disbeforeme = 0 for x, y in iamdistruption: if m * (x - 1) + y - 1 == orig: print("Waste") break elif m * (x - 1) + y - 1 < orig: disbeforeme += 1 else: afterdis = (orig % 3 - disbeforeme) % 3 print(mapp[afterdis])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
v = ["Carrots", "Kiwis", "Grapes"] n, m, k, t = map(int, input().split()) w = [] for i in range(k): a, b = map(int, input().split()) w.append((a - 1) * m + b - 1) w.append(n * m) w.sort() for i in range(t): a, b = map(int, input().split()) c, wi = (a - 1) * m + b - 1, 0 while w[wi] < c: wi += 1 print("Waste" if w[wi] == c else v[(c - wi) % 3])
ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = [int(i) for i in input().split()] waste = [] for j in range(k): a = [int(z) for z in input().split()] waste.append(a) waste.sort() for y in range(t): b = [int(y) for y in input().split()] if True: count = 0 f = 0 for q in range(k): if waste[q][0] < b[0]: count += 1 continue elif waste[q][0] == b[0]: if waste[q][1] == b[1]: print("Waste") f = 1 break elif waste[q][1] > b[1]: break else: count += 1 else: break if f == 1: continue expected = (b[0] - 1) * m + b[1] reality = expected - count rem = reality % 3 if rem == 2: print("Kiwis") elif rem == 1: print("Carrots") else: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [n * m + 1] for i in range(k): a, b = map(int, input().split()) waste.append((a - 1) * m + b) waste.sort() for i in range(t): i, j = map(int, input().split()) ind = (i - 1) * m + j for index, x in enumerate(waste): if x == ind: print("Waste") break elif x > ind: ind = ind - index val = ind % 3 if val == 1: print("Carrots") elif val == 2: print("Kiwis") else: print("Grapes") break
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
z = list(map(int, input().split())) hold = [0] * z[0] lst = [] for i in range(z[2]): a, b = map(int, input().split()) lst.append((a, b)) hold[a - 1] += 1 lst.sort() for k in range(1, len(hold)): hold[k] += hold[k - 1] for j in range(z[3]): v, b = map(int, input().split()) if (v, b) in lst: print("Waste") else: ans = (v - 1) * z[1] + b if v - 2 >= 0: ans -= hold[v - 2] for l in lst: if l[0] == v and l[1] < b: ans -= 1 if l[0] > v or l[0] == v and l[1] > b: break print(["Grapes", "Carrots", "Kiwis"][ans % 3])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST STRING STRING STRING BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) m, l = m % 3, (m + 1) % 3 p = [[] for i in range(n + 1)] for i in range(k): x, y = map(int, input().split()) p[x].append(y) r = [len(i) for i in p] for i in range(1, n + 1): r[i] += r[i - 1] r, q = [0] + r, [0] * t for i in range(t): x, y = map(int, input().split()) if y in p[x]: q[i] = "Waste" else: d = r[x] + sum(j < y for j in p[x]) d = m * x + y - d - l q[i] = ["Carrots", "Kiwis", "Grapes"][d % 3] print("\n".join(q))
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR LIST STRING STRING STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def read(): return map(int, input().split()) plants = ["Carrots", "Kiwis", "Grapes", "Waste"] n, m, k, t = read() waste_pos = set() for _ in range(k): x, y = read() pos = (x - 1) * m + (y - 1) waste_pos.add(pos) for _ in range(t): x, y = read() res = (x - 1) * m + (y - 1) sub = 0 if res in waste_pos: ans = 3 else: sub = sum(elm < res for elm in waste_pos) ans = (res - sub) % 3 print(plants[ans])
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [] queries = [] plants = {(0): "Carrots", (1): "Kiwis", (2): "Grapes"} waste_cells = 0 for _ in range(k): waste.append(list(map(int, input().split()))) for _ in range(t): query = list(map(int, input().split())) if query in waste: print("Waste") else: wastes = 0 for i in waste: if i < query: wastes += 1 i = (query[0] - 1) * m + (query[1] - 1) - wastes print(plants[i % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().strip().split()) w = [] for i in range(k): a, b = map(int, input().strip().split()) c = [] c.append(a) c.append(b) w.append(c) w.sort() d = ["Carrots", "Kiwis", "Grapes"] for i in range(t): a, b = map(int, input().strip().split()) if [a, b] in w: print("Waste") else: l = 0 for j in range(k - 1, -1, -1): if [a, b] > w[j]: l = j + 1 break print(d[((a - 1) * m + b - 1 - l) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF LIST VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = [int(i) for i in input().split()] waste = [] for i in range(k): a, b = [int(i) for i in input().split()] waste.append((a - 1) * m + b) crop = ["Carrots", "Kiwis", "Grapes"] waste.sort() nn = len(waste) for i in range(t): a, b = [int(i) for i in input().split()] c = (a - 1) * m + b i = 0 while i < nn and waste[i] < c: i += 1 if i < nn and waste[i] == c: print("Waste") else: no = c - i - 1 print(crop[no % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, w, q = [int(i) for i in input().split()] waste = [] for i in range(w): waste.append(tuple(map(int, input().split()))) waste.sort(key=lambda s: (s[0], s[1])) def wl(nw, w, x): d = 0 f = nw - 1 m = (d + f) // 2 while f >= d: m = (d + f) // 2 if w[m][0] >= x[0]: f = m - 1 else: d = m + 1 return d def wc(nw, w, x): d = wl(nw, w, x) f = wl(nw, w, (x[0] + 1, x[1])) - 1 m = (d + f) // 2 while f >= d: m = (d + f) // 2 if w[m][1] >= x[1]: f = m - 1 else: d = m + 1 return d def choice(d, x, w): c = "" if d < len(w) and w[d] == x: c = "Waste" else: k = (m * (x[0] - 1) + x[1] - d) % 3 if k == 1: c = "Carrots" elif k == 2: c = "Kiwis" else: c = "Grapes" return c res = [] for i in range(q): x = tuple(int(i) for i in input().split()) res.append(choice(wc(w, waste, x), x, waste)) for i in res: print(i)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING IF VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def get_crop(n, m, waste, i, j): curr = m * i + j if curr in waste: return "Waste" new = curr i = 0 while i < len(waste) and waste[i] < curr: new -= 1 i += 1 if new % 3 == 0: return "Carrots" elif new % 3 == 1: return "Kiwis" else: return "Grapes" s = input().split() n, m, k, t = int(s[0]), int(s[1]), int(s[2]), int(s[3]) waste = [] for i in range(k): s = input().split() waste.append(m * (int(s[0]) - 1) + int(s[1]) - 1) def partition_Lomuto(tab, l, r): pivot = tab[r] j = l for i in range(l, r): if tab[i] < pivot: tab[i], tab[j] = tab[j], tab[i] j += 1 tab[r], tab[j] = tab[j], tab[r] return j def quickSort(tab, l, r): if l < r: q = partition_Lomuto(tab, l, r) quickSort(tab, l, q - 1) quickSort(tab, q + 1, r) quickSort(waste, 0, len(waste) - 1) for i in range(t): s = input().split() print(get_crop(n, m, waste, int(s[0]) - 1, int(s[1]) - 1))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN STRING IF BIN_OP VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
[n, m, k, t] = list(map(int, input().split())) black = [] Plants = ["Carrots", "Kiwis", "Grapes"] for i in range(k): black.append(tuple(map(int, input().split()))) black.sort() queries = [] for i in range(t): queries.append(tuple(map(int, input().split()))) for q in queries: if q in black: print("Waste") else: index = 0 for i in range(len(black)): if black[i] > q: break else: index += 1 cellno = (q[0] - 1) * m + q[1] actual = (cellno - index) % 3 print(Plants[actual - 1])
ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
food = ["Carrots", "Kiwis", "Grapes"] n, m, k, t = [int(x) for x in input().split(" ")] wasts = [] for _k in range(k): _x, _y = [(int(x) - 1) for x in input().split(" ")] wasts.append((_x, _y)) wasts = sorted(wasts, key=lambda x: x) queries = [] for _t in range(t): query = [(int(x) - 1) for x in input().split(" ")] queries.append([query[0], query[1], _t, "", 0]) queries = sorted(queries, key=lambda query: query) for i in range(t): query = queries[i] for wast in wasts: if query[0] == wast[0] and query[1] == wast[1]: queries[i][3] = "Waste" if query[0] > wast[0] or query[0] == wast[0] and query[1] > wast[1]: queries[i][4] += 1 ans = [""] * t for query in queries: ans[query[2]] = ( food[(m * query[0] + query[1] - query[4]) % 3] if query[3] == "" else query[3] ) for a in ans: print(a)
ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = list(map(int, input().split())) waste_cell = set() for i in range(k): row, col = list(map(int, input().split())) which_cell = m * (row - 1) + col waste_cell.add(which_cell) crop = {(1): "Carrots", (2): "Kiwis", (0): "Grapes"} def waste_cell_before(total_cell): count = 0 for cell in sorted(waste_cell): if cell > total_cell: return count else: count += 1 return count for query in range(t): row, col = list(map(int, input().split())) total_cell = m * (row - 1) + col if total_cell in waste_cell: print("Waste") else: total_cell = total_cell - waste_cell_before(total_cell) print(crop[total_cell % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split(" ")) posMat = [] for i in range(k): x, y = map(int, input().split(" ")) posMat.append((x - 1) * m + y) posMat = sorted(posMat) for j in range(t): x, y = map(int, input().split(" ")) pos = (x - 1) * m + y if pos in posMat: print("Waste") else: sumX = 0 index = 0 while posMat[index] < pos: sumX += 1 index += 1 if index >= len(posMat): break pos -= sumX if pos % 3 == 0: print("Grapes") if pos % 3 == 1: print("Carrots") if pos % 3 == 2: print("Kiwis")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) k = [list(map(int, input().split())) for i in range(k)] for i in range(t): x = list(map(int, input().split())) print( "Waste" if x in k else ["Grapes", "Carrots", "Kiwis"][ (x[0] * m - m + x[1] - sum(map(lambda i: i < x, k))) % 3 ] )
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR STRING LIST STRING STRING STRING BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [] for i in range(k): waste.append(tuple(map(int, input().split()))) hashmap = dict() for a in waste: hashmap[a] = 1 ans = {(1): "Carrots", (2): "Kiwis", (0): "Grapes"} for _ in range(t): a, b = map(int, input().split()) if (a, b) in hashmap: print("Waste") else: total = (a - 1) * m + b subtract = 0 for i in range(k): if waste[i][0] < a: subtract += 1 elif waste[i][0] == a and waste[i][1] < b: subtract += 1 total -= subtract print(ans[total % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) waste = [tuple(map(int, input().split())) for _ in range(k)] def getCount2(waste, q1, q2): count = 0 for index, val in enumerate(waste): if val[0] < q1 and val[1] <= m: count = count + 1 elif val[0] == q1 and val[1] < q2: count = count + 1 else: pass return count for q in range(t): q1, q2 = map(int, input().split()) I = (q1 - 1) * m + (q2 - 1) J = getCount2(waste, q1, q2) a = (I - J) % 3 if (q1, q2) in waste: print("Waste") elif a == 0: print("Carrots") elif a == 1: print("Kiwis") else: print("Grapes")
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = list(map(int, input().split())) w = [] crops = ["Carrots", "Kiwis", "Grapes"] def getNumWaste(pos): ans = 0 for i in w: if i < pos: ans += 1 elif i == pos: return -1 return ans for i in range(k): a, b = list(map(int, input().split())) a -= 1 b -= 1 w.append(a * m + b) ans = [] for x in range(t): i, j = list(map(int, input().split())) i -= 1 j -= 1 pos = i * m + j nw = getNumWaste(pos) if nw == -1: ans.append("Waste") else: ans.append(crops[(pos - nw) % 3]) for i in ans: print(i)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
import sys def ints_input(): return [int(i) for i in sys.stdin.readline().strip("\n").split(" ")] def print_list(arr): sys.stdout.writelines(str(x) + " " for x in arr) sys.stdout.write("\n") def fast_input(type=str): return type(sys.stdin.readline().strip("\n")) n, m, k, t = ints_input() wastes = [] for i in range(k): wastes.append(tuple(ints_input())) wastes.sort() wastes_indexes = [] for f in wastes: wastes_indexes.append((f[0] - 1) * m + (f[1] - 1)) fruits = ["Carrots", "Kiwis", "Grapes"] for i in range(t): c = 0 f = tuple(ints_input()) x = (f[0] - 1) * m + (f[1] - 1) for waste in wastes_indexes: if x > waste: c += 1 elif x == waste: print("Waste") break else: break if x != waste: print(fruits[(x - c) % 3])
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def mi(): return map(int, input().split()) n, m, k, t = mi() wasterowscount = [0] * (n + 1) d = {(0): "Carrots", (1): "Kiwis", (2): "Grapes"} waste = [[]] * (n + 1) def fun(x, y): global waste if y in waste[x]: print("Waste") return 0 cur = (x - 1) * m - wasterowscount[x - 1] cur += y for i in range(wasterowscount[x] - wasterowscount[x - 1]): if waste[x][i] < y: cur -= 1 cur -= 1 cur %= 3 print(d[cur]) for i in range(len(waste)): waste[i] = waste[i][:] for i in range(k): x, y = mi() waste[x].append(y) wasterowscount[x] += 1 for i in range(2, len(wasterowscount)): wasterowscount[i] += wasterowscount[i - 1] for i in range(t): x, y = mi() fun(x, y)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR BIN_OP LIST LIST BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def main(): n, m, k, t = map(int, input().split()) uf = [] for _ in range(k): a, b = map(int, input().split()) uf.append([a, b]) crd = [] for _ in range(t): i, j = map(int, input().split()) crd.append([i, j]) for p1 in crd: total = (p1[0] - 1) * m + p1[1] - 1 cnt = 0 status = False for p2 in uf: num = (p2[0] - 1) * m + p2[1] - 1 if total == num: status = True break elif num < total: cnt += 1 if status: print("Waste") continue res = (total % 3 - cnt) % 3 if res == 0: print("Carrots") elif res == 1: print("Kiwis") elif res == 2: print("Grapes") main()
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 LIST VAR VAR 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 LIST VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) p = [] fruit = ["Carrots", "Kiwis", "Grapes"] for i in range(k): a, b = map(int, input().split()) p.append([a, b]) p.sort() for q in range(t): a, b = map(int, input().split()) if [a, b] in p: print("Waste") else: I = (a - 1) * m + b - 1 i = 0 while i < k: if p[i][0] == a: if p[i][1] > b: break elif p[i][0] > a: break i += 1 print(fruit[(I - i) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
f = [] n, m, k, t = map(int, input().split()) for i in range(k): f.append(list(map(int, input().split()))) f.sort() for j in range(t): a, b = map(int, input().split()) if [a, b] not in f: c = b + (a - 1) * m u = 0 for s in f: if s[1] + (s[0] - 1) * m < c: u += 1 c -= u if c % 3 == 1: print("Carrots") elif c % 3 == 2: print("Kiwis") else: print("Grapes") else: print("Waste")
ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
rows, cols, waste, t = map(int, input().split()) w = [] for i in range(waste): i, j = map(int, input().split()) w.append([i, j]) w.sort() fruits = ["Carrots", "Kiwis", "Grapes"] for i in range(t): i, j = map(int, input().split()) if [i, j] in w: print("Waste") else: J = (i - 1) * cols + (j - 1) I = 0 for a, b in w: if a < i or a == i and b < j: I += 1 else: break print(fruits[(J - I) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) def index(l, r): return l * m + r k_list = [] d = {(0): "Carrots", (1): "Kiwis", (2): "Grapes"} for i in range(k): l, r = map(int, input().split()) k_list.append((l - 1, r - 1)) k_list.sort() for i in range(t): cnt = 0 l, r = map(int, input().split()) l -= 1 r -= 1 v = False for j in k_list: if j[0] < l: cnt += 1 elif j[0] == l: if j[1] < r: cnt += 1 elif j[1] == r: print("Waste") v = True else: break if not v: print(d[(index(l, r) - cnt) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = input().strip().split(" ") n = int(n) m = int(m) k = int(k) t = int(t) ar = [] for i in range(k): inp = input().strip().split(" ") ar.append((int(inp[0]) - 1) * m + int(inp[1]) - 1) ar.sort() for i in range(t): inp = input().strip().split(" ") inp[0] = int(inp[0]) - 1 inp[1] = int(inp[1]) - 1 temp = inp[0] * m + inp[1] Waste_count = 0 flag = 0 for j in range(k): if ar[j] == temp: print("Waste") flag = 1 elif ar[j] < temp: Waste_count += 1 else: break if flag == 0: temp = temp - Waste_count if temp % 3 == 1: print("Kiwis") elif temp % 3 == 2: print("Grapes") else: print("Carrots")
ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
inp = str(input()).split(" ") n = int(inp[0]) m = int(inp[1]) k = int(inp[2]) t = int(inp[3]) wasteSpace = [] for _ in range(k): inp = str(input()).split(" ") while inp == [""]: inp = str(input()).split(" ") x = int(inp[0]) - 1 y = int(inp[1]) - 1 wasteSpace.append((x, y)) wasteSpace.sort() def isWaste(x, y): return (x, y) in wasteSpace def countPos(x, y): l = 0 r = len(wasteSpace) - 1 while r >= l: m = l + (r - l) // 2 if wasteSpace[m] > (x, y): r = m - 1 else: l = m + 1 return r + 1 for _ in range(t): inp = str(input()).split(" ") while inp == [""]: inp = str(input()).split(" ") x = int(inp[0]) - 1 y = int(inp[1]) - 1 if isWaste(x, y): print("Waste") else: wasteCount = countPos(x, y) total = x * m + y - wasteCount if total % 3 == 0: print("Carrots") elif total % 3 == 1: print("Kiwis") else: print("Grapes")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING WHILE VAR LIST STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING WHILE VAR LIST STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split()) arr = [] for i in range(k): a, b = map(int, input().split()) arr.append((a - 1) * m + b) arr.sort() for i in range(t): x, y = map(int, input().split()) c = 0 s = (x - 1) * m + y p = 0 for j in arr: if j == s: p = 1 print("Waste") break elif j < s: c += 1 continue else: break d = {(1): "Carrots", (2): "Kiwis", (0): "Grapes"} if p == 0: print(d[(s - c) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, num_wasted, num_queries = map(int, input().split()) wasted = [None for i in range(num_wasted)] for i in range(num_wasted): a, b = map(lambda s: int(s) - 1, input().split()) wasted[i] = a * m + b wasted_set = set(wasted) wasted.sort() crops = ["Carrots", "Kiwis", "Grapes"] for i in range(num_queries): a, b = map(lambda s: int(s) - 1, input().split()) q = a * m + b if q in wasted_set: print("Waste") continue count = 0 for w in wasted: if w > q: break count += 1 print(crops[(q - count) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
A = list(map(int, input().split())) n = A[0] m = A[1] k = A[2] q = A[3] wastepos = [] for i in range(k): a, b = list(map(int, input().split())) wastepos += [[a - 1, b - 1]] Items = ["Carrots", "Kiwis", "Grapes"] for _ in range(q): a, b = list(map(int, input().split())) res = (a - 1) * m + b if [a - 1, b - 1] in wastepos: print("Waste") continue wastepos.append([a - 1, b - 1]) wastepos.sort() res -= wastepos.index([a - 1, b - 1]) wastepos.remove([a - 1, b - 1]) print(Items[res % 3 - 1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
n, m, k, t = map(int, input().split(" ")) field = [] for _ in range(k): a, b = map(int, input().split(" ")) field.append((a - 1) * m + (b - 1)) field.sort() dic = {(0): "Carrots", (1): "Kiwis", (2): "Grapes"} for _ in range(t): flag = 0 x, y = map(int, input().split(" ")) value = (x - 1) * m + (y - 1) for i in range(len(field)): if value == field[i]: print("Waste") flag = 1 break elif value < field[i]: break elif value > field[i] and i == len(field) - 1: i += 1 if flag == 0: print(dic[(value - i) % 3])
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
from sys import stdin def get_ints(): return list(map(int, stdin.readline().strip().split())) n, m, k, t = get_ints() seq = ["Carrots", "Kiwis", "Grapes"] wastes = [] dic = {} for _ in range(k): a, b = get_ints() wastes.append((a - 1) * m + b - 1) dic[(a - 1) * m + b - 1] = 1 wastes = sorted(wastes) for _ in range(t): a, b = get_ints() shouldbe = (a - 1) * m + b - 1 if shouldbe in dic: print("Waste") continue numbefore = sum([(1) for x in wastes if x < shouldbe]) print(seq[(shouldbe - numbefore) % 3])
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
def inp(): return map(int, input().split()) def print_arr(arr): print(*arr, sep="\n") def get_col(arr, i): return [row[i] for row in arr] n, m, k, t = inp() waste, quary, plant = [], [], ["Grapes", "Carrots", "Kiwis"] for i in range(k): a, b = inp() waste.append((a - 1) * m + b) for i in range(t): x, y = inp() quary.append([i, (x - 1) * m + y]) waste.sort() quary.sort(key=lambda x: x[1]) ix, i = 0, 0 while i < t: if ix == k: quary[i][1] = plant[(quary[i][1] - ix) % 3] i += 1 elif quary[i][1] == waste[ix]: quary[i][1] = "Waste" i += 1 elif quary[i][1] < waste[ix]: quary[i][1] = plant[(quary[i][1] - ix) % 3] i += 1 else: ix += 1 quary.sort(key=lambda x: x[0]) print_arr(get_col(quary, 1))
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Fox Ciel saw a large field while she was on a bus. The field was a n Γ— m rectangle divided into 1 Γ— 1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes. After seeing the field carefully, Ciel found that the crop plants of each cell were planted in following procedure: * Assume that the rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right, and a cell in row i and column j is represented as (i, j). * First, each field is either cultivated or waste. Crop plants will be planted in the cultivated cells in the order of (1, 1) β†’ ... β†’ (1, m) β†’ (2, 1) β†’ ... β†’ (2, m) β†’ ... β†’ (n, 1) β†’ ... β†’ (n, m). Waste cells will be ignored. * Crop plants (either carrots or kiwis or grapes) will be planted in each cell one after another cyclically. Carrots will be planted in the first cell, then kiwis in the second one, grapes in the third one, carrots in the forth one, kiwis in the fifth one, and so on. The following figure will show you the example of this procedure. Here, a white square represents a cultivated cell, and a black square represents a waste cell. <image> Now she is wondering how to determine the crop plants in some certain cells. Input In the first line there are four positive integers n, m, k, t (1 ≀ n ≀ 4Β·104, 1 ≀ m ≀ 4Β·104, 1 ≀ k ≀ 103, 1 ≀ t ≀ 103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in a certain cell. Following each k lines contains two integers a, b (1 ≀ a ≀ n, 1 ≀ b ≀ m), which denotes a cell (a, b) is waste. It is guaranteed that the same cell will not appear twice in this section. Following each t lines contains two integers i, j (1 ≀ i ≀ n, 1 ≀ j ≀ m), which is a query that asks you the kind of crop plants of a cell (i, j). Output For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. Examples Input 4 5 5 6 4 3 1 3 3 3 2 5 3 2 1 3 1 4 2 3 2 4 1 1 1 1 Output Waste Grapes Carrots Kiwis Carrots Carrots Note The sample corresponds to the figure in the statement.
btngan = 0 a = [int(x) for x in input().split(" ")] wastec = 0 xi = a[0] xj = a[1] waste = [[(0) for x in range(2)] for y in range(a[2])] for i in range(0, a[2]): w = [int(x) for x in input().split(" ")] waste[i] = w for i in range(0, a[3]): count = 0 p = [int(x) for x in input().split(" ")] ii = p[0] jj = p[1] if [ii, jj] in waste: print("Waste") else: wastec = 0 for i in range(a[2]): if waste[i][0] < ii: wastec += 1 elif waste[i][0] == ii and waste[i][1] < jj: wastec += 1 else: continue btngan = ii * a[1] - (a[1] - jj) btngan = btngan - wastec if btngan % 3 == 1: print("Carrots") elif btngan % 3 == 2: print("Kiwis") elif btngan % 3 == 0: print("Grapes")
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF LIST VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
There is a forest that we model as a plane and live $n$ rare animals. Animal number $i$ has its lair in the point $(x_{i}, y_{i})$. In order to protect them, a decision to build a nature reserve has been made. The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the forest. All animals drink from this river, therefore it must have at least one common point with the reserve. On the other hand, ships constantly sail along the river, so the reserve must not have more than one common point with the river. For convenience, scientists have made a transformation of coordinates so that the river is defined by $y = 0$. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve. -----Input----- The first line contains one integer $n$ ($1 \le n \le 10^5$) β€” the number of animals. Each of the next $n$ lines contains two integers $x_{i}$, $y_{i}$ ($-10^7 \le x_{i}, y_{i} \le 10^7$) β€” the coordinates of the $i$-th animal's lair. It is guaranteed that $y_{i} \neq 0$. No two lairs coincide. -----Output----- If the reserve cannot be built, print $-1$. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 1 0 1 Output 0.5 Input 3 0 1 0 2 0 -3 Output -1 Input 2 0 1 1 1 Output 0.625 -----Note----- In the first sample it is optimal to build the reserve with the radius equal to $0.5$ and the center in $(0,\ 0.5)$. In the second sample it is impossible to build a reserve. In the third sample it is optimal to build the reserve with the radius equal to $\frac{5}{8}$ and the center in $(\frac{1}{2},\ \frac{5}{8})$.
l, r = -100000000, 1000000000 def check(mid): mx = 0 for i in range(n): x, y = x1[i], y1[i] mx = max(mx, (x1[i] - mid) ** 2 / (2 * y1[i]) + y1[i] / 2) return mx n = int(input()) count1 = 0 count2 = 0 x1 = [] y1 = [] for i in range(n): a, b = list(map(int, input().split())) if b >= 0: count1 += 1 else: count2 += 1 x1.append(a) y1.append(abs(b)) if count1 and count2: print(-1) return for i in range(100): mid1 = l + (r - l) / 3 mid2 = r - (r - l) / 3 if check(mid1) > check(mid2): l = mid1 else: r = mid2 print(check(l))
ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
There is a forest that we model as a plane and live $n$ rare animals. Animal number $i$ has its lair in the point $(x_{i}, y_{i})$. In order to protect them, a decision to build a nature reserve has been made. The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the forest. All animals drink from this river, therefore it must have at least one common point with the reserve. On the other hand, ships constantly sail along the river, so the reserve must not have more than one common point with the river. For convenience, scientists have made a transformation of coordinates so that the river is defined by $y = 0$. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve. -----Input----- The first line contains one integer $n$ ($1 \le n \le 10^5$) β€” the number of animals. Each of the next $n$ lines contains two integers $x_{i}$, $y_{i}$ ($-10^7 \le x_{i}, y_{i} \le 10^7$) β€” the coordinates of the $i$-th animal's lair. It is guaranteed that $y_{i} \neq 0$. No two lairs coincide. -----Output----- If the reserve cannot be built, print $-1$. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 1 0 1 Output 0.5 Input 3 0 1 0 2 0 -3 Output -1 Input 2 0 1 1 1 Output 0.625 -----Note----- In the first sample it is optimal to build the reserve with the radius equal to $0.5$ and the center in $(0,\ 0.5)$. In the second sample it is impossible to build a reserve. In the third sample it is optimal to build the reserve with the radius equal to $\frac{5}{8}$ and the center in $(\frac{1}{2},\ \frac{5}{8})$.
import sys input = sys.stdin.readline class Point: def __init__(self, x, y): self.x = x self.y = y def get(x0, a, n): r = 0 for i in range(n): p = (x0 - a[i].x) * (x0 - a[i].x) + 1.0 * a[i].y * a[i].y p = p / 2.0 / a[i].y if p < 0: p = -p r = max(r, p) return r def main(): n = int(input()) pos, neg = False, False a = [] for i in range(n): x, y = map(int, input().split()) t = Point(x, y) if t.y > 0: pos = True else: neg = True a.append(t) if pos and neg: return -1 if neg: for i in range(n): a[i].y = -a[i].y L, R = -100000000.0, 100000000.0 for i in range(120): x1 = L + (R - L) / 3 x2 = R - (R - L) / 3 if get(x1, a, n) < get(x2, a, n): R = x2 else: L = x1 return get(L, a, n) print(main())
IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
There is a forest that we model as a plane and live $n$ rare animals. Animal number $i$ has its lair in the point $(x_{i}, y_{i})$. In order to protect them, a decision to build a nature reserve has been made. The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the forest. All animals drink from this river, therefore it must have at least one common point with the reserve. On the other hand, ships constantly sail along the river, so the reserve must not have more than one common point with the river. For convenience, scientists have made a transformation of coordinates so that the river is defined by $y = 0$. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve. -----Input----- The first line contains one integer $n$ ($1 \le n \le 10^5$) β€” the number of animals. Each of the next $n$ lines contains two integers $x_{i}$, $y_{i}$ ($-10^7 \le x_{i}, y_{i} \le 10^7$) β€” the coordinates of the $i$-th animal's lair. It is guaranteed that $y_{i} \neq 0$. No two lairs coincide. -----Output----- If the reserve cannot be built, print $-1$. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 1 0 1 Output 0.5 Input 3 0 1 0 2 0 -3 Output -1 Input 2 0 1 1 1 Output 0.625 -----Note----- In the first sample it is optimal to build the reserve with the radius equal to $0.5$ and the center in $(0,\ 0.5)$. In the second sample it is impossible to build a reserve. In the third sample it is optimal to build the reserve with the radius equal to $\frac{5}{8}$ and the center in $(\frac{1}{2},\ \frac{5}{8})$.
def bs(x, y, n, p): r = 0 for i in range(n): z = (p - x[i]) * (p - x[i]) + 1.0 * y[i] * y[i] z = z / 2.0 z = z / y[i] z = abs(z) r = max(z, r) return r n = int(input()) y = [] x = [] k = z = 0 for i in range(n): a, b = [int(i) for i in input().split()] if b > 0: k = 1 if b < 0: z = 1 x.append(a) y.append(b) if k == 1 and z == 1: print(-1) else: z = 120 l = min(x) rt = max(x) while z: p1 = (2 * l + rt) / 3 p2 = (2 * rt + l) / 3 if bs(x, y, n, p1) < bs(x, y, n, p2): rt = p2 else: l = p1 z = z - 1 print(bs(x, y, n, l))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
There is a forest that we model as a plane and live $n$ rare animals. Animal number $i$ has its lair in the point $(x_{i}, y_{i})$. In order to protect them, a decision to build a nature reserve has been made. The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the forest. All animals drink from this river, therefore it must have at least one common point with the reserve. On the other hand, ships constantly sail along the river, so the reserve must not have more than one common point with the river. For convenience, scientists have made a transformation of coordinates so that the river is defined by $y = 0$. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve. -----Input----- The first line contains one integer $n$ ($1 \le n \le 10^5$) β€” the number of animals. Each of the next $n$ lines contains two integers $x_{i}$, $y_{i}$ ($-10^7 \le x_{i}, y_{i} \le 10^7$) β€” the coordinates of the $i$-th animal's lair. It is guaranteed that $y_{i} \neq 0$. No two lairs coincide. -----Output----- If the reserve cannot be built, print $-1$. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 1 0 1 Output 0.5 Input 3 0 1 0 2 0 -3 Output -1 Input 2 0 1 1 1 Output 0.625 -----Note----- In the first sample it is optimal to build the reserve with the radius equal to $0.5$ and the center in $(0,\ 0.5)$. In the second sample it is impossible to build a reserve. In the third sample it is optimal to build the reserve with the radius equal to $\frac{5}{8}$ and the center in $(\frac{1}{2},\ \frac{5}{8})$.
n, l, r = 0, -100000000, 1000000000 x, y = [], [] def cal(mid): mx = 0 for i in range(n): mx = max(mx, (x[i] - mid) ** 2 / (2 * y[i]) + y[i] / 2) return mx n = int(input()) for i in range(n): a, b = map(int, input().split()) x.append(a), y.append(b) for i in range(1, n): if y[i] * y[0] < 0: print(-1) exit(0) if y[i] < 0: y[i] *= -1 if y[0] < 0: y[0] *= -1 for it in range(100): m1, m2 = l + (r - l) / 3, r - (r - l) / 3 v1, v2 = cal(m1), cal(m2) if v1 > v2: l = m1 else: r = m2 print(cal(m1))
ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd. You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon. Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square. You can rotate $2n$-gon and/or the square. -----Input----- The first line contains a single integer $T$ ($1 \le T \le 200$)Β β€” the number of test cases. Next $T$ lines contain descriptions of test casesΒ β€” one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon. -----Output----- Print $T$ real numbersΒ β€” one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. -----Example----- Input 3 2 4 200 Output 1.000000000 2.414213562 127.321336469
res = [ "1.9318516577", "3.1962266127", "4.4657021374", "5.7368566318", "7.0087710109", "8.2810937889", "9.5536612999", "10.8263870658", "12.0992210840", "13.3721323881", "14.6451008008", "15.9181125992", "17.1911581674", "18.4642304645", "19.7373243730", "21.0104359486", "22.2835621274", "23.5567005950", "24.8298493956", "26.1030070624", "27.3761723567", "28.6493442355", "29.9225218838", "31.1957045846", "32.4688917510", "33.7420828616", "35.0152774926", "36.2884752855", "37.5616759142", "38.8348790854", "40.1080845709", "41.3812921427", "42.6545016376", "43.9277128601", "45.2009256798", "46.4741399664", "47.7473555894", "49.0205724836", "50.2937904862", "51.5670095970", "52.8402296531", "54.1134506545", "55.3866725034", "56.6598951346", "57.9331185155", "59.2063425809", "60.4795673309", "61.7527926676", "63.0260185910", "64.2992450360", "65.5724720025", "66.8456994254", "68.1189273372", "69.3921556401", "70.6653843669", "71.9386134847", "73.2118429612", "74.4850727635", "75.7583029245", "77.0315333788", "78.3047641265", "79.5779951349", "80.8512264368", "82.1244579994", "83.3976897901", "84.6709218417", "85.9441540888", "87.2173865641", "88.4906192349", "89.7638521014", "91.0370851308", "92.3103183558", "93.5835517764", "94.8567853273", "96.1300190739", "97.4032529508", "98.6764869581", "99.9497211284", "101.2229554291", "102.4961898602", "103.7694244216", "105.0426591134", "106.3158939031", "107.5891287905", "108.8623638083", "110.1355989239", "111.4088341698", "112.6820694810", "113.9553048899", "115.2285403967", "116.5017760012", "117.7750116709", "119.0482474385", "120.3214832712", "121.5947192017", "122.8679551973", "124.1411912582", "125.4144273843", "126.6876635756", "127.9608998646", ] t = int(input()) for i in range(t): n = int(input()) print(res[(n - 1) // 2 - 1])
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The first and only line contains integer $k$ ($1 \le k \le 10^{12}$) β€” the position to process ($1$-based index). -----Output----- Print the $k$-th digit of the resulting infinite sequence. -----Examples----- Input 7 Output 7 Input 21 Output 5
k = int(input("")) a = [9] i = 1 if k < 10: print(k) else: while k > a[-1]: a.append((10 ** (i + 1) - 10**i) * (i + 1) + a[i - 1]) i += 1 cat = len(a) diff = k - a[-2] step = int(diff / cat) rem = diff % cat if rem == 0: number = 10 ** (cat - 1) - 1 + step print(str(number)[-1]) else: number = 10 ** (cat - 1) + step print(str(number)[rem - 1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The first and only line contains integer $k$ ($1 \le k \le 10^{12}$) β€” the position to process ($1$-based index). -----Output----- Print the $k$-th digit of the resulting infinite sequence. -----Examples----- Input 7 Output 7 Input 21 Output 5
digit = 1 x = int(input()) start_range = 1 end_range = 9 nine = 9 total = 0 while x > end_range: start_range = end_range + 1 digit += 1 end_range += digit * nine * pow(10, digit - 1) total = total + start_range start = pow(10, digit - 1) number = int((x - start_range) / digit) index = int((x - start_range) % digit) start = start + number string = str(start) print(string[index])
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The first and only line contains integer $k$ ($1 \le k \le 10^{12}$) β€” the position to process ($1$-based index). -----Output----- Print the $k$-th digit of the resulting infinite sequence. -----Examples----- Input 7 Output 7 Input 21 Output 5
idx = {} idx[0] = 0 s = 0 num = 9 for digit in range(1, 12): s += num * digit idx[digit] = s num = num * 10 N = int(input()) nubmer = 0 r = 0 d = 0 for digit in range(1, 12): if N <= idx[digit] and N > idx[digit - 1]: number = (N - idx[digit - 1]) // digit r = (N - idx[digit - 1]) % digit d = digit break if r != 0: number += 1 num = 10 ** (d - 1) + number - 1 digit = [int(i) for i in str(num)] if r == 0: print(digit[-1]) else: print(digit[r - 1])
ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER