description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil. The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal. Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team. Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum. It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself. The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p). A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team. It is guaranteed that every hero is able to destroy any megaboss alone. Input The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal. In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c. Output Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking. Examples Input 3 Troll likes Dracul Dracul likes Anka Snowy likes Hexadecimal 210 200 180 Output 30 3 Input 2 Anka likes Chapay Chapay likes Anka 10000 50 50 Output 1950 2 Note A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
from itertools import combinations, permutations, product n = int(input()) names = {} nex = 0 mama = 128 liking = [0] * mama likes = [([0] * 7) for _ in range(7)] def getName(name): global nex if name in names: return names[name] names[name] = nex nex += 1 return names[name] for _ in range(n): a, b, c = input().split() likes[getName(a)][getName(c)] = 1 bosses = [int(x) for x in input().split()] part = set() part.add((0, 0, 0)) dipart = 10**10 for i in range(1, 4): for j in range(i, 7): k = 7 - i - j if k < j: continue for per in permutations(bosses): aa = per[0] // i, per[1] // j, per[2] // k difi = max(aa) - min(aa) if difi < dipart: dipart = difi part = set() part.add((i, j, k)) elif difi == dipart: part.add((i, j, k)) for i, j in product(range(7), repeat=2): if likes[i][j] == 0: continue mask = 1 << i | 1 << j for k in range(mama): if k & mask == mask: liking[k] += 1 nums = list(range(7)) def tonum(ite): r = 0 for nu in ite: r |= 1 << nu return r bea = 0 for a, b, c in part: for pera in combinations(range(7), a): lefta = [x for x in nums if x not in pera] for perb in combinations(lefta, b): perc = [x for x in lefta if x not in perb] susu = liking[tonum(pera)] + liking[tonum(perb)] + liking[tonum(perc)] if susu > bea: bea = susu print(dipart, bea)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil. The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal. Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team. Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum. It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself. The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p). A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team. It is guaranteed that every hero is able to destroy any megaboss alone. Input The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal. In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c. Output Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking. Examples Input 3 Troll likes Dracul Dracul likes Anka Snowy likes Hexadecimal 210 200 180 Output 30 3 Input 2 Anka likes Chapay Chapay likes Anka 10000 50 50 Output 1950 2 Note A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
import itertools heroes = ["Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal"] n = int(input()) edges = [] for i in range(n): p, likes, q = input().split() edges.append((heroes.index(p), heroes.index(q))) boss_xp = list(map(int, input().split())) min_difference = float("inf") max_liking = float("-inf") for assignment in itertools.product(range(3), repeat=7): assignment_heroes = [ [hero for hero, boss in enumerate(assignment) if boss == i] for i in range(3) ] if any(len(attackers) == 0 for attackers in assignment_heroes): continue xp_division = [ (xp // len(attackers)) for xp, attackers in zip(boss_xp, assignment_heroes) ] difference = max(xp_division) - min(xp_division) if difference < min_difference: min_difference = difference max_liking = sum( len([(p, q) for p, q in edges if p in attackers and q in attackers]) for attackers in assignment_heroes ) elif difference == min_difference: liking = sum( len([(p, q) for p, q in edges if p in attackers and q in attackers]) for attackers in assignment_heroes ) max_liking = max(max_liking, liking) print("%d %d" % (min_difference, max_liking))
IMPORT ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil. The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal. Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team. Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum. It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself. The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p). A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team. It is guaranteed that every hero is able to destroy any megaboss alone. Input The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal. In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c. Output Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking. Examples Input 3 Troll likes Dracul Dracul likes Anka Snowy likes Hexadecimal 210 200 180 Output 30 3 Input 2 Anka likes Chapay Chapay likes Anka 10000 50 50 Output 1950 2 Note A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
from itertools import * p = {"An": 0, "Ch": 1, "Cl": 2, "Tr": 3, "Dr": 4, "Sn": 5, "He": 6} def f(): u, l, v = input().split() return p[u[:2]], p[v[:2]] s = [f() for k in range(int(input()))] a, b, c = map(int, input().split()) d = l = 9000000000.0 for i in range(1, 6): for j in range(1, 7 - i): k = 7 - i - j t = [a // i, b // j, c // k] t = max(t) - min(t) if t < d: d, l = t, 0 if t == d: for q in set(permutations([0] * i + [1] * j + [2] * k)): l = max(l, sum(q[u] == q[v] for u, v in s)) print(d, l)
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil. The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal. Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team. Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum. It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself. The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p). A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team. It is guaranteed that every hero is able to destroy any megaboss alone. Input The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal. In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c. Output Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking. Examples Input 3 Troll likes Dracul Dracul likes Anka Snowy likes Hexadecimal 210 200 180 Output 30 3 Input 2 Anka likes Chapay Chapay likes Anka 10000 50 50 Output 1950 2 Note A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
from itertools import combinations def main(): heroes = ("Anka", "Chapay", "Cleo", "Troll", "Dracul", "Snowy", "Hexadecimal") sympaty = [([False] * 7) for _ in range(7)] for _ in range(int(input())): a, _, b = input().split() sympaty[heroes.index(a)][heroes.index(b)] = True a, b, c = map(int, input().split()) tmp, res = [], [] for i in range(1, 6): for j in range(1, 7 - i): t = int(a / i), int(b / j), int(c / (7 - i - j)) tmp.append((max(t) - min(t), i, j)) delta = min(tmp)[0] for i, j in ((i, j) for x, i, j in tmp if x == delta): for aa in combinations(range(7), i): rest = [x for x in range(7) if x not in aa] for bb in combinations(rest, j): res.append( sum( sum(sympaty[x][y] for x in xy for y in xy) for xy in (aa, bb, [x for x in rest if x not in bb]) ) ) print(delta, max(res)) main()
FUNC_DEF ASSIGN VAR STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil. The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal. Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team. Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum. It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself. The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p). A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team. It is guaranteed that every hero is able to destroy any megaboss alone. Input The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself. In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal. In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c. Output Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team). When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking. Examples Input 3 Troll likes Dracul Dracul likes Anka Snowy likes Hexadecimal 210 200 180 Output 30 3 Input 2 Anka likes Chapay Chapay likes Anka 10000 50 50 Output 1950 2 Note A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
R = range S = str.split I = input L = S("Anka Chapay Cleo Troll Dracul Snowy Hexadecimal") h = {} for i in R(7): h[L[i]] = i d = [[] for i in R(9)] for z in "0" * int(I()): a, _, b = S(I()) d[h[a]] += [h[b]] a, b, c = map(int, S(I())) o = [10**9, 0] def C(q, w, e, n): if n == 7: if not (q and w and e): return p = [a // len(q), b // len(w), c // len(e)] p = max(p) - min(p) l = sum(k in g for g in (q, w, e) for h in g for k in d[h]) global o if o[0] > p or o[0] == p and o[1] < l: o = p, l else: C(q + [n], w, e, n + 1) C(q, w + [n], e, n + 1) C(q, w, e + [n], n + 1) C([], [], [], 0) print(o[0], o[1])
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER IF VAR VAR VAR RETURN ASSIGN VAR LIST BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST LIST LIST NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Let's define the niceness of a sequence of positive integers X1,X2,…,XN$X_1, X_2, \dots, X_N$ as the sum of greatest common divisors of all pairs of its elements, i.e. N∑i=1N∑j=i+1gcd(Xi,Xj).∑i=1N∑j=i+1Ngcd(Xi,Xj).\sum_{i=1}^N \sum_{j=i+1}^N \mathrm{gcd}(X_i, X_j)\;. For example, the niceness of the sequence [1,2,2]$[1, 2, 2]$ is gcd(1,2)+gcd(1,2)+gcd(2,2)=4$gcd(1, 2) + gcd(1, 2) + gcd(2, 2) = 4$. You are given a sequence A1,A2,…,AN$A_1, A_2, \dots, A_N$; each of its elements is either a positive integer or missing. Consider all possible ways to replace each missing element of A$A$ by a positive integer (not necessarily the same for each element) such that the sum of all elements is equal to S$S$. Your task is to find the total niceness of all resulting sequences, i.e. compute the niceness of each possible resulting sequence and sum up all these values. Since the answer may be very large, compute it modulo 109+7$10^9 + 7$. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains two space-separated integers N$N$ and S$S$. - The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \dots, A_N$. Missing elements in this sequence are denoted by −1$-1$. -----Output----- For each test case, print a single line containing one integer — the total niceness modulo 109+7$10^9 + 7$. -----Constraints----- - 1≤T≤20$1 \le T \le 20$ - 1≤N,S≤50$1 \le N, S \le 50$ - 1≤Ai≤50$1 \le A_i \le 50$ or Ai=−1$A_i = -1$ for each valid i$i$ -----Subtasks----- Subtask #1 (30 points): - 1≤N,S≤18$1 \le N, S \le 18$ - 1≤Ai≤18$1 \le A_i \le 18$ or Ai=−1$A_i = -1$ for each valid i$i$ Subtask #2 (70 points): original constraints -----Example Input----- 3 3 3 1 1 -1 4 8 1 -1 -1 3 3 10 -1 -1 -1 -----Example Output----- 3 23 150 -----Explanation----- Example case 1: There is only one possible way to fill in the missing element; the resulting sequence is [1,1,1]$[1, 1, 1]$. Its niceness is 3$3$. Example case 2: There is only three possible ways to fill in the missing elements; the resulting sequences are [1,1,3,3]$[1, 1, 3, 3]$, [1,3,1,3]$[1, 3, 1, 3]$, and [1,2,2,3]$[1, 2, 2, 3]$. The sum of their niceness is 8+8+7=23$8 + 8 + 7 = 23$.
mod = 10**9 + 7 def gcd(a, b): return b and gcd(b, a % b) or a def fac50(): f = [0] * 51 f[0] = 1 f[1] = 1 for i in range(1, 51): f[i] = f[i - 1] * i % mod return f def gcd110(): gc = [([0] * 111) for i in range(111)] for i in range(111): for j in range(111): gc[i][j] = gcd(i, j) return gc factorials = fac50() gcds = gcd110() def rule_asc(n, l): a = [(0) for i in range(n + 1)] k = 1 a[1] = n while k != 0: x = a[k - 1] + 1 y = a[k] - 1 k -= 1 while x <= y and k < l - 1: a[k] = x y -= x k += 1 a[k] = x + y yield a[: k + 1] def niceness(s): t = 0 for i in range(len(s)): for j in range(i + 1, len(s)): t = (t + gcds[s[i]][s[j]]) % mod return t def permcount(s, c): f = [s.count(x) for x in set(s)] p = factorials[c] for e in f: p = p * pow(factorials[e], mod - 2, mod) % mod return p def main(): t = int(input()) for i in range(t): n, s = [int(item) for item in input().split()] a = [int(item) for item in input().split()] b = [i for i in a if i != -1] s -= sum(b) ones = a.count(-1) if s < 0: print(0) elif s == 0 and ones == 0: print(niceness(a) % mod) elif s > 0 and ones == 0: print(0) else: t = 0 for seq in rule_asc(s, ones): if len(seq) == ones: p = permcount(seq, ones) t = (t + p % mod * (niceness(b + seq) % mod) % mod) % mod print(t) main()
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
def main(): res = 0 ind = 0 curr = [] letterflag = False chars = list(input()) for c in chars: if c.isalpha(): if letterflag: val = int("".join(curr)) res = max(res, val) curr = curr[ind:] else: letterflag = True curr.append("9") ind = len(curr) else: curr.append(c) val = int("".join(curr)) res = max(res, val) print(res) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
t = input() r = r1 = "" mx = -1 for i in range(len(t)): if t[i] >= "A" and t[i] <= "Z": r = r1 + "9" r1 = "" else: r = r + t[i] r1 = r1 + t[i] if int(r) > mx: mx = int(r) print(mx)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
high = 0 s = input() for i in range(len(s)): gg = "" l = 0 if s[i].isdigit() == True: gg += s[i] else: gg += str(9) l = 1 j = i + 1 while j < len(s) and (l < 1 or s[j].isdigit() == True): if s[j].isdigit() == False: gg = gg + str(9) l += 1 else: gg += s[j] j += 1 if high < int(gg): high = int(gg) print(high)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
str = input() l = len(str) p = 1 maxm = 0 for i in range(0, l): ans2 = "" ans1 = "" if ord(str[i]) >= 65 and ord(str[i]) <= 90: p = 0 j = i - 1 while True: if j >= 0: if ord(str[j]) >= 65 and ord(str[j]) <= 90: break else: ans1 = ans1 + str[j] j = j - 1 else: break j = i + 1 while True: if j < l: if ord(str[j]) >= 65 and ord(str[j]) <= 90: break else: ans2 = ans2 + str[j] j = j + 1 else: break ans = ans1[::-1] + "9" + ans2 ans = int(ans) if ans >= maxm: maxm = ans if p == 1: print(int(str)) else: print(maxm)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER STRING VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
string = input() max_no = 0 for i in range(len(string)): var_occur = 0 check_no = str() j = i while j < len(string) and var_occur < 2: if string[j].isalpha(): if var_occur == 0: check_no += "9" var_occur += 1 else: var_occur += 1 else: check_no += string[j] j += 1 max_no = max(max_no, int(check_no)) print(max_no)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
s = input() start = -1 end = -1 a = [] l = len(s) for i in s: a.append(i) chars = 0 nums = 0 for i in a: if i >= "A" and i <= "Z": chars += 1 else: nums += 1 if chars <= 1: ans = "" for i in a: if i >= "0" and i <= "9": ans += i else: ans += "9" print(int(ans)) else: temp = [] for i in range(l): if a[i] >= "A" and a[i] <= "Z": a[i] = "9" temp.append(i) ans = 9 st = s[: temp[0]] + "9" + s[temp[0] + 1 : temp[1]] if st != "" and int(st) > ans: ans = int(st) l2 = len(temp) for i in range(1, l2 - 1): x = s[temp[i - 1] + 1 : temp[i]] + "9" + s[temp[i] + 1 : temp[i + 1]] if x != "" and int(x) > ans: ans = int(x) x = s[temp[l2 - 2] + 1 : temp[l2 - 1]] + "9" + s[temp[l2 - 1] + 1 :] if x != "" and int(x) > ans: ans = int(x) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR STRING VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiometer had four needles, out of which the user would direct three of them to lie over symbols on the face of the device to ask a question. The fourth needle then swung into action and pointed to various symbols one after another, thus telling the answer. For this problem, consider the alethiometer consisting of symbols : digits '0'-'9' and letters 'A'-'Z'. Learned scholars were debating the age of the Universe, and they requested Lyra to find out the age from the alethiometer. Having asked the question, the fourth needle started spouting out symbols, which Lyra quickly recorded. In that long string of characters, she knows that some substring corresponds to the age of the Universe. She also knows that the alethiometer could have wrongly pointed out atmost one digit (0-9) as a letter (A-Z). She then wonders what is the maximum possible age of the Universe. Given the set of symbols the alethiometer pointed out, help her find the maximum age of the Universe, which could correspond to a substring of the original string with atmost one letter changed. Note: We consider a substring to be a contiguous part of the string S Also, the alethiometer wrongly reports only a letter. All the digits remain as they are. -----Input----- Each input consists of a single string S which is what Lyra recorded from the fourth needle's pointing. -----Output----- Output one number, the maximum possible answer. -----Constraints----- - 1 ≤ |S| ≤ 1,000 - S will only contain digits 0-9 and uppercase Latin letters. -----Example----- Input1: 06454 Input2: C0D3C43F Output1: 6454 Output2: 3943 -----Explanation----- In the first example, there is no choice as to what the number can be. It has to be 6,454. In the second example, there are a total of 41 possible strings (one for the original, and 10 for changing each letter). You can verify that the maximum number as a substring is got by making the string "C0D3943F".
p = input() if len(p) >= 1 and len(p) <= 1000: i = 0 k = 0 x = 0 m = 0 while i < len(p): if p[i].isdigit(): j = i c = "" k = 0 if i > 0: if p[i - 1].isalpha(): c = c + "9" k = 1 if i > 1 and p[i - 2].isdigit(): c = p[i - 2] + c if p[i - 1].isdigit() and int(p[i - 1] != 0): c = c + p[i - 1] while i < len(p): if p[i].isdigit(): c = c + p[i] if p[i].isalpha(): if k == 1: break k = 1 c = c + "9" i = i + 1 if int(c) > x: x = int(c) i = j else: m = m + 1 i = i + 1 if x == 0 and m == len(p): print(9) else: print(x)
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
def divs(n): res = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) res.append(n // i) if int(n**0.5) ** 2 == n: res.pop() return res def main(): n, m = map(int, input().split()) angles = [set() for i in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 a1 = b - a if a1 < 0: a1 += n angles[a].add(a1) b1 = a - b if b1 < 0: b1 += n angles[b].add(b1) d = divs(n) for di in d: if di == n: continue flag = 1 for i in range(n): if angles[i] != angles[(i + di) % n]: flag = 0 break if flag == 1: print("Yes") return 0 print("No") return 0 main()
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
n, m = map(int, input().split()) arr = [set() for i in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 f = b - a if f < 0: f += n arr[a].add(f) f = a - b if f < 0: f += n arr[b].add(f) lst = [1] for i in range(2, int(n**0.5) + 1): if n % i == 0: lst.append(i) lst.append(n // i) flag = 0 for el in lst: for i in range(n): next = (i + el) % n if arr[i] != arr[next]: flag = 1 break if flag == 0: print("Yes") exit(0) flag = 0 print("No")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
cin = lambda: [*map(int, input().split())] n, m = cin() se = set() x = [tuple(sorted(cin())) for _ in range(m)] for e in x: se.add((e[0] - 1, e[1] - 1)) for i in range(1, n): if n % i != 0: continue ok = True for e in se: if tuple(sorted([(e[0] + i) % n, (e[1] + i) % n])) not in se: ok = False break if ok: print("Yes") exit(0) print("No")
ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
n, m = [int(x) for x in input().split()] segs = set() for i in range(m): segs.add(tuple(sorted(int(x) - 1 for x in input().split()))) for i in range(1, n): if n % i != 0: continue j = 0 for a, b in segs: if tuple(sorted(((a + i) % n, (b + i) % n))) not in segs: break j += 1 if j == m: print("Yes") exit() print("No")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
import sys def No(): print("No") sys.exit() def divi(n): res = [1] for i in range(2, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res N, M = map(int, input().split()) DN = divi(N) dis = [set() for _ in range(N // 2 + 1)] for i in range(M): a, b = map(lambda x: int(x) - 1, sys.stdin.readline().split()) fn, ln = (a - b) % N, (b - a) % N if fn < ln: dis[fn].add(b) elif ln < fn: dis[ln].add(a) else: dis[fn].add(a) dis[fn].add(b) for dn in DN: for D in dis: if not D: continue for d in D: if (d + dn) % N not in D: break else: continue break else: print("Yes") sys.exit() No()
IMPORT FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER 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 BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR IF VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
n, m = map(int, input().split()) a = [] for i in range(m): a.append(list(map(int, input().split()))) if a[i][0] > a[i][1]: a[i][0], a[i][1] = a[i][1], a[i][0] if a[i][1] - a[i][0] > n / 2: a[i][0] += n a[i][0], a[i][1] = a[i][1], a[i][0] if m == 1: if a[0][1] - a[0][i] == n / 2: print("Yes") else: print("No") exit(0) a.sort() for i in range(m): a.append([a[i][0] + n, a[i][1] + n]) b = [] for i in range(2 * m - 1): if a[i][1] - a[i][0] == n / 2: b.append( (a[i][1] - a[i][0], min(a[i + 1][0] - a[i][0], n - a[i + 1][0] + a[i][0])) ) else: b.append((a[i][1] - a[i][0], a[i + 1][0] - a[i][0])) z = [0] * 2 * m l = r = 0 for i in range(1, m): if i <= r: z[i] = min(z[i - l], r - i + 1) while i + z[i] < len(b) and b[i + z[i]] == b[z[i]]: z[i] += 1 if i + z[i] - 1 > r: l = i r = i + z[i] - 1 if z[i] >= m: print("Yes") exit(0) print("No")
ASSIGN 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 IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
nz = [int(x) for x in input().split()] edges = set() divisors = set() for x in range(0, nz[1]): uv = [y for y in input().split()] edges.add(uv[0] + " " + uv[1]) for x in range(1, nz[0]): if nz[0] % x == 0: divisors.add(x) flag = 0 for y in divisors: flag = 0 for x in edges: u = (int(x.split()[0]) + y) % nz[0] v = (int(x.split()[1]) + y) % nz[0] if u == 0: u = nz[0] if v == 0: v = nz[0] if str(u) + " " + str(v) not in edges: if str(v) + " " + str(u) not in edges: flag = 1 break if flag == 0: print("Yes") break if flag == 1: print("No")
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
def getPrimeDivisors(n): primes = [True] * (n + 1) primes[0] = False primes[1] = False for i in range(2, n + 1): if primes[i]: tmp = i * 2 while tmp <= n: primes[tmp] = False tmp += i divs = [] for k, v in enumerate(primes): if v and n % k == 0: divs.append(k) return divs def valid(div, n, s): inc = n // div for a, b in s: a2, b2 = a + inc, b + inc if a2 > n: a2 -= n if b2 > n: b2 -= n if (a2, b2) in s or (b2, a2) in s: continue return False return True def sol(n, s): divs = getPrimeDivisors(n) for div in divs: if valid(div, n, s): return "Yes" return "No" [n, m] = [int(x) for x in input().split()] s = set() for _ in range(m): s.add(tuple([int(x) for x in input().split()])) print(sol(n, s))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN STRING RETURN STRING ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1. There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points. Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one. Input The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively. The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i. It is guaranteed that no segments coincide. Output Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks). You can output each letter in any case (upper or lower). Examples Input 12 6 1 3 3 7 5 7 7 11 9 11 11 3 Output Yes Input 9 6 4 5 5 6 7 8 8 9 1 2 2 3 Output Yes Input 10 3 1 2 3 2 7 2 Output No Input 10 2 1 6 2 7 Output Yes Note The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center. <image>
n, m = map(int, input().split()) a = set() for i in range(m): c, d = map(int, input().split()) c %= n d %= n a.add((min(c, d), max(c, d))) def comprobar(x): global a, n b = set() for c, d in a: c += x d += x c %= n d %= n if (min(c, d), max(c, d)) not in a: return False return True for i in range(1, n): if n % i == 0: if comprobar(i): print("Yes") exit() print("No")
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
lines = [] for i in range(4): lines.append(list(map(int, input().split(" ")))) first_dots = [i[:2] for i in lines] second_dots = [i[2:4] for i in lines] dots = first_dots + second_dots def loop8(i): if i < 4: return i + 4 else: return i - 4 is_line = [(first_dots[dot] != second_dots[dot]) for dot in range(4)] if sum(is_line) < 4: print("NO") else: dots_have_a_twin = [] all_twins_on_the_same_line = [] for dot in range(8): has_a_twin = [] twin_on_the_same_line = [] for i in range(8): has_a_twin.append(dots[dot] == dots[i]) if dots[dot] == dots[i]: twin_on_the_same_line.append(dots[loop8(dot)] == dots[loop8(i)]) dots_have_a_twin.append(sum(has_a_twin)) all_twins_on_the_same_line.append(sum(twin_on_the_same_line)) if dots_have_a_twin != [(2) for i in range(8)]: print("NO") elif all_twins_on_the_same_line != [(1) for i in range(8)]: print("NO") elif ( sum( [ ( (first_dots[dot][0] == second_dots[dot][0]) | (first_dots[dot][1] == second_dots[dot][1]) ) for dot in range(4) ] ) < 4 ): print("NO") else: all_vertical = [(dots[i][0] == dots[i + 1][0]) for i in range(7)] all_horizontal = [(dots[i][1] == dots[i + 1][1]) for i in range(7)] if (sum(all_vertical) == 7) | (sum(all_horizontal) == 7): print("NO") else: print("YES")
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 STRING ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
points = {} x = set() y = set() segms = set() for i in range(4): x1, y1, x2, y2 = map(int, input().split()) x.add(x1) x.add(x2) y.add(y1) y.add(y2) a = x1, y1 b = x2, y2 segms.add((min(a, b), max(a, b))) if len(set([y1, y2])) + len(set([x1, x2])) != 3: print("NO") break if a not in points: points[a] = 0 points[a] += 1 if b not in points: points[b] = 0 points[b] += 1 else: for a in points: if points[a] != 2: print("NO") break else: if len(x) == 2 and len(y) == 2 and len(segms) == 4: print("YES") else: print("NO")
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
accepted = True lines = [] dic = {} for i in range(4): line = list(map(int, input().split(" "))) if line[0] == line[2] and line[1] == line[3]: accepted = False lines.append(((line[0], line[1]), (line[2], line[3]))) if not (line[0] == line[2] or line[1] == line[3]): accepted = False if lines[-1][0] not in dic.keys(): dic[lines[-1][0]] = [(i, 0)] else: dic[lines[-1][0]].append((i, 0)) if lines[-1][1] not in dic.keys(): dic[lines[-1][1]] = [(i, 1)] else: dic[lines[-1][1]].append((i, 1)) zero, one = set(), set() for key in dic.keys(): if len(set(dic[key])) != 2: accepted = False zero.add(key[0]) one.add(key[1]) j = 0 for entry1 in lines[j:]: for entry2 in lines[j + 1 :]: if entry1[0] == entry2[1] and entry1[1] == entry2[0]: accepted = False if entry1 == entry2: accepted = False j += 1 if len(zero) == 1 or len(one) == 1: accepted = False print("YES") if accepted else print("NO")
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER LIST VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER LIST VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def is_rect(): def seg(): [x0, y0, x1, y1] = input().split(" ") return int(x0), int(y0), int(x1), int(y1) def parallel(x0, x1, y0, y1, x2, x3, y2, y3): return ( y0 == y1 and y2 == y3 and y0 != y2 and (x2 == x0 and x3 == x1 or x3 == x0 and x2 == x1) ) def shared(sx0, sy0, x1, y1, x2, y2): return sx0, y1, x2, y1, x2, sy0, x2, y1 x0, y0, x1, y1 = seg() x2, y2, x3, y3 = seg() x4, y4, x5, y5 = seg() x6, y6, x7, y7 = seg() def find_corner(x0, y0, x1, y1, x2, y2, x3, y3): if x0 == x2 and y0 == y2: return x0, y0 elif x0 == x3 and y0 == y3: return x0, y0 elif x1 == x2 and y1 == y2: return x1, y1 elif x1 == x3 and y1 == y3: return x1, y1 else: return None, None def flip_seg(cx, cy, x0, y0, x1, y1): if cx == x0 and cy == y0: return x0, y0, x1, y1 elif cx == x1 and cy == y1: return x1, y1, x0, y0 cx0, cy0 = find_corner(x0, y0, x1, y1, x2, y2, x3, y3) if cx0 == None: cx0, cy0 = find_corner(x0, y0, x1, y1, x4, y4, x5, y5) if cx0 == None: cx0, cy0 = find_corner(x0, y0, x1, y1, x6, y6, x7, y7) if cx0 == None: return False else: x2, y2, x3, y3, x6, y6, x7, y7 = x6, y6, x7, y7, x2, y2, x3, y3 else: x2, y2, x3, y3, x4, y4, x5, y5 = x4, y4, x5, y5, x2, y2, x3, y3 cx1, cy1 = find_corner(x4, y4, x5, y5, x6, y6, x7, y7) if cx1 == None: return False if cx0 == cx1 or cy0 == cy1: return False x0, y0, x1, y1 = flip_seg(cx0, cy0, x0, y0, x1, y1) x2, y2, x3, y3 = flip_seg(cx0, cy0, x2, y2, x3, y3) x4, y4, x5, y5 = flip_seg(cx1, cy1, x4, y4, x5, y5) x6, y6, x7, y7 = flip_seg(cx1, cy1, x6, y6, x7, y7) if x1 == x0: pass elif y1 == y0: x0, y0, x1, y1, x2, y2, x3, y3 = x2, y2, x3, y3, x0, y0, x1, y1 else: return False if x0 != x1 or y2 != y3: return False if x5 == x4: pass elif y5 == y4: x4, y4, x5, y5, x6, y6, x7, y7 = x6, y6, x7, y7, x4, y4, x5, y5 else: return False if x4 != x5 or y6 != y7: return False if y1 == cy1 and x3 == cx1 and y5 == cy0 and x7 == cx0: return True else: return False if is_rect(): print("YES") else: print("NO")
FUNC_DEF FUNC_DEF ASSIGN LIST VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR RETURN NONE NONE FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NONE RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def read_points(): hSegs = [] vSegs = [] for i in range(4): rawline = input().split() line = { "p1": [int(rawline[0]), int(rawline[1])], "p2": [int(rawline[2]), int(rawline[3])], } if line["p1"][0] == line["p2"][0]: if line["p1"][1] > line["p2"][1]: line["p2"][1], line["p1"][1] = line["p1"][1], line["p2"][1] vSegs.append(line) elif line["p1"][1] == line["p2"][1]: if line["p1"][0] > line["p2"][0]: line["p2"][0], line["p1"][0] = line["p1"][0], line["p2"][0] hSegs.append(line) else: return False if line["p1"][1] == line["p2"][1] and line["p1"][0] == line["p2"][0]: return False if len(hSegs) != 2 or len(vSegs) != 2: return False hSegs.sort(key=lambda a: a["p1"][1]) vSegs.sort(key=lambda a: a["p1"][0]) if hSegs[0]["p1"][1] == hSegs[1]["p1"][1] or vSegs[0]["p1"][0] == vSegs[1]["p1"][0]: return False for h in hSegs: if h["p1"][0] != vSegs[0]["p1"][0]: return False if h["p2"][0] != vSegs[1]["p1"][0]: return False for v in vSegs: if v["p1"][1] != hSegs[0]["p1"][1]: return False if v["p2"][1] != hSegs[1]["p1"][1]: return False return True print("YES" if read_points() else "NO")
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR STRING NUMBER VAR STRING NUMBER IF VAR STRING NUMBER VAR STRING NUMBER ASSIGN VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING NUMBER VAR STRING NUMBER IF VAR STRING NUMBER VAR STRING NUMBER ASSIGN VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER IF VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR VAR STRING NUMBER IF VAR NUMBER STRING NUMBER VAR NUMBER STRING NUMBER VAR NUMBER STRING NUMBER VAR NUMBER STRING NUMBER RETURN NUMBER FOR VAR VAR IF VAR STRING NUMBER VAR NUMBER STRING NUMBER RETURN NUMBER IF VAR STRING NUMBER VAR NUMBER STRING NUMBER RETURN NUMBER FOR VAR VAR IF VAR STRING NUMBER VAR NUMBER STRING NUMBER RETURN NUMBER IF VAR STRING NUMBER VAR NUMBER STRING NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def main(): segments = [list(map(int, input().split())) for _ in range(4)] start = segments[0][0], segments[0][1] point = segments[0][2], segments[0][3] points = set() points.add(start) points.add(point) coords = [set(), set()] coords[0].add(point[0]) coords[0].add(start[0]) coords[1].add(point[1]) coords[1].add(start[1]) if start[0] != point[0] and start[1] != point[1]: return False del segments[0] while segments: for i in range(len(segments)): seg = segments[i] if (seg[0], seg[1]) == point: nextpoint = seg[2], seg[3] elif (seg[2], seg[3]) == point: nextpoint = seg[0], seg[1] else: continue points.add(nextpoint) coords[0].add(nextpoint[0]) coords[1].add(nextpoint[1]) if point[0] != nextpoint[0] and point[1] != nextpoint[1]: return False point = nextpoint del segments[i] break else: return False return ( point == start and len(points) == 4 and len(coords[0]) == 2 and len(coords[1]) == 2 ) if main(): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR RETURN NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
a = [tuple(map(int, input().split())) for i in range(4)] a = [ ((x1, y1, x2, y2) if (x1, y1) < (x2, y2) else (x2, y2, x1, y1)) for x1, y1, x2, y2 in a ] x0, x1, y0, y1 = ( min(a[0][0], a[0][2], a[1][0], a[1][2], a[2][0], a[2][2], a[3][0], a[3][2]), max(a[0][0], a[0][2], a[1][0], a[1][2], a[2][0], a[2][2], a[3][0], a[3][2]), min(a[0][1], a[0][3], a[1][1], a[1][3], a[2][1], a[2][3], a[3][1], a[3][3]), max(a[0][1], a[0][3], a[1][1], a[1][3], a[2][1], a[2][3], a[3][1], a[3][3]), ) print( "YES" if (x1 - x0) * (y1 - y0) > 0 and (x0, y0, x1, y0) in a and (x0, y1, x1, y1) in a and (x0, y0, x0, y1) in a and (x1, y0, x1, y1) in a else "NO" )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR 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 BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR STRING STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
s = {(0): 0, (1): 0} for i in range(4): a, b, c, d = input().split() if a == c and b != d: s[0] += 1 if b == d and a != c: s[1] += 1 for q in [(a, b), (c, d)]: s[q] = s.get(q, 0) + 1 print("YES" if all(i == 2 for i in s.values()) else "NO")
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR LIST VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR STRING STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def main(): dict = {(0): 0, (1): 0} final = "YES" for i in range(4): x1, y1, x2, y2 = input().split() if x1 == x2 and y1 != y2: dict[0] += 1 elif y1 == y2 and x1 != x2: dict[1] += 1 for j in [(x1, y1), (x2, y2)]: dict[j] = dict.get(j, 0) + 1 for i in dict.values(): if i != 2: final = "NO" print(final) main()
FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR LIST VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def main(): coo = [] coords = [[], [], [], []] dia = 0 for i in range(4): x1, y1, x2, y2 = map(int, input().split()) coo.append([x1, y1]) coo.append([x2, y2]) coords[i].append(min([x1, y1], [x2, y2])) coords[i].append(max([x1, y1], [x2, y2])) if x1 != x2 and y1 != y2: dia += 1 if x1 == x2 and y1 == y2: dia += 1 counts = [] for i in coo: counts.append(coo.count(i)) rep = [] for i in range(4): rep.append(coords.count(coords[i])) med = [] for i in range(4): hyp = ( (coo[i * 2][0] - coo[i * 2 + 1][0]) ** 2 + (coo[i * 2][1] - coo[i * 2 + 1][1]) ** 2 ) ** 0.5 med.append(hyp) if ( sum(counts) == 16 and counts.count(counts[0]) == 8 and dia == 0 and sum(rep) == 4 ): if med.count(med[0]) == 4: print("YES") elif ( med.count(med[0]) == 2 and med.count(med[1]) == 2 and med.count(med[2]) == 2 ): print("YES") else: print("NO") else: print("NO") main()
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST LIST LIST LIST LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR LIST VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR LIST VAR VAR LIST VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
Lines = 4 * [None] for i in range(4): Lines[i] = list(map(int, input().split())) if Lines[i][0] == Lines[i][2]: Lines[i][1], Lines[i][3] = min(Lines[i][1], Lines[i][3]), max( Lines[i][1], Lines[i][3] ) elif Lines[i][1] == Lines[i][3]: Lines[i][0], Lines[i][2] = min(Lines[i][0], Lines[i][2]), max( Lines[i][0], Lines[i][2] ) else: print("NO") exit(0) Lines.sort() for i in range(4): if Lines[i][:2] == Lines[i][2:]: print("NO") exit(0) if ( Lines[0][:2] == Lines[1][:2] and Lines[0][2:] == Lines[2][:2] and Lines[1][2:] == Lines[3][:2] and Lines[2][2:] == Lines[3][2:] ): for i in range(3): if Lines[i] == Lines[i + 1]: print("NO") exit(0) print("YES") else: print("NO")
ASSIGN VAR BIN_OP NUMBER LIST NONE FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
liste = [] i = 0 i2 = 0 distance = [] answer = "YES" for _ in range(4): x1, y1, x2, y2 = map(int, input().split(" ")) liste.append([(x1, y1), (x2, y2)]) def perpendiculaire(vect1, vect2): return vect1[0] * vect2[0] + vect1[1] * vect2[1] def search(liste, point, excluded_index): for i in range(4): if point in liste[i] and i != excluded_index: return i, liste[i].index(point) return -1, -1 index, i = 0, 0 for _ in range(4): element = liste[index] (x1, y1), (x2, y2) = element[i], element[1 - i] vector1 = x2 - x1, y2 - y1 distance.append(abs(x2 - x1) + abs(y2 - y1)) index, i = search(liste, (x2, y2), index) if index == -1: answer = "NO" break element = liste[index] (x1, y1), (x2, y2) = element[i], element[1 - i] vector2 = x2 - x1, y2 - y1 if ( perpendiculaire(vector1, vector2) != 0 or 0 not in vector1 or 0 not in vector2 or vector1 == (0, 0) or vector2 == (0, 0) ): answer = "NO" break if answer == "YES": if distance[0] != distance[2] or distance[1] != distance[3]: answer = "NO" print(answer)
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR RETURN NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def is_rect(es): v = set([]) for e in es: if not (e[0] == e[2] or e[1] == e[3]): return False v.add((e[0], e[1])) v.add((e[2], e[3])) if len(v) != 4: return False xs = set([]) ys = set([]) for vi in v: xs.add(vi[0]) ys.add(vi[1]) if len(xs) != 2 or len(ys) != 2: return False t = b = r = l = False for e in es: t = t or e[1] == e[3] and e[0] != e[2] and e[1] == max(ys) b = b or e[1] == e[3] and e[0] != e[2] and e[1] == min(ys) r = r or e[0] == e[2] and e[1] != e[3] and e[0] == max(xs) l = l or e[0] == e[2] and e[1] != e[3] and e[0] == min(xs) return t and b and l and r e1 = list(map(int, input().split(" "))) e2 = list(map(int, input().split(" "))) e3 = list(map(int, input().split(" "))) e4 = list(map(int, input().split(" "))) if is_rect((e1, e2, e3, e4)): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def segmentos_iguales(l1, l2): return l1[:2] == l2[2:4] and l1[2:4] == l2[:2] or l1 == l2 def paralela(linea): return linea[0] == linea[2] or linea[1] == linea[3] def degenerada(linea): return linea[0] == linea[2] and linea[1] == linea[3] lineas = [] for _ in range(4): lineas.append(input().split()) x, y = set(), set() for i in range(4): x.add(lineas[i][0]) y.add(lineas[i][1]) x.add(lineas[i][2]) y.add(lineas[i][3]) if len(x) != 2 or len(y) != 2: print("NO") else: for i in range(4): if not paralela(lineas[i]) or degenerada(lineas[i]): print("NO") break else: flag = False for i in range(3): for j in range(i + 1, 4): if segmentos_iguales(lineas[i], lineas[j]): print("NO") flag = True break if flag: break else: print("YES")
FUNC_DEF RETURN VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR VAR FUNC_DEF RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_DEF RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def main(): line_1 = input().strip().split() line_1 = list(map(int, line_1)) line_2 = input().strip().split() line_2 = list(map(int, line_2)) line_3 = input().strip().split() line_3 = list(map(int, line_3)) line_4 = input().strip().split() line_4 = list(map(int, line_4)) x_line_count = 0 y_line_count = 0 points = set() if ( line_1 == line_2 or line_1 == line_3 or line_1 == line_4 or line_2 == line_3 or line_2 == line_4 or line_3 == line_4 ): return "NO" for line in (line_1, line_2, line_3, line_4): if line[0] == line[2] and line[1] != line[3]: x_line_count += 1 elif line[1] == line[3] and line[0] != line[2]: y_line_count += 1 points.add((line[0], line[1])) points.add((line[2], line[3])) if x_line_count != 2 or y_line_count != 2: return "NO" if len(points) != 4: return "NO" return "YES" print(main())
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN STRING FOR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def checkXY(line): if line[0] == line[2] and line[1] != line[3]: return "X" elif line[1] == line[3] and line[0] != line[2]: return "Y" lines = [list(map(int, input().split())) for _ in range(4)] output = "YES" for line in lines: if checkXY(line) is None: output = "NO" for i in range(3): if checkXY(lines[i]) == "X": for j in range(i + 1, 4): if checkXY(lines[j]) == "Y": if lines[j][0] == lines[i][2] and lines[j][1] == lines[i][3]: lines[i + 1], lines[j] = lines[j], lines[i + 1] break elif lines[j][2] == lines[i][2] and lines[j][3] == lines[i][3]: lines[j][0], lines[j][1], lines[j][2], lines[j][3] = ( lines[j][2], lines[j][3], lines[j][0], lines[j][1], ) lines[i + 1], lines[j] = lines[j], lines[i + 1] break else: output = "NO" break elif checkXY(lines[i]) == "Y": for j in range(i + 1, 4): if checkXY(lines[j]) == "X": if lines[j][0] == lines[i][2] and lines[j][1] == lines[i][3]: lines[i + 1], lines[j] = lines[j], lines[i + 1] break elif lines[j][2] == lines[i][2] and lines[j][3] == lines[i][3]: lines[j][0], lines[j][1], lines[j][2], lines[j][3] = ( lines[j][2], lines[j][3], lines[j][0], lines[j][1], ) lines[i + 1], lines[j] = lines[j], lines[i + 1] break else: output = "NO" break if lines[3][2] != lines[0][0] or lines[3][3] != lines[0][1]: output = "NO" print(output)
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR STRING IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR STRING IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
pontos = set() retas = set() fail = False for i in range(0, 4): s = list(map(int, input().split())) if s[0] != s[2] and s[1] != s[3]: fail = True p1 = s[0], s[1] p2 = s[2], s[3] if p1 == p2: fail = True menor = min(p1, p2) maior = max(p1, p2) retas.add((menor[0], menor[1], maior[0], maior[1])) pontos.add(p1) pontos.add(p2) if len(pontos) != 4 or len(retas) != 4: fail = True ordenados = sorted(list(pontos)) if not fail: area = abs(ordenados[2][0] - ordenados[0][0]) * abs( ordenados[1][1] - ordenados[0][1] ) if ( not fail and ordenados[0][0] == ordenados[1][0] and ordenados[0][1] == ordenados[2][1] and ordenados[1][1] == ordenados[3][1] and ordenados[2][0] == ordenados[3][0] and area > 0 ): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR 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 EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
from sys import stdin class my_vector: def __init__(self, x1, y1, x2, y2): self.i_coord = x1, y1 self.end_coord = x2, y2 self.my_vector = y2 - y1, x2 - x1 def __mul__(self, other): return ( self.my_vector[0] * other.my_vector[0] + self.my_vector[1] * other.my_vector[1] ) def problem(lines): v_dict = {} number = 0 for row in lines: number += 1 x1, y1, x2, y2 = row.strip().split() v_dict[number] = my_vector(int(x1), int(y1), int(x2), int(y2)) A = 1 B = [] C = [] D = [] possible_candidates = {2, 3, 4} for i in range(2, 5): if v_dict[A].i_coord == v_dict[i].i_coord: if v_dict[A].end_coord == v_dict[i].end_coord: return False possible_candidates.remove(i) B.append(i) elif v_dict[A].i_coord == v_dict[i].end_coord: if v_dict[A].end_coord == v_dict[i].i_coord: return False possible_candidates.remove(i) B.append(i) elif v_dict[A].end_coord == v_dict[i].end_coord: if v_dict[A].i_coord == v_dict[i].i_coord: return False possible_candidates.remove(i) C.append(i) elif v_dict[A].end_coord == v_dict[i].i_coord: if v_dict[A].i_coord == v_dict[i].end_coord: return False possible_candidates.remove(i) C.append(i) if len(B) == 1 and len(C) == 1: B = B.pop() C = C.pop() D = possible_candidates.pop() if ( v_dict[D].i_coord == v_dict[B].i_coord or v_dict[D].i_coord == v_dict[B].end_coord ): if ( v_dict[D].end_coord != v_dict[C].i_coord and v_dict[D].end_coord != v_dict[C].end_coord ): return False elif ( v_dict[D].end_coord == v_dict[B].i_coord or v_dict[D].end_coord == v_dict[B].end_coord ): if ( v_dict[D].i_coord != v_dict[C].i_coord and v_dict[D].i_coord != v_dict[C].end_coord ): return False else: return False else: return False x_coord = my_vector(0, 0, 0, 1) y_coord = my_vector(0, 0, 1, 0) x_p = 0 y_p = 0 for i in range(1, 5): if x_coord * v_dict[i] == 0: x_p += 1 elif y_coord * v_dict[i] == 0: y_p += 1 else: return False coords = set() for _, v in v_dict.items(): coords.add(v.i_coord) coords.add(v.end_coord) if len(coords) == 4 and x_p == 2 and y_p == 2: return True else: return False return True def main(): if problem(stdin.readlines()): print("YES") else: print("NO") main()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
H, V = 0, 0 p = set() s = set() for _ in range(4): x, y, x_, y_ = list(map(int, input().split())) if x == x_: V += 1 if y == y_: H += 1 p.add((x, y)) p.add((x_, y_)) s.add(((x, y), (x_, y_))) s.add(((x_, y_), (x, y))) if len(s) != 8 or len(p) != 4 or H != 2 or V != 2: print("NO") else: print("YES")
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
__author__ = "Darren" def solve(): points = set() horizontal, vertical = 0, 0 horizontal_lines, vertical_lines = [], [] for _i in range(4): x1, y1, x2, y2 = map(int, input().split()) if x1 != x2 and y1 != y2 or x1 == x2 and y1 == y2: print("NO") return elif x1 != x2 and y1 == y2: horizontal += 1 if x1 < x2: horizontal_lines.append((x1, y1, x2, y2)) else: horizontal_lines.append((x2, y2, x1, y1)) else: vertical += 1 if y1 < y2: vertical_lines.append((x1, y1, x2, y2)) else: vertical_lines.append((x2, y2, x1, y1)) points.add((x1, y1)) points.add((x2, y2)) if ( len(points) == 4 and horizontal == 2 and vertical == 2 and horizontal_lines[0] != horizontal_lines[1] and vertical_lines[0] != vertical_lines[1] ): print("YES") else: print("NO") solve()
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST 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 VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
respuesta = True puntos = [] todos = [] Xcords = [] Ycords = [] verticales = 0 horizontales = 0 for k in range(0, 4): linea = input().split(" ") if linea[0] == linea[2] and linea[1] == linea[3]: respuesta = False elif linea[0] != linea[2] and linea[1] != linea[3]: respuesta = False elif linea[0] == linea[2] and linea[1] != linea[3]: verticales = verticales + 1 elif linea[0] != linea[2] and linea[1] == linea[3]: horizontales = horizontales + 1 punto1 = [linea[0], linea[1]] punto2 = [linea[2], linea[3]] todos.append(punto1) todos.append(punto2) if (punto1 in puntos) == False: puntos.append(punto1) if (punto2 in puntos) == False: puntos.append(punto2) x1 = linea[0] x2 = linea[2] y1 = linea[1] y2 = linea[3] if (x1 in Xcords) == False: Xcords.append(x1) if (x2 in Xcords) == False: Xcords.append(x2) if (y1 in Ycords) == False: Ycords.append(y1) if (y2 in Ycords) == False: Ycords.append(y2) for xd in puntos: contador = 0 for xdd in todos: if xd == xdd: contador = contador + 1 if contador != 2: respuesta = False if horizontales != 2 or verticales != 2: respuesta = False if len(Xcords) != 2 or len(Ycords) != 2: respuesta = False if len(puntos) != 4: respuesta = False if respuesta == True: print("YES") elif respuesta == False: print("NO")
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
hor = [] ver = [] points = [] for i in range(4): data = input() lst = [int(i) for i in data.split()] x1, y1, x2, y2 = lst points.extend([[x1, y1], [x2, y2]]) if x1 == x2: if y1 != y2: ver.append(y1) elif y1 == y2: if x1 != x2: hor.append(x1) else: break check = True if not len(ver) == len(hor) == 2: check = False def checkpoints(points): for point in points: if points.count(point) != 2: return False return True if check: if checkpoints(points): print("YES") else: check = False if not check: print("NO")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST LIST VAR VAR LIST VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
puntos = {(0): 0, (1): 0} for i in range(4): linea = list(map(int, input().split())) p1 = linea[0], linea[1] p2 = linea[2], linea[3] if p1[0] == p2[0] and p1[1] != p2[1]: puntos[0] += 1 elif p1[0] != p2[0] and p1[1] == p2[1]: puntos[1] += 1 for punto in [p1, p2]: puntos[punto] = puntos.get(punto, 0) + 1 if all(i == 2 for i in puntos.values()): print("YES") else: print("NO")
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR LIST VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def check(): coordenadas = set() ejes_equis = set() ejes_ygriega = set() combis_lineas = [] for n in range(4): actual = input().split(" ") coords = [actual[0] + "-" + actual[1], actual[2] + "-" + actual[3]] exes = [actual[0], actual[2]] yes = [actual[1], actual[3]] if coords[0] + coords[1] in combis_lineas: return "NO" combis_lineas.extend([coords[0] + coords[1], coords[1] + coords[0]]) if actual[0] != actual[2] and actual[1] != actual[3]: return "NO" elif coords[0] == coords[1]: return "NO" else: coordenadas.update(coords) ejes_equis.update(exes) ejes_ygriega.update(yes) if len(coordenadas) == 4 and len(ejes_equis) == 2 and len(ejes_ygriega) == 2: return "YES" else: return "NO" delve = check() print(delve)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR RETURN STRING EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
segments = [] for i in range(4): segments.append(tuple(map(int, input().split()))) for i in range(len(segments)): x1, y1, x2, y2 = segments[i] if x2 < x1: segments[i] = x2, y2, x1, y1 if y2 < y1: segments[i] = x2, y2, x1, y1 if len(set(segments)) != 4: print("NO") exit() for i in range(4): x1, y1, x2, y2 = segments[i] if x1 == x2 and y1 == y2: print("NO") exit() if x1 != x2 and y1 != y2: print("NO") exit() pointset = set([]) for x1, y1, x2, y2 in segments: pointset.add((x1, y1)) pointset.add((x2, y2)) if len(pointset) == 4: pointlist = list(pointset) xlist = [p[0] for p in pointset] ylist = [p[1] for p in pointset] if len(set(xlist)) != 2 or len(set(ylist)) != 2: print("NO") exit() print("YES") else: print("NO")
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER 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 EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
def distance(a, b, c, d): return (d - b) ** 2 + (c - a) ** 2 def slope(a, b, c, d): if a == c: return float("inf") else: return (d - b) / (c - a) def CF14C(): infinity = 0 zero = 0 counter = {} points = set() for i in range(4): a, b, c, d = list(map(int, input().split())) points.add((a, b)) points.add((c, d)) s = slope(a, b, c, d) if s == float("inf"): infinity += 1 elif s == 0: zero += 1 side = distance(a, b, c, d) if side == 0: return False counter[side] = counter.get(side, 0) + 1 if len(points) != 4: return False if zero != 2 and infinity != 2: return False if len(counter) > 2: return False points = sorted(list(points), key=lambda x: (x[0], x[1])) a, b = points[0] c, d = points[1] e, f = points[2] g, h = points[3] sides = list(counter.keys()) d1 = distance(a, b, c, d) d2 = distance(b, c, d, e) d3 = distance(a, b, e, f) if len(sides) > 1: if sides[0] + sides[1] != max(d1, d2, d3): return False elif sides[0] * 2 != max(d1, d2, d3): return False return True res = CF14C() print("YES" if res else "NO")
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR STRING RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
Vertical = [] Horizontal = [] check = True for i in range(0, 4): T = [int(x) for x in input().split()] if T[0] == T[2] and T[1] == T[3]: check = False elif T[0] == T[2]: Vertical.append(T) elif T[1] == T[3]: Horizontal.append(T) else: check = False if len(Vertical) == 2: if len(Horizontal) == 2: VC1 = Vertical[0][1] == Vertical[1][1] or Vertical[0][1] == Vertical[1][3] VC2 = Vertical[0][3] == Vertical[1][1] or Vertical[0][3] == Vertical[1][3] HC1 = ( Horizontal[0][0] == Horizontal[1][0] or Horizontal[0][0] == Horizontal[1][2] ) HC2 = ( Horizontal[0][2] == Horizontal[1][0] or Horizontal[0][2] == Horizontal[1][2] ) VV = set() HV = set() for i in Vertical: VV.add((i[0], i[1])) VV.add((i[2], i[3])) for i in Horizontal: for j in i: HV.add((i[0], i[1])) HV.add((i[2], i[3])) FinalCheck = VV == HV else: VC1 = 0 VC2 = 0 HC1 = 0 HC2 = 0 FinalCheck = 0 else: VC1 = 0 VC2 = 0 HC1 = 0 HC2 = 0 FinalCheck = 0 if check * FinalCheck * VC1 * VC2 * HC1 * HC2: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
a = [] for i in range(4): b = list(map(int, input().split())) a.append([b[:2], b[2:]]) c = [] a0 = [[[k for k in j] for j in i] for i in a] for i in range(4): z = 0 for k in range(2): if a[i][k] != -1: for j in range(4): if ( i != j and a[i][k] in a[j] and a0[i] != a0[j] and a0[i] != a0[j][::-1] ): if a[j][0] == a[i][k]: a[j][0] = -1 else: a[j][1] = -1 c.append(a[i][k]) break else: print("NO") z = 1 break if z: break else: if ( c[0][0] == c[1][0] and c[2][0] == c[3][0] and c[2][0] != c[0][0] and c[0][1] != c[1][1] and sorted([c[0][1], c[1][1]]) == sorted([c[2][1], c[3][1]]) ): print("YES") elif ( c[0][0] == c[2][0] and c[1][0] == c[3][0] and c[3][0] != c[0][0] and c[0][1] != c[2][1] and sorted([c[0][1], c[2][1]]) == sorted([c[1][1], c[3][1]]) ): print("YES") elif ( c[0][0] == c[3][0] and c[2][0] == c[1][0] and c[1][0] != c[0][0] and c[0][1] != c[3][1] and sorted([c[0][1], c[3][1]]) == sorted([c[2][1], c[1][1]]) ): print("YES") else: print("NO")
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 LIST VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF 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 FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
x, y = 0, 0 mp = {} for i in range(4): x1, y1, x2, y2 = map(int, input().split()) if x1 == x2 and y1 != y2: x += 1 if y1 == y2 and x1 != x2: y += 1 if (x1, y1) not in mp: mp[x1, y1] = 1 else: mp[x1, y1] += 1 if (x2, y2) not in mp: mp[x2, y2] = 1 else: mp[x2, y2] += 1 flag = False if x == 2 and y == 2: flag = True for key, wd in mp.items(): if wd != 2: flag = False print("YES") if flag else print("NO")
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT 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 NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
a = {} ox, oy = 0, 0 for i in range(4): x1, y1, x2, y2 = map(int, input().split()) a[x1, y1] = a.get((x1, y1), 0) + 1 a[x2, y2] = a.get((x2, y2), 0) + 1 if x1 == x2 and y1 != y2: ox += 1 if y1 == y2 and x1 != x2: oy += 1 ans = "YES" for p in a.values(): if p != 2: ans = "NO" break if ox != 2 or oy != 2: ans = "NO" print(ans)
ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him. Input The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. Output Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». Examples Input 1 1 6 1 1 0 6 0 6 0 6 1 1 1 1 0 Output YES Input 0 0 0 3 2 0 0 0 2 2 2 0 0 2 2 2 Output NO
arr = [] arr1 = [] arr2 = [] for i in range(0, 4): x1, y1, x2, y2 = map(int, input().split()) p1 = x1, y1 p2 = x2, y2 p3 = x1, y1, x2, y2 arr2.append(p3) arr.append(p1) arr.append(p2) arr1 = list(set(arr)) if len(arr1) > 4 or len(arr1) < 4: print("NO") exit() minx = 10000000000 maxx = -10000000000 miny = 10000000000 maxy = -10000000000 for i in range(0, len(arr1)): if minx > arr1[i][0]: minx = arr1[i][0] if maxx < arr1[i][0]: maxx = arr1[i][0] if miny > arr1[i][1]: miny = arr1[i][1] if maxy < arr1[i][1]: maxy = arr1[i][1] arr3 = [] arr3.append((minx, miny, maxx, miny)) arr3.append((maxx, miny, maxx, maxy)) arr3.append((maxx, maxy, minx, maxy)) arr3.append((minx, maxy, minx, miny)) count = 0 for i in range(0, 4): for j in range(0, 4): if ( arr3[i][0] == arr2[j][0] and arr3[i][1] == arr2[j][1] and arr3[i][2] == arr2[j][2] and arr3[i][3] == arr2[j][3] ): count += 1 break elif ( arr3[i][2] == arr2[j][0] and arr3[i][3] == arr2[j][1] and arr3[i][0] == arr2[j][2] and arr3[i][1] == arr2[j][3] ): count += 1 break if count == 4: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER 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 VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
from itertools import permutations nums = list(map(int, input().split())) o = input().split() print( min( eval("min(((a{0}b){1}c){2}d,(a{0}b){2}(c{1}d))".format(*o)) for a, b, c, d in permutations(nums) ) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR VAR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
n = list(map(int, input().split())) s = input() n.sort() if s == "+ + +": print(sum(n)) elif s == "+ + *": print(n[0] * sum(n[1:4])) elif s == "+ * +" or s == "* + +": print(n[2] + n[3] + n[0] * n[1]) elif s == "* * *": print(n[0] * n[1] * n[2] * n[3]) elif s == "* * +": print(n[0] * n[3] + n[1] * n[2]) elif s == "* + *": print(n[0] * (n[3] + n[1] * n[2])) elif s == "+ * *": print(n[0] * n[1] * (n[2] + n[3]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def f(q, t): a, b, c = sorted(q) if t == "**": return a * b * c if t == "++": return a + b + c if t == "*+": return a * b + c if t == "+*": return a * (b + c) p = sorted(list(map(int, input().split()))) t = input()[::2] x, t = t[0], t[1:] if x == "*": s = p[0] * p[1] * p[2] * p[3] for i in range(3): for j in range(i + 1, 4): q = p[:] q[i] *= q[j] q.pop(j) s = min(f(q, t), s) print(s) else: print(f([p[0], p[1], p[2] + p[3]], t))
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR STRING RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR STRING RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR STRING RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR STRING RETURN BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
from itertools import combinations nl = list(map(int, input().split())) ol = input().split() ans = 10000000000000 for x in combinations(nl, 2): a, b = x tl = nl[:] tl.remove(a) tl.remove(b) if ol[0] == "+": tl.append(a + b) else: tl.append(a * b) for y in combinations(tl, 2): i, j = y sl = tl[:] sl.remove(i) sl.remove(j) if ol[1] == "+": sl.append(i + j) else: sl.append(i * j) if ol[2] == "+": mm = sl[0] + sl[1] else: mm = sl[0] * sl[1] if ans > mm: ans = mm print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def fun(a, op): lst = [] for i in range(0, len(a)): for j in range(i + 1, len(a)): k = a.copy() k.remove(a[i]) k.remove(a[j]) if op == "+": k.append(a[i] + a[j]) else: k.append(a[i] * a[j]) lst.append(k) return lst n = [int(i) for i in input().split()] f, s, t = map(str, input().split()) ans = [] ff = fun(n, f) ss = [fun(i, s) for i in ff] for i in ss: for j in i: ans.append(fun(j, t)[0][0]) print(min(ans))
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
nums = list(map(int, input().split())) ops = input().split() ans = float("inf") def solve(nums, ops, level): global ans if len(nums) == 1: ans = min(ans, nums[0]) return n = len(nums) for i in range(n): for j in range(i + 1, n): l = nums[i] r = nums[j] nums.pop(i) nums.pop(j - 1) if ops[0] == "*": nums.append(l * r) solve(nums, ops[1:], level + 1) nums.pop() else: nums.append(l + r) solve(nums, ops[1:], level + 1) nums.pop() nums.insert(i, l) nums.insert(j, r) solve(nums, ops, 0) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
s = list(map(int, input().split())) d = list(input().split()) min_ = 1000**4 for i in range(4): for j in range(i + 1, 4): if d[0] == "+": test1 = s[i] + s[j] test2 = s[i] + s[j] test3_1 = s[i] + s[j] else: test1 = s[i] * s[j] test2 = s[i] * s[j] test3_1 = s[i] * s[j] f = s.copy() f.pop(i) f.pop(j - 1) if d[1] == "+": test1 += f[0] test2 += f[1] test3 = f[1] + f[0] else: test1 *= f[0] test2 *= f[1] test3 = f[1] * f[0] if d[2] == "+": test1 += f[1] test2 += f[0] test3 += test3_1 else: test1 *= f[1] test2 *= f[0] test3 *= test3_1 new = min(test1, test2, test3) if new < min_: min_ = new print(min_)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
import itertools terms = list(map(int, input().split())) operators = input().split() def seek(terms, operators): best = None if len(terms) == 1: return terms[0] for i, a in enumerate(terms): for j in range(i + 1, len(terms)): b = terms[j] if operators[0] == "+": x = a + b else: x = a * b y = seek(terms[:i] + terms[i + 1 : j] + terms[j + 1 :] + [x], operators[1:]) if best == None or y < best: best = y return best print(seek(terms, operators))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NONE IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER LIST VAR VAR NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
I = input a = I().split() def f(s, z): if not z: return int(s[0]) m = 10**99 for i in s: t = s[:] t.remove(i) for j in t: k = t[:] k.remove(j) m = min(m, f(k + [str(eval(i + z[0] + j))], z[1:])) return m print(f(a, I().split()))
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR LIST FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def z(a, b, k=0, f=1): n = len(a) if n == 2: if b[k] == "+": return a[0] + a[1] return a[0] * a[1] c = -1 for i in range(n): for j in range(i + 1, n): if b[k] == "+": g = list(a) a[i] += a[j] a = a[:j] + a[j + 1 :] d = z(a, b, k + 1, f + 1) if c == -1 or d < c: c = d a = list(g) else: g = list(a) a[i] *= a[j] a = a[:j] + a[j + 1 :] d = z(a, b, k + 1, f + 1) if c == -1 or d < c: c = d a = list(g) return c print(z(list(map(int, input().split())), input().split()))
FUNC_DEF NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING RETURN BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
import sys class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = self.next_line() self.index = 0 val = self.buff[self.index] self.index += 1 return val def next_line(self): return sys.stdin.readline().split() def next_ints(self): return [int(x) for x in sys.stdin.readline().split()] def next_int(self): return int(self.next()) def solve(self): x = self.next_ints() op = self.next_line() print(self.dfs(x, op)) def dfs(self, x, op): if len(x) == 1: return x[0] r = 1000000000000 t = 4 - len(x) for i in range(0, len(x)): for j in range(i + 1, len(x)): xx = [] for k in range(0, len(x)): if k != i and k != j: xx.append(x[k]) if op[t] == "+": xx.append(x[i] + x[j]) else: xx.append(x[i] * x[j]) r = min(r, self.dfs(xx, op)) return r Main().solve()
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR EXPR FUNC_CALL FUNC_CALL VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
a = list(map(int, input().split())) o = list(map(str, input().split())) min_elem = float("inf") def f(a, o): n = len(a) global min_elem if n == 1: min_elem = min(min_elem, a[0]) elif o[0] == "+": if n == 2: f([a[0] + a[1]], []) elif n == 3: f([a[0] + a[1], a[2]], o[1:]) f([a[0], a[1] + a[2]], o[1:]) f([a[0] + a[2], a[1]], o[1:]) else: f([a[0] + a[1], a[2], a[3]], o[1:]) f([a[0] + a[2], a[1], a[3]], o[1:]) f([a[0] + a[3], a[1], a[2]], o[1:]) f([a[1] + a[2], a[0], a[3]], o[1:]) f([a[1] + a[3], a[0], a[2]], o[1:]) f([a[2] + a[3], a[0], a[1]], o[1:]) elif n == 2: f([a[0] * a[1]], []) elif n == 3: f([a[0] * a[1], a[2]], o[1:]) f([a[0], a[1] * a[2]], o[1:]) f([a[0] * a[2], a[1]], o[1:]) else: f([a[0] * a[1], a[2], a[3]], o[1:]) f([a[0] * a[2], a[1], a[3]], o[1:]) f([a[0] * a[3], a[1], a[2]], o[1:]) f([a[1] * a[2], a[0], a[3]], o[1:]) f([a[1] * a[3], a[0], a[2]], o[1:]) f([a[2] * a[3], a[0], a[1]], o[1:]) f(a, o) print(min_elem)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER LIST IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER LIST IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def rec(num, com): if len(num) == 1: return num[0] ret = 10**100 for i in range(len(num)): for j in range(i + 1, len(num)): residual = [] for k in range(len(num)): if k != i and k != j: residual.append(num[k]) if com[0] == "+": residual.append(num[i] + num[j]) else: residual.append(num[i] * num[j]) ret = min(ret, rec(residual, com[1:])) return ret a, b, c, d = map(int, input().split()) commands = input().split() numbers = [a, b, c, d] print(rec(numbers, commands))
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
ans = float("inf") op = { "+": lambda x, y: x + y, "-": lambda x, y: x - y, "/": lambda x, y: x / y, "*": lambda x, y: x * y, } def rec_3(a, b): global ans temp = 0 temp = op[st[2]](a, b) if st[2] == "+" else op["*"](a, b) ans = min(ans, temp) def rec_2(a, b, c): if st[1] == "+": rec_3(a + b, c) rec_3(a + c, b) rec_3(b + c, a) else: rec_3(a * b, c) rec_3(a * c, b) rec_3(b * c, a) def rec_1(a, b, c, d): if st[0] == "+": rec_2(a + b, c, d) rec_2(a + c, b, d) rec_2(a + d, b, c) rec_2(b + c, a, d) rec_2(b + d, a, c) rec_2(c + d, a, b) else: rec_2(a * b, c, d) rec_2(a * c, b, d) rec_2(a * d, b, c) rec_2(b * c, a, d) rec_2(b * d, a, c) rec_2(c * d, a, b) nom = list(map(int, input().split())) st = list(map(str, input().split())) rec_1(nom[0], nom[1], nom[2], nom[3]) print(ans)
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def a(op_num, inp): if op_num == 3: if m[0] < 0 or res[0] < m[0]: m[0] = res[0] return for i in range(len(inp) - 1): for j in range(i + 1, len(inp)): temp = res[0] res[0] = inp[i] * inp[j] if ops[op_num] == "*" else inp[i] + inp[j] temp_inp = [] for k in range(len(inp)): if k != i and k != j: temp_inp.append(inp[k]) temp_inp.append(res[0]) a(op_num + 1, temp_inp) res[0] = temp arr = [int(x) for x in input().split()] ops = [c for c in input().split()] res = [0] m = [-1] a(0, arr) print(m[0])
FUNC_DEF IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def cal(a, b, c): if c[0] == "+": return int(a) + int(b) return int(a) * int(b) num = input().split() op = input().split() def DFS(l, no): if no == 3: return int(l[0]) else: ln = len(l) ans = 10**100 for i in range(ln): for j in range(i + 1, ln): ll = [] for k in range(ln): if i != k and j != k: ll.append(l[k]) ll.append(cal(l[i], l[j], op[no])) ans = min(ans, DFS(ll, no + 1)) return ans print(DFS(num, 0))
FUNC_DEF IF VAR NUMBER STRING RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def f(a, b, c, t): if t == "**": return a * b * c if t == "++": return a + b + c if t == "*+": return a * b + c if t == "+*": return a * (b + c) a, b, c, d = sorted(list(map(int, input().split()))) t = input()[::2] if t == "*+*": print(a * (b * c + d)) elif t == "**+": print(a * d + b * c) elif t[0] == "*": a, b, c = sorted([a * b, c, d]) print(f(a, b, c, t[1:])) else: print(f(a, b, c + d, t[1:]))
FUNC_DEF IF VAR STRING RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR STRING RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR STRING RETURN BIN_OP BIN_OP VAR VAR VAR IF VAR STRING RETURN BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
ar = list(map(int, input().split())) br = input().split() ans = float("inf") def gen(ar, ind): global ans if len(ar) == 1: ans = min(ans, ar[0]) return for i in range(len(ar)): for j in range(i): nw = ar.copy() vl = ar[i] + ar[j] if br[ind] == "+" else ar[i] * ar[j] nw.append(vl) del nw[nw.index(ar[i])] del nw[nw.index(ar[j])] gen(nw, ind + 1) gen(ar, 0) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
from itertools import permutations ch = list(map(int, input().split())) op = list(input().split()) def f(oper, x, y): if oper == "*": return x * y else: return x + y ans = 10**12 for a, b, c, d in permutations(ch): ans = min( ans, min( f(op[2], f(op[1], f(op[0], a, b), c), d), f(op[2], f(op[0], a, b), f(op[1], c, d)), ), ) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR STRING RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def combs(a, op, ans): if 1 == len(a): if a[0] < ans[0]: ans[0] = a[0] return for i in range(len(a)): for j in range(i + 1, len(a)): na = [] for k in range(len(a)): if k != i and k != j: na.append(a[k]) if op[0] == "*": na.append(a[i] * a[j]) else: na.append(a[i] + a[j]) combs(na, op[1:], ans) a = [1000**5] l = list(map(int, input().split())) op = input().split() combs(l, op, a) print(a[0])
FUNC_DEF IF NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def fun(arr, op, o): if o == 3: return arr[-1] mn = float("inf") for i in range(0, 3): if arr[i] == -1: continue var = arr[i] arr[i] = -1 for j in range(i, 4): if arr[j] == -1: continue var2 = arr[j] if op[o] == "*": arr[j] = var * arr[j] if op[o] == "+": arr[j] = var + arr[j] mn = min(mn, fun(arr, op, o + 1)) arr[j] = var2 arr[i] = var return mn arr = list(map(int, input().split())) op = input().split() print(fun(arr, op, 0))
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def cal(n, c): if c == 1: return sum(n) elif c == 2: return n[0] * n[1] * n[2] * n[3] elif c == 3: return n[0] * (n[1] + n[2] + n[3]) elif c == 4: return n[0] * n[1] + n[2] + n[3] elif c == 5: return n[0] * n[1] + n[2] + n[3] elif c == 6: return (n[2] + n[3]) * (n[0] * n[1]) elif c == 7: return (n[1] * n[2] + n[3]) * n[0] elif c == 8: return n[0] * n[3] + n[2] * n[1] ls = sorted(list(map(int, input().split()))) cd = input() dic = { "+ + +": 1, "* * *": 2, "+ + *": 3, "+ * +": 4, "* + +": 5, "+ * *": 6, "* + *": 7, "* * +": 8, } print(cal(ls, dic[cd]))
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
a, b, c, d = list(map(int, input().strip().split(" "))) first, second, third = input().strip().split(" ") min_value = 1000000000000 if first == "+": f_op = [ [a + b, c, d], [a + c, b, d], [a + d, b, c], [b + c, a, d], [b + d, a, c], [c + d, a, b], ] else: f_op = [ [a * b, c, d], [a * c, b, d], [a * d, b, c], [b * c, a, d], [b * d, a, c], [c * d, a, b], ] for i in range(6): x = f_op[i][0] y = f_op[i][1] z = f_op[i][2] if second == "+": s_op = [[x + y, z], [x + z, y], [y + z, x]] else: s_op = [[x * y, z], [x * z, y], [y * z, x]] if third == "+": m = min( [s_op[0][0] + s_op[0][1], s_op[1][0] + s_op[1][1], s_op[2][0] + s_op[2][1]] ) else: m = min( [s_op[0][0] * s_op[0][1], s_op[1][0] * s_op[1][1], s_op[2][0] * s_op[2][1]] ) min_value = min(min_value, m) print(min_value)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR LIST LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR LIST BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR LIST LIST BIN_OP VAR VAR VAR LIST BIN_OP VAR VAR VAR LIST BIN_OP VAR VAR VAR ASSIGN VAR LIST LIST BIN_OP VAR VAR VAR LIST BIN_OP VAR VAR VAR LIST BIN_OP VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def perform(a, b, o): if o == "+": return a + b return a * b def fun(arr, op, ind): if ind == 3: return arr[0] mn = float("inf") for i in range(0, len(arr) - 1): for j in range(i + 1, len(arr)): new_arr = arr.copy() new_arr[j] = perform(arr[j], arr[i], op[ind]) new_arr.pop(i) mn = min(mn, fun(new_arr, op, ind + 1)) return mn arr = list(map(int, input().split())) op = input().split() print(fun(arr, op, 0))
FUNC_DEF IF VAR STRING RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. Input First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) Output Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Examples Input 1 1 1 1 + + * Output 3 Input 2 2 2 2 * * + Output 8 Input 1 2 3 4 * + + Output 9
def delete(i, j, l): t = [] m = 0 while m < len(l): if m != i and m != j: t.append(l[m]) m += 1 return t n = list(map(int, input().split())) o = list(input().split()) n = [n] def brute(l, u): i = 0 second = list() while i < len(l): j = 0 while j < len(l[0]): k = 0 while k < len(l[0]): x = list() if k != j: x.append(eval(str(l[i][j]) + o[u] + str(l[i][k]))) second.append(x + delete(k, j, l[i].copy())) k += 1 j += 1 i += 1 return second second = brute(n, 0) third = brute(second, 1) fourth = brute(third, 2) m = 2**100 for i in fourth: m = min(m, i[0]) print(m)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
def main(): grumpy = [ "don't even", "are you serious?", "worse", "terrible", "no way", "go die in a hole", ] print(9) res = input() if res in grumpy: print("grumpy") return else: print("normal") return main()
FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys flag = 0 q = set() for i in range(10): print(i) sys.stdout.flush() s = input() if s != "no": if ( s in "great!" or s in "don't think so" or s in "not bad" or s in "cool" or s in "don't touch me!" ): print("normal") else: print("grumpy") break
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys good = {"great", "not bad", "cool", "don't touch me", "don't think so"} for i in range(10): print(i) sys.stdout.flush() s = input() if s == "no way" or s != "no" and s not in good: print("grumpy") exit(0) elif s in good: print("normal") exit(0)
IMPORT ASSIGN VAR STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
for i in range(10): print(i) reaction = input() if reaction != "no": for part in ("no way", "die", "worse", "terrible", "even", "are"): if part in reaction: print("grumpy") break else: print("normal") break
FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING FOR VAR STRING STRING STRING STRING STRING STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
normal = dict() normal["no"] = 5 normal["don't think so"] = 1 normal["don't touch me"] = 1 normal["great"] = 1 normal["not bad"] = 1 normal["cool"] = 1 print(9, flush=True) res = input().strip() if res not in normal: print("grumpy", flush=True) else: print("normal", flush=True)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
i = 0 while 1: print(i) i += 1 x = input()[-2:] if x != "no": print(["normal", "grumpy"][x in "lenuseay"]) break
ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR LIST STRING STRING VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys i, ans = 0, "no" while ans == "no": print(i) i += 1 sys.stdout.flush() ans = input() if ans[:3] in ("gre", "don", "not", "coo") and not ans.endswith("even"): print("normal") else: print("grumpy")
IMPORT ASSIGN VAR VAR NUMBER STRING WHILE VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING STRING STRING STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys normal = False nos = 0 for i in range(10): print(i) sys.stdout.flush() s = input() if s in ["cool", "great", "don't think so", "not bad", "don't touch me"]: normal = True break elif s != "no": break else: nos += 1 if nos > 3: normal = True break print("normal" if normal else "grumpy")
IMPORT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
flag = False for i in range(10): print(i) j = input().strip() if ( j == "cool" or j == "not bad" or j == "great" or j == "don't think so" or j == "don't touch me" ): flag = True break if j != "no": break if flag: print("normal") else: print("grumpy")
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
no = 0 for i in range(10): print(i) inp = input() if inp == "no": no += 1 if no == 4: exit(print("normal")) continue if ( inp == "cool" or inp == "don't think so" or inp == "not bad" or inp == "don't touch me" or inp == "great" ): exit(print("normal")) exit(print("grumpy"))
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
for i in range(10): print(i) t = input() if t in [ "no way", "go die in a hole", "are you serious", "worse", "terrible", "don't even", ]: print("grumpy") exit(0) elif t != "no": print("normal") exit(0)
FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR LIST STRING STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
n = [ "no", "great", "dontthinkso", "donttouchme", "notbad", "cool", "no", "no", "no", "no", ] g = [ "no", "donteven", "areyouserious", "godieinahole", "worse", "terrible", "noway", "noway", "no", "no", ] for i in range(10): print(i, flush=True) v = "".join(c for c in input().lower() if "a" <= c <= "z") if v in n and v in g: n.remove(v) g.remove(v) continue print("grumpy" if v in g else "normal") break
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys for i in range(10): print(i) sys.stdout.flush() a = sys.stdin.readline().strip().lower() if "cool" in a or "great" in a or "not bad" in a or "think" in a: print("normal") sys.exit(0) if ( "die" in a or "serious" in a or "way" in a or "worse" in a or "terrible" in a or "even" in a ): print("grumpy") sys.exit(0)
IMPORT FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
i = 0 print(i) ch = input() if ch == "no": i = i + 1 while ch == "no": print(i) ch = input() i = i + 1 if ( ch == "don't even" or ch == "terrible" or ch == "worse" or ch == "are you serious" or ch == "go die in a hole" or ch == "no way" ): print("grumpy") else: print("normal")
ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
grumpy = [ "are you serious", "don't even", "go die in a hole", "terrible", "worse", "no way", ] grumpyFlag = False for i in range(10): print(i) response = input() if response == "no": continue elif response in grumpy: grumpyFlag = True break else: break if grumpyFlag: print("grumpy") else: print("normal")
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
for i in range(10): print(i) b = input() if ( "don't even" in b or "terrible" in b or "serious" in b or "worse" in b or "go die" in b or "way" in b ): print("grumpy") break elif b != "no": print("normal") break elif i > 2: print("normal") break
FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys from sys import exit a = ["no", "no", "no", "no", "no", "don'", "grea", "don'", "not ", "cool"] b = ["no", "no", "no", "no w", "no w", "go d", "wors", "terr", "don'", "are "] for i in range(9): sys.stdout.write(str(i)) sys.stdout.write("\n") sys.stdout.flush() inp = input() if inp.__len__() > 4: inp = inp[:4] if inp in a: a.remove(inp) else: print("grumpy") exit() if inp in b: b.remove(inp) else: print("normal") exit() sys.stdout.write("normal") sys.stdout.flush() exit() for i in range(10): print(i) a = input() if a.__len__() > 2: if a[-2:] == "en": print("grumpy") exit() print("normal")
IMPORT ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys def check(s): if s == "no": return "dn" elif s in ["great", "don't think so", "don't touch me", "not bad", "cool"]: return "n" else: return "g" print(0) sys.stdout.flush() t = check(input()) for i in range(1, 10): if t == "dn": print(i) sys.stdout.flush() t = check(input()) elif t == "n": print("normal") sys.stdout.flush() sys.exit(0) else: print("grumpy") sys.stdout.flush() sys.exit(0)
IMPORT FUNC_DEF IF VAR STRING RETURN STRING IF VAR LIST STRING STRING STRING STRING STRING RETURN STRING RETURN STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
def main(): for i in range(10): print(i) result = str(input()) if result == "no": continue if ( result == "cool" or result == "great" or result == "don't think so" or result == "don't touch me" or result == "not bad" ): print("normal") break else: print("grumpy") break main()
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
grum = [ "don't even", "are you serious", "go die in a hole", "worse", "terrible", "no way", ] for i in range(10): print(i) s = str(input()).lower() if s != "no": print("grumpy" if s in grum else "normal") break
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
a = ["great", "don't think so", "not bad", "don't touch me", "cool"] for i in range(10): print(i) ans = input() if ans != "no": if ans in a: print("normal") exit() else: print("grumpy") exit()
ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
for i in range(0, 10): print(i, flush=True) s = input() if s != "no": print(["normal", "grumpy"][s[-2:] in "lenuseay"], flush=True) break
FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR LIST STRING STRING VAR NUMBER STRING NUMBER